1 /*
2  * Copyright (c) 2015-2016, Freescale Semiconductor, Inc.
3  * Copyright 2016-2017 NXP
4  *
5  * Redistribution and use in source and binary forms, with or without modification,
6  * are permitted provided that the following conditions are met:
7  *
8  * o Redistributions of source code must retain the above copyright notice, this list
9  *   of conditions and the following disclaimer.
10  *
11  * o Redistributions in binary form must reproduce the above copyright notice, this
12  *   list of conditions and the following disclaimer in the documentation and/or
13  *   other materials provided with the distribution.
14  *
15  * o Neither the name of the copyright holder nor the names of its
16  *   contributors may be used to endorse or promote products derived from this
17  *   software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 #include "fsl_uart.h"
32 
33 /*******************************************************************************
34  * Definitions
35  ******************************************************************************/
36 
37 /* UART transfer state. */
38 enum _uart_tansfer_states
39 {
40     kUART_TxIdle,         /* TX idle. */
41     kUART_TxBusy,         /* TX busy. */
42     kUART_RxIdle,         /* RX idle. */
43     kUART_RxBusy,         /* RX busy. */
44     kUART_RxFramingError, /* Rx framing error */
45     kUART_RxParityError   /* Rx parity error */
46 };
47 
48 /* Typedef for interrupt handler. */
49 typedef void (*uart_isr_t)(UART_Type *base, uart_handle_t *handle);
50 
51 /*******************************************************************************
52  * Prototypes
53  ******************************************************************************/
54 
55 /*!
56  * @brief Get the UART instance from peripheral base address.
57  *
58  * @param base UART peripheral base address.
59  * @return UART instance.
60  */
61 uint32_t UART_GetInstance(UART_Type *base);
62 
63 /*!
64  * @brief Get the length of received data in RX ring buffer.
65  *
66  * @param handle UART handle pointer.
67  * @return Length of received data in RX ring buffer.
68  */
69 static size_t UART_TransferGetRxRingBufferLength(uart_handle_t *handle);
70 
71 /*!
72  * @brief Check whether the RX ring buffer is full.
73  *
74  * @param handle UART handle pointer.
75  * @retval true  RX ring buffer is full.
76  * @retval false RX ring buffer is not full.
77  */
78 static bool UART_TransferIsRxRingBufferFull(uart_handle_t *handle);
79 
80 /*!
81  * @brief Read RX register using non-blocking method.
82  *
83  * This function reads data from the TX register directly, upper layer must make
84  * sure the RX register is full or TX FIFO has data before calling this function.
85  *
86  * @param base UART peripheral base address.
87  * @param data Start addresss of the buffer to store the received data.
88  * @param length Size of the buffer.
89  */
90 static void UART_ReadNonBlocking(UART_Type *base, uint8_t *data, size_t length);
91 
92 /*!
93  * @brief Write to TX register using non-blocking method.
94  *
95  * This function writes data to the TX register directly, upper layer must make
96  * sure the TX register is empty or TX FIFO has empty room before calling this function.
97  *
98  * @note This function does not check whether all the data has been sent out to bus,
99  * so before disable TX, check kUART_TransmissionCompleteFlag to ensure the TX is
100  * finished.
101  *
102  * @param base UART peripheral base address.
103  * @param data Start addresss of the data to write.
104  * @param length Size of the buffer to be sent.
105  */
106 static void UART_WriteNonBlocking(UART_Type *base, const uint8_t *data, size_t length);
107 
108 /*******************************************************************************
109  * Variables
110  ******************************************************************************/
111 /* Array of UART handle. */
112 #if (defined(UART5))
113 #define UART_HANDLE_ARRAY_SIZE 6
114 #else /* UART5 */
115 #if (defined(UART4))
116 #define UART_HANDLE_ARRAY_SIZE 5
117 #else /* UART4 */
118 #if (defined(UART3))
119 #define UART_HANDLE_ARRAY_SIZE 4
120 #else /* UART3 */
121 #if (defined(UART2))
122 #define UART_HANDLE_ARRAY_SIZE 3
123 #else /* UART2 */
124 #if (defined(UART1))
125 #define UART_HANDLE_ARRAY_SIZE 2
126 #else /* UART1 */
127 #if (defined(UART0))
128 #define UART_HANDLE_ARRAY_SIZE 1
129 #else /* UART0 */
130 #error No UART instance.
131 #endif /* UART 0 */
132 #endif /* UART 1 */
133 #endif /* UART 2 */
134 #endif /* UART 3 */
135 #endif /* UART 4 */
136 #endif /* UART 5 */
137 static uart_handle_t *s_uartHandle[UART_HANDLE_ARRAY_SIZE];
138 /* Array of UART peripheral base address. */
139 static UART_Type *const s_uartBases[] = UART_BASE_PTRS;
140 
141 /* Array of UART IRQ number. */
142 static const IRQn_Type s_uartIRQ[] = UART_RX_TX_IRQS;
143 #if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
144 /* Array of UART clock name. */
145 static const clock_ip_name_t s_uartClock[] = UART_CLOCKS;
146 #endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
147 
148 /* UART ISR for transactional APIs. */
149 static uart_isr_t s_uartIsr;
150 
151 /*******************************************************************************
152  * Code
153  ******************************************************************************/
154 
UART_GetInstance(UART_Type * base)155 uint32_t UART_GetInstance(UART_Type *base)
156 {
157     uint32_t instance;
158     uint32_t uartArrayCount = (sizeof(s_uartBases) / sizeof(s_uartBases[0]));
159 
160     /* Find the instance index from base address mappings. */
161     for (instance = 0; instance < uartArrayCount; instance++)
162     {
163         if (s_uartBases[instance] == base)
164         {
165             break;
166         }
167     }
168 
169     assert(instance < uartArrayCount);
170 
171     return instance;
172 }
173 
UART_TransferGetRxRingBufferLength(uart_handle_t * handle)174 static size_t UART_TransferGetRxRingBufferLength(uart_handle_t *handle)
175 {
176     assert(handle);
177 
178     size_t size;
179 
180     if (handle->rxRingBufferTail > handle->rxRingBufferHead)
181     {
182         size = (size_t)(handle->rxRingBufferHead + handle->rxRingBufferSize - handle->rxRingBufferTail);
183     }
184     else
185     {
186         size = (size_t)(handle->rxRingBufferHead - handle->rxRingBufferTail);
187     }
188 
189     return size;
190 }
191 
UART_TransferIsRxRingBufferFull(uart_handle_t * handle)192 static bool UART_TransferIsRxRingBufferFull(uart_handle_t *handle)
193 {
194     assert(handle);
195 
196     bool full;
197 
198     if (UART_TransferGetRxRingBufferLength(handle) == (handle->rxRingBufferSize - 1U))
199     {
200         full = true;
201     }
202     else
203     {
204         full = false;
205     }
206 
207     return full;
208 }
209 
UART_Init(UART_Type * base,const uart_config_t * config,uint32_t srcClock_Hz)210 status_t UART_Init(UART_Type *base, const uart_config_t *config, uint32_t srcClock_Hz)
211 {
212     assert(config);
213     assert(config->baudRate_Bps);
214 #if defined(FSL_FEATURE_UART_HAS_FIFO) && FSL_FEATURE_UART_HAS_FIFO
215     assert(FSL_FEATURE_UART_FIFO_SIZEn(base) >= config->txFifoWatermark);
216     assert(FSL_FEATURE_UART_FIFO_SIZEn(base) >= config->rxFifoWatermark);
217 #endif
218 
219     uint16_t sbr = 0;
220     uint8_t temp = 0;
221     uint32_t baudDiff = 0;
222 
223     /* Calculate the baud rate modulo divisor, sbr*/
224     sbr = srcClock_Hz / (config->baudRate_Bps * 16);
225     /* set sbrTemp to 1 if the sourceClockInHz can not satisfy the desired baud rate */
226     if (sbr == 0)
227     {
228         sbr = 1;
229     }
230 #if defined(FSL_FEATURE_UART_HAS_BAUD_RATE_FINE_ADJUST_SUPPORT) && FSL_FEATURE_UART_HAS_BAUD_RATE_FINE_ADJUST_SUPPORT
231     /* Determine if a fractional divider is needed to fine tune closer to the
232      * desired baud, each value of brfa is in 1/32 increments,
233      * hence the multiply-by-32. */
234     uint32_t tempBaud = 0;
235 
236     uint16_t brfa = (2 * srcClock_Hz / (config->baudRate_Bps)) - 32 * sbr;
237 
238     /* Calculate the baud rate based on the temporary SBR values and BRFA */
239     tempBaud = (srcClock_Hz * 2 / ((sbr * 32 + brfa)));
240     baudDiff =
241         (tempBaud > config->baudRate_Bps) ? (tempBaud - config->baudRate_Bps) : (config->baudRate_Bps - tempBaud);
242 
243 #else
244     /* Calculate the baud rate based on the temporary SBR values */
245     baudDiff = (srcClock_Hz / (sbr * 16)) - config->baudRate_Bps;
246 
247     /* Select the better value between sbr and (sbr + 1) */
248     if (baudDiff > (config->baudRate_Bps - (srcClock_Hz / (16 * (sbr + 1)))))
249     {
250         baudDiff = config->baudRate_Bps - (srcClock_Hz / (16 * (sbr + 1)));
251         sbr++;
252     }
253 #endif
254 
255     /* next, check to see if actual baud rate is within 3% of desired baud rate
256      * based on the calculate SBR value */
257     if (baudDiff > ((config->baudRate_Bps / 100) * 3))
258     {
259         /* Unacceptable baud rate difference of more than 3%*/
260         return kStatus_UART_BaudrateNotSupport;
261     }
262 
263 #if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
264     /* Enable uart clock */
265     CLOCK_EnableClock(s_uartClock[UART_GetInstance(base)]);
266 #endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
267 
268     /* Disable UART TX RX before setting. */
269     base->C2 &= ~(UART_C2_TE_MASK | UART_C2_RE_MASK);
270 
271     /* Write the sbr value to the BDH and BDL registers*/
272     base->BDH = (base->BDH & ~UART_BDH_SBR_MASK) | (uint8_t)(sbr >> 8);
273     base->BDL = (uint8_t)sbr;
274 
275 #if defined(FSL_FEATURE_UART_HAS_BAUD_RATE_FINE_ADJUST_SUPPORT) && FSL_FEATURE_UART_HAS_BAUD_RATE_FINE_ADJUST_SUPPORT
276     /* Write the brfa value to the register*/
277     base->C4 = (base->C4 & ~UART_C4_BRFA_MASK) | (brfa & UART_C4_BRFA_MASK);
278 #endif
279 
280     /* Set bit count and parity mode. */
281     temp = base->C1 & ~(UART_C1_PE_MASK | UART_C1_PT_MASK | UART_C1_M_MASK);
282 
283     if (kUART_ParityDisabled != config->parityMode)
284     {
285         temp |= (UART_C1_M_MASK | (uint8_t)config->parityMode);
286     }
287 
288     base->C1 = temp;
289 
290 #if defined(FSL_FEATURE_UART_HAS_STOP_BIT_CONFIG_SUPPORT) && FSL_FEATURE_UART_HAS_STOP_BIT_CONFIG_SUPPORT
291     /* Set stop bit per char */
292     base->BDH = (base->BDH & ~UART_BDH_SBNS_MASK) | UART_BDH_SBNS((uint8_t)config->stopBitCount);
293 #endif
294 
295 #if defined(FSL_FEATURE_UART_HAS_FIFO) && FSL_FEATURE_UART_HAS_FIFO
296     /* Set tx/rx FIFO watermark */
297     base->TWFIFO = config->txFifoWatermark;
298     base->RWFIFO = config->rxFifoWatermark;
299 
300     /* Enable tx/rx FIFO */
301     base->PFIFO |= (UART_PFIFO_TXFE_MASK | UART_PFIFO_RXFE_MASK);
302 
303     /* Flush FIFO */
304     base->CFIFO |= (UART_CFIFO_TXFLUSH_MASK | UART_CFIFO_RXFLUSH_MASK);
305 #endif
306 
307     /* Enable TX/RX base on configure structure. */
308     temp = base->C2;
309 
310     if (config->enableTx)
311     {
312         temp |= UART_C2_TE_MASK;
313     }
314 
315     if (config->enableRx)
316     {
317         temp |= UART_C2_RE_MASK;
318     }
319 
320     base->C2 = temp;
321 
322     return kStatus_Success;
323 }
324 
UART_Deinit(UART_Type * base)325 void UART_Deinit(UART_Type *base)
326 {
327 #if defined(FSL_FEATURE_UART_HAS_FIFO) && FSL_FEATURE_UART_HAS_FIFO
328     /* Wait tx FIFO send out*/
329     while (0 != base->TCFIFO)
330     {
331     }
332 #endif
333     /* Wait last char shoft out */
334     while (0 == (base->S1 & UART_S1_TC_MASK))
335     {
336     }
337 
338     /* Disable the module. */
339     base->C2 = 0;
340 
341 #if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
342     /* Disable uart clock */
343     CLOCK_DisableClock(s_uartClock[UART_GetInstance(base)]);
344 #endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
345 }
346 
UART_GetDefaultConfig(uart_config_t * config)347 void UART_GetDefaultConfig(uart_config_t *config)
348 {
349     assert(config);
350 
351     config->baudRate_Bps = 115200U;
352     config->parityMode = kUART_ParityDisabled;
353 #if defined(FSL_FEATURE_UART_HAS_STOP_BIT_CONFIG_SUPPORT) && FSL_FEATURE_UART_HAS_STOP_BIT_CONFIG_SUPPORT
354     config->stopBitCount = kUART_OneStopBit;
355 #endif
356 #if defined(FSL_FEATURE_UART_HAS_FIFO) && FSL_FEATURE_UART_HAS_FIFO
357     config->txFifoWatermark = 0;
358     config->rxFifoWatermark = 1;
359 #endif
360     config->enableTx = false;
361     config->enableRx = false;
362 }
363 
UART_SetBaudRate(UART_Type * base,uint32_t baudRate_Bps,uint32_t srcClock_Hz)364 status_t UART_SetBaudRate(UART_Type *base, uint32_t baudRate_Bps, uint32_t srcClock_Hz)
365 {
366     assert(baudRate_Bps);
367 
368     uint16_t sbr = 0;
369     uint32_t baudDiff = 0;
370     uint8_t oldCtrl;
371 
372     /* Calculate the baud rate modulo divisor, sbr*/
373     sbr = srcClock_Hz / (baudRate_Bps * 16);
374     /* set sbrTemp to 1 if the sourceClockInHz can not satisfy the desired baud rate */
375     if (sbr == 0)
376     {
377         sbr = 1;
378     }
379 #if defined(FSL_FEATURE_UART_HAS_BAUD_RATE_FINE_ADJUST_SUPPORT) && FSL_FEATURE_UART_HAS_BAUD_RATE_FINE_ADJUST_SUPPORT
380     /* Determine if a fractional divider is needed to fine tune closer to the
381      * desired baud, each value of brfa is in 1/32 increments,
382      * hence the multiply-by-32. */
383     uint32_t tempBaud = 0;
384 
385     uint16_t brfa = (2 * srcClock_Hz / (baudRate_Bps)) - 32 * sbr;
386 
387     /* Calculate the baud rate based on the temporary SBR values and BRFA */
388     tempBaud = (srcClock_Hz * 2 / ((sbr * 32 + brfa)));
389     baudDiff = (tempBaud > baudRate_Bps) ? (tempBaud - baudRate_Bps) : (baudRate_Bps - tempBaud);
390 #else
391     /* Calculate the baud rate based on the temporary SBR values */
392     baudDiff = (srcClock_Hz / (sbr * 16)) - baudRate_Bps;
393 
394     /* Select the better value between sbr and (sbr + 1) */
395     if (baudDiff > (baudRate_Bps - (srcClock_Hz / (16 * (sbr + 1)))))
396     {
397         baudDiff = baudRate_Bps - (srcClock_Hz / (16 * (sbr + 1)));
398         sbr++;
399     }
400 #endif
401 
402     /* next, check to see if actual baud rate is within 3% of desired baud rate
403      * based on the calculate SBR value */
404     if (baudDiff < ((baudRate_Bps / 100) * 3))
405     {
406         /* Store C2 before disable Tx and Rx */
407         oldCtrl = base->C2;
408 
409         /* Disable UART TX RX before setting. */
410         base->C2 &= ~(UART_C2_TE_MASK | UART_C2_RE_MASK);
411 
412         /* Write the sbr value to the BDH and BDL registers*/
413         base->BDH = (base->BDH & ~UART_BDH_SBR_MASK) | (uint8_t)(sbr >> 8);
414         base->BDL = (uint8_t)sbr;
415 
416 #if defined(FSL_FEATURE_UART_HAS_BAUD_RATE_FINE_ADJUST_SUPPORT) && FSL_FEATURE_UART_HAS_BAUD_RATE_FINE_ADJUST_SUPPORT
417         /* Write the brfa value to the register*/
418         base->C4 = (base->C4 & ~UART_C4_BRFA_MASK) | (brfa & UART_C4_BRFA_MASK);
419 #endif
420         /* Restore C2. */
421         base->C2 = oldCtrl;
422 
423         return kStatus_Success;
424     }
425     else
426     {
427         /* Unacceptable baud rate difference of more than 3%*/
428         return kStatus_UART_BaudrateNotSupport;
429     }
430 }
431 
UART_EnableInterrupts(UART_Type * base,uint32_t mask)432 void UART_EnableInterrupts(UART_Type *base, uint32_t mask)
433 {
434     mask &= kUART_AllInterruptsEnable;
435 
436     /* The interrupt mask is combined by control bits from several register: ((CFIFO<<24) | (C3<<16) | (C2<<8) |(BDH))
437      */
438     base->BDH |= mask;
439     base->C2 |= (mask >> 8);
440     base->C3 |= (mask >> 16);
441 
442 #if defined(FSL_FEATURE_UART_HAS_FIFO) && FSL_FEATURE_UART_HAS_FIFO
443     base->CFIFO |= (mask >> 24);
444 #endif
445 }
446 
UART_DisableInterrupts(UART_Type * base,uint32_t mask)447 void UART_DisableInterrupts(UART_Type *base, uint32_t mask)
448 {
449     mask &= kUART_AllInterruptsEnable;
450 
451     /* The interrupt mask is combined by control bits from several register: ((CFIFO<<24) | (C3<<16) | (C2<<8) |(BDH))
452      */
453     base->BDH &= ~mask;
454     base->C2 &= ~(mask >> 8);
455     base->C3 &= ~(mask >> 16);
456 
457 #if defined(FSL_FEATURE_UART_HAS_FIFO) && FSL_FEATURE_UART_HAS_FIFO
458     base->CFIFO &= ~(mask >> 24);
459 #endif
460 }
461 
UART_GetEnabledInterrupts(UART_Type * base)462 uint32_t UART_GetEnabledInterrupts(UART_Type *base)
463 {
464     uint32_t temp;
465 
466     temp = base->BDH | ((uint32_t)(base->C2) << 8) | ((uint32_t)(base->C3) << 16);
467 
468 #if defined(FSL_FEATURE_UART_HAS_FIFO) && FSL_FEATURE_UART_HAS_FIFO
469     temp |= ((uint32_t)(base->CFIFO) << 24);
470 #endif
471 
472     return temp & kUART_AllInterruptsEnable;
473 }
474 
UART_GetStatusFlags(UART_Type * base)475 uint32_t UART_GetStatusFlags(UART_Type *base)
476 {
477     uint32_t status_flag;
478 
479     status_flag = base->S1 | ((uint32_t)(base->S2) << 8);
480 
481 #if defined(FSL_FEATURE_UART_HAS_EXTENDED_DATA_REGISTER_FLAGS) && FSL_FEATURE_UART_HAS_EXTENDED_DATA_REGISTER_FLAGS
482     status_flag |= ((uint32_t)(base->ED) << 16);
483 #endif
484 
485 #if defined(FSL_FEATURE_UART_HAS_FIFO) && FSL_FEATURE_UART_HAS_FIFO
486     status_flag |= ((uint32_t)(base->SFIFO) << 24);
487 #endif
488 
489     return status_flag;
490 }
491 
UART_ClearStatusFlags(UART_Type * base,uint32_t mask)492 status_t UART_ClearStatusFlags(UART_Type *base, uint32_t mask)
493 {
494     uint8_t reg = base->S2;
495     status_t status;
496 
497 #if defined(FSL_FEATURE_UART_HAS_LIN_BREAK_DETECT) && FSL_FEATURE_UART_HAS_LIN_BREAK_DETECT
498     reg &= ~(UART_S2_RXEDGIF_MASK | UART_S2_LBKDIF_MASK);
499 #else
500     reg &= ~UART_S2_RXEDGIF_MASK;
501 #endif
502 
503     base->S2 = reg | (uint8_t)(mask >> 8);
504 
505 #if defined(FSL_FEATURE_UART_HAS_FIFO) && FSL_FEATURE_UART_HAS_FIFO
506     base->SFIFO = (uint8_t)(mask >> 24);
507 #endif
508 
509     if (mask & (kUART_IdleLineFlag | kUART_NoiseErrorFlag | kUART_FramingErrorFlag | kUART_ParityErrorFlag))
510     {
511         /* Read base->D to clear the flags. */
512         (void)base->S1;
513         (void)base->D;
514     }
515 
516     if (mask & kUART_RxOverrunFlag)
517     {
518         /* Read base->D to clear the flags and Flush all data in FIFO. */
519         (void)base->S1;
520         (void)base->D;
521 #if defined(FSL_FEATURE_UART_HAS_FIFO) && FSL_FEATURE_UART_HAS_FIFO
522         /* Flush FIFO date, otherwise FIFO pointer will be in unknown state. */
523         base->CFIFO |= UART_CFIFO_RXFLUSH_MASK;
524 #endif
525     }
526 
527     /* If some flags still pending. */
528     if (mask & UART_GetStatusFlags(base))
529     {
530         /* Some flags can only clear or set by the hardware itself, these flags are: kUART_TxDataRegEmptyFlag,
531         kUART_TransmissionCompleteFlag, kUART_RxDataRegFullFlag, kUART_RxActiveFlag, kUART_NoiseErrorInRxDataRegFlag,
532         kUART_ParityErrorInRxDataRegFlag, kUART_TxFifoEmptyFlag, kUART_RxFifoEmptyFlag. */
533         status = kStatus_UART_FlagCannotClearManually;
534     }
535     else
536     {
537         status = kStatus_Success;
538     }
539 
540     return status;
541 }
542 
UART_WriteBlocking(UART_Type * base,const uint8_t * data,size_t length)543 void UART_WriteBlocking(UART_Type *base, const uint8_t *data, size_t length)
544 {
545     /* This API can only ensure that the data is written into the data buffer but can't
546     ensure all data in the data buffer are sent into the transmit shift buffer. */
547     while (length--)
548     {
549         while (!(base->S1 & UART_S1_TDRE_MASK))
550         {
551         }
552         base->D = *(data++);
553     }
554 }
555 
UART_WriteNonBlocking(UART_Type * base,const uint8_t * data,size_t length)556 static void UART_WriteNonBlocking(UART_Type *base, const uint8_t *data, size_t length)
557 {
558     assert(data);
559 
560     size_t i;
561 
562     /* The Non Blocking write data API assume user have ensured there is enough space in
563     peripheral to write. */
564     for (i = 0; i < length; i++)
565     {
566         base->D = data[i];
567     }
568 }
569 
UART_ReadBlocking(UART_Type * base,uint8_t * data,size_t length)570 status_t UART_ReadBlocking(UART_Type *base, uint8_t *data, size_t length)
571 {
572     assert(data);
573 
574     uint32_t statusFlag;
575 
576     while (length--)
577     {
578 #if defined(FSL_FEATURE_UART_HAS_FIFO) && FSL_FEATURE_UART_HAS_FIFO
579         while (!base->RCFIFO)
580 #else
581         while (!(base->S1 & UART_S1_RDRF_MASK))
582 #endif
583         {
584             statusFlag = UART_GetStatusFlags(base);
585 
586             if (statusFlag & kUART_RxOverrunFlag)
587             {
588                 return kStatus_UART_RxHardwareOverrun;
589             }
590 
591             if (statusFlag & kUART_NoiseErrorFlag)
592             {
593                 return kStatus_UART_NoiseError;
594             }
595 
596             if (statusFlag & kUART_FramingErrorFlag)
597             {
598                 return kStatus_UART_FramingError;
599             }
600 
601             if (statusFlag & kUART_ParityErrorFlag)
602             {
603                 return kStatus_UART_ParityError;
604             }
605         }
606         *(data++) = base->D;
607     }
608 
609     return kStatus_Success;
610 }
611 
UART_ReadNonBlocking(UART_Type * base,uint8_t * data,size_t length)612 static void UART_ReadNonBlocking(UART_Type *base, uint8_t *data, size_t length)
613 {
614     assert(data);
615 
616     size_t i;
617 
618     /* The Non Blocking read data API assume user have ensured there is enough space in
619     peripheral to write. */
620     for (i = 0; i < length; i++)
621     {
622         data[i] = base->D;
623     }
624 }
625 
UART_TransferCreateHandle(UART_Type * base,uart_handle_t * handle,uart_transfer_callback_t callback,void * userData)626 void UART_TransferCreateHandle(UART_Type *base,
627                                uart_handle_t *handle,
628                                uart_transfer_callback_t callback,
629                                void *userData)
630 {
631     assert(handle);
632 
633     uint32_t instance;
634 
635     /* Zero the handle. */
636     memset(handle, 0, sizeof(*handle));
637 
638     /* Set the TX/RX state. */
639     handle->rxState = kUART_RxIdle;
640     handle->txState = kUART_TxIdle;
641 
642     /* Set the callback and user data. */
643     handle->callback = callback;
644     handle->userData = userData;
645 
646 #if defined(FSL_FEATURE_UART_HAS_FIFO) && FSL_FEATURE_UART_HAS_FIFO
647     /* Note:
648        Take care of the RX FIFO, RX interrupt request only assert when received bytes
649        equal or more than RX water mark, there is potential issue if RX water
650        mark larger than 1.
651        For example, if RX FIFO water mark is 2, upper layer needs 5 bytes and
652        5 bytes are received. the last byte will be saved in FIFO but not trigger
653        RX interrupt because the water mark is 2.
654      */
655     base->RWFIFO = 1U;
656 #endif
657 
658     /* Get instance from peripheral base address. */
659     instance = UART_GetInstance(base);
660 
661     /* Save the handle in global variables to support the double weak mechanism. */
662     s_uartHandle[instance] = handle;
663 
664     s_uartIsr = UART_TransferHandleIRQ;
665     /* Enable interrupt in NVIC. */
666     EnableIRQ(s_uartIRQ[instance]);
667 }
668 
UART_TransferStartRingBuffer(UART_Type * base,uart_handle_t * handle,uint8_t * ringBuffer,size_t ringBufferSize)669 void UART_TransferStartRingBuffer(UART_Type *base, uart_handle_t *handle, uint8_t *ringBuffer, size_t ringBufferSize)
670 {
671     assert(handle);
672     assert(ringBuffer);
673 
674     /* Setup the ringbuffer address */
675     handle->rxRingBuffer = ringBuffer;
676     handle->rxRingBufferSize = ringBufferSize;
677     handle->rxRingBufferHead = 0U;
678     handle->rxRingBufferTail = 0U;
679 
680     /* Enable the interrupt to accept the data when user need the ring buffer. */
681     UART_EnableInterrupts(
682         base, kUART_RxDataRegFullInterruptEnable | kUART_RxOverrunInterruptEnable | kUART_FramingErrorInterruptEnable);
683     /* Enable parity error interrupt when parity mode is enable*/
684     if (UART_C1_PE_MASK & base->C1)
685     {
686         UART_EnableInterrupts(base, kUART_ParityErrorInterruptEnable);
687     }
688 }
689 
UART_TransferStopRingBuffer(UART_Type * base,uart_handle_t * handle)690 void UART_TransferStopRingBuffer(UART_Type *base, uart_handle_t *handle)
691 {
692     assert(handle);
693 
694     if (handle->rxState == kUART_RxIdle)
695     {
696         UART_DisableInterrupts(base, kUART_RxDataRegFullInterruptEnable | kUART_RxOverrunInterruptEnable |
697                                          kUART_FramingErrorInterruptEnable);
698         /* Disable parity error interrupt when parity mode is enable*/
699         if (UART_C1_PE_MASK & base->C1)
700         {
701             UART_DisableInterrupts(base, kUART_ParityErrorInterruptEnable);
702         }
703     }
704 
705     handle->rxRingBuffer = NULL;
706     handle->rxRingBufferSize = 0U;
707     handle->rxRingBufferHead = 0U;
708     handle->rxRingBufferTail = 0U;
709 }
710 
UART_TransferSendNonBlocking(UART_Type * base,uart_handle_t * handle,uart_transfer_t * xfer)711 status_t UART_TransferSendNonBlocking(UART_Type *base, uart_handle_t *handle, uart_transfer_t *xfer)
712 {
713     assert(handle);
714     assert(xfer);
715     assert(xfer->dataSize);
716     assert(xfer->data);
717 
718     status_t status;
719 
720     /* Return error if current TX busy. */
721     if (kUART_TxBusy == handle->txState)
722     {
723         status = kStatus_UART_TxBusy;
724     }
725     else
726     {
727         handle->txData = xfer->data;
728         handle->txDataSize = xfer->dataSize;
729         handle->txDataSizeAll = xfer->dataSize;
730         handle->txState = kUART_TxBusy;
731 
732         /* Enable transmiter interrupt. */
733         UART_EnableInterrupts(base, kUART_TxDataRegEmptyInterruptEnable);
734 
735         status = kStatus_Success;
736     }
737 
738     return status;
739 }
740 
UART_TransferAbortSend(UART_Type * base,uart_handle_t * handle)741 void UART_TransferAbortSend(UART_Type *base, uart_handle_t *handle)
742 {
743     assert(handle);
744 
745     UART_DisableInterrupts(base, kUART_TxDataRegEmptyInterruptEnable | kUART_TransmissionCompleteInterruptEnable);
746 
747     handle->txDataSize = 0;
748     handle->txState = kUART_TxIdle;
749 }
750 
UART_TransferGetSendCount(UART_Type * base,uart_handle_t * handle,uint32_t * count)751 status_t UART_TransferGetSendCount(UART_Type *base, uart_handle_t *handle, uint32_t *count)
752 {
753     assert(handle);
754     assert(count);
755 
756     if (kUART_TxIdle == handle->txState)
757     {
758         return kStatus_NoTransferInProgress;
759     }
760 
761     *count = handle->txDataSizeAll - handle->txDataSize;
762 
763     return kStatus_Success;
764 }
765 
UART_TransferReceiveNonBlocking(UART_Type * base,uart_handle_t * handle,uart_transfer_t * xfer,size_t * receivedBytes)766 status_t UART_TransferReceiveNonBlocking(UART_Type *base,
767                                          uart_handle_t *handle,
768                                          uart_transfer_t *xfer,
769                                          size_t *receivedBytes)
770 {
771     assert(handle);
772     assert(xfer);
773     assert(xfer->data);
774     assert(xfer->dataSize);
775 
776     uint32_t i;
777     status_t status;
778     /* How many bytes to copy from ring buffer to user memory. */
779     size_t bytesToCopy = 0U;
780     /* How many bytes to receive. */
781     size_t bytesToReceive;
782     /* How many bytes currently have received. */
783     size_t bytesCurrentReceived;
784 
785     /* How to get data:
786        1. If RX ring buffer is not enabled, then save xfer->data and xfer->dataSize
787           to uart handle, enable interrupt to store received data to xfer->data. When
788           all data received, trigger callback.
789        2. If RX ring buffer is enabled and not empty, get data from ring buffer first.
790           If there are enough data in ring buffer, copy them to xfer->data and return.
791           If there are not enough data in ring buffer, copy all of them to xfer->data,
792           save the xfer->data remained empty space to uart handle, receive data
793           to this empty space and trigger callback when finished. */
794 
795     if (kUART_RxBusy == handle->rxState)
796     {
797         status = kStatus_UART_RxBusy;
798     }
799     else
800     {
801         bytesToReceive = xfer->dataSize;
802         bytesCurrentReceived = 0U;
803 
804         /* If RX ring buffer is used. */
805         if (handle->rxRingBuffer)
806         {
807             /* Disable UART RX IRQ, protect ring buffer. */
808             UART_DisableInterrupts(base, kUART_RxDataRegFullInterruptEnable);
809 
810             /* How many bytes in RX ring buffer currently. */
811             bytesToCopy = UART_TransferGetRxRingBufferLength(handle);
812 
813             if (bytesToCopy)
814             {
815                 bytesToCopy = MIN(bytesToReceive, bytesToCopy);
816 
817                 bytesToReceive -= bytesToCopy;
818 
819                 /* Copy data from ring buffer to user memory. */
820                 for (i = 0U; i < bytesToCopy; i++)
821                 {
822                     xfer->data[bytesCurrentReceived++] = handle->rxRingBuffer[handle->rxRingBufferTail];
823 
824                     /* Wrap to 0. Not use modulo (%) because it might be large and slow. */
825                     if (handle->rxRingBufferTail + 1U == handle->rxRingBufferSize)
826                     {
827                         handle->rxRingBufferTail = 0U;
828                     }
829                     else
830                     {
831                         handle->rxRingBufferTail++;
832                     }
833                 }
834             }
835 
836             /* If ring buffer does not have enough data, still need to read more data. */
837             if (bytesToReceive)
838             {
839                 /* No data in ring buffer, save the request to UART handle. */
840                 handle->rxData = xfer->data + bytesCurrentReceived;
841                 handle->rxDataSize = bytesToReceive;
842                 handle->rxDataSizeAll = bytesToReceive;
843                 handle->rxState = kUART_RxBusy;
844             }
845 
846             /* Enable UART RX IRQ if previously enabled. */
847             UART_EnableInterrupts(base, kUART_RxDataRegFullInterruptEnable);
848 
849             /* Call user callback since all data are received. */
850             if (0 == bytesToReceive)
851             {
852                 if (handle->callback)
853                 {
854                     handle->callback(base, handle, kStatus_UART_RxIdle, handle->userData);
855                 }
856             }
857         }
858         /* Ring buffer not used. */
859         else
860         {
861             handle->rxData = xfer->data + bytesCurrentReceived;
862             handle->rxDataSize = bytesToReceive;
863             handle->rxDataSizeAll = bytesToReceive;
864             handle->rxState = kUART_RxBusy;
865 
866             /* Enable RX/Rx overrun/framing error interrupt. */
867             UART_EnableInterrupts(base, kUART_RxDataRegFullInterruptEnable | kUART_RxOverrunInterruptEnable |
868                                             kUART_FramingErrorInterruptEnable);
869             /* Enable parity error interrupt when parity mode is enable*/
870             if (UART_C1_PE_MASK & base->C1)
871             {
872                 UART_EnableInterrupts(base, kUART_ParityErrorInterruptEnable);
873             }
874         }
875 
876         /* Return the how many bytes have read. */
877         if (receivedBytes)
878         {
879             *receivedBytes = bytesCurrentReceived;
880         }
881 
882         status = kStatus_Success;
883     }
884 
885     return status;
886 }
887 
UART_TransferAbortReceive(UART_Type * base,uart_handle_t * handle)888 void UART_TransferAbortReceive(UART_Type *base, uart_handle_t *handle)
889 {
890     assert(handle);
891 
892     /* Only abort the receive to handle->rxData, the RX ring buffer is still working. */
893     if (!handle->rxRingBuffer)
894     {
895         /* Disable RX interrupt. */
896         UART_DisableInterrupts(base, kUART_RxDataRegFullInterruptEnable | kUART_RxOverrunInterruptEnable |
897                                          kUART_FramingErrorInterruptEnable);
898         /* Disable parity error interrupt when parity mode is enable*/
899         if (UART_C1_PE_MASK & base->C1)
900         {
901             UART_DisableInterrupts(base, kUART_ParityErrorInterruptEnable);
902         }
903     }
904 
905     handle->rxDataSize = 0U;
906     handle->rxState = kUART_RxIdle;
907 }
908 
UART_TransferGetReceiveCount(UART_Type * base,uart_handle_t * handle,uint32_t * count)909 status_t UART_TransferGetReceiveCount(UART_Type *base, uart_handle_t *handle, uint32_t *count)
910 {
911     assert(handle);
912     assert(count);
913 
914     if (kUART_RxIdle == handle->rxState)
915     {
916         return kStatus_NoTransferInProgress;
917     }
918 
919     if (!count)
920     {
921         return kStatus_InvalidArgument;
922     }
923 
924     *count = handle->rxDataSizeAll - handle->rxDataSize;
925 
926     return kStatus_Success;
927 }
928 
UART_TransferHandleIRQ(UART_Type * base,uart_handle_t * handle)929 void UART_TransferHandleIRQ(UART_Type *base, uart_handle_t *handle)
930 {
931     assert(handle);
932 
933     uint8_t count;
934     uint8_t tempCount;
935 
936     /* If RX framing error */
937     if (UART_S1_FE_MASK & base->S1)
938     {
939         /* Read base->D to clear framing error flag, otherwise the RX does not work. */
940         while (base->S1 & UART_S1_RDRF_MASK)
941         {
942             (void)base->D;
943         }
944 #if defined(FSL_FEATURE_UART_HAS_FIFO) && FSL_FEATURE_UART_HAS_FIFO
945         /* Flush FIFO date, otherwise FIFO pointer will be in unknown state. */
946         base->CFIFO |= UART_CFIFO_RXFLUSH_MASK;
947 #endif
948 
949         handle->rxState = kUART_RxFramingError;
950         handle->rxDataSize = 0U;
951         /* Trigger callback. */
952         if (handle->callback)
953         {
954             handle->callback(base, handle, kStatus_UART_FramingError, handle->userData);
955         }
956     }
957 
958     /* If RX parity error */
959     if (UART_S1_PF_MASK & base->S1)
960     {
961         /* Read base->D to clear parity error flag, otherwise the RX does not work. */
962         while (base->S1 & UART_S1_RDRF_MASK)
963         {
964             (void)base->D;
965         }
966 #if defined(FSL_FEATURE_UART_HAS_FIFO) && FSL_FEATURE_UART_HAS_FIFO
967         /* Flush FIFO date, otherwise FIFO pointer will be in unknown state. */
968         base->CFIFO |= UART_CFIFO_RXFLUSH_MASK;
969 #endif
970 
971         handle->rxState = kUART_RxParityError;
972         handle->rxDataSize = 0U;
973         /* Trigger callback. */
974         if (handle->callback)
975         {
976             handle->callback(base, handle, kStatus_UART_ParityError, handle->userData);
977         }
978     }
979 
980     /* If RX overrun. */
981     if (UART_S1_OR_MASK & base->S1)
982     {
983         /* Read base->D to clear overrun flag, otherwise the RX does not work. */
984         while (base->S1 & UART_S1_RDRF_MASK)
985         {
986             (void)base->D;
987         }
988 #if defined(FSL_FEATURE_UART_HAS_FIFO) && FSL_FEATURE_UART_HAS_FIFO
989         /* Flush FIFO date, otherwise FIFO pointer will be in unknown state. */
990         base->CFIFO |= UART_CFIFO_RXFLUSH_MASK;
991 #endif
992         /* Trigger callback. */
993         if (handle->callback)
994         {
995             handle->callback(base, handle, kStatus_UART_RxHardwareOverrun, handle->userData);
996         }
997     }
998 
999     /* Receive data register full */
1000     if ((UART_S1_RDRF_MASK & base->S1) && (UART_C2_RIE_MASK & base->C2))
1001     {
1002 /* Get the size that can be stored into buffer for this interrupt. */
1003 #if defined(FSL_FEATURE_UART_HAS_FIFO) && FSL_FEATURE_UART_HAS_FIFO
1004         count = base->RCFIFO;
1005 #else
1006         count = 1;
1007 #endif
1008 
1009         /* If handle->rxDataSize is not 0, first save data to handle->rxData. */
1010         while ((count) && (handle->rxDataSize))
1011         {
1012 #if defined(FSL_FEATURE_UART_HAS_FIFO) && FSL_FEATURE_UART_HAS_FIFO
1013             tempCount = MIN(handle->rxDataSize, count);
1014 #else
1015             tempCount = 1;
1016 #endif
1017 
1018             /* Using non block API to read the data from the registers. */
1019             UART_ReadNonBlocking(base, handle->rxData, tempCount);
1020             handle->rxData += tempCount;
1021             handle->rxDataSize -= tempCount;
1022             count -= tempCount;
1023 
1024             /* If all the data required for upper layer is ready, trigger callback. */
1025             if (!handle->rxDataSize)
1026             {
1027                 handle->rxState = kUART_RxIdle;
1028 
1029                 if (handle->callback)
1030                 {
1031                     handle->callback(base, handle, kStatus_UART_RxIdle, handle->userData);
1032                 }
1033             }
1034         }
1035 
1036         /* If use RX ring buffer, receive data to ring buffer. */
1037         if (handle->rxRingBuffer)
1038         {
1039             while (count--)
1040             {
1041                 /* If RX ring buffer is full, trigger callback to notify over run. */
1042                 if (UART_TransferIsRxRingBufferFull(handle))
1043                 {
1044                     if (handle->callback)
1045                     {
1046                         handle->callback(base, handle, kStatus_UART_RxRingBufferOverrun, handle->userData);
1047                     }
1048                 }
1049 
1050                 /* If ring buffer is still full after callback function, the oldest data is overrided. */
1051                 if (UART_TransferIsRxRingBufferFull(handle))
1052                 {
1053                     /* Increase handle->rxRingBufferTail to make room for new data. */
1054                     if (handle->rxRingBufferTail + 1U == handle->rxRingBufferSize)
1055                     {
1056                         handle->rxRingBufferTail = 0U;
1057                     }
1058                     else
1059                     {
1060                         handle->rxRingBufferTail++;
1061                     }
1062                 }
1063 
1064                 /* Read data. */
1065                 handle->rxRingBuffer[handle->rxRingBufferHead] = base->D;
1066 
1067                 /* Increase handle->rxRingBufferHead. */
1068                 if (handle->rxRingBufferHead + 1U == handle->rxRingBufferSize)
1069                 {
1070                     handle->rxRingBufferHead = 0U;
1071                 }
1072                 else
1073                 {
1074                     handle->rxRingBufferHead++;
1075                 }
1076             }
1077         }
1078 
1079         else if (!handle->rxDataSize)
1080         {
1081             /* Disable RX interrupt/overrun interrupt/fram error interrupt */
1082             UART_DisableInterrupts(base, kUART_RxDataRegFullInterruptEnable | kUART_RxOverrunInterruptEnable |
1083                                              kUART_FramingErrorInterruptEnable);
1084 
1085             /* Disable parity error interrupt when parity mode is enable*/
1086             if (UART_C1_PE_MASK & base->C1)
1087             {
1088                 UART_DisableInterrupts(base, kUART_ParityErrorInterruptEnable);
1089             }
1090         }
1091         else
1092         {
1093         }
1094     }
1095 
1096     /* If framing error or parity error happened, stop the RX interrupt when ues no ring buffer */
1097     if (((handle->rxState == kUART_RxFramingError) || (handle->rxState == kUART_RxParityError)) &&
1098         (!handle->rxRingBuffer))
1099     {
1100         UART_DisableInterrupts(base, kUART_RxDataRegFullInterruptEnable | kUART_RxOverrunInterruptEnable |
1101                                          kUART_FramingErrorInterruptEnable);
1102 
1103         /* Disable parity error interrupt when parity mode is enable*/
1104         if (UART_C1_PE_MASK & base->C1)
1105         {
1106             UART_DisableInterrupts(base, kUART_ParityErrorInterruptEnable);
1107         }
1108     }
1109 
1110     /* Send data register empty and the interrupt is enabled. */
1111     if ((base->S1 & UART_S1_TDRE_MASK) && (base->C2 & UART_C2_TIE_MASK))
1112     {
1113 /* Get the bytes that available at this moment. */
1114 #if defined(FSL_FEATURE_UART_HAS_FIFO) && FSL_FEATURE_UART_HAS_FIFO
1115         count = FSL_FEATURE_UART_FIFO_SIZEn(base) - base->TCFIFO;
1116 #else
1117         count = 1;
1118 #endif
1119 
1120         while ((count) && (handle->txDataSize))
1121         {
1122 #if defined(FSL_FEATURE_UART_HAS_FIFO) && FSL_FEATURE_UART_HAS_FIFO
1123             tempCount = MIN(handle->txDataSize, count);
1124 #else
1125             tempCount = 1;
1126 #endif
1127 
1128             /* Using non block API to write the data to the registers. */
1129             UART_WriteNonBlocking(base, handle->txData, tempCount);
1130             handle->txData += tempCount;
1131             handle->txDataSize -= tempCount;
1132             count -= tempCount;
1133 
1134             /* If all the data are written to data register, TX finished. */
1135             if (!handle->txDataSize)
1136             {
1137                 handle->txState = kUART_TxIdle;
1138 
1139                 /* Disable TX register empty interrupt. */
1140                 base->C2 = (base->C2 & ~UART_C2_TIE_MASK);
1141 
1142                 /* Trigger callback. */
1143                 if (handle->callback)
1144                 {
1145                     handle->callback(base, handle, kStatus_UART_TxIdle, handle->userData);
1146                 }
1147             }
1148         }
1149     }
1150 }
1151 
UART_TransferHandleErrorIRQ(UART_Type * base,uart_handle_t * handle)1152 void UART_TransferHandleErrorIRQ(UART_Type *base, uart_handle_t *handle)
1153 {
1154     /* To be implemented by User. */
1155 }
1156 
1157 #if defined(UART0)
1158 #if ((!(defined(FSL_FEATURE_SOC_LPSCI_COUNT))) || \
1159      ((defined(FSL_FEATURE_SOC_LPSCI_COUNT)) && (FSL_FEATURE_SOC_LPSCI_COUNT == 0)))
UART0_DriverIRQHandler(void)1160 void UART0_DriverIRQHandler(void)
1161 {
1162     s_uartIsr(UART0, s_uartHandle[0]);
1163 }
1164 
UART0_RX_TX_DriverIRQHandler(void)1165 void UART0_RX_TX_DriverIRQHandler(void)
1166 {
1167     UART0_DriverIRQHandler();
1168 }
1169 #endif
1170 #endif
1171 
1172 #if defined(UART1)
UART1_DriverIRQHandler(void)1173 void UART1_DriverIRQHandler(void)
1174 {
1175     s_uartIsr(UART1, s_uartHandle[1]);
1176 }
1177 
UART1_RX_TX_DriverIRQHandler(void)1178 void UART1_RX_TX_DriverIRQHandler(void)
1179 {
1180     UART1_DriverIRQHandler();
1181 }
1182 #endif
1183 
1184 #if defined(UART2)
UART2_DriverIRQHandler(void)1185 void UART2_DriverIRQHandler(void)
1186 {
1187     s_uartIsr(UART2, s_uartHandle[2]);
1188 }
1189 
UART2_RX_TX_DriverIRQHandler(void)1190 void UART2_RX_TX_DriverIRQHandler(void)
1191 {
1192     UART2_DriverIRQHandler();
1193 }
1194 #endif
1195 
1196 #if defined(UART3)
UART3_DriverIRQHandler(void)1197 void UART3_DriverIRQHandler(void)
1198 {
1199     s_uartIsr(UART3, s_uartHandle[3]);
1200 }
1201 
UART3_RX_TX_DriverIRQHandler(void)1202 void UART3_RX_TX_DriverIRQHandler(void)
1203 {
1204     UART3_DriverIRQHandler();
1205 }
1206 #endif
1207 
1208 #if defined(UART4)
UART4_DriverIRQHandler(void)1209 void UART4_DriverIRQHandler(void)
1210 {
1211     s_uartIsr(UART4, s_uartHandle[4]);
1212 }
1213 
UART4_RX_TX_DriverIRQHandler(void)1214 void UART4_RX_TX_DriverIRQHandler(void)
1215 {
1216     UART4_DriverIRQHandler();
1217 }
1218 #endif
1219 
1220 #if defined(UART5)
UART5_DriverIRQHandler(void)1221 void UART5_DriverIRQHandler(void)
1222 {
1223     s_uartIsr(UART5, s_uartHandle[5]);
1224 }
1225 
UART5_RX_TX_DriverIRQHandler(void)1226 void UART5_RX_TX_DriverIRQHandler(void)
1227 {
1228     UART5_DriverIRQHandler();
1229 }
1230 #endif
1231