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
@@ -65,18 +60,18 @@ int32_t uart_initialize(void)
65
60
{
66
61
clear_buffers ();
67
62
cb_buf .tx_size = 0 ;
68
- USART_INSTANCE .Initialize (uart_handler );
69
- USART_INSTANCE .PowerControl (ARM_POWER_FULL );
63
+ CMSIS_UART_INSTANCE .Initialize (uart_handler );
64
+ CMSIS_UART_INSTANCE .PowerControl (ARM_POWER_FULL );
70
65
71
66
return 1 ;
72
67
}
73
68
74
69
int32_t uart_uninitialize (void )
75
70
{
76
- USART_INSTANCE .Control (ARM_USART_CONTROL_RX , 0 );
77
- USART_INSTANCE .Control (ARM_USART_ABORT_RECEIVE , 0U );
78
- USART_INSTANCE .PowerControl (ARM_POWER_OFF );
79
- USART_INSTANCE .Uninitialize ();
71
+ CMSIS_UART_INSTANCE .Control (ARM_USART_CONTROL_RX , 0 );
72
+ CMSIS_UART_INSTANCE .Control (ARM_USART_ABORT_RECEIVE , 0U );
73
+ CMSIS_UART_INSTANCE .PowerControl (ARM_POWER_OFF );
74
+ CMSIS_UART_INSTANCE .Uninitialize ();
80
75
clear_buffers ();
81
76
cb_buf .tx_size = 0 ;
82
77
@@ -86,10 +81,10 @@ int32_t uart_uninitialize(void)
86
81
int32_t uart_reset (void )
87
82
{
88
83
// disable interrupt
89
- NVIC_DisableIRQ (USART_IRQ );
84
+ NVIC_DisableIRQ (CMSIS_UART_IRQ );
90
85
clear_buffers ();
91
86
// enable interrupt
92
- NVIC_EnableIRQ (USART_IRQ );
87
+ NVIC_EnableIRQ (CMSIS_UART_IRQ );
93
88
94
89
return 1 ;
95
90
}
@@ -158,23 +153,23 @@ int32_t uart_set_configuration(UART_Configuration *config)
158
153
break ;
159
154
}
160
155
161
- NVIC_DisableIRQ (USART_IRQ );
156
+ NVIC_DisableIRQ (CMSIS_UART_IRQ );
162
157
clear_buffers ();
163
158
164
159
// If there was no Receive() call in progress aborting it is harmless.
165
- USART_INSTANCE .Control (ARM_USART_CONTROL_RX , 0U );
166
- USART_INSTANCE .Control (ARM_USART_ABORT_RECEIVE , 0U );
160
+ CMSIS_UART_INSTANCE .Control (ARM_USART_CONTROL_RX , 0U );
161
+ CMSIS_UART_INSTANCE .Control (ARM_USART_ABORT_RECEIVE , 0U );
167
162
168
- uint32_t r = USART_INSTANCE .Control (control , config -> Baudrate );
163
+ uint32_t r = CMSIS_UART_INSTANCE .Control (control , config -> Baudrate );
169
164
if (r != ARM_DRIVER_OK ) {
170
165
return 0 ;
171
166
}
172
- USART_INSTANCE .Control (ARM_USART_CONTROL_TX , 1 );
173
- USART_INSTANCE .Control (ARM_USART_CONTROL_RX , 1 );
174
- USART_INSTANCE .Receive (& (cb_buf .rx ), 1 );
167
+ CMSIS_UART_INSTANCE .Control (ARM_USART_CONTROL_TX , 1 );
168
+ CMSIS_UART_INSTANCE .Control (ARM_USART_CONTROL_RX , 1 );
169
+ CMSIS_UART_INSTANCE .Receive (& (cb_buf .rx ), 1 );
175
170
176
- NVIC_ClearPendingIRQ (USART_IRQ );
177
- NVIC_EnableIRQ (USART_IRQ );
171
+ NVIC_ClearPendingIRQ (CMSIS_UART_IRQ );
172
+ NVIC_EnableIRQ (CMSIS_UART_IRQ );
178
173
179
174
return 1 ;
180
175
}
@@ -201,15 +196,15 @@ int32_t uart_write_data(uint8_t *data, uint16_t size)
201
196
202
197
// Disable interrupts to prevent the uart_handler from modifying the
203
198
// circular buffer at the same time.
204
- NVIC_DisableIRQ (USART_IRQ );
199
+ NVIC_DisableIRQ (CMSIS_UART_IRQ );
205
200
uint32_t cnt = circ_buf_write (& write_buffer , data , size );
206
201
if (cb_buf .tx_size == 0 && circ_buf_count_used (& write_buffer ) > 0 ) {
207
202
// There's no pending transfer, so we need to start the process.
208
203
cb_buf .tx = circ_buf_pop (& write_buffer );
209
- USART_INSTANCE .Send (& (cb_buf .tx ), 1 );
204
+ CMSIS_UART_INSTANCE .Send (& (cb_buf .tx ), 1 );
210
205
cb_buf .tx_size = 1 ;
211
206
}
212
- NVIC_EnableIRQ (USART_IRQ );
207
+ NVIC_EnableIRQ (CMSIS_UART_IRQ );
213
208
214
209
return cnt ;
215
210
}
@@ -229,13 +224,13 @@ void uart_handler(uint32_t event) {
229
224
} else {
230
225
// Drop character
231
226
}
232
- USART_INSTANCE .Receive (& (cb_buf .rx ), 1 );
227
+ CMSIS_UART_INSTANCE .Receive (& (cb_buf .rx ), 1 );
233
228
}
234
229
235
230
if (event & ARM_USART_EVENT_SEND_COMPLETE ) {
236
231
if (circ_buf_count_used (& write_buffer ) > 0 ) {
237
232
cb_buf .tx = circ_buf_pop (& write_buffer );
238
- USART_INSTANCE .Send (& (cb_buf .tx ), 1 );
233
+ CMSIS_UART_INSTANCE .Send (& (cb_buf .tx ), 1 );
239
234
} else {
240
235
// Signals that next call to uart_write_data() should start a
241
236
// transfer.
0 commit comments