20
20
*/
21
21
22
22
#include "string.h"
23
- #include "fsl_device_registers.h"
24
- #include "fsl_usart_cmsis.h"
25
23
#include "uart.h"
26
24
#include "util.h"
27
25
#include "cortex_m.h"
28
26
#include "circ_buf.h"
29
27
#include "settings.h" // for config_get_overflow_detect
30
-
31
- #define USART_INSTANCE (Driver_USART0)
32
- #define USART_IRQ (FLEXCOMM0_IRQn)
33
-
34
- extern uint32_t SystemCoreClock ;
28
+ #include "Driver_USART.h"
29
+ #include "IO_Config.h"
35
30
36
31
static void clear_buffers (void );
37
32
@@ -64,18 +59,18 @@ int32_t uart_initialize(void)
64
59
{
65
60
clear_buffers ();
66
61
cb_buf .tx_size = 0 ;
67
- USART_INSTANCE .Initialize (uart_handler );
68
- USART_INSTANCE .PowerControl (ARM_POWER_FULL );
62
+ CMSIS_UART_INSTANCE .Initialize (uart_handler );
63
+ CMSIS_UART_INSTANCE .PowerControl (ARM_POWER_FULL );
69
64
70
65
return 1 ;
71
66
}
72
67
73
68
int32_t uart_uninitialize (void )
74
69
{
75
- USART_INSTANCE .Control (ARM_USART_CONTROL_RX , 0 );
76
- USART_INSTANCE .Control (ARM_USART_ABORT_RECEIVE , 0U );
77
- USART_INSTANCE .PowerControl (ARM_POWER_OFF );
78
- USART_INSTANCE .Uninitialize ();
70
+ CMSIS_UART_INSTANCE .Control (ARM_USART_CONTROL_RX , 0 );
71
+ CMSIS_UART_INSTANCE .Control (ARM_USART_ABORT_RECEIVE , 0U );
72
+ CMSIS_UART_INSTANCE .PowerControl (ARM_POWER_OFF );
73
+ CMSIS_UART_INSTANCE .Uninitialize ();
79
74
clear_buffers ();
80
75
cb_buf .tx_size = 0 ;
81
76
@@ -85,14 +80,14 @@ int32_t uart_uninitialize(void)
85
80
int32_t uart_reset (void )
86
81
{
87
82
// disable interrupt
88
- NVIC_DisableIRQ (USART_IRQ );
83
+ NVIC_DisableIRQ (CMSIS_UART_IRQ );
89
84
clear_buffers ();
90
85
if (cb_buf .tx_size != 0 ) {
91
- USART_INSTANCE .Control (ARM_USART_ABORT_SEND , 0U );
86
+ CMSIS_UART_INSTANCE .Control (ARM_USART_ABORT_SEND , 0U );
92
87
cb_buf .tx_size = 0 ;
93
88
}
94
89
// enable interrupt
95
- NVIC_EnableIRQ (USART_IRQ );
90
+ NVIC_EnableIRQ (CMSIS_UART_IRQ );
96
91
97
92
return 1 ;
98
93
}
@@ -161,27 +156,27 @@ int32_t uart_set_configuration(UART_Configuration *config)
161
156
break ;
162
157
}
163
158
164
- NVIC_DisableIRQ (USART_IRQ );
159
+ NVIC_DisableIRQ (CMSIS_UART_IRQ );
165
160
clear_buffers ();
166
161
if (cb_buf .tx_size != 0 ) {
167
- USART_INSTANCE .Control (ARM_USART_ABORT_SEND , 0U );
162
+ CMSIS_UART_INSTANCE .Control (ARM_USART_ABORT_SEND , 0U );
168
163
cb_buf .tx_size = 0 ;
169
164
}
170
165
171
166
// If there was no Receive() call in progress aborting it is harmless.
172
- USART_INSTANCE .Control (ARM_USART_CONTROL_RX , 0U );
173
- USART_INSTANCE .Control (ARM_USART_ABORT_RECEIVE , 0U );
167
+ CMSIS_UART_INSTANCE .Control (ARM_USART_CONTROL_RX , 0U );
168
+ CMSIS_UART_INSTANCE .Control (ARM_USART_ABORT_RECEIVE , 0U );
174
169
175
- uint32_t r = USART_INSTANCE .Control (control , config -> Baudrate );
170
+ uint32_t r = CMSIS_UART_INSTANCE .Control (control , config -> Baudrate );
176
171
if (r != ARM_DRIVER_OK ) {
177
172
return 0 ;
178
173
}
179
- USART_INSTANCE .Control (ARM_USART_CONTROL_TX , 1 );
180
- USART_INSTANCE .Control (ARM_USART_CONTROL_RX , 1 );
181
- USART_INSTANCE .Receive (& (cb_buf .rx ), 1 );
174
+ CMSIS_UART_INSTANCE .Control (ARM_USART_CONTROL_TX , 1 );
175
+ CMSIS_UART_INSTANCE .Control (ARM_USART_CONTROL_RX , 1 );
176
+ CMSIS_UART_INSTANCE .Receive (& (cb_buf .rx ), 1 );
182
177
183
- NVIC_ClearPendingIRQ (USART_IRQ );
184
- NVIC_EnableIRQ (USART_IRQ );
178
+ NVIC_ClearPendingIRQ (CMSIS_UART_IRQ );
179
+ NVIC_EnableIRQ (CMSIS_UART_IRQ );
185
180
186
181
return 1 ;
187
182
}
@@ -215,7 +210,7 @@ static void uart_start_tx_transfer() {
215
210
}
216
211
cb_buf .tx_size = tx_size ;
217
212
if (tx_size ) {
218
- USART_INSTANCE .Send (buf , tx_size );
213
+ CMSIS_UART_INSTANCE .Send (buf , tx_size );
219
214
}
220
215
}
221
216
@@ -254,7 +249,7 @@ void uart_handler(uint32_t event) {
254
249
} else {
255
250
// Drop character
256
251
}
257
- USART_INSTANCE .Receive (& (cb_buf .rx ), 1 );
252
+ CMSIS_UART_INSTANCE .Receive (& (cb_buf .rx ), 1 );
258
253
}
259
254
260
255
if (event & ARM_USART_EVENT_SEND_COMPLETE ) {
0 commit comments