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,10 +80,10 @@ 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
// enable interrupt
91
- NVIC_EnableIRQ(USART_IRQ );
86
+ NVIC_EnableIRQ(CMSIS_UART_IRQ );
92
87
93
88
return 1;
94
89
}
@@ -157,23 +152,23 @@ int32_t uart_set_configuration(UART_Configuration *config)
157
152
break;
158
153
}
159
154
160
- NVIC_DisableIRQ(USART_IRQ );
155
+ NVIC_DisableIRQ(CMSIS_UART_IRQ );
161
156
clear_buffers();
162
157
163
158
// If there was no Receive() call in progress aborting it is harmless.
164
- USART_INSTANCE .Control(ARM_USART_CONTROL_RX, 0U);
165
- USART_INSTANCE .Control(ARM_USART_ABORT_RECEIVE, 0U);
159
+ CMSIS_UART_INSTANCE .Control(ARM_USART_CONTROL_RX, 0U);
160
+ CMSIS_UART_INSTANCE .Control(ARM_USART_ABORT_RECEIVE, 0U);
166
161
167
- uint32_t r = USART_INSTANCE .Control(control, config->Baudrate);
162
+ uint32_t r = CMSIS_UART_INSTANCE .Control(control, config->Baudrate);
168
163
if (r != ARM_DRIVER_OK) {
169
164
return 0;
170
165
}
171
- USART_INSTANCE .Control(ARM_USART_CONTROL_TX, 1);
172
- USART_INSTANCE .Control(ARM_USART_CONTROL_RX, 1);
173
- USART_INSTANCE .Receive(&(cb_buf.rx), 1);
166
+ CMSIS_UART_INSTANCE .Control(ARM_USART_CONTROL_TX, 1);
167
+ CMSIS_UART_INSTANCE .Control(ARM_USART_CONTROL_RX, 1);
168
+ CMSIS_UART_INSTANCE .Receive(&(cb_buf.rx), 1);
174
169
175
- NVIC_ClearPendingIRQ(USART_IRQ );
176
- NVIC_EnableIRQ(USART_IRQ );
170
+ NVIC_ClearPendingIRQ(CMSIS_UART_IRQ );
171
+ NVIC_EnableIRQ(CMSIS_UART_IRQ );
177
172
178
173
return 1;
179
174
}
@@ -203,7 +198,7 @@ static void uart_start_tx_transfer() {
203
198
}
204
199
cb_buf.tx_size = tx_size;
205
200
if (tx_size) {
206
- USART_INSTANCE .Send(buf, tx_size);
201
+ CMSIS_UART_INSTANCE .Send(buf, tx_size);
207
202
}
208
203
}
209
204
@@ -242,7 +237,7 @@ void uart_handler(uint32_t event) {
242
237
} else {
243
238
// Drop character
244
239
}
245
- USART_INSTANCE .Receive(&(cb_buf.rx), 1);
240
+ CMSIS_UART_INSTANCE .Receive(&(cb_buf.rx), 1);
246
241
}
247
242
248
243
if (event & ARM_USART_EVENT_SEND_COMPLETE) {
0 commit comments