fsl_uart.c 37 KB

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