1 /*
2 * Copyright 2018 NXP
3 * All rights reserved.
4 *
5 *
6 * SPDX-License-Identifier: BSD-3-Clause
7 */
8
9 #include "fsl_common.h"
10 #include "fsl_uart.h"
11
12 #include "fsl_adapter_uart.h"
13
14 /*******************************************************************************
15 * Definitions
16 ******************************************************************************/
17 #ifndef NDEBUG
18 #if (defined(DEBUG_CONSOLE_ASSERT_DISABLE) && (DEBUG_CONSOLE_ASSERT_DISABLE > 0U))
19 #undef assert
20 #define assert(n)
21 #endif
22 #endif
23
24 #if (defined(UART_ADAPTER_NON_BLOCKING_MODE) && (UART_ADAPTER_NON_BLOCKING_MODE > 0U))
25 /*! @brief uart RX state structure. */
26 typedef struct _hal_uart_receive_state
27 {
28 volatile uint8_t *buffer;
29 volatile uint32_t bufferLength;
30 volatile uint32_t bufferSofar;
31 } hal_uart_receive_state_t;
32
33 /*! @brief uart TX state structure. */
34 typedef struct _hal_uart_send_state
35 {
36 volatile uint8_t *buffer;
37 volatile uint32_t bufferLength;
38 volatile uint32_t bufferSofar;
39 } hal_uart_send_state_t;
40 #endif
41 /*! @brief uart state structure. */
42 typedef struct _hal_uart_state
43 {
44 #if (defined(UART_ADAPTER_NON_BLOCKING_MODE) && (UART_ADAPTER_NON_BLOCKING_MODE > 0U))
45 hal_uart_transfer_callback_t callback;
46 void *callbackParam;
47 #if (defined(HAL_UART_TRANSFER_MODE) && (HAL_UART_TRANSFER_MODE > 0U))
48 uart_handle_t hardwareHandle;
49 #endif
50 hal_uart_receive_state_t rx;
51 hal_uart_send_state_t tx;
52 #endif
53 uint8_t instance;
54 } hal_uart_state_t;
55
56 /*******************************************************************************
57 * Prototypes
58 ******************************************************************************/
59
60 /*******************************************************************************
61 * Variables
62 ******************************************************************************/
63 static UART_Type *const s_UartAdapterBase[] = UART_BASE_PTRS;
64
65 #if (defined(UART_ADAPTER_NON_BLOCKING_MODE) && (UART_ADAPTER_NON_BLOCKING_MODE > 0U))
66
67 #if !(defined(HAL_UART_TRANSFER_MODE) && (HAL_UART_TRANSFER_MODE > 0U))
68 /* Array of UART IRQ number. */
69 static const IRQn_Type s_UartIRQ[] = UART_IRQS;
70
71 static hal_uart_state_t *s_UartState[sizeof(s_UartAdapterBase) / sizeof(UART_Type *)];
72 #endif
73
74 #endif
75
76 /*******************************************************************************
77 * Code
78 ******************************************************************************/
79
80 #if (defined(HAL_UART_TRANSFER_MODE) && (HAL_UART_TRANSFER_MODE > 0U))
HAL_UartGetStatus(status_t status)81 static hal_uart_status_t HAL_UartGetStatus(status_t status)
82 {
83 hal_uart_status_t uartStatus = kStatus_HAL_UartError;
84 switch (status)
85 {
86 case kStatus_Success:
87 uartStatus = kStatus_HAL_UartSuccess;
88 break;
89 case kStatus_UART_TxBusy:
90 uartStatus = kStatus_HAL_UartTxBusy;
91 break;
92 case kStatus_UART_RxBusy:
93 uartStatus = kStatus_HAL_UartRxBusy;
94 break;
95 case kStatus_UART_TxIdle:
96 uartStatus = kStatus_HAL_UartTxIdle;
97 break;
98 case kStatus_UART_RxIdle:
99 uartStatus = kStatus_HAL_UartRxIdle;
100 break;
101 case kStatus_UART_BaudrateNotSupport:
102 uartStatus = kStatus_HAL_UartBaudrateNotSupport;
103 break;
104 case kStatus_UART_NoiseError:
105 case kStatus_UART_FramingError:
106 case kStatus_UART_ParityError:
107 uartStatus = kStatus_HAL_UartProtocolError;
108 break;
109 default:
110 /* This comments for MISRA C-2012 Rule 16.4 */
111 break;
112 }
113 return uartStatus;
114 }
115 #else
HAL_UartGetStatus(status_t status)116 static hal_uart_status_t HAL_UartGetStatus(status_t status)
117 {
118 if (kStatus_Success == status)
119 {
120 return kStatus_HAL_UartSuccess;
121 }
122 else
123 {
124 return kStatus_HAL_UartError;
125 }
126 }
127 #endif
128
129 #if (defined(UART_ADAPTER_NON_BLOCKING_MODE) && (UART_ADAPTER_NON_BLOCKING_MODE > 0U))
130
131 #if (defined(HAL_UART_TRANSFER_MODE) && (HAL_UART_TRANSFER_MODE > 0U))
HAL_UartCallback(UART_Type * base,uart_handle_t * handle,status_t status,void * callbackParam)132 static void HAL_UartCallback(UART_Type *base, uart_handle_t *handle, status_t status, void *callbackParam)
133 {
134 hal_uart_state_t *uartHandle;
135 hal_uart_status_t uartStatus = HAL_UartGetStatus(status);
136 assert(callbackParam);
137
138 uartHandle = (hal_uart_state_t *)callbackParam;
139
140 if (kStatus_HAL_UartProtocolError == uartStatus)
141 {
142 if (uartHandle->hardwareHandle.rxDataSize)
143 {
144 uartStatus = kStatus_HAL_UartError;
145 }
146 }
147
148 if (uartHandle->callback)
149 {
150 uartHandle->callback(uartHandle, uartStatus, uartHandle->callbackParam);
151 }
152 }
153
154 #else
155
HAL_UartInterruptHandle(uint8_t instance)156 static void HAL_UartInterruptHandle(uint8_t instance)
157 {
158 hal_uart_state_t *uartHandle = s_UartState[instance];
159
160 if (NULL == uartHandle)
161 {
162 return;
163 }
164
165 /* Receive data register full */
166 if (UART_GetStatusFlag(s_UartAdapterBase[instance], kUART_RxReadyFlag))
167 {
168 UART_ClearStatusFlag(s_UartAdapterBase[instance], kUART_RxReadyFlag);
169
170 if (UART_GetEnabledInterrupts(s_UartAdapterBase[instance]) & kUART_RxReadyEnable)
171 {
172 if (uartHandle->rx.buffer)
173 {
174 uartHandle->rx.buffer[uartHandle->rx.bufferSofar++] = UART_ReadByte(s_UartAdapterBase[instance]);
175 if (uartHandle->rx.bufferSofar >= uartHandle->rx.bufferLength)
176 {
177 /* Disable RX interrupt/overrun interrupt/framing error interrupt */
178 UART_DisableInterrupts(s_UartAdapterBase[instance],
179 kUART_RxReadyEnable | kUART_AgingTimerEnable | kUART_RxOverrunEnable |
180 kUART_ParityErrorEnable | kUART_FrameErrorEnable);
181 uartHandle->rx.buffer = NULL;
182 if (uartHandle->callback)
183 {
184 uartHandle->callback(uartHandle, kStatus_HAL_UartRxIdle, uartHandle->callbackParam);
185 }
186 }
187 }
188 }
189 }
190
191 /* Send data register empty and the interrupt is enabled. */
192 if (UART_GetStatusFlag(s_UartAdapterBase[instance], kUART_TxEmptyFlag))
193 {
194 UART_ClearStatusFlag(s_UartAdapterBase[instance], kUART_TxEmptyFlag);
195
196 if (UART_GetEnabledInterrupts(s_UartAdapterBase[instance]) & kUART_TxReadyEnable)
197 {
198 if (uartHandle->tx.buffer)
199 {
200 UART_WriteByte(s_UartAdapterBase[instance], uartHandle->tx.buffer[uartHandle->tx.bufferSofar++]);
201 if (uartHandle->tx.bufferSofar >= uartHandle->tx.bufferLength)
202 {
203 UART_DisableInterrupts(s_UartAdapterBase[uartHandle->instance], kUART_TxReadyEnable);
204 uartHandle->tx.buffer = NULL;
205 if (uartHandle->callback)
206 {
207 uartHandle->callback(uartHandle, kStatus_HAL_UartTxIdle, uartHandle->callbackParam);
208 }
209 }
210 }
211 }
212 }
213 }
214 #endif
215
216 #endif
217
HAL_UartInit(hal_uart_handle_t handle,const hal_uart_config_t * uart_config)218 hal_uart_status_t HAL_UartInit(hal_uart_handle_t handle, const hal_uart_config_t *uart_config)
219 {
220 hal_uart_state_t *uartHandle;
221 uart_config_t uartConfig;
222 status_t status;
223 assert(handle);
224 assert(uart_config);
225 assert(uart_config->instance < (sizeof(s_UartAdapterBase) / sizeof(UART_Type *)));
226 assert(s_UartAdapterBase[uart_config->instance]);
227
228 assert(HAL_UART_HANDLE_SIZE >= sizeof(hal_uart_state_t));
229
230 UART_GetDefaultConfig(&uartConfig);
231 uartConfig.baudRate_Bps = uart_config->baudRate_Bps;
232
233 if (kHAL_UartParityEven == uart_config->parityMode)
234 {
235 uartConfig.parityMode = kUART_ParityEven;
236 }
237 else if (kHAL_UartParityOdd == uart_config->parityMode)
238 {
239 uartConfig.parityMode = kUART_ParityOdd;
240 }
241 else
242 {
243 uartConfig.parityMode = kUART_ParityDisabled;
244 }
245
246 if (kHAL_UartTwoStopBit == uart_config->stopBitCount)
247 {
248 uartConfig.stopBitCount = kUART_TwoStopBit;
249 }
250 else
251 {
252 uartConfig.stopBitCount = kUART_OneStopBit;
253 }
254 uartConfig.enableRx = (bool)uart_config->enableRx;
255 uartConfig.enableTx = (bool)uart_config->enableTx;
256
257 status = UART_Init(s_UartAdapterBase[uart_config->instance], &uartConfig, uart_config->srcClock_Hz);
258
259 if (kStatus_Success != status)
260 {
261 return HAL_UartGetStatus(status);
262 }
263
264 uartHandle = (hal_uart_state_t *)handle;
265 uartHandle->instance = uart_config->instance;
266
267 #if (defined(UART_ADAPTER_NON_BLOCKING_MODE) && (UART_ADAPTER_NON_BLOCKING_MODE > 0U))
268
269 #if (defined(HAL_UART_TRANSFER_MODE) && (HAL_UART_TRANSFER_MODE > 0U))
270 UART_TransferCreateHandle(s_UartAdapterBase[uart_config->instance], &uartHandle->hardwareHandle,
271 (uart_transfer_callback_t)HAL_UartCallback, handle);
272 #else
273 s_UartState[uartHandle->instance] = uartHandle;
274 /* Enable interrupt in NVIC. */
275 NVIC_SetPriority((IRQn_Type)s_UartIRQ[uart_config->instance], HAL_UART_ISR_PRIORITY);
276 EnableIRQ(s_UartIRQ[uart_config->instance]);
277 #endif
278
279 #endif
280
281 return kStatus_HAL_UartSuccess;
282 }
283
HAL_UartDeinit(hal_uart_handle_t handle)284 hal_uart_status_t HAL_UartDeinit(hal_uart_handle_t handle)
285 {
286 hal_uart_state_t *uartHandle;
287
288 assert(handle);
289
290 uartHandle = (hal_uart_state_t *)handle;
291
292 UART_Deinit(s_UartAdapterBase[uartHandle->instance]);
293
294 #if (defined(UART_ADAPTER_NON_BLOCKING_MODE) && (UART_ADAPTER_NON_BLOCKING_MODE > 0U))
295
296 #if !(defined(HAL_UART_TRANSFER_MODE) && (HAL_UART_TRANSFER_MODE > 0U))
297 s_UartState[uartHandle->instance] = NULL;
298 #endif
299
300 #endif
301
302 return kStatus_HAL_UartSuccess;
303 }
304
HAL_UartReceiveBlocking(hal_uart_handle_t handle,uint8_t * data,size_t length)305 hal_uart_status_t HAL_UartReceiveBlocking(hal_uart_handle_t handle, uint8_t *data, size_t length)
306 {
307 hal_uart_state_t *uartHandle;
308 status_t status;
309 assert(handle);
310 assert(data);
311 assert(length);
312
313 uartHandle = (hal_uart_state_t *)handle;
314
315 #if (defined(UART_ADAPTER_NON_BLOCKING_MODE) && (UART_ADAPTER_NON_BLOCKING_MODE > 0U))
316 if (uartHandle->rx.buffer)
317 {
318 return kStatus_HAL_UartRxBusy;
319 }
320 #endif
321
322 status = UART_ReadBlocking(s_UartAdapterBase[uartHandle->instance], data, length);
323
324 return HAL_UartGetStatus(status);
325 }
326
HAL_UartSendBlocking(hal_uart_handle_t handle,const uint8_t * data,size_t length)327 hal_uart_status_t HAL_UartSendBlocking(hal_uart_handle_t handle, const uint8_t *data, size_t length)
328 {
329 hal_uart_state_t *uartHandle;
330 assert(handle);
331 assert(data);
332 assert(length);
333
334 uartHandle = (hal_uart_state_t *)handle;
335
336 #if (defined(UART_ADAPTER_NON_BLOCKING_MODE) && (UART_ADAPTER_NON_BLOCKING_MODE > 0U))
337 if (uartHandle->tx.buffer)
338 {
339 return kStatus_HAL_UartTxBusy;
340 }
341 #endif
342
343 (void)UART_WriteBlocking(s_UartAdapterBase[uartHandle->instance], data, length);
344
345 return kStatus_HAL_UartSuccess;
346 }
347
HAL_UartEnterLowpower(hal_uart_handle_t handle)348 hal_uart_status_t HAL_UartEnterLowpower(hal_uart_handle_t handle)
349 {
350 assert(handle);
351
352 return kStatus_HAL_UartSuccess;
353 }
354
HAL_UartExitLowpower(hal_uart_handle_t handle)355 hal_uart_status_t HAL_UartExitLowpower(hal_uart_handle_t handle)
356 {
357 assert(handle);
358
359 return kStatus_HAL_UartSuccess;
360 }
361
362 #if (defined(UART_ADAPTER_NON_BLOCKING_MODE) && (UART_ADAPTER_NON_BLOCKING_MODE > 0U))
363
364 #if (defined(HAL_UART_TRANSFER_MODE) && (HAL_UART_TRANSFER_MODE > 0U))
365
HAL_UartTransferInstallCallback(hal_uart_handle_t handle,hal_uart_transfer_callback_t callback,void * callbackParam)366 hal_uart_status_t HAL_UartTransferInstallCallback(hal_uart_handle_t handle,
367 hal_uart_transfer_callback_t callback,
368 void *callbackParam)
369 {
370 hal_uart_state_t *uartHandle;
371
372 assert(handle);
373 assert(HAL_UART_TRANSFER_MODE);
374
375 uartHandle = (hal_uart_state_t *)handle;
376
377 uartHandle->callbackParam = callbackParam;
378 uartHandle->callback = callback;
379
380 return kStatus_HAL_UartSuccess;
381 }
382
HAL_UartTransferReceiveNonBlocking(hal_uart_handle_t handle,hal_uart_transfer_t * transfer)383 hal_uart_status_t HAL_UartTransferReceiveNonBlocking(hal_uart_handle_t handle, hal_uart_transfer_t *transfer)
384 {
385 hal_uart_state_t *uartHandle;
386 status_t status;
387 assert(handle);
388 assert(transfer);
389 assert(HAL_UART_TRANSFER_MODE);
390
391 uartHandle = (hal_uart_state_t *)handle;
392
393 status = UART_TransferReceiveNonBlocking(s_UartAdapterBase[uartHandle->instance], &uartHandle->hardwareHandle,
394 (uart_transfer_t *)transfer, NULL);
395
396 return HAL_UartGetStatus(status);
397 }
398
HAL_UartTransferSendNonBlocking(hal_uart_handle_t handle,hal_uart_transfer_t * transfer)399 hal_uart_status_t HAL_UartTransferSendNonBlocking(hal_uart_handle_t handle, hal_uart_transfer_t *transfer)
400 {
401 hal_uart_state_t *uartHandle;
402 status_t status;
403 assert(handle);
404 assert(transfer);
405 assert(HAL_UART_TRANSFER_MODE);
406
407 uartHandle = (hal_uart_state_t *)handle;
408
409 status = UART_TransferSendNonBlocking(s_UartAdapterBase[uartHandle->instance], &uartHandle->hardwareHandle,
410 (uart_transfer_t *)transfer);
411
412 return HAL_UartGetStatus(status);
413 }
414
HAL_UartTransferGetReceiveCount(hal_uart_handle_t handle,uint32_t * count)415 hal_uart_status_t HAL_UartTransferGetReceiveCount(hal_uart_handle_t handle, uint32_t *count)
416 {
417 hal_uart_state_t *uartHandle;
418 status_t status;
419 assert(handle);
420 assert(count);
421 assert(HAL_UART_TRANSFER_MODE);
422
423 uartHandle = (hal_uart_state_t *)handle;
424
425 status = UART_TransferGetReceiveCount(s_UartAdapterBase[uartHandle->instance], &uartHandle->hardwareHandle, count);
426
427 return HAL_UartGetStatus(status);
428 }
429
HAL_UartTransferGetSendCount(hal_uart_handle_t handle,uint32_t * count)430 hal_uart_status_t HAL_UartTransferGetSendCount(hal_uart_handle_t handle, uint32_t *count)
431 {
432 hal_uart_state_t *uartHandle;
433 status_t status;
434 assert(handle);
435 assert(count);
436 assert(HAL_UART_TRANSFER_MODE);
437
438 uartHandle = (hal_uart_state_t *)handle;
439
440 status = UART_TransferGetSendCount(s_UartAdapterBase[uartHandle->instance], &uartHandle->hardwareHandle, count);
441
442 return HAL_UartGetStatus(status);
443 }
444
HAL_UartTransferAbortReceive(hal_uart_handle_t handle)445 hal_uart_status_t HAL_UartTransferAbortReceive(hal_uart_handle_t handle)
446 {
447 hal_uart_state_t *uartHandle;
448 assert(handle);
449 assert(HAL_UART_TRANSFER_MODE);
450
451 uartHandle = (hal_uart_state_t *)handle;
452
453 UART_TransferAbortReceive(s_UartAdapterBase[uartHandle->instance], &uartHandle->hardwareHandle);
454
455 return kStatus_HAL_UartSuccess;
456 }
457
HAL_UartTransferAbortSend(hal_uart_handle_t handle)458 hal_uart_status_t HAL_UartTransferAbortSend(hal_uart_handle_t handle)
459 {
460 hal_uart_state_t *uartHandle;
461 assert(handle);
462 assert(HAL_UART_TRANSFER_MODE);
463
464 uartHandle = (hal_uart_state_t *)handle;
465
466 UART_TransferAbortSend(s_UartAdapterBase[uartHandle->instance], &uartHandle->hardwareHandle);
467
468 return kStatus_HAL_UartSuccess;
469 }
470
471 #else
472
473 /* None transactional API with non-blocking mode. */
HAL_UartInstallCallback(hal_uart_handle_t handle,hal_uart_transfer_callback_t callback,void * callbackParam)474 hal_uart_status_t HAL_UartInstallCallback(hal_uart_handle_t handle,
475 hal_uart_transfer_callback_t callback,
476 void *callbackParam)
477 {
478 hal_uart_state_t *uartHandle;
479
480 assert(handle);
481 assert(!HAL_UART_TRANSFER_MODE);
482
483 uartHandle = (hal_uart_state_t *)handle;
484
485 uartHandle->callbackParam = callbackParam;
486 uartHandle->callback = callback;
487
488 return kStatus_HAL_UartSuccess;
489 }
490
HAL_UartReceiveNonBlocking(hal_uart_handle_t handle,uint8_t * data,size_t length)491 hal_uart_status_t HAL_UartReceiveNonBlocking(hal_uart_handle_t handle, uint8_t *data, size_t length)
492 {
493 hal_uart_state_t *uartHandle;
494 assert(handle);
495 assert(data);
496 assert(length);
497 assert(!HAL_UART_TRANSFER_MODE);
498
499 uartHandle = (hal_uart_state_t *)handle;
500
501 if (uartHandle->rx.buffer)
502 {
503 return kStatus_HAL_UartRxBusy;
504 }
505
506 uartHandle->rx.bufferLength = length;
507 uartHandle->rx.bufferSofar = 0;
508 uartHandle->rx.buffer = data;
509 /* Enable RX/Rx overrun/framing error interrupt. */
510 UART_EnableInterrupts(s_UartAdapterBase[uartHandle->instance],
511 kUART_RxReadyEnable | kUART_AgingTimerEnable | kUART_RxOverrunEnable);
512 return kStatus_HAL_UartSuccess;
513 }
514
HAL_UartSendNonBlocking(hal_uart_handle_t handle,uint8_t * data,size_t length)515 hal_uart_status_t HAL_UartSendNonBlocking(hal_uart_handle_t handle, uint8_t *data, size_t length)
516 {
517 hal_uart_state_t *uartHandle;
518 assert(handle);
519 assert(data);
520 assert(length);
521 assert(!HAL_UART_TRANSFER_MODE);
522
523 uartHandle = (hal_uart_state_t *)handle;
524
525 if (uartHandle->tx.buffer)
526 {
527 return kStatus_HAL_UartTxBusy;
528 }
529 uartHandle->tx.bufferLength = length;
530 uartHandle->tx.bufferSofar = 0;
531 uartHandle->tx.buffer = (volatile uint8_t *)data;
532 UART_EnableInterrupts(s_UartAdapterBase[uartHandle->instance], kUART_TxReadyEnable);
533 return kStatus_HAL_UartSuccess;
534 }
535
HAL_UartGetReceiveCount(hal_uart_handle_t handle,uint32_t * reCount)536 hal_uart_status_t HAL_UartGetReceiveCount(hal_uart_handle_t handle, uint32_t *reCount)
537 {
538 hal_uart_state_t *uartHandle;
539 assert(handle);
540 assert(reCount);
541 assert(!HAL_UART_TRANSFER_MODE);
542
543 uartHandle = (hal_uart_state_t *)handle;
544
545 if (uartHandle->rx.buffer)
546 {
547 *reCount = uartHandle->rx.bufferSofar;
548 return kStatus_HAL_UartSuccess;
549 }
550 return kStatus_HAL_UartError;
551 }
552
HAL_UartGetSendCount(hal_uart_handle_t handle,uint32_t * seCount)553 hal_uart_status_t HAL_UartGetSendCount(hal_uart_handle_t handle, uint32_t *seCount)
554 {
555 hal_uart_state_t *uartHandle;
556 assert(handle);
557 assert(seCount);
558 assert(!HAL_UART_TRANSFER_MODE);
559
560 uartHandle = (hal_uart_state_t *)handle;
561
562 if (uartHandle->tx.buffer)
563 {
564 *seCount = uartHandle->tx.bufferSofar;
565 return kStatus_HAL_UartSuccess;
566 }
567 return kStatus_HAL_UartError;
568 }
569
HAL_UartAbortReceive(hal_uart_handle_t handle)570 hal_uart_status_t HAL_UartAbortReceive(hal_uart_handle_t handle)
571 {
572 hal_uart_state_t *uartHandle;
573 assert(handle);
574 assert(!HAL_UART_TRANSFER_MODE);
575
576 uartHandle = (hal_uart_state_t *)handle;
577
578 if (uartHandle->rx.buffer)
579 {
580 /* Disable RX interrupt/overrun interrupt/framing error interrupt */
581 UART_DisableInterrupts(s_UartAdapterBase[uartHandle->instance],
582 kUART_RxReadyEnable | kUART_AgingTimerEnable | kUART_RxOverrunEnable |
583 kUART_ParityErrorEnable | kUART_FrameErrorEnable);
584 uartHandle->rx.buffer = NULL;
585 }
586
587 return kStatus_HAL_UartSuccess;
588 }
589
HAL_UartAbortSend(hal_uart_handle_t handle)590 hal_uart_status_t HAL_UartAbortSend(hal_uart_handle_t handle)
591 {
592 hal_uart_state_t *uartHandle;
593 assert(handle);
594 assert(!HAL_UART_TRANSFER_MODE);
595
596 uartHandle = (hal_uart_state_t *)handle;
597
598 if (uartHandle->tx.buffer)
599 {
600 UART_DisableInterrupts(s_UartAdapterBase[uartHandle->instance], kUART_TxReadyEnable);
601 uartHandle->tx.buffer = NULL;
602 }
603
604 return kStatus_HAL_UartSuccess;
605 }
606
607 #endif
608
609 #if (defined(HAL_UART_TRANSFER_MODE) && (HAL_UART_TRANSFER_MODE > 0U))
610
HAL_UartIsrFunction(hal_uart_handle_t handle)611 void HAL_UartIsrFunction(hal_uart_handle_t handle)
612 {
613 hal_uart_state_t *uartHandle;
614 assert(handle);
615 assert(HAL_UART_TRANSFER_MODE);
616
617 uartHandle = (hal_uart_state_t *)handle;
618
619 #if 0
620 DisableIRQ(s_UartIRQ[uartHandle->instance]);
621 #endif
622 UART_TransferHandleIRQ(s_UartAdapterBase[uartHandle->instance], &uartHandle->hardwareHandle);
623 #if 0
624 NVIC_SetPriority((IRQn_Type)s_UartIRQ[uartHandle->instance], HAL_UART_ISR_PRIORITY);
625 EnableIRQ(s_UartIRQ[uartHandle->instance]);
626 #endif
627 }
628
629 #else
630
HAL_UartIsrFunction(hal_uart_handle_t handle)631 void HAL_UartIsrFunction(hal_uart_handle_t handle)
632 {
633 hal_uart_state_t *uartHandle;
634 assert(handle);
635 assert(!HAL_UART_TRANSFER_MODE);
636
637 uartHandle = (hal_uart_state_t *)handle;
638
639 #if 0
640 DisableIRQ(s_UartIRQ[uartHandle->instance]);
641 #endif
642 HAL_UartInterruptHandle(uartHandle->instance);
643 #if 0
644 NVIC_SetPriority((IRQn_Type)s_UartIRQ[uartHandle->instance], HAL_UART_ISR_PRIORITY);
645 EnableIRQ(s_UartIRQ[uartHandle->instance]);
646 #endif
647 }
648
649 #if defined(UART1)
UART1_IRQHandler(void)650 void UART1_IRQHandler(void)
651 {
652 HAL_UartInterruptHandle(1);
653 SDK_ISR_EXIT_BARRIER;
654 }
655 #endif
656
657 #if defined(UART2)
UART2_IRQHandler(void)658 void UART2_IRQHandler(void)
659 {
660 HAL_UartInterruptHandle(2);
661 SDK_ISR_EXIT_BARRIER;
662 }
663 #endif
664
665 #if defined(UART3)
UART3_IRQHandler(void)666 void UART3_IRQHandler(void)
667 {
668 HAL_UartInterruptHandle(3);
669 SDK_ISR_EXIT_BARRIER;
670 }
671 #endif
672
673 #if defined(UART4)
UART4_IRQHandler(void)674 void UART4_IRQHandler(void)
675 {
676 HAL_UartInterruptHandle(4);
677 SDK_ISR_EXIT_BARRIER;
678 }
679 #endif
680
681 #if defined(UART5)
UART5_IRQHandler(void)682 void UART5_IRQHandler(void)
683 {
684 HAL_UartInterruptHandle(5);
685 SDK_ISR_EXIT_BARRIER;
686 }
687 #endif
688
689 #if defined(UART6)
UART6_IRQHandler(void)690 void UART6_IRQHandler(void)
691 {
692 HAL_UartInterruptHandle(6);
693 SDK_ISR_EXIT_BARRIER;
694 }
695 #endif
696
697 #if defined(UART7)
UART7_IRQHandler(void)698 void UART7_IRQHandler(void)
699 {
700 HAL_UartInterruptHandle(7);
701 SDK_ISR_EXIT_BARRIER;
702 }
703 #endif
704
705 #if defined(UART8)
UART8_IRQHandler(void)706 void UART8_IRQHandler(void)
707 {
708 HAL_UartInterruptHandle(8);
709 SDK_ISR_EXIT_BARRIER;
710 }
711 #endif
712
713 #endif
714
715 #endif
716