2020 */
2121
2222#include "string.h"
23- #include "fsl_device_registers.h"
24- #include "fsl_usart_cmsis.h"
2523#include "uart.h"
2624#include "util.h"
2725#include "cortex_m.h"
2826#include "circ_buf.h"
2927#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"
3530
3631static void clear_buffers (void );
3732
@@ -65,18 +60,18 @@ int32_t uart_initialize(void)
6560{
6661 clear_buffers ();
6762 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 );
7065
7166 return 1 ;
7267}
7368
7469int32_t uart_uninitialize (void )
7570{
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 ();
8075 clear_buffers ();
8176 cb_buf .tx_size = 0 ;
8277
@@ -86,10 +81,10 @@ int32_t uart_uninitialize(void)
8681int32_t uart_reset (void )
8782{
8883 // disable interrupt
89- NVIC_DisableIRQ (USART_IRQ );
84+ NVIC_DisableIRQ (CMSIS_UART_IRQ );
9085 clear_buffers ();
9186 // enable interrupt
92- NVIC_EnableIRQ (USART_IRQ );
87+ NVIC_EnableIRQ (CMSIS_UART_IRQ );
9388
9489 return 1 ;
9590}
@@ -158,23 +153,23 @@ int32_t uart_set_configuration(UART_Configuration *config)
158153 break ;
159154 }
160155
161- NVIC_DisableIRQ (USART_IRQ );
156+ NVIC_DisableIRQ (CMSIS_UART_IRQ );
162157 clear_buffers ();
163158
164159 // 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 );
167162
168- uint32_t r = USART_INSTANCE .Control (control , config -> Baudrate );
163+ uint32_t r = CMSIS_UART_INSTANCE .Control (control , config -> Baudrate );
169164 if (r != ARM_DRIVER_OK ) {
170165 return 0 ;
171166 }
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 );
175170
176- NVIC_ClearPendingIRQ (USART_IRQ );
177- NVIC_EnableIRQ (USART_IRQ );
171+ NVIC_ClearPendingIRQ (CMSIS_UART_IRQ );
172+ NVIC_EnableIRQ (CMSIS_UART_IRQ );
178173
179174 return 1 ;
180175}
@@ -201,15 +196,15 @@ int32_t uart_write_data(uint8_t *data, uint16_t size)
201196
202197 // Disable interrupts to prevent the uart_handler from modifying the
203198 // circular buffer at the same time.
204- NVIC_DisableIRQ (USART_IRQ );
199+ NVIC_DisableIRQ (CMSIS_UART_IRQ );
205200 uint32_t cnt = circ_buf_write (& write_buffer , data , size );
206201 if (cb_buf .tx_size == 0 && circ_buf_count_used (& write_buffer ) > 0 ) {
207202 // There's no pending transfer, so we need to start the process.
208203 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 );
210205 cb_buf .tx_size = 1 ;
211206 }
212- NVIC_EnableIRQ (USART_IRQ );
207+ NVIC_EnableIRQ (CMSIS_UART_IRQ );
213208
214209 return cnt ;
215210}
@@ -229,13 +224,13 @@ void uart_handler(uint32_t event) {
229224 } else {
230225 // Drop character
231226 }
232- USART_INSTANCE .Receive (& (cb_buf .rx ), 1 );
227+ CMSIS_UART_INSTANCE .Receive (& (cb_buf .rx ), 1 );
233228 }
234229
235230 if (event & ARM_USART_EVENT_SEND_COMPLETE ) {
236231 if (circ_buf_count_used (& write_buffer ) > 0 ) {
237232 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 );
239234 } else {
240235 // Signals that next call to uart_write_data() should start a
241236 // transfer.
0 commit comments