fsl_lpuart.c 59 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771
  1. /*
  2. * The Clear BSD License
  3. * Copyright (c) 2015-2016, Freescale Semiconductor, Inc.
  4. * Copyright 2016-2017 NXP
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without modification,
  8. * are permitted (subject to the limitations in the disclaimer below) provided
  9. * that the following conditions are met:
  10. *
  11. * o Redistributions of source code must retain the above copyright notice, this list
  12. * of conditions and the following disclaimer.
  13. *
  14. * o Redistributions in binary form must reproduce the above copyright notice, this
  15. * list of conditions and the following disclaimer in the documentation and/or
  16. * other materials provided with the distribution.
  17. *
  18. * o Neither the name of the copyright holder nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE.
  23. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  24. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  25. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  26. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
  27. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  28. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  29. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  30. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  31. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  32. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  33. */
  34. #include "fsl_lpuart.h"
  35. /*******************************************************************************
  36. * Definitions
  37. ******************************************************************************/
  38. /* Component ID definition, used by tools. */
  39. #ifndef FSL_COMPONENT_ID
  40. #define FSL_COMPONENT_ID "platform.drivers.lpuart"
  41. #endif
  42. /* LPUART transfer state. */
  43. enum _lpuart_transfer_states
  44. {
  45. kLPUART_TxIdle, /*!< TX idle. */
  46. kLPUART_TxBusy, /*!< TX busy. */
  47. kLPUART_RxIdle, /*!< RX idle. */
  48. kLPUART_RxBusy /*!< RX busy. */
  49. };
  50. /* Typedef for interrupt handler. */
  51. typedef void (*lpuart_isr_t)(LPUART_Type *base, lpuart_handle_t *handle);
  52. /*******************************************************************************
  53. * Prototypes
  54. ******************************************************************************/
  55. /*!
  56. * @brief Check whether the RX ring buffer is full.
  57. *
  58. * @userData handle LPUART handle pointer.
  59. * @retval true RX ring buffer is full.
  60. * @retval false RX ring buffer is not full.
  61. */
  62. static bool LPUART_TransferIsRxRingBufferFull(LPUART_Type *base, lpuart_handle_t *handle);
  63. /*!
  64. * @brief Write to TX register using non-blocking method.
  65. *
  66. * This function writes data to the TX register directly, upper layer must make
  67. * sure the TX register is empty or TX FIFO has empty room before calling this function.
  68. *
  69. * @note This function does not check whether all the data has been sent out to bus,
  70. * so before disable TX, check kLPUART_TransmissionCompleteFlag to ensure the TX is
  71. * finished.
  72. *
  73. * @param base LPUART peripheral base address.
  74. * @param data Start addresss of the data to write.
  75. * @param length Size of the buffer to be sent.
  76. */
  77. static void LPUART_WriteNonBlocking(LPUART_Type *base, const uint8_t *data, size_t length);
  78. /*!
  79. * @brief Read RX register using non-blocking method.
  80. *
  81. * This function reads data from the TX register directly, upper layer must make
  82. * sure the RX register is full or TX FIFO has data before calling this function.
  83. *
  84. * @param base LPUART peripheral base address.
  85. * @param data Start addresss of the buffer to store the received data.
  86. * @param length Size of the buffer.
  87. */
  88. static void LPUART_ReadNonBlocking(LPUART_Type *base, uint8_t *data, size_t length);
  89. /*******************************************************************************
  90. * Variables
  91. ******************************************************************************/
  92. /* Array of LPUART peripheral base address. */
  93. static LPUART_Type *const s_lpuartBases[] = LPUART_BASE_PTRS;
  94. /* Array of LPUART handle. */
  95. static lpuart_handle_t *s_lpuartHandle[ARRAY_SIZE(s_lpuartBases)];
  96. /* Array of LPUART IRQ number. */
  97. #if defined(FSL_FEATURE_LPUART_HAS_SEPARATE_RX_TX_IRQ) && FSL_FEATURE_LPUART_HAS_SEPARATE_RX_TX_IRQ
  98. static const IRQn_Type s_lpuartRxIRQ[] = LPUART_RX_IRQS;
  99. static const IRQn_Type s_lpuartTxIRQ[] = LPUART_TX_IRQS;
  100. #else
  101. static const IRQn_Type s_lpuartIRQ[] = LPUART_RX_TX_IRQS;
  102. #endif
  103. #if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
  104. /* Array of LPUART clock name. */
  105. static const clock_ip_name_t s_lpuartClock[] = LPUART_CLOCKS;
  106. #if defined(LPUART_PERIPH_CLOCKS)
  107. /* Array of LPUART functional clock name. */
  108. static const clock_ip_name_t s_lpuartPeriphClocks[] = LPUART_PERIPH_CLOCKS;
  109. #endif
  110. #endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
  111. /* LPUART ISR for transactional APIs. */
  112. static lpuart_isr_t s_lpuartIsr;
  113. /*******************************************************************************
  114. * Code
  115. ******************************************************************************/
  116. uint32_t LPUART_GetInstance(LPUART_Type *base)
  117. {
  118. uint32_t instance;
  119. /* Find the instance index from base address mappings. */
  120. for (instance = 0; instance < ARRAY_SIZE(s_lpuartBases); instance++)
  121. {
  122. if (s_lpuartBases[instance] == base)
  123. {
  124. break;
  125. }
  126. }
  127. assert(instance < ARRAY_SIZE(s_lpuartBases));
  128. return instance;
  129. }
  130. size_t LPUART_TransferGetRxRingBufferLength(LPUART_Type *base, lpuart_handle_t *handle)
  131. {
  132. assert(handle);
  133. size_t size;
  134. if (handle->rxRingBufferTail > handle->rxRingBufferHead)
  135. {
  136. size = (size_t)(handle->rxRingBufferHead + handle->rxRingBufferSize - handle->rxRingBufferTail);
  137. }
  138. else
  139. {
  140. size = (size_t)(handle->rxRingBufferHead - handle->rxRingBufferTail);
  141. }
  142. return size;
  143. }
  144. static bool LPUART_TransferIsRxRingBufferFull(LPUART_Type *base, lpuart_handle_t *handle)
  145. {
  146. assert(handle);
  147. bool full;
  148. if (LPUART_TransferGetRxRingBufferLength(base, handle) == (handle->rxRingBufferSize - 1U))
  149. {
  150. full = true;
  151. }
  152. else
  153. {
  154. full = false;
  155. }
  156. return full;
  157. }
  158. static void LPUART_WriteNonBlocking(LPUART_Type *base, const uint8_t *data, size_t length)
  159. {
  160. assert(data);
  161. size_t i;
  162. /* The Non Blocking write data API assume user have ensured there is enough space in
  163. peripheral to write. */
  164. for (i = 0; i < length; i++)
  165. {
  166. base->DATA = data[i];
  167. }
  168. }
  169. static void LPUART_ReadNonBlocking(LPUART_Type *base, uint8_t *data, size_t length)
  170. {
  171. assert(data);
  172. size_t i;
  173. #if defined(FSL_FEATURE_LPUART_HAS_7BIT_DATA_SUPPORT) && FSL_FEATURE_LPUART_HAS_7BIT_DATA_SUPPORT
  174. uint32_t ctrl = base->CTRL;
  175. bool isSevenDataBits =
  176. ((ctrl & LPUART_CTRL_M7_MASK) || ((!(ctrl & LPUART_CTRL_M_MASK)) && (ctrl & LPUART_CTRL_PE_MASK)));
  177. #endif
  178. /* The Non Blocking read data API assume user have ensured there is enough space in
  179. peripheral to write. */
  180. for (i = 0; i < length; i++)
  181. {
  182. #if defined(FSL_FEATURE_LPUART_HAS_7BIT_DATA_SUPPORT) && FSL_FEATURE_LPUART_HAS_7BIT_DATA_SUPPORT
  183. if (isSevenDataBits)
  184. {
  185. data[i] = (base->DATA & 0x7F);
  186. }
  187. else
  188. {
  189. data[i] = base->DATA;
  190. }
  191. #else
  192. data[i] = base->DATA;
  193. #endif
  194. }
  195. }
  196. status_t LPUART_Init(LPUART_Type *base, const lpuart_config_t *config, uint32_t srcClock_Hz)
  197. {
  198. assert(config);
  199. assert(config->baudRate_Bps);
  200. #if defined(FSL_FEATURE_LPUART_HAS_FIFO) && FSL_FEATURE_LPUART_HAS_FIFO
  201. assert(FSL_FEATURE_LPUART_FIFO_SIZEn(base) >= config->txFifoWatermark);
  202. assert(FSL_FEATURE_LPUART_FIFO_SIZEn(base) >= config->rxFifoWatermark);
  203. #endif
  204. uint32_t temp;
  205. uint16_t sbr, sbrTemp;
  206. uint32_t osr, osrTemp, tempDiff, calculatedBaud, baudDiff;
  207. /* This LPUART instantiation uses a slightly different baud rate calculation
  208. * The idea is to use the best OSR (over-sampling rate) possible
  209. * Note, OSR is typically hard-set to 16 in other LPUART instantiations
  210. * loop to find the best OSR value possible, one that generates minimum baudDiff
  211. * iterate through the rest of the supported values of OSR */
  212. baudDiff = config->baudRate_Bps;
  213. osr = 0;
  214. sbr = 0;
  215. for (osrTemp = 4; osrTemp <= 32; osrTemp++)
  216. {
  217. /* calculate the temporary sbr value */
  218. sbrTemp = (srcClock_Hz / (config->baudRate_Bps * osrTemp));
  219. /*set sbrTemp to 1 if the sourceClockInHz can not satisfy the desired baud rate*/
  220. if (sbrTemp == 0)
  221. {
  222. sbrTemp = 1;
  223. }
  224. /* Calculate the baud rate based on the temporary OSR and SBR values */
  225. calculatedBaud = (srcClock_Hz / (osrTemp * sbrTemp));
  226. tempDiff = calculatedBaud - config->baudRate_Bps;
  227. /* Select the better value between srb and (sbr + 1) */
  228. if (tempDiff > (config->baudRate_Bps - (srcClock_Hz / (osrTemp * (sbrTemp + 1)))))
  229. {
  230. tempDiff = config->baudRate_Bps - (srcClock_Hz / (osrTemp * (sbrTemp + 1)));
  231. sbrTemp++;
  232. }
  233. if (tempDiff <= baudDiff)
  234. {
  235. baudDiff = tempDiff;
  236. osr = osrTemp; /* update and store the best OSR value calculated */
  237. sbr = sbrTemp; /* update store the best SBR value calculated */
  238. }
  239. }
  240. /* Check to see if actual baud rate is within 3% of desired baud rate
  241. * based on the best calculate OSR value */
  242. if (baudDiff > ((config->baudRate_Bps / 100) * 3))
  243. {
  244. /* Unacceptable baud rate difference of more than 3%*/
  245. return kStatus_LPUART_BaudrateNotSupport;
  246. }
  247. #if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
  248. uint32_t instance = LPUART_GetInstance(base);
  249. /* Enable lpuart clock */
  250. CLOCK_EnableClock(s_lpuartClock[instance]);
  251. #if defined(LPUART_PERIPH_CLOCKS)
  252. CLOCK_EnableClock(s_lpuartPeriphClocks[instance]);
  253. #endif
  254. #endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
  255. #if defined(FSL_FEATURE_LPUART_HAS_GLOBAL) && FSL_FEATURE_LPUART_HAS_GLOBAL
  256. /*Reset all internal logic and registers, except the Global Register */
  257. LPUART_SoftwareReset(base);
  258. #else
  259. /* Disable LPUART TX RX before setting. */
  260. base->CTRL &= ~(LPUART_CTRL_TE_MASK | LPUART_CTRL_RE_MASK);
  261. #endif
  262. temp = base->BAUD;
  263. /* Acceptable baud rate, check if OSR is between 4x and 7x oversampling.
  264. * If so, then "BOTHEDGE" sampling must be turned on */
  265. if ((osr > 3) && (osr < 8))
  266. {
  267. temp |= LPUART_BAUD_BOTHEDGE_MASK;
  268. }
  269. /* program the osr value (bit value is one less than actual value) */
  270. temp &= ~LPUART_BAUD_OSR_MASK;
  271. temp |= LPUART_BAUD_OSR(osr - 1);
  272. /* write the sbr value to the BAUD registers */
  273. temp &= ~LPUART_BAUD_SBR_MASK;
  274. base->BAUD = temp | LPUART_BAUD_SBR(sbr);
  275. /* Set bit count and parity mode. */
  276. base->BAUD &= ~LPUART_BAUD_M10_MASK;
  277. temp = base->CTRL &
  278. ~(LPUART_CTRL_PE_MASK | LPUART_CTRL_PT_MASK | LPUART_CTRL_M_MASK | LPUART_CTRL_ILT_MASK |
  279. LPUART_CTRL_IDLECFG_MASK);
  280. temp |=
  281. (uint8_t)config->parityMode | LPUART_CTRL_IDLECFG(config->rxIdleConfig) | LPUART_CTRL_ILT(config->rxIdleType);
  282. #if defined(FSL_FEATURE_LPUART_HAS_7BIT_DATA_SUPPORT) && FSL_FEATURE_LPUART_HAS_7BIT_DATA_SUPPORT
  283. if (kLPUART_SevenDataBits == config->dataBitsCount)
  284. {
  285. if (kLPUART_ParityDisabled != config->parityMode)
  286. {
  287. temp &= ~LPUART_CTRL_M7_MASK; /* Seven data bits and one parity bit */
  288. }
  289. else
  290. {
  291. temp |= LPUART_CTRL_M7_MASK;
  292. }
  293. }
  294. else
  295. #endif
  296. {
  297. if (kLPUART_ParityDisabled != config->parityMode)
  298. {
  299. temp |= LPUART_CTRL_M_MASK; /* Eight data bits and one parity bit */
  300. }
  301. }
  302. base->CTRL = temp;
  303. #if defined(FSL_FEATURE_LPUART_HAS_STOP_BIT_CONFIG_SUPPORT) && FSL_FEATURE_LPUART_HAS_STOP_BIT_CONFIG_SUPPORT
  304. /* set stop bit per char */
  305. temp = base->BAUD & ~LPUART_BAUD_SBNS_MASK;
  306. base->BAUD = temp | LPUART_BAUD_SBNS((uint8_t)config->stopBitCount);
  307. #endif
  308. #if defined(FSL_FEATURE_LPUART_HAS_FIFO) && FSL_FEATURE_LPUART_HAS_FIFO
  309. /* Set tx/rx WATER watermark
  310. Note:
  311. Take care of the RX FIFO, RX interrupt request only assert when received bytes
  312. equal or more than RX water mark, there is potential issue if RX water
  313. mark larger than 1.
  314. For example, if RX FIFO water mark is 2, upper layer needs 5 bytes and
  315. 5 bytes are received. the last byte will be saved in FIFO but not trigger
  316. RX interrupt because the water mark is 2.
  317. */
  318. base->WATER = (((uint32_t)(config->rxFifoWatermark) << 16) | config->txFifoWatermark);
  319. /* Enable tx/rx FIFO */
  320. base->FIFO |= (LPUART_FIFO_TXFE_MASK | LPUART_FIFO_RXFE_MASK);
  321. /* Flush FIFO */
  322. base->FIFO |= (LPUART_FIFO_TXFLUSH_MASK | LPUART_FIFO_RXFLUSH_MASK);
  323. #endif
  324. /* Clear all status flags */
  325. temp = (LPUART_STAT_RXEDGIF_MASK | LPUART_STAT_IDLE_MASK | LPUART_STAT_OR_MASK | LPUART_STAT_NF_MASK |
  326. LPUART_STAT_FE_MASK | LPUART_STAT_PF_MASK);
  327. #if defined(FSL_FEATURE_LPUART_HAS_LIN_BREAK_DETECT) && FSL_FEATURE_LPUART_HAS_LIN_BREAK_DETECT
  328. temp |= LPUART_STAT_LBKDIF_MASK;
  329. #endif
  330. #if defined(FSL_FEATURE_LPUART_HAS_ADDRESS_MATCHING) && FSL_FEATURE_LPUART_HAS_ADDRESS_MATCHING
  331. temp |= (LPUART_STAT_MA1F_MASK | LPUART_STAT_MA2F_MASK);
  332. #endif
  333. #if defined(FSL_FEATURE_LPUART_HAS_MODEM_SUPPORT) && FSL_FEATURE_LPUART_HAS_MODEM_SUPPORT
  334. /* Set the CTS configuration/TX CTS source. */
  335. base->MODIR |= LPUART_MODIR_TXCTSC(config->txCtsConfig) | LPUART_MODIR_TXCTSSRC(config->txCtsSource);
  336. if (config->enableRxRTS)
  337. {
  338. /* Enable the receiver RTS(request-to-send) function. */
  339. base->MODIR |= LPUART_MODIR_RXRTSE_MASK;
  340. }
  341. if (config->enableTxCTS)
  342. {
  343. /* Enable the CTS(clear-to-send) function. */
  344. base->MODIR |= LPUART_MODIR_TXCTSE_MASK;
  345. }
  346. #endif
  347. /* Set data bits order. */
  348. if (config->isMsb)
  349. {
  350. temp |= LPUART_STAT_MSBF_MASK;
  351. }
  352. else
  353. {
  354. temp &= ~LPUART_STAT_MSBF_MASK;
  355. }
  356. base->STAT |= temp;
  357. /* Enable TX/RX base on configure structure. */
  358. temp = base->CTRL;
  359. if (config->enableTx)
  360. {
  361. temp |= LPUART_CTRL_TE_MASK;
  362. }
  363. if (config->enableRx)
  364. {
  365. temp |= LPUART_CTRL_RE_MASK;
  366. }
  367. base->CTRL = temp;
  368. return kStatus_Success;
  369. }
  370. void LPUART_Deinit(LPUART_Type *base)
  371. {
  372. uint32_t temp;
  373. #if defined(FSL_FEATURE_LPUART_HAS_FIFO) && FSL_FEATURE_LPUART_HAS_FIFO
  374. /* Wait tx FIFO send out*/
  375. while (0 != ((base->WATER & LPUART_WATER_TXCOUNT_MASK) >> LPUART_WATER_TXWATER_SHIFT))
  376. {
  377. }
  378. #endif
  379. /* Wait last char shoft out */
  380. while (0 == (base->STAT & LPUART_STAT_TC_MASK))
  381. {
  382. }
  383. /* Clear all status flags */
  384. temp = (LPUART_STAT_RXEDGIF_MASK | LPUART_STAT_IDLE_MASK | LPUART_STAT_OR_MASK | LPUART_STAT_NF_MASK |
  385. LPUART_STAT_FE_MASK | LPUART_STAT_PF_MASK);
  386. #if defined(FSL_FEATURE_LPUART_HAS_LIN_BREAK_DETECT) && FSL_FEATURE_LPUART_HAS_LIN_BREAK_DETECT
  387. temp |= LPUART_STAT_LBKDIF_MASK;
  388. #endif
  389. #if defined(FSL_FEATURE_LPUART_HAS_ADDRESS_MATCHING) && FSL_FEATURE_LPUART_HAS_ADDRESS_MATCHING
  390. temp |= (LPUART_STAT_MA1F_MASK | LPUART_STAT_MA2F_MASK);
  391. #endif
  392. base->STAT |= temp;
  393. /* Disable the module. */
  394. base->CTRL = 0;
  395. #if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
  396. uint32_t instance = LPUART_GetInstance(base);
  397. /* Disable lpuart clock */
  398. CLOCK_DisableClock(s_lpuartClock[instance]);
  399. #if defined(LPUART_PERIPH_CLOCKS)
  400. CLOCK_DisableClock(s_lpuartPeriphClocks[instance]);
  401. #endif
  402. #endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
  403. }
  404. void LPUART_GetDefaultConfig(lpuart_config_t *config)
  405. {
  406. assert(config);
  407. config->baudRate_Bps = 115200U;
  408. config->parityMode = kLPUART_ParityDisabled;
  409. config->dataBitsCount = kLPUART_EightDataBits;
  410. config->isMsb = false;
  411. #if defined(FSL_FEATURE_LPUART_HAS_STOP_BIT_CONFIG_SUPPORT) && FSL_FEATURE_LPUART_HAS_STOP_BIT_CONFIG_SUPPORT
  412. config->stopBitCount = kLPUART_OneStopBit;
  413. #endif
  414. #if defined(FSL_FEATURE_LPUART_HAS_FIFO) && FSL_FEATURE_LPUART_HAS_FIFO
  415. config->txFifoWatermark = 0;
  416. config->rxFifoWatermark = 0;
  417. #endif
  418. #if defined(FSL_FEATURE_LPUART_HAS_MODEM_SUPPORT) && FSL_FEATURE_LPUART_HAS_MODEM_SUPPORT
  419. config->enableRxRTS = false;
  420. config->enableTxCTS = false;
  421. config->txCtsConfig = kLPUART_CtsSampleAtStart;
  422. config->txCtsSource = kLPUART_CtsSourcePin;
  423. #endif
  424. config->rxIdleType = kLPUART_IdleTypeStartBit;
  425. config->rxIdleConfig = kLPUART_IdleCharacter1;
  426. config->enableTx = false;
  427. config->enableRx = false;
  428. }
  429. status_t LPUART_SetBaudRate(LPUART_Type *base, uint32_t baudRate_Bps, uint32_t srcClock_Hz)
  430. {
  431. assert(baudRate_Bps);
  432. uint32_t temp, oldCtrl;
  433. uint16_t sbr, sbrTemp;
  434. uint32_t osr, osrTemp, tempDiff, calculatedBaud, baudDiff;
  435. /* This LPUART instantiation uses a slightly different baud rate calculation
  436. * The idea is to use the best OSR (over-sampling rate) possible
  437. * Note, OSR is typically hard-set to 16 in other LPUART instantiations
  438. * loop to find the best OSR value possible, one that generates minimum baudDiff
  439. * iterate through the rest of the supported values of OSR */
  440. baudDiff = baudRate_Bps;
  441. osr = 0;
  442. sbr = 0;
  443. for (osrTemp = 4; osrTemp <= 32; osrTemp++)
  444. {
  445. /* calculate the temporary sbr value */
  446. sbrTemp = (srcClock_Hz / (baudRate_Bps * osrTemp));
  447. /*set sbrTemp to 1 if the sourceClockInHz can not satisfy the desired baud rate*/
  448. if (sbrTemp == 0)
  449. {
  450. sbrTemp = 1;
  451. }
  452. /* Calculate the baud rate based on the temporary OSR and SBR values */
  453. calculatedBaud = (srcClock_Hz / (osrTemp * sbrTemp));
  454. tempDiff = calculatedBaud - baudRate_Bps;
  455. /* Select the better value between srb and (sbr + 1) */
  456. if (tempDiff > (baudRate_Bps - (srcClock_Hz / (osrTemp * (sbrTemp + 1)))))
  457. {
  458. tempDiff = baudRate_Bps - (srcClock_Hz / (osrTemp * (sbrTemp + 1)));
  459. sbrTemp++;
  460. }
  461. if (tempDiff <= baudDiff)
  462. {
  463. baudDiff = tempDiff;
  464. osr = osrTemp; /* update and store the best OSR value calculated */
  465. sbr = sbrTemp; /* update store the best SBR value calculated */
  466. }
  467. }
  468. /* Check to see if actual baud rate is within 3% of desired baud rate
  469. * based on the best calculate OSR value */
  470. if (baudDiff < ((baudRate_Bps / 100) * 3))
  471. {
  472. /* Store CTRL before disable Tx and Rx */
  473. oldCtrl = base->CTRL;
  474. /* Disable LPUART TX RX before setting. */
  475. base->CTRL &= ~(LPUART_CTRL_TE_MASK | LPUART_CTRL_RE_MASK);
  476. temp = base->BAUD;
  477. /* Acceptable baud rate, check if OSR is between 4x and 7x oversampling.
  478. * If so, then "BOTHEDGE" sampling must be turned on */
  479. if ((osr > 3) && (osr < 8))
  480. {
  481. temp |= LPUART_BAUD_BOTHEDGE_MASK;
  482. }
  483. /* program the osr value (bit value is one less than actual value) */
  484. temp &= ~LPUART_BAUD_OSR_MASK;
  485. temp |= LPUART_BAUD_OSR(osr - 1);
  486. /* write the sbr value to the BAUD registers */
  487. temp &= ~LPUART_BAUD_SBR_MASK;
  488. base->BAUD = temp | LPUART_BAUD_SBR(sbr);
  489. /* Restore CTRL. */
  490. base->CTRL = oldCtrl;
  491. return kStatus_Success;
  492. }
  493. else
  494. {
  495. /* Unacceptable baud rate difference of more than 3%*/
  496. return kStatus_LPUART_BaudrateNotSupport;
  497. }
  498. }
  499. void LPUART_EnableInterrupts(LPUART_Type *base, uint32_t mask)
  500. {
  501. base->BAUD |= ((mask << 8) & (LPUART_BAUD_LBKDIE_MASK | LPUART_BAUD_RXEDGIE_MASK));
  502. #if defined(FSL_FEATURE_LPUART_HAS_FIFO) && FSL_FEATURE_LPUART_HAS_FIFO
  503. base->FIFO = (base->FIFO & ~(LPUART_FIFO_TXOF_MASK | LPUART_FIFO_RXUF_MASK)) |
  504. ((mask << 8) & (LPUART_FIFO_TXOFE_MASK | LPUART_FIFO_RXUFE_MASK));
  505. #endif
  506. mask &= 0xFFFFFF00U;
  507. base->CTRL |= mask;
  508. }
  509. void LPUART_DisableInterrupts(LPUART_Type *base, uint32_t mask)
  510. {
  511. base->BAUD &= ~((mask << 8) & (LPUART_BAUD_LBKDIE_MASK | LPUART_BAUD_RXEDGIE_MASK));
  512. #if defined(FSL_FEATURE_LPUART_HAS_FIFO) && FSL_FEATURE_LPUART_HAS_FIFO
  513. base->FIFO = (base->FIFO & ~(LPUART_FIFO_TXOF_MASK | LPUART_FIFO_RXUF_MASK)) &
  514. ~((mask << 8) & (LPUART_FIFO_TXOFE_MASK | LPUART_FIFO_RXUFE_MASK));
  515. #endif
  516. mask &= 0xFFFFFF00U;
  517. base->CTRL &= ~mask;
  518. }
  519. uint32_t LPUART_GetEnabledInterrupts(LPUART_Type *base)
  520. {
  521. uint32_t temp;
  522. temp = (base->BAUD & (LPUART_BAUD_LBKDIE_MASK | LPUART_BAUD_RXEDGIE_MASK)) >> 8;
  523. #if defined(FSL_FEATURE_LPUART_HAS_FIFO) && FSL_FEATURE_LPUART_HAS_FIFO
  524. temp |= (base->FIFO & (LPUART_FIFO_TXOFE_MASK | LPUART_FIFO_RXUFE_MASK)) >> 8;
  525. #endif
  526. temp |= (base->CTRL & 0xFF0C000);
  527. return temp;
  528. }
  529. uint32_t LPUART_GetStatusFlags(LPUART_Type *base)
  530. {
  531. uint32_t temp;
  532. temp = base->STAT;
  533. #if defined(FSL_FEATURE_LPUART_HAS_FIFO) && FSL_FEATURE_LPUART_HAS_FIFO
  534. temp |= (base->FIFO &
  535. (LPUART_FIFO_TXEMPT_MASK | LPUART_FIFO_RXEMPT_MASK | LPUART_FIFO_TXOF_MASK | LPUART_FIFO_RXUF_MASK)) >>
  536. 16;
  537. #endif
  538. return temp;
  539. }
  540. status_t LPUART_ClearStatusFlags(LPUART_Type *base, uint32_t mask)
  541. {
  542. uint32_t temp;
  543. status_t status;
  544. #if defined(FSL_FEATURE_LPUART_HAS_FIFO) && FSL_FEATURE_LPUART_HAS_FIFO
  545. temp = (uint32_t)base->FIFO;
  546. temp &= (uint32_t)(~(LPUART_FIFO_TXOF_MASK | LPUART_FIFO_RXUF_MASK));
  547. temp |= (mask << 16) & (LPUART_FIFO_TXOF_MASK | LPUART_FIFO_RXUF_MASK);
  548. base->FIFO = temp;
  549. #endif
  550. temp = (uint32_t)base->STAT;
  551. #if defined(FSL_FEATURE_LPUART_HAS_LIN_BREAK_DETECT) && FSL_FEATURE_LPUART_HAS_LIN_BREAK_DETECT
  552. temp &= (uint32_t)(~(LPUART_STAT_LBKDIF_MASK));
  553. temp |= mask & LPUART_STAT_LBKDIF_MASK;
  554. #endif
  555. temp &= (uint32_t)(~(LPUART_STAT_RXEDGIF_MASK | LPUART_STAT_IDLE_MASK | LPUART_STAT_OR_MASK | LPUART_STAT_NF_MASK |
  556. LPUART_STAT_FE_MASK | LPUART_STAT_PF_MASK));
  557. temp |= mask & (LPUART_STAT_RXEDGIF_MASK | LPUART_STAT_IDLE_MASK | LPUART_STAT_OR_MASK | LPUART_STAT_NF_MASK |
  558. LPUART_STAT_FE_MASK | LPUART_STAT_PF_MASK);
  559. #if defined(FSL_FEATURE_LPUART_HAS_ADDRESS_MATCHING) && FSL_FEATURE_LPUART_HAS_ADDRESS_MATCHING
  560. temp &= (uint32_t)(~(LPUART_STAT_MA2F_MASK | LPUART_STAT_MA1F_MASK));
  561. temp |= mask & (LPUART_STAT_MA2F_MASK | LPUART_STAT_MA1F_MASK);
  562. #endif
  563. base->STAT = temp;
  564. /* If some flags still pending. */
  565. if (mask & LPUART_GetStatusFlags(base))
  566. {
  567. /* Some flags can only clear or set by the hardware itself, these flags are: kLPUART_TxDataRegEmptyFlag,
  568. kLPUART_TransmissionCompleteFlag, kLPUART_RxDataRegFullFlag, kLPUART_RxActiveFlag,
  569. kLPUART_NoiseErrorInRxDataRegFlag, kLPUART_ParityErrorInRxDataRegFlag,
  570. kLPUART_TxFifoEmptyFlag, kLPUART_RxFifoEmptyFlag. */
  571. status = kStatus_LPUART_FlagCannotClearManually; /* flags can not clear manually */
  572. }
  573. else
  574. {
  575. status = kStatus_Success;
  576. }
  577. return status;
  578. }
  579. void LPUART_WriteBlocking(LPUART_Type *base, const uint8_t *data, size_t length)
  580. {
  581. assert(data);
  582. /* This API can only ensure that the data is written into the data buffer but can't
  583. ensure all data in the data buffer are sent into the transmit shift buffer. */
  584. while (length--)
  585. {
  586. while (!(base->STAT & LPUART_STAT_TDRE_MASK))
  587. {
  588. }
  589. base->DATA = *(data++);
  590. }
  591. }
  592. status_t LPUART_ReadBlocking(LPUART_Type *base, uint8_t *data, size_t length)
  593. {
  594. assert(data);
  595. uint32_t statusFlag;
  596. #if defined(FSL_FEATURE_LPUART_HAS_7BIT_DATA_SUPPORT) && FSL_FEATURE_LPUART_HAS_7BIT_DATA_SUPPORT
  597. uint32_t ctrl = base->CTRL;
  598. bool isSevenDataBits =
  599. ((ctrl & LPUART_CTRL_M7_MASK) || ((!(ctrl & LPUART_CTRL_M_MASK)) && (ctrl & LPUART_CTRL_PE_MASK)));
  600. #endif
  601. while (length--)
  602. {
  603. #if defined(FSL_FEATURE_LPUART_HAS_FIFO) && FSL_FEATURE_LPUART_HAS_FIFO
  604. while (0 == ((base->WATER & LPUART_WATER_RXCOUNT_MASK) >> LPUART_WATER_RXCOUNT_SHIFT))
  605. #else
  606. while (!(base->STAT & LPUART_STAT_RDRF_MASK))
  607. #endif
  608. {
  609. statusFlag = LPUART_GetStatusFlags(base);
  610. if (statusFlag & kLPUART_RxOverrunFlag)
  611. {
  612. LPUART_ClearStatusFlags(base, kLPUART_RxOverrunFlag);
  613. return kStatus_LPUART_RxHardwareOverrun;
  614. }
  615. if (statusFlag & kLPUART_NoiseErrorFlag)
  616. {
  617. LPUART_ClearStatusFlags(base, kLPUART_NoiseErrorFlag);
  618. return kStatus_LPUART_NoiseError;
  619. }
  620. if (statusFlag & kLPUART_FramingErrorFlag)
  621. {
  622. LPUART_ClearStatusFlags(base, kLPUART_FramingErrorFlag);
  623. return kStatus_LPUART_FramingError;
  624. }
  625. if (statusFlag & kLPUART_ParityErrorFlag)
  626. {
  627. LPUART_ClearStatusFlags(base, kLPUART_ParityErrorFlag);
  628. return kStatus_LPUART_ParityError;
  629. }
  630. }
  631. #if defined(FSL_FEATURE_LPUART_HAS_7BIT_DATA_SUPPORT) && FSL_FEATURE_LPUART_HAS_7BIT_DATA_SUPPORT
  632. if (isSevenDataBits)
  633. {
  634. *(data++) = (base->DATA & 0x7F);
  635. }
  636. else
  637. {
  638. *(data++) = base->DATA;
  639. }
  640. #else
  641. *(data++) = base->DATA;
  642. #endif
  643. }
  644. return kStatus_Success;
  645. }
  646. void LPUART_TransferCreateHandle(LPUART_Type *base,
  647. lpuart_handle_t *handle,
  648. lpuart_transfer_callback_t callback,
  649. void *userData)
  650. {
  651. assert(handle);
  652. uint32_t instance;
  653. #if defined(FSL_FEATURE_LPUART_HAS_7BIT_DATA_SUPPORT) && FSL_FEATURE_LPUART_HAS_7BIT_DATA_SUPPORT
  654. uint32_t ctrl = base->CTRL;
  655. bool isSevenDataBits =
  656. ((ctrl & LPUART_CTRL_M7_MASK) || ((!(ctrl & LPUART_CTRL_M_MASK)) && (ctrl & LPUART_CTRL_PE_MASK)));
  657. #endif
  658. /* Zero the handle. */
  659. memset(handle, 0, sizeof(lpuart_handle_t));
  660. /* Set the TX/RX state. */
  661. handle->rxState = kLPUART_RxIdle;
  662. handle->txState = kLPUART_TxIdle;
  663. /* Set the callback and user data. */
  664. handle->callback = callback;
  665. handle->userData = userData;
  666. #if defined(FSL_FEATURE_LPUART_HAS_7BIT_DATA_SUPPORT) && FSL_FEATURE_LPUART_HAS_7BIT_DATA_SUPPORT
  667. /* Initial seven data bits flag */
  668. handle->isSevenDataBits = isSevenDataBits;
  669. #endif
  670. /* Get instance from peripheral base address. */
  671. instance = LPUART_GetInstance(base);
  672. /* Save the handle in global variables to support the double weak mechanism. */
  673. s_lpuartHandle[instance] = handle;
  674. s_lpuartIsr = LPUART_TransferHandleIRQ;
  675. /* Enable interrupt in NVIC. */
  676. #if defined(FSL_FEATURE_LPUART_HAS_SEPARATE_RX_TX_IRQ) && FSL_FEATURE_LPUART_HAS_SEPARATE_RX_TX_IRQ
  677. EnableIRQ(s_lpuartRxIRQ[instance]);
  678. EnableIRQ(s_lpuartTxIRQ[instance]);
  679. #else
  680. EnableIRQ(s_lpuartIRQ[instance]);
  681. #endif
  682. }
  683. void LPUART_TransferStartRingBuffer(LPUART_Type *base,
  684. lpuart_handle_t *handle,
  685. uint8_t *ringBuffer,
  686. size_t ringBufferSize)
  687. {
  688. assert(handle);
  689. assert(ringBuffer);
  690. /* Setup the ring buffer address */
  691. handle->rxRingBuffer = ringBuffer;
  692. handle->rxRingBufferSize = ringBufferSize;
  693. handle->rxRingBufferHead = 0U;
  694. handle->rxRingBufferTail = 0U;
  695. /* Enable the interrupt to accept the data when user need the ring buffer. */
  696. LPUART_EnableInterrupts(base, kLPUART_RxDataRegFullInterruptEnable | kLPUART_RxOverrunInterruptEnable);
  697. }
  698. void LPUART_TransferStopRingBuffer(LPUART_Type *base, lpuart_handle_t *handle)
  699. {
  700. assert(handle);
  701. if (handle->rxState == kLPUART_RxIdle)
  702. {
  703. LPUART_DisableInterrupts(base, kLPUART_RxDataRegFullInterruptEnable | kLPUART_RxOverrunInterruptEnable);
  704. }
  705. handle->rxRingBuffer = NULL;
  706. handle->rxRingBufferSize = 0U;
  707. handle->rxRingBufferHead = 0U;
  708. handle->rxRingBufferTail = 0U;
  709. }
  710. status_t LPUART_TransferSendNonBlocking(LPUART_Type *base, lpuart_handle_t *handle, lpuart_transfer_t *xfer)
  711. {
  712. assert(handle);
  713. assert(xfer);
  714. assert(xfer->data);
  715. assert(xfer->dataSize);
  716. status_t status;
  717. /* Return error if current TX busy. */
  718. if (kLPUART_TxBusy == handle->txState)
  719. {
  720. status = kStatus_LPUART_TxBusy;
  721. }
  722. else
  723. {
  724. handle->txData = xfer->data;
  725. handle->txDataSize = xfer->dataSize;
  726. handle->txDataSizeAll = xfer->dataSize;
  727. handle->txState = kLPUART_TxBusy;
  728. /* Enable transmiter interrupt. */
  729. LPUART_EnableInterrupts(base, kLPUART_TxDataRegEmptyInterruptEnable);
  730. status = kStatus_Success;
  731. }
  732. return status;
  733. }
  734. void LPUART_TransferAbortSend(LPUART_Type *base, lpuart_handle_t *handle)
  735. {
  736. assert(handle);
  737. LPUART_DisableInterrupts(base, kLPUART_TxDataRegEmptyInterruptEnable | kLPUART_TransmissionCompleteInterruptEnable);
  738. handle->txDataSize = 0;
  739. handle->txState = kLPUART_TxIdle;
  740. }
  741. status_t LPUART_TransferGetSendCount(LPUART_Type *base, lpuart_handle_t *handle, uint32_t *count)
  742. {
  743. assert(handle);
  744. assert(count);
  745. if (kLPUART_TxIdle == handle->txState)
  746. {
  747. return kStatus_NoTransferInProgress;
  748. }
  749. *count = handle->txDataSizeAll - handle->txDataSize;
  750. return kStatus_Success;
  751. }
  752. status_t LPUART_TransferReceiveNonBlocking(LPUART_Type *base,
  753. lpuart_handle_t *handle,
  754. lpuart_transfer_t *xfer,
  755. size_t *receivedBytes)
  756. {
  757. assert(handle);
  758. assert(xfer);
  759. assert(xfer->data);
  760. assert(xfer->dataSize);
  761. uint32_t i;
  762. status_t status;
  763. /* How many bytes to copy from ring buffer to user memory. */
  764. size_t bytesToCopy = 0U;
  765. /* How many bytes to receive. */
  766. size_t bytesToReceive;
  767. /* How many bytes currently have received. */
  768. size_t bytesCurrentReceived;
  769. /* How to get data:
  770. 1. If RX ring buffer is not enabled, then save xfer->data and xfer->dataSize
  771. to lpuart handle, enable interrupt to store received data to xfer->data. When
  772. all data received, trigger callback.
  773. 2. If RX ring buffer is enabled and not empty, get data from ring buffer first.
  774. If there are enough data in ring buffer, copy them to xfer->data and return.
  775. If there are not enough data in ring buffer, copy all of them to xfer->data,
  776. save the xfer->data remained empty space to lpuart handle, receive data
  777. to this empty space and trigger callback when finished. */
  778. if (kLPUART_RxBusy == handle->rxState)
  779. {
  780. status = kStatus_LPUART_RxBusy;
  781. }
  782. else
  783. {
  784. bytesToReceive = xfer->dataSize;
  785. bytesCurrentReceived = 0;
  786. /* If RX ring buffer is used. */
  787. if (handle->rxRingBuffer)
  788. {
  789. /* Disable LPUART RX IRQ, protect ring buffer. */
  790. LPUART_DisableInterrupts(base, kLPUART_RxDataRegFullInterruptEnable);
  791. /* How many bytes in RX ring buffer currently. */
  792. bytesToCopy = LPUART_TransferGetRxRingBufferLength(base, handle);
  793. if (bytesToCopy)
  794. {
  795. bytesToCopy = MIN(bytesToReceive, bytesToCopy);
  796. bytesToReceive -= bytesToCopy;
  797. /* Copy data from ring buffer to user memory. */
  798. for (i = 0U; i < bytesToCopy; i++)
  799. {
  800. xfer->data[bytesCurrentReceived++] = handle->rxRingBuffer[handle->rxRingBufferTail];
  801. /* Wrap to 0. Not use modulo (%) because it might be large and slow. */
  802. if (handle->rxRingBufferTail + 1U == handle->rxRingBufferSize)
  803. {
  804. handle->rxRingBufferTail = 0U;
  805. }
  806. else
  807. {
  808. handle->rxRingBufferTail++;
  809. }
  810. }
  811. }
  812. /* If ring buffer does not have enough data, still need to read more data. */
  813. if (bytesToReceive)
  814. {
  815. /* No data in ring buffer, save the request to LPUART handle. */
  816. handle->rxData = xfer->data + bytesCurrentReceived;
  817. handle->rxDataSize = bytesToReceive;
  818. handle->rxDataSizeAll = bytesToReceive;
  819. handle->rxState = kLPUART_RxBusy;
  820. }
  821. /* Enable LPUART RX IRQ if previously enabled. */
  822. LPUART_EnableInterrupts(base, kLPUART_RxDataRegFullInterruptEnable);
  823. /* Call user callback since all data are received. */
  824. if (0 == bytesToReceive)
  825. {
  826. if (handle->callback)
  827. {
  828. handle->callback(base, handle, kStatus_LPUART_RxIdle, handle->userData);
  829. }
  830. }
  831. }
  832. /* Ring buffer not used. */
  833. else
  834. {
  835. handle->rxData = xfer->data + bytesCurrentReceived;
  836. handle->rxDataSize = bytesToReceive;
  837. handle->rxDataSizeAll = bytesToReceive;
  838. handle->rxState = kLPUART_RxBusy;
  839. /* Enable RX interrupt. */
  840. LPUART_EnableInterrupts(base, kLPUART_RxDataRegFullInterruptEnable | kLPUART_RxOverrunInterruptEnable |
  841. kLPUART_IdleLineInterruptEnable);
  842. }
  843. /* Return the how many bytes have read. */
  844. if (receivedBytes)
  845. {
  846. *receivedBytes = bytesCurrentReceived;
  847. }
  848. status = kStatus_Success;
  849. }
  850. return status;
  851. }
  852. void LPUART_TransferAbortReceive(LPUART_Type *base, lpuart_handle_t *handle)
  853. {
  854. assert(handle);
  855. /* Only abort the receive to handle->rxData, the RX ring buffer is still working. */
  856. if (!handle->rxRingBuffer)
  857. {
  858. /* Disable RX interrupt. */
  859. LPUART_DisableInterrupts(base, kLPUART_RxDataRegFullInterruptEnable | kLPUART_RxOverrunInterruptEnable |
  860. kLPUART_IdleLineInterruptEnable);
  861. }
  862. handle->rxDataSize = 0U;
  863. handle->rxState = kLPUART_RxIdle;
  864. }
  865. status_t LPUART_TransferGetReceiveCount(LPUART_Type *base, lpuart_handle_t *handle, uint32_t *count)
  866. {
  867. assert(handle);
  868. assert(count);
  869. if (kLPUART_RxIdle == handle->rxState)
  870. {
  871. return kStatus_NoTransferInProgress;
  872. }
  873. *count = handle->rxDataSizeAll - handle->rxDataSize;
  874. return kStatus_Success;
  875. }
  876. void LPUART_TransferHandleIRQ(LPUART_Type *base, lpuart_handle_t *handle)
  877. {
  878. assert(handle);
  879. uint8_t count;
  880. uint8_t tempCount;
  881. /* If RX overrun. */
  882. if (LPUART_STAT_OR_MASK & base->STAT)
  883. {
  884. /* Clear overrun flag, otherwise the RX does not work. */
  885. base->STAT = ((base->STAT & 0x3FE00000U) | LPUART_STAT_OR_MASK);
  886. /* Trigger callback. */
  887. if (handle->callback)
  888. {
  889. handle->callback(base, handle, kStatus_LPUART_RxHardwareOverrun, handle->userData);
  890. }
  891. }
  892. /* If IDLE flag is set and the IDLE interrupt is enabled. */
  893. if ((LPUART_STAT_IDLE_MASK & base->STAT) && (LPUART_CTRL_ILIE_MASK & base->CTRL))
  894. {
  895. #if defined(FSL_FEATURE_LPUART_HAS_FIFO) && FSL_FEATURE_LPUART_HAS_FIFO
  896. count = ((uint8_t)((base->WATER & LPUART_WATER_RXCOUNT_MASK) >> LPUART_WATER_RXCOUNT_SHIFT));
  897. while ((count) && (handle->rxDataSize))
  898. {
  899. tempCount = MIN(handle->rxDataSize, count);
  900. /* Using non block API to read the data from the registers. */
  901. LPUART_ReadNonBlocking(base, handle->rxData, tempCount);
  902. handle->rxData += tempCount;
  903. handle->rxDataSize -= tempCount;
  904. count -= tempCount;
  905. /* If rxDataSize is 0, disable idle line interrupt.*/
  906. if (!(handle->rxDataSize))
  907. {
  908. handle->rxState = kLPUART_RxIdle;
  909. LPUART_DisableInterrupts(base, kLPUART_RxDataRegFullInterruptEnable | kLPUART_RxOverrunInterruptEnable);
  910. if (handle->callback)
  911. {
  912. handle->callback(base, handle, kStatus_LPUART_RxIdle, handle->userData);
  913. }
  914. }
  915. }
  916. #endif
  917. /* Clear IDLE flag.*/
  918. base->STAT |= LPUART_STAT_IDLE_MASK;
  919. /* If rxDataSize is 0, disable idle line interrupt.*/
  920. if (!(handle->rxDataSize))
  921. {
  922. LPUART_DisableInterrupts(base, kLPUART_IdleLineInterruptEnable);
  923. }
  924. /* If callback is not NULL and rxDataSize is not 0. */
  925. if ((handle->callback) && (handle->rxDataSize))
  926. {
  927. handle->callback(base, handle, kStatus_LPUART_IdleLineDetected, handle->userData);
  928. }
  929. }
  930. /* Receive data register full */
  931. if ((LPUART_STAT_RDRF_MASK & base->STAT) && (LPUART_CTRL_RIE_MASK & base->CTRL))
  932. {
  933. /* Get the size that can be stored into buffer for this interrupt. */
  934. #if defined(FSL_FEATURE_LPUART_HAS_FIFO) && FSL_FEATURE_LPUART_HAS_FIFO
  935. count = ((uint8_t)((base->WATER & LPUART_WATER_RXCOUNT_MASK) >> LPUART_WATER_RXCOUNT_SHIFT));
  936. #else
  937. count = 1;
  938. #endif
  939. /* If handle->rxDataSize is not 0, first save data to handle->rxData. */
  940. while ((count) && (handle->rxDataSize))
  941. {
  942. #if defined(FSL_FEATURE_LPUART_HAS_FIFO) && FSL_FEATURE_LPUART_HAS_FIFO
  943. tempCount = MIN(handle->rxDataSize, count);
  944. #else
  945. tempCount = 1;
  946. #endif
  947. /* Using non block API to read the data from the registers. */
  948. LPUART_ReadNonBlocking(base, handle->rxData, tempCount);
  949. handle->rxData += tempCount;
  950. handle->rxDataSize -= tempCount;
  951. count -= tempCount;
  952. /* If all the data required for upper layer is ready, trigger callback. */
  953. if (!handle->rxDataSize)
  954. {
  955. handle->rxState = kLPUART_RxIdle;
  956. if (handle->callback)
  957. {
  958. handle->callback(base, handle, kStatus_LPUART_RxIdle, handle->userData);
  959. }
  960. }
  961. }
  962. /* If use RX ring buffer, receive data to ring buffer. */
  963. if (handle->rxRingBuffer)
  964. {
  965. while (count--)
  966. {
  967. /* If RX ring buffer is full, trigger callback to notify over run. */
  968. if (LPUART_TransferIsRxRingBufferFull(base, handle))
  969. {
  970. if (handle->callback)
  971. {
  972. handle->callback(base, handle, kStatus_LPUART_RxRingBufferOverrun, handle->userData);
  973. }
  974. }
  975. /* If ring buffer is still full after callback function, the oldest data is overrided. */
  976. if (LPUART_TransferIsRxRingBufferFull(base, handle))
  977. {
  978. /* Increase handle->rxRingBufferTail to make room for new data. */
  979. if (handle->rxRingBufferTail + 1U == handle->rxRingBufferSize)
  980. {
  981. handle->rxRingBufferTail = 0U;
  982. }
  983. else
  984. {
  985. handle->rxRingBufferTail++;
  986. }
  987. }
  988. /* Read data. */
  989. #if defined(FSL_FEATURE_LPUART_HAS_7BIT_DATA_SUPPORT) && FSL_FEATURE_LPUART_HAS_7BIT_DATA_SUPPORT
  990. if (handle->isSevenDataBits)
  991. {
  992. handle->rxRingBuffer[handle->rxRingBufferHead] = (base->DATA & 0x7F);
  993. }
  994. else
  995. {
  996. handle->rxRingBuffer[handle->rxRingBufferHead] = base->DATA;
  997. }
  998. #else
  999. handle->rxRingBuffer[handle->rxRingBufferHead] = base->DATA;
  1000. #endif
  1001. /* Increase handle->rxRingBufferHead. */
  1002. if (handle->rxRingBufferHead + 1U == handle->rxRingBufferSize)
  1003. {
  1004. handle->rxRingBufferHead = 0U;
  1005. }
  1006. else
  1007. {
  1008. handle->rxRingBufferHead++;
  1009. }
  1010. }
  1011. }
  1012. /* If no receive requst pending, stop RX interrupt. */
  1013. else if (!handle->rxDataSize)
  1014. {
  1015. LPUART_DisableInterrupts(base, kLPUART_RxDataRegFullInterruptEnable | kLPUART_RxOverrunInterruptEnable);
  1016. }
  1017. else
  1018. {
  1019. }
  1020. }
  1021. /* Send data register empty and the interrupt is enabled. */
  1022. if ((base->STAT & LPUART_STAT_TDRE_MASK) && (base->CTRL & LPUART_CTRL_TIE_MASK))
  1023. {
  1024. /* Get the bytes that available at this moment. */
  1025. #if defined(FSL_FEATURE_LPUART_HAS_FIFO) && FSL_FEATURE_LPUART_HAS_FIFO
  1026. count = FSL_FEATURE_LPUART_FIFO_SIZEn(base) -
  1027. ((base->WATER & LPUART_WATER_TXCOUNT_MASK) >> LPUART_WATER_TXCOUNT_SHIFT);
  1028. #else
  1029. count = 1;
  1030. #endif
  1031. while ((count) && (handle->txDataSize))
  1032. {
  1033. #if defined(FSL_FEATURE_LPUART_HAS_FIFO) && FSL_FEATURE_LPUART_HAS_FIFO
  1034. tempCount = MIN(handle->txDataSize, count);
  1035. #else
  1036. tempCount = 1;
  1037. #endif
  1038. /* Using non block API to write the data to the registers. */
  1039. LPUART_WriteNonBlocking(base, handle->txData, tempCount);
  1040. handle->txData += tempCount;
  1041. handle->txDataSize -= tempCount;
  1042. count -= tempCount;
  1043. /* If all the data are written to data register, notify user with the callback, then TX finished. */
  1044. if (!handle->txDataSize)
  1045. {
  1046. handle->txState = kLPUART_TxIdle;
  1047. /* Disable TX register empty interrupt. */
  1048. base->CTRL = (base->CTRL & ~LPUART_CTRL_TIE_MASK);
  1049. /* Trigger callback. */
  1050. if (handle->callback)
  1051. {
  1052. handle->callback(base, handle, kStatus_LPUART_TxIdle, handle->userData);
  1053. }
  1054. }
  1055. }
  1056. }
  1057. }
  1058. void LPUART_TransferHandleErrorIRQ(LPUART_Type *base, lpuart_handle_t *handle)
  1059. {
  1060. /* To be implemented by User. */
  1061. }
  1062. #if defined(FSL_FEATURE_LPUART_HAS_SHARED_IRQ0_IRQ1) && FSL_FEATURE_LPUART_HAS_SHARED_IRQ0_IRQ1
  1063. #if defined(FSL_FEATURE_LPUART_HAS_SEPARATE_RX_TX_IRQ) && FSL_FEATURE_LPUART_HAS_SEPARATE_RX_TX_IRQ
  1064. void LPUART0_LPUART1_RX_DriverIRQHandler(void)
  1065. {
  1066. if (CLOCK_isEnabledClock(s_lpuartClock[0]))
  1067. {
  1068. if ((LPUART_STAT_OR_MASK & LPUART0->STAT) ||
  1069. ((LPUART_STAT_RDRF_MASK & LPUART0->STAT) && (LPUART_CTRL_RIE_MASK & LPUART0->CTRL)))
  1070. {
  1071. s_lpuartIsr(LPUART0, s_lpuartHandle[0]);
  1072. }
  1073. }
  1074. if (CLOCK_isEnabledClock(s_lpuartClock[1]))
  1075. {
  1076. if ((LPUART_STAT_OR_MASK & LPUART1->STAT) ||
  1077. ((LPUART_STAT_RDRF_MASK & LPUART1->STAT) && (LPUART_CTRL_RIE_MASK & LPUART1->CTRL)))
  1078. {
  1079. s_lpuartIsr(LPUART1, s_lpuartHandle[1]);
  1080. }
  1081. }
  1082. /* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
  1083. exception return operation might vector to incorrect interrupt */
  1084. #if defined __CORTEX_M && (__CORTEX_M == 4U)
  1085. __DSB();
  1086. #endif
  1087. }
  1088. void LPUART0_LPUART1_TX_DriverIRQHandler(void)
  1089. {
  1090. if (CLOCK_isEnabledClock(s_lpuartClock[0]))
  1091. {
  1092. if ((LPUART_STAT_OR_MASK & LPUART0->STAT) ||
  1093. ((LPUART0->STAT & LPUART_STAT_TDRE_MASK) && (LPUART0->CTRL & LPUART_CTRL_TIE_MASK)))
  1094. {
  1095. s_lpuartIsr(LPUART0, s_lpuartHandle[0]);
  1096. }
  1097. }
  1098. if (CLOCK_isEnabledClock(s_lpuartClock[1]))
  1099. {
  1100. if ((LPUART_STAT_OR_MASK & LPUART1->STAT) ||
  1101. ((LPUART1->STAT & LPUART_STAT_TDRE_MASK) && (LPUART1->CTRL & LPUART_CTRL_TIE_MASK)))
  1102. {
  1103. s_lpuartIsr(LPUART1, s_lpuartHandle[1]);
  1104. }
  1105. }
  1106. /* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
  1107. exception return operation might vector to incorrect interrupt */
  1108. #if defined __CORTEX_M && (__CORTEX_M == 4U)
  1109. __DSB();
  1110. #endif
  1111. }
  1112. #else
  1113. void LPUART0_LPUART1_DriverIRQHandler(void)
  1114. {
  1115. if (CLOCK_isEnabledClock(s_lpuartClock[0]))
  1116. {
  1117. if ((LPUART_STAT_OR_MASK & LPUART0->STAT) ||
  1118. ((LPUART_STAT_RDRF_MASK & LPUART0->STAT) && (LPUART_CTRL_RIE_MASK & LPUART0->CTRL)) ||
  1119. ((LPUART0->STAT & LPUART_STAT_TDRE_MASK) && (LPUART0->CTRL & LPUART_CTRL_TIE_MASK)))
  1120. {
  1121. s_lpuartIsr(LPUART0, s_lpuartHandle[0]);
  1122. }
  1123. }
  1124. if (CLOCK_isEnabledClock(s_lpuartClock[1]))
  1125. {
  1126. if ((LPUART_STAT_OR_MASK & LPUART1->STAT) ||
  1127. ((LPUART_STAT_RDRF_MASK & LPUART1->STAT) && (LPUART_CTRL_RIE_MASK & LPUART1->CTRL)) ||
  1128. ((LPUART1->STAT & LPUART_STAT_TDRE_MASK) && (LPUART1->CTRL & LPUART_CTRL_TIE_MASK)))
  1129. {
  1130. s_lpuartIsr(LPUART1, s_lpuartHandle[1]);
  1131. }
  1132. }
  1133. /* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
  1134. exception return operation might vector to incorrect interrupt */
  1135. #if defined __CORTEX_M && (__CORTEX_M == 4U)
  1136. __DSB();
  1137. #endif
  1138. }
  1139. #endif
  1140. #endif
  1141. #if defined(LPUART0)
  1142. #if !(defined(FSL_FEATURE_LPUART_HAS_SHARED_IRQ0_IRQ1) && FSL_FEATURE_LPUART_HAS_SHARED_IRQ0_IRQ1)
  1143. #if defined(FSL_FEATURE_LPUART_HAS_SEPARATE_RX_TX_IRQ) && FSL_FEATURE_LPUART_HAS_SEPARATE_RX_TX_IRQ
  1144. void LPUART0_TX_DriverIRQHandler(void)
  1145. {
  1146. s_lpuartIsr(LPUART0, s_lpuartHandle[0]);
  1147. /* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
  1148. exception return operation might vector to incorrect interrupt */
  1149. #if defined __CORTEX_M && (__CORTEX_M == 4U)
  1150. __DSB();
  1151. #endif
  1152. }
  1153. void LPUART0_RX_DriverIRQHandler(void)
  1154. {
  1155. s_lpuartIsr(LPUART0, s_lpuartHandle[0]);
  1156. /* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
  1157. exception return operation might vector to incorrect interrupt */
  1158. #if defined __CORTEX_M && (__CORTEX_M == 4U)
  1159. __DSB();
  1160. #endif
  1161. }
  1162. #else
  1163. void LPUART0_DriverIRQHandler(void)
  1164. {
  1165. s_lpuartIsr(LPUART0, s_lpuartHandle[0]);
  1166. /* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
  1167. exception return operation might vector to incorrect interrupt */
  1168. #if defined __CORTEX_M && (__CORTEX_M == 4U)
  1169. __DSB();
  1170. #endif
  1171. }
  1172. #endif
  1173. #endif
  1174. #endif
  1175. #if defined(LPUART1)
  1176. #if !(defined(FSL_FEATURE_LPUART_HAS_SHARED_IRQ0_IRQ1) && FSL_FEATURE_LPUART_HAS_SHARED_IRQ0_IRQ1)
  1177. #if defined(FSL_FEATURE_LPUART_HAS_SEPARATE_RX_TX_IRQ) && FSL_FEATURE_LPUART_HAS_SEPARATE_RX_TX_IRQ
  1178. void LPUART1_TX_DriverIRQHandler(void)
  1179. {
  1180. s_lpuartIsr(LPUART1, s_lpuartHandle[1]);
  1181. /* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
  1182. exception return operation might vector to incorrect interrupt */
  1183. #if defined __CORTEX_M && (__CORTEX_M == 4U)
  1184. __DSB();
  1185. #endif
  1186. }
  1187. void LPUART1_RX_DriverIRQHandler(void)
  1188. {
  1189. s_lpuartIsr(LPUART1, s_lpuartHandle[1]);
  1190. /* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
  1191. exception return operation might vector to incorrect interrupt */
  1192. #if defined __CORTEX_M && (__CORTEX_M == 4U)
  1193. __DSB();
  1194. #endif
  1195. }
  1196. #else
  1197. void LPUART1_DriverIRQHandler(void)
  1198. {
  1199. s_lpuartIsr(LPUART1, s_lpuartHandle[1]);
  1200. /* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
  1201. exception return operation might vector to incorrect interrupt */
  1202. #if defined __CORTEX_M && (__CORTEX_M == 4U)
  1203. __DSB();
  1204. #endif
  1205. }
  1206. #endif
  1207. #endif
  1208. #endif
  1209. #if defined(LPUART2)
  1210. #if defined(FSL_FEATURE_LPUART_HAS_SEPARATE_RX_TX_IRQ) && FSL_FEATURE_LPUART_HAS_SEPARATE_RX_TX_IRQ
  1211. void LPUART2_TX_DriverIRQHandler(void)
  1212. {
  1213. s_lpuartIsr(LPUART2, s_lpuartHandle[2]);
  1214. /* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
  1215. exception return operation might vector to incorrect interrupt */
  1216. #if defined __CORTEX_M && (__CORTEX_M == 4U)
  1217. __DSB();
  1218. #endif
  1219. }
  1220. void LPUART2_RX_DriverIRQHandler(void)
  1221. {
  1222. s_lpuartIsr(LPUART2, s_lpuartHandle[2]);
  1223. /* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
  1224. exception return operation might vector to incorrect interrupt */
  1225. #if defined __CORTEX_M && (__CORTEX_M == 4U)
  1226. __DSB();
  1227. #endif
  1228. }
  1229. #else
  1230. void LPUART2_DriverIRQHandler(void)
  1231. {
  1232. s_lpuartIsr(LPUART2, s_lpuartHandle[2]);
  1233. /* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
  1234. exception return operation might vector to incorrect interrupt */
  1235. #if defined __CORTEX_M && (__CORTEX_M == 4U)
  1236. __DSB();
  1237. #endif
  1238. }
  1239. #endif
  1240. #endif
  1241. #if defined(LPUART3)
  1242. #if defined(FSL_FEATURE_LPUART_HAS_SEPARATE_RX_TX_IRQ) && FSL_FEATURE_LPUART_HAS_SEPARATE_RX_TX_IRQ
  1243. void LPUART3_TX_DriverIRQHandler(void)
  1244. {
  1245. s_lpuartIsr(LPUART3, s_lpuartHandle[3]);
  1246. /* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
  1247. exception return operation might vector to incorrect interrupt */
  1248. #if defined __CORTEX_M && (__CORTEX_M == 4U)
  1249. __DSB();
  1250. #endif
  1251. }
  1252. void LPUART3_RX_DriverIRQHandler(void)
  1253. {
  1254. s_lpuartIsr(LPUART3, s_lpuartHandle[3]);
  1255. /* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
  1256. exception return operation might vector to incorrect interrupt */
  1257. #if defined __CORTEX_M && (__CORTEX_M == 4U)
  1258. __DSB();
  1259. #endif
  1260. }
  1261. #else
  1262. void LPUART3_DriverIRQHandler(void)
  1263. {
  1264. s_lpuartIsr(LPUART3, s_lpuartHandle[3]);
  1265. /* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
  1266. exception return operation might vector to incorrect interrupt */
  1267. #if defined __CORTEX_M && (__CORTEX_M == 4U)
  1268. __DSB();
  1269. #endif
  1270. }
  1271. #endif
  1272. #endif
  1273. #if defined(LPUART4)
  1274. #if defined(FSL_FEATURE_LPUART_HAS_SEPARATE_RX_TX_IRQ) && FSL_FEATURE_LPUART_HAS_SEPARATE_RX_TX_IRQ
  1275. void LPUART4_TX_DriverIRQHandler(void)
  1276. {
  1277. s_lpuartIsr(LPUART4, s_lpuartHandle[4]);
  1278. /* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
  1279. exception return operation might vector to incorrect interrupt */
  1280. #if defined __CORTEX_M && (__CORTEX_M == 4U)
  1281. __DSB();
  1282. #endif
  1283. }
  1284. void LPUART4_RX_DriverIRQHandler(void)
  1285. {
  1286. s_lpuartIsr(LPUART4, s_lpuartHandle[4]);
  1287. /* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
  1288. exception return operation might vector to incorrect interrupt */
  1289. #if defined __CORTEX_M && (__CORTEX_M == 4U)
  1290. __DSB();
  1291. #endif
  1292. }
  1293. #else
  1294. void LPUART4_DriverIRQHandler(void)
  1295. {
  1296. s_lpuartIsr(LPUART4, s_lpuartHandle[4]);
  1297. /* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
  1298. exception return operation might vector to incorrect interrupt */
  1299. #if defined __CORTEX_M && (__CORTEX_M == 4U)
  1300. __DSB();
  1301. #endif
  1302. }
  1303. #endif
  1304. #endif
  1305. #if defined(LPUART5)
  1306. #if defined(FSL_FEATURE_LPUART_HAS_SEPARATE_RX_TX_IRQ) && FSL_FEATURE_LPUART_HAS_SEPARATE_RX_TX_IRQ
  1307. void LPUART5_TX_DriverIRQHandler(void)
  1308. {
  1309. s_lpuartIsr(LPUART5, s_lpuartHandle[5]);
  1310. /* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
  1311. exception return operation might vector to incorrect interrupt */
  1312. #if defined __CORTEX_M && (__CORTEX_M == 4U)
  1313. __DSB();
  1314. #endif
  1315. }
  1316. void LPUART5_RX_DriverIRQHandler(void)
  1317. {
  1318. s_lpuartIsr(LPUART5, s_lpuartHandle[5]);
  1319. /* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
  1320. exception return operation might vector to incorrect interrupt */
  1321. #if defined __CORTEX_M && (__CORTEX_M == 4U)
  1322. __DSB();
  1323. #endif
  1324. }
  1325. #else
  1326. void LPUART5_DriverIRQHandler(void)
  1327. {
  1328. s_lpuartIsr(LPUART5, s_lpuartHandle[5]);
  1329. /* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
  1330. exception return operation might vector to incorrect interrupt */
  1331. #if defined __CORTEX_M && (__CORTEX_M == 4U)
  1332. __DSB();
  1333. #endif
  1334. }
  1335. #endif
  1336. #endif
  1337. #if defined(LPUART6)
  1338. #if defined(FSL_FEATURE_LPUART_HAS_SEPARATE_RX_TX_IRQ) && FSL_FEATURE_LPUART_HAS_SEPARATE_RX_TX_IRQ
  1339. void LPUART6_TX_DriverIRQHandler(void)
  1340. {
  1341. s_lpuartIsr(LPUART6, s_lpuartHandle[6]);
  1342. /* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
  1343. exception return operation might vector to incorrect interrupt */
  1344. #if defined __CORTEX_M && (__CORTEX_M == 4U)
  1345. __DSB();
  1346. #endif
  1347. }
  1348. void LPUART6_RX_DriverIRQHandler(void)
  1349. {
  1350. s_lpuartIsr(LPUART6, s_lpuartHandle[6]);
  1351. /* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
  1352. exception return operation might vector to incorrect interrupt */
  1353. #if defined __CORTEX_M && (__CORTEX_M == 4U)
  1354. __DSB();
  1355. #endif
  1356. }
  1357. #else
  1358. void LPUART6_DriverIRQHandler(void)
  1359. {
  1360. s_lpuartIsr(LPUART6, s_lpuartHandle[6]);
  1361. /* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
  1362. exception return operation might vector to incorrect interrupt */
  1363. #if defined __CORTEX_M && (__CORTEX_M == 4U)
  1364. __DSB();
  1365. #endif
  1366. }
  1367. #endif
  1368. #endif
  1369. #if defined(LPUART7)
  1370. #if defined(FSL_FEATURE_LPUART_HAS_SEPARATE_RX_TX_IRQ) && FSL_FEATURE_LPUART_HAS_SEPARATE_RX_TX_IRQ
  1371. void LPUART7_TX_DriverIRQHandler(void)
  1372. {
  1373. s_lpuartIsr(LPUART7, s_lpuartHandle[7]);
  1374. /* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
  1375. exception return operation might vector to incorrect interrupt */
  1376. #if defined __CORTEX_M && (__CORTEX_M == 4U)
  1377. __DSB();
  1378. #endif
  1379. }
  1380. void LPUART7_RX_DriverIRQHandler(void)
  1381. {
  1382. s_lpuartIsr(LPUART7, s_lpuartHandle[7]);
  1383. /* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
  1384. exception return operation might vector to incorrect interrupt */
  1385. #if defined __CORTEX_M && (__CORTEX_M == 4U)
  1386. __DSB();
  1387. #endif
  1388. }
  1389. #else
  1390. void LPUART7_DriverIRQHandler(void)
  1391. {
  1392. s_lpuartIsr(LPUART7, s_lpuartHandle[7]);
  1393. /* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
  1394. exception return operation might vector to incorrect interrupt */
  1395. #if defined __CORTEX_M && (__CORTEX_M == 4U)
  1396. __DSB();
  1397. #endif
  1398. }
  1399. #endif
  1400. #endif
  1401. #if defined(LPUART8)
  1402. #if defined(FSL_FEATURE_LPUART_HAS_SEPARATE_RX_TX_IRQ) && FSL_FEATURE_LPUART_HAS_SEPARATE_RX_TX_IRQ
  1403. void LPUART8_TX_DriverIRQHandler(void)
  1404. {
  1405. s_lpuartIsr(LPUART8, s_lpuartHandle[8]);
  1406. /* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
  1407. exception return operation might vector to incorrect interrupt */
  1408. #if defined __CORTEX_M && (__CORTEX_M == 4U)
  1409. __DSB();
  1410. #endif
  1411. }
  1412. void LPUART8_RX_DriverIRQHandler(void)
  1413. {
  1414. s_lpuartIsr(LPUART8, s_lpuartHandle[8]);
  1415. /* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
  1416. exception return operation might vector to incorrect interrupt */
  1417. #if defined __CORTEX_M && (__CORTEX_M == 4U)
  1418. __DSB();
  1419. #endif
  1420. }
  1421. #else
  1422. void LPUART8_DriverIRQHandler(void)
  1423. {
  1424. s_lpuartIsr(LPUART8, s_lpuartHandle[8]);
  1425. /* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
  1426. exception return operation might vector to incorrect interrupt */
  1427. #if defined __CORTEX_M && (__CORTEX_M == 4U)
  1428. __DSB();
  1429. #endif
  1430. }
  1431. #endif
  1432. #endif
  1433. #if defined(CM4_0__LPUART)
  1434. void M4_0_LPUART_DriverIRQHandler(void)
  1435. {
  1436. s_lpuartIsr(CM4_0__LPUART, s_lpuartHandle[LPUART_GetInstance(CM4_0__LPUART)]);
  1437. /* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
  1438. exception return operation might vector to incorrect interrupt */
  1439. #if defined __CORTEX_M && (__CORTEX_M == 4U)
  1440. __DSB();
  1441. #endif
  1442. }
  1443. #endif
  1444. #if defined(CM4_1__LPUART)
  1445. void M4_1_LPUART_DriverIRQHandler(void)
  1446. {
  1447. s_lpuartIsr(CM4_1__LPUART, s_lpuartHandle[LPUART_GetInstance(CM4_1__LPUART)]);
  1448. /* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
  1449. exception return operation might vector to incorrect interrupt */
  1450. #if defined __CORTEX_M && (__CORTEX_M == 4U)
  1451. __DSB();
  1452. #endif
  1453. }
  1454. #endif
  1455. #if defined(CM4__LPUART)
  1456. void M4_LPUART_DriverIRQHandler(void)
  1457. {
  1458. s_lpuartIsr(CM4__LPUART, s_lpuartHandle[LPUART_GetInstance(CM4__LPUART)]);
  1459. /* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
  1460. exception return operation might vector to incorrect interrupt */
  1461. #if defined __CORTEX_M && (__CORTEX_M == 4U)
  1462. __DSB();
  1463. #endif
  1464. }
  1465. #endif
  1466. #if defined(DMA__LPUART0)
  1467. void DMA_UART0_INT_DriverIRQHandler(void)
  1468. {
  1469. s_lpuartIsr(DMA__LPUART0, s_lpuartHandle[LPUART_GetInstance(DMA__LPUART0)]);
  1470. /* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
  1471. exception return operation might vector to incorrect interrupt */
  1472. #if defined __CORTEX_M && (__CORTEX_M == 4U)
  1473. __DSB();
  1474. #endif
  1475. }
  1476. #endif
  1477. #if defined(DMA__LPUART1)
  1478. void DMA_UART1_INT_DriverIRQHandler(void)
  1479. {
  1480. s_lpuartIsr(DMA__LPUART1, s_lpuartHandle[LPUART_GetInstance(DMA__LPUART1)]);
  1481. /* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
  1482. exception return operation might vector to incorrect interrupt */
  1483. #if defined __CORTEX_M && (__CORTEX_M == 4U)
  1484. __DSB();
  1485. #endif
  1486. }
  1487. #endif
  1488. #if defined(DMA__LPUART2)
  1489. void DMA_UART2_INT_DriverIRQHandler(void)
  1490. {
  1491. s_lpuartIsr(DMA__LPUART2, s_lpuartHandle[LPUART_GetInstance(DMA__LPUART2)]);
  1492. /* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
  1493. exception return operation might vector to incorrect interrupt */
  1494. #if defined __CORTEX_M && (__CORTEX_M == 4U)
  1495. __DSB();
  1496. #endif
  1497. }
  1498. #endif
  1499. #if defined(DMA__LPUART3)
  1500. void DMA_UART3_INT_DriverIRQHandler(void)
  1501. {
  1502. s_lpuartIsr(DMA__LPUART3, s_lpuartHandle[LPUART_GetInstance(DMA__LPUART3)]);
  1503. /* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
  1504. exception return operation might vector to incorrect interrupt */
  1505. #if defined __CORTEX_M && (__CORTEX_M == 4U)
  1506. __DSB();
  1507. #endif
  1508. }
  1509. #endif
  1510. #if defined(DMA__LPUART4)
  1511. void DMA_UART4_INT_DriverIRQHandler(void)
  1512. {
  1513. s_lpuartIsr(DMA__LPUART4, s_lpuartHandle[LPUART_GetInstance(DMA__LPUART4)]);
  1514. /* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
  1515. exception return operation might vector to incorrect interrupt */
  1516. #if defined __CORTEX_M && (__CORTEX_M == 4U)
  1517. __DSB();
  1518. #endif
  1519. }
  1520. #endif
  1521. #if defined(ADMA__LPUART0)
  1522. void ADMA_UART0_INT_DriverIRQHandler(void)
  1523. {
  1524. s_lpuartIsr(ADMA__LPUART0, s_lpuartHandle[LPUART_GetInstance(ADMA__LPUART0)]);
  1525. /* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
  1526. exception return operation might vector to incorrect interrupt */
  1527. #if defined __CORTEX_M && (__CORTEX_M == 4U)
  1528. __DSB();
  1529. #endif
  1530. }
  1531. #endif
  1532. #if defined(ADMA__LPUART1)
  1533. void ADMA_UART1_INT_DriverIRQHandler(void)
  1534. {
  1535. s_lpuartIsr(ADMA__LPUART1, s_lpuartHandle[LPUART_GetInstance(ADMA__LPUART1)]);
  1536. /* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
  1537. exception return operation might vector to incorrect interrupt */
  1538. #if defined __CORTEX_M && (__CORTEX_M == 4U)
  1539. __DSB();
  1540. #endif
  1541. }
  1542. #endif
  1543. #if defined(ADMA__LPUART2)
  1544. void ADMA_UART2_INT_DriverIRQHandler(void)
  1545. {
  1546. s_lpuartIsr(ADMA__LPUART2, s_lpuartHandle[LPUART_GetInstance(ADMA__LPUART2)]);
  1547. /* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
  1548. exception return operation might vector to incorrect interrupt */
  1549. #if defined __CORTEX_M && (__CORTEX_M == 4U)
  1550. __DSB();
  1551. #endif
  1552. }
  1553. #endif
  1554. #if defined(ADMA__LPUART3)
  1555. void ADMA_UART3_INT_DriverIRQHandler(void)
  1556. {
  1557. s_lpuartIsr(ADMA__LPUART3, s_lpuartHandle[LPUART_GetInstance(ADMA__LPUART3)]);
  1558. /* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
  1559. exception return operation might vector to incorrect interrupt */
  1560. #if defined __CORTEX_M && (__CORTEX_M == 4U)
  1561. __DSB();
  1562. #endif
  1563. }
  1564. #endif