fsl_lpuart.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-2016, Freescale Semiconductor, Inc.
3  * Copyright 2016-2020 NXP
4  * All rights reserved.
5  *
6  * SPDX-License-Identifier: BSD-3-Clause
7  */
8 
9 #include "fsl_lpuart.h"
10 
11 /*******************************************************************************
12  * Definitions
13  ******************************************************************************/
14 
15 /* Component ID definition, used by tools. */
16 #ifndef FSL_COMPONENT_ID
17 #define FSL_COMPONENT_ID "platform.drivers.lpuart"
18 #endif
19 
20 /* LPUART transfer state. */
21 enum
22 {
27 };
28 
29 /* Typedef for interrupt handler. */
30 typedef void (*lpuart_isr_t)(LPUART_Type *base, lpuart_handle_t *handle);
31 
32 /*******************************************************************************
33  * Prototypes
34  ******************************************************************************/
43 
58 static void LPUART_WriteNonBlocking(LPUART_Type *base, const uint8_t *data, size_t length);
59 
70 static void LPUART_ReadNonBlocking(LPUART_Type *base, uint8_t *data, size_t length);
71 
72 /*******************************************************************************
73  * Variables
74  ******************************************************************************/
75 /* Array of LPUART peripheral base address. */
77 /* Array of LPUART handle. */
79 /* Array of LPUART IRQ number. */
80 #if defined(FSL_FEATURE_LPUART_HAS_SEPARATE_RX_TX_IRQ) && FSL_FEATURE_LPUART_HAS_SEPARATE_RX_TX_IRQ
81 static const IRQn_Type s_lpuartRxIRQ[] = LPUART_RX_IRQS;
82 static const IRQn_Type s_lpuartTxIRQ[] = LPUART_TX_IRQS;
83 #else
85 #endif
86 #if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
87 /* Array of LPUART clock name. */
89 
90 #if defined(LPUART_PERIPH_CLOCKS)
91 /* Array of LPUART functional clock name. */
92 static const clock_ip_name_t s_lpuartPeriphClocks[] = LPUART_PERIPH_CLOCKS;
93 #endif
94 
95 #endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
96 
97 /* LPUART ISR for transactional APIs. */
98 #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
99 static lpuart_isr_t s_lpuartIsr = (lpuart_isr_t)DefaultISR;
100 #else
102 #endif
103 
104 /*******************************************************************************
105  * Code
106  ******************************************************************************/
114 {
115  uint32_t instance;
116 
117  /* Find the instance index from base address mappings. */
118  for (instance = 0U; instance < ARRAY_SIZE(s_lpuartBases); instance++)
119  {
120  if (s_lpuartBases[instance] == base)
121  {
122  break;
123  }
124  }
125 
126  assert(instance < ARRAY_SIZE(s_lpuartBases));
127 
128  return instance;
129 }
130 
138 {
139  assert(NULL != handle);
140 
141  size_t size;
142  size_t tmpRxRingBufferSize = handle->rxRingBufferSize;
143  uint16_t tmpRxRingBufferTail = handle->rxRingBufferTail;
144  uint16_t tmpRxRingBufferHead = handle->rxRingBufferHead;
145 
146  if (tmpRxRingBufferTail > tmpRxRingBufferHead)
147  {
148  size = ((size_t)tmpRxRingBufferHead + tmpRxRingBufferSize - (size_t)tmpRxRingBufferTail);
149  }
150  else
151  {
152  size = ((size_t)tmpRxRingBufferHead - (size_t)tmpRxRingBufferTail);
153  }
154 
155  return size;
156 }
157 
159 {
160  assert(NULL != handle);
161 
162  bool full;
163 
164  if (LPUART_TransferGetRxRingBufferLength(base, handle) == (handle->rxRingBufferSize - 1U))
165  {
166  full = true;
167  }
168  else
169  {
170  full = false;
171  }
172  return full;
173 }
174 
175 static void LPUART_WriteNonBlocking(LPUART_Type *base, const uint8_t *data, size_t length)
176 {
177  assert(NULL != data);
178 
179  size_t i;
180 
181  /* The Non Blocking write data API assume user have ensured there is enough space in
182  peripheral to write. */
183  for (i = 0; i < length; i++)
184  {
185  base->DATA = data[i];
186  }
187 }
188 
189 static void LPUART_ReadNonBlocking(LPUART_Type *base, uint8_t *data, size_t length)
190 {
191  assert(NULL != data);
192 
193  size_t i;
194 #if defined(FSL_FEATURE_LPUART_HAS_7BIT_DATA_SUPPORT) && FSL_FEATURE_LPUART_HAS_7BIT_DATA_SUPPORT
195  uint32_t ctrl = base->CTRL;
196  bool isSevenDataBits = (((ctrl & LPUART_CTRL_M7_MASK) != 0U) ||
197  (((ctrl & LPUART_CTRL_M_MASK) == 0U) && ((ctrl & LPUART_CTRL_PE_MASK) != 0U)));
198 #endif
199 
200  /* The Non Blocking read data API assume user have ensured there is enough space in
201  peripheral to write. */
202  for (i = 0; i < length; i++)
203  {
204 #if defined(FSL_FEATURE_LPUART_HAS_7BIT_DATA_SUPPORT) && FSL_FEATURE_LPUART_HAS_7BIT_DATA_SUPPORT
205  if (isSevenDataBits)
206  {
207  data[i] = (uint8_t)(base->DATA & 0x7FU);
208  }
209  else
210  {
211  data[i] = (uint8_t)base->DATA;
212  }
213 #else
214  data[i] = (uint8_t)(base->DATA);
215 #endif
216  }
217 }
218 
243 status_t LPUART_Init(LPUART_Type *base, const lpuart_config_t *config, uint32_t srcClock_Hz)
244 {
245  assert(NULL != config);
246  assert(0U < config->baudRate_Bps);
247 #if defined(FSL_FEATURE_LPUART_HAS_FIFO) && FSL_FEATURE_LPUART_HAS_FIFO
248  assert((uint8_t)FSL_FEATURE_LPUART_FIFO_SIZEn(base) >= config->txFifoWatermark);
249  assert((uint8_t)FSL_FEATURE_LPUART_FIFO_SIZEn(base) >= config->rxFifoWatermark);
250 #endif
251 
252  status_t status = kStatus_Success;
253  uint32_t temp;
254  uint16_t sbr, sbrTemp;
255  uint8_t osr, osrTemp;
256  uint32_t tempDiff, calculatedBaud, baudDiff;
257 
258  /* This LPUART instantiation uses a slightly different baud rate calculation
259  * The idea is to use the best OSR (over-sampling rate) possible
260  * Note, OSR is typically hard-set to 16 in other LPUART instantiations
261  * loop to find the best OSR value possible, one that generates minimum baudDiff
262  * iterate through the rest of the supported values of OSR */
263 
264  baudDiff = config->baudRate_Bps;
265  osr = 0U;
266  sbr = 0U;
267  for (osrTemp = 4U; osrTemp <= 32U; osrTemp++)
268  {
269  /* calculate the temporary sbr value */
270  sbrTemp = (uint16_t)((srcClock_Hz * 10U / (config->baudRate_Bps * (uint32_t)osrTemp) + 5U) / 10U);
271  /*set sbrTemp to 1 if the sourceClockInHz can not satisfy the desired baud rate*/
272  if (sbrTemp == 0U)
273  {
274  sbrTemp = 1U;
275  }
276  /* Calculate the baud rate based on the temporary OSR and SBR values */
277  calculatedBaud = (srcClock_Hz / ((uint32_t)osrTemp * (uint32_t)sbrTemp));
278  tempDiff = calculatedBaud > config->baudRate_Bps ? (calculatedBaud - config->baudRate_Bps) :
279  (config->baudRate_Bps - calculatedBaud);
280 
281  if (tempDiff <= baudDiff)
282  {
283  baudDiff = tempDiff;
284  osr = osrTemp; /* update and store the best OSR value calculated */
285  sbr = sbrTemp; /* update store the best SBR value calculated */
286  }
287  }
288 
289  /* Check to see if actual baud rate is within 3% of desired baud rate
290  * based on the best calculate OSR value */
291  if (baudDiff > ((config->baudRate_Bps / 100U) * 3U))
292  {
293  /* Unacceptable baud rate difference of more than 3%*/
295  }
296  else
297  {
298 #if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
299 
300  uint32_t instance = LPUART_GetInstance(base);
301 
302  /* Enable lpuart clock */
303  CLOCK_EnableClock(s_lpuartClock[instance]);
304 #if defined(LPUART_PERIPH_CLOCKS)
305  CLOCK_EnableClock(s_lpuartPeriphClocks[instance]);
306 #endif
307 
308 #endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
309 
310 #if defined(FSL_FEATURE_LPUART_HAS_GLOBAL) && FSL_FEATURE_LPUART_HAS_GLOBAL
311  /*Reset all internal logic and registers, except the Global Register */
312  LPUART_SoftwareReset(base);
313 #else
314  /* Disable LPUART TX RX before setting. */
316 #endif
317 
318  temp = base->BAUD;
319 
320  /* Acceptable baud rate, check if OSR is between 4x and 7x oversampling.
321  * If so, then "BOTHEDGE" sampling must be turned on */
322  if ((osr > 3U) && (osr < 8U))
323  {
325  }
326 
327  /* program the osr value (bit value is one less than actual value) */
328  temp &= ~LPUART_BAUD_OSR_MASK;
329  temp |= LPUART_BAUD_OSR((uint32_t)osr - 1UL);
330 
331  /* write the sbr value to the BAUD registers */
332  temp &= ~LPUART_BAUD_SBR_MASK;
333  base->BAUD = temp | LPUART_BAUD_SBR(sbr);
334 
335  /* Set bit count and parity mode. */
336  base->BAUD &= ~LPUART_BAUD_M10_MASK;
337 
340 
341  temp |= (uint8_t)config->parityMode | LPUART_CTRL_IDLECFG(config->rxIdleConfig) |
342  LPUART_CTRL_ILT(config->rxIdleType);
343 
344 #if defined(FSL_FEATURE_LPUART_HAS_7BIT_DATA_SUPPORT) && FSL_FEATURE_LPUART_HAS_7BIT_DATA_SUPPORT
345  if (kLPUART_SevenDataBits == config->dataBitsCount)
346  {
347  if (kLPUART_ParityDisabled != config->parityMode)
348  {
349  temp &= ~LPUART_CTRL_M7_MASK; /* Seven data bits and one parity bit */
350  }
351  else
352  {
353  temp |= LPUART_CTRL_M7_MASK;
354  }
355  }
356  else
357 #endif
358  {
359  if (kLPUART_ParityDisabled != config->parityMode)
360  {
361  temp |= LPUART_CTRL_M_MASK; /* Eight data bits and one parity bit */
362  }
363  }
364 
365  base->CTRL = temp;
366 
367 #if defined(FSL_FEATURE_LPUART_HAS_STOP_BIT_CONFIG_SUPPORT) && FSL_FEATURE_LPUART_HAS_STOP_BIT_CONFIG_SUPPORT
368  /* set stop bit per char */
369  temp = base->BAUD & ~LPUART_BAUD_SBNS_MASK;
370  base->BAUD = temp | LPUART_BAUD_SBNS((uint8_t)config->stopBitCount);
371 #endif
372 
373 #if defined(FSL_FEATURE_LPUART_HAS_FIFO) && FSL_FEATURE_LPUART_HAS_FIFO
374  /* Set tx/rx WATER watermark
375  Note:
376  Take care of the RX FIFO, RX interrupt request only assert when received bytes
377  equal or more than RX water mark, there is potential issue if RX water
378  mark larger than 1.
379  For example, if RX FIFO water mark is 2, upper layer needs 5 bytes and
380  5 bytes are received. the last byte will be saved in FIFO but not trigger
381  RX interrupt because the water mark is 2.
382  */
383  base->WATER = (((uint32_t)(config->rxFifoWatermark) << 16U) | config->txFifoWatermark);
384 
385  /* Enable tx/rx FIFO */
387 
388  /* Flush FIFO */
390 #endif
391 
392  /* Clear all status flags */
395 
396 #if defined(FSL_FEATURE_LPUART_HAS_LIN_BREAK_DETECT) && FSL_FEATURE_LPUART_HAS_LIN_BREAK_DETECT
397  temp |= LPUART_STAT_LBKDIF_MASK;
398 #endif
399 
400 #if defined(FSL_FEATURE_LPUART_HAS_ADDRESS_MATCHING) && FSL_FEATURE_LPUART_HAS_ADDRESS_MATCHING
402 #endif
403 
404 #if defined(FSL_FEATURE_LPUART_HAS_MODEM_SUPPORT) && FSL_FEATURE_LPUART_HAS_MODEM_SUPPORT
405  /* Set the CTS configuration/TX CTS source. */
406  base->MODIR |= LPUART_MODIR_TXCTSC(config->txCtsConfig) | LPUART_MODIR_TXCTSSRC(config->txCtsSource);
407  if (true == config->enableRxRTS)
408  {
409  /* Enable the receiver RTS(request-to-send) function. */
411  }
412  if (true == config->enableTxCTS)
413  {
414  /* Enable the CTS(clear-to-send) function. */
416  }
417 #endif
418 
419  /* Set data bits order. */
420  if (true == config->isMsb)
421  {
422  temp |= LPUART_STAT_MSBF_MASK;
423  }
424  else
425  {
426  temp &= ~LPUART_STAT_MSBF_MASK;
427  }
428 
429  base->STAT |= temp;
430 
431  /* Enable TX/RX base on configure structure. */
432  temp = base->CTRL;
433  if (true == config->enableTx)
434  {
435  temp |= LPUART_CTRL_TE_MASK;
436  }
437 
438  if (true == config->enableRx)
439  {
440  temp |= LPUART_CTRL_RE_MASK;
441  }
442 
443  base->CTRL = temp;
444  }
445 
446  return status;
447 }
456 {
457  uint32_t temp;
458 
459 #if defined(FSL_FEATURE_LPUART_HAS_FIFO) && FSL_FEATURE_LPUART_HAS_FIFO
460  /* Wait tx FIFO send out*/
461  while (0U != ((base->WATER & LPUART_WATER_TXCOUNT_MASK) >> LPUART_WATER_TXWATER_SHIFT))
462  {
463  }
464 #endif
465  /* Wait last char shift out */
466  while (0U == (base->STAT & LPUART_STAT_TC_MASK))
467  {
468  }
469 
470  /* Clear all status flags */
473 
474 #if defined(FSL_FEATURE_LPUART_HAS_LIN_BREAK_DETECT) && FSL_FEATURE_LPUART_HAS_LIN_BREAK_DETECT
475  temp |= LPUART_STAT_LBKDIF_MASK;
476 #endif
477 
478 #if defined(FSL_FEATURE_LPUART_HAS_ADDRESS_MATCHING) && FSL_FEATURE_LPUART_HAS_ADDRESS_MATCHING
480 #endif
481 
482  base->STAT |= temp;
483 
484  /* Disable the module. */
485  base->CTRL = 0U;
486 
487 #if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
488  uint32_t instance = LPUART_GetInstance(base);
489 
490  /* Disable lpuart clock */
492 
493 #if defined(LPUART_PERIPH_CLOCKS)
494  CLOCK_DisableClock(s_lpuartPeriphClocks[instance]);
495 #endif
496 
497 #endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
498 }
499 
520 {
521  assert(NULL != config);
522 
523  /* Initializes the configure structure to zero. */
524  (void)memset(config, 0, sizeof(*config));
525 
526  config->baudRate_Bps = 115200U;
527  config->parityMode = kLPUART_ParityDisabled;
528  config->dataBitsCount = kLPUART_EightDataBits;
529  config->isMsb = false;
530 #if defined(FSL_FEATURE_LPUART_HAS_STOP_BIT_CONFIG_SUPPORT) && FSL_FEATURE_LPUART_HAS_STOP_BIT_CONFIG_SUPPORT
531  config->stopBitCount = kLPUART_OneStopBit;
532 #endif
533 #if defined(FSL_FEATURE_LPUART_HAS_FIFO) && FSL_FEATURE_LPUART_HAS_FIFO
534  config->txFifoWatermark = 0U;
535  config->rxFifoWatermark = 0U;
536 #endif
537 #if defined(FSL_FEATURE_LPUART_HAS_MODEM_SUPPORT) && FSL_FEATURE_LPUART_HAS_MODEM_SUPPORT
538  config->enableRxRTS = false;
539  config->enableTxCTS = false;
540  config->txCtsConfig = kLPUART_CtsSampleAtStart;
541  config->txCtsSource = kLPUART_CtsSourcePin;
542 #endif
543  config->rxIdleType = kLPUART_IdleTypeStartBit;
544  config->rxIdleConfig = kLPUART_IdleCharacter1;
545  config->enableTx = false;
546  config->enableRx = false;
547 }
548 
564 status_t LPUART_SetBaudRate(LPUART_Type *base, uint32_t baudRate_Bps, uint32_t srcClock_Hz)
565 {
566  assert(0U < baudRate_Bps);
567 
568  status_t status = kStatus_Success;
569  uint32_t temp, oldCtrl;
570  uint16_t sbr, sbrTemp;
571  uint8_t osr, osrTemp;
572  uint32_t tempDiff, calculatedBaud, baudDiff;
573 
574  /* This LPUART instantiation uses a slightly different baud rate calculation
575  * The idea is to use the best OSR (over-sampling rate) possible
576  * Note, OSR is typically hard-set to 16 in other LPUART instantiations
577  * loop to find the best OSR value possible, one that generates minimum baudDiff
578  * iterate through the rest of the supported values of OSR */
579 
580  baudDiff = baudRate_Bps;
581  osr = 0U;
582  sbr = 0U;
583  for (osrTemp = 4U; osrTemp <= 32U; osrTemp++)
584  {
585  /* calculate the temporary sbr value */
586  sbrTemp = (uint16_t)((srcClock_Hz * 10U / (baudRate_Bps * (uint32_t)osrTemp) + 5U) / 10U);
587  /*set sbrTemp to 1 if the sourceClockInHz can not satisfy the desired baud rate*/
588  if (sbrTemp == 0U)
589  {
590  sbrTemp = 1U;
591  }
592  /* Calculate the baud rate based on the temporary OSR and SBR values */
593  calculatedBaud = srcClock_Hz / ((uint32_t)osrTemp * (uint32_t)sbrTemp);
594 
595  tempDiff = calculatedBaud > baudRate_Bps ? (calculatedBaud - baudRate_Bps) : (baudRate_Bps - calculatedBaud);
596 
597  if (tempDiff <= baudDiff)
598  {
599  baudDiff = tempDiff;
600  osr = osrTemp; /* update and store the best OSR value calculated */
601  sbr = sbrTemp; /* update store the best SBR value calculated */
602  }
603  }
604 
605  /* Check to see if actual baud rate is within 3% of desired baud rate
606  * based on the best calculate OSR value */
607  if (baudDiff < (uint32_t)((baudRate_Bps / 100U) * 3U))
608  {
609  /* Store CTRL before disable Tx and Rx */
610  oldCtrl = base->CTRL;
611 
612  /* Disable LPUART TX RX before setting. */
614 
615  temp = base->BAUD;
616 
617  /* Acceptable baud rate, check if OSR is between 4x and 7x oversampling.
618  * If so, then "BOTHEDGE" sampling must be turned on */
619  if ((osr > 3U) && (osr < 8U))
620  {
622  }
623 
624  /* program the osr value (bit value is one less than actual value) */
625  temp &= ~LPUART_BAUD_OSR_MASK;
626  temp |= LPUART_BAUD_OSR((uint32_t)osr - 1UL);
627 
628  /* write the sbr value to the BAUD registers */
629  temp &= ~LPUART_BAUD_SBR_MASK;
630  base->BAUD = temp | LPUART_BAUD_SBR(sbr);
631 
632  /* Restore CTRL. */
633  base->CTRL = oldCtrl;
634  }
635  else
636  {
637  /* Unacceptable baud rate difference of more than 3%*/
639  }
640 
641  return status;
642 }
643 
657 void LPUART_EnableInterrupts(LPUART_Type *base, uint32_t mask)
658 {
659  base->BAUD |= ((mask << 8U) & (LPUART_BAUD_LBKDIE_MASK | LPUART_BAUD_RXEDGIE_MASK));
660 #if defined(FSL_FEATURE_LPUART_HAS_FIFO) && FSL_FEATURE_LPUART_HAS_FIFO
661  base->FIFO = (base->FIFO & ~(LPUART_FIFO_TXOF_MASK | LPUART_FIFO_RXUF_MASK)) |
662  ((mask << 8U) & (LPUART_FIFO_TXOFE_MASK | LPUART_FIFO_RXUFE_MASK));
663 #endif
664  mask &= 0xFFFFFF00U;
665  base->CTRL |= mask;
666 }
667 
681 void LPUART_DisableInterrupts(LPUART_Type *base, uint32_t mask)
682 {
683  base->BAUD &= ~((mask << 8U) & (LPUART_BAUD_LBKDIE_MASK | LPUART_BAUD_RXEDGIE_MASK));
684 #if defined(FSL_FEATURE_LPUART_HAS_FIFO) && FSL_FEATURE_LPUART_HAS_FIFO
685  base->FIFO = (base->FIFO & ~(LPUART_FIFO_TXOF_MASK | LPUART_FIFO_RXUF_MASK)) &
686  ~((mask << 8U) & (LPUART_FIFO_TXOFE_MASK | LPUART_FIFO_RXUFE_MASK));
687 #endif
688  mask &= 0xFFFFFF00U;
689  base->CTRL &= ~mask;
690 }
691 
713 {
714  uint32_t temp;
715  temp = (base->BAUD & (LPUART_BAUD_LBKDIE_MASK | LPUART_BAUD_RXEDGIE_MASK)) >> 8U;
716 #if defined(FSL_FEATURE_LPUART_HAS_FIFO) && FSL_FEATURE_LPUART_HAS_FIFO
717  temp |= (base->FIFO & (LPUART_FIFO_TXOFE_MASK | LPUART_FIFO_RXUFE_MASK)) >> 8U;
718 #endif
719  temp |= (uint32_t)(base->CTRL & 0xFF0C000u);
720 
721  return temp;
722 }
723 
742 {
743  uint32_t temp;
744  temp = base->STAT;
745 #if defined(FSL_FEATURE_LPUART_HAS_FIFO) && FSL_FEATURE_LPUART_HAS_FIFO
746  temp |= (base->FIFO &
748  16U;
749 #endif
750  return temp;
751 }
752 
773 {
774  uint32_t temp;
775  status_t status;
776 #if defined(FSL_FEATURE_LPUART_HAS_FIFO) && FSL_FEATURE_LPUART_HAS_FIFO
777  temp = (uint32_t)base->FIFO;
778  temp &= (uint32_t)(~(LPUART_FIFO_TXOF_MASK | LPUART_FIFO_RXUF_MASK));
779  temp |= (mask << 16U) & (LPUART_FIFO_TXOF_MASK | LPUART_FIFO_RXUF_MASK);
780  base->FIFO = temp;
781 #endif
782  temp = (uint32_t)base->STAT;
784  temp &= (uint32_t)(~(LPUART_STAT_LBKDIF_MASK));
785  temp |= mask & LPUART_STAT_LBKDIF_MASK;
786 #endif
791 #if defined(FSL_FEATURE_LPUART_HAS_ADDRESS_MATCHING) && FSL_FEATURE_LPUART_HAS_ADDRESS_MATCHING
792  temp &= (uint32_t)(~(LPUART_STAT_MA2F_MASK | LPUART_STAT_MA1F_MASK));
793  temp |= mask & (LPUART_STAT_MA2F_MASK | LPUART_STAT_MA1F_MASK);
794 #endif
795  base->STAT = temp;
796  /* If some flags still pending. */
797  if (0U != (mask & LPUART_GetStatusFlags(base)))
798  {
799  /* Some flags can only clear or set by the hardware itself, these flags are: kLPUART_TxDataRegEmptyFlag,
800  kLPUART_TransmissionCompleteFlag, kLPUART_RxDataRegFullFlag, kLPUART_RxActiveFlag,
801  kLPUART_NoiseErrorInRxDataRegFlag, kLPUART_ParityErrorInRxDataRegFlag,
802  kLPUART_TxFifoEmptyFlag, kLPUART_RxFifoEmptyFlag. */
803  status = kStatus_LPUART_FlagCannotClearManually; /* flags can not clear manually */
804  }
805  else
806  {
807  status = kStatus_Success;
808  }
809 
810  return status;
811 }
812 
825 status_t LPUART_WriteBlocking(LPUART_Type *base, const uint8_t *data, size_t length)
826 {
827  assert(NULL != data);
828 
829  const uint8_t *dataAddress = data;
830  size_t transferSize = length;
831 
832 #if UART_RETRY_TIMES
833  uint32_t waitTimes;
834 #endif
835 
836  while (0U != transferSize)
837  {
838 #if UART_RETRY_TIMES
839  waitTimes = UART_RETRY_TIMES;
840  while ((0U == (base->STAT & LPUART_STAT_TDRE_MASK)) && (0U != --waitTimes))
841 #else
842  while (0U == (base->STAT & LPUART_STAT_TDRE_MASK))
843 #endif
844  {
845  }
846 #if UART_RETRY_TIMES
847  if (0U == waitTimes)
848  {
849  return kStatus_LPUART_Timeout;
850  }
851 #endif
852  base->DATA = *(dataAddress);
853  dataAddress++;
854  transferSize--;
855  }
856  /* Ensure all the data in the transmit buffer are sent out to bus. */
857 #if UART_RETRY_TIMES
858  waitTimes = UART_RETRY_TIMES;
859  while ((0U == (base->STAT & LPUART_STAT_TC_MASK)) && (0U != --waitTimes))
860 #else
861  while (0U == (base->STAT & LPUART_STAT_TC_MASK))
862 #endif
863  {
864  }
865 #if UART_RETRY_TIMES
866  if (0U == waitTimes)
867  {
868  return kStatus_LPUART_Timeout;
869  }
870 #endif
871  return kStatus_Success;
872 }
873 
890 status_t LPUART_ReadBlocking(LPUART_Type *base, uint8_t *data, size_t length)
891 {
892  assert(NULL != data);
893 
894  status_t status = kStatus_Success;
895  uint32_t statusFlag;
896  uint8_t *dataAddress = data;
897 
898 #if defined(FSL_FEATURE_LPUART_HAS_7BIT_DATA_SUPPORT) && FSL_FEATURE_LPUART_HAS_7BIT_DATA_SUPPORT
899  uint32_t ctrl = base->CTRL;
900  bool isSevenDataBits = (((ctrl & LPUART_CTRL_M7_MASK) != 0U) ||
901  (((ctrl & LPUART_CTRL_M_MASK) == 0U) && ((ctrl & LPUART_CTRL_PE_MASK) != 0U)));
902 #endif
903 
904 #if UART_RETRY_TIMES
905  uint32_t waitTimes;
906 #endif
907 
908  while (0U != (length--))
909  {
910 #if UART_RETRY_TIMES
911  waitTimes = UART_RETRY_TIMES;
912 #endif
913 #if defined(FSL_FEATURE_LPUART_HAS_FIFO) && FSL_FEATURE_LPUART_HAS_FIFO
914  while (0U == ((base->WATER & LPUART_WATER_RXCOUNT_MASK) >> LPUART_WATER_RXCOUNT_SHIFT))
915 #else
916  while (0U == (base->STAT & LPUART_STAT_RDRF_MASK))
917 #endif
918  {
919 #if UART_RETRY_TIMES
920  if (0U == --waitTimes)
921  {
922  status = kStatus_LPUART_Timeout;
923  break;
924  }
925 #endif
926  statusFlag = LPUART_GetStatusFlags(base);
927 
928  if (0U != (statusFlag & (uint32_t)kLPUART_RxOverrunFlag))
929  {
930  status = ((kStatus_Success == LPUART_ClearStatusFlags(base, (uint32_t)kLPUART_RxOverrunFlag)) ?
933  /* Other error flags(FE, NF, and PF) are prevented from setting once OR is set, no need to check other
934  * error flags*/
935  break;
936  }
937 
938  if (0U != (statusFlag & (uint32_t)kLPUART_ParityErrorFlag))
939  {
940  status = ((kStatus_Success == LPUART_ClearStatusFlags(base, (uint32_t)kLPUART_ParityErrorFlag)) ?
943  }
944 
945  if (0U != (statusFlag & (uint32_t)kLPUART_FramingErrorFlag))
946  {
947  status = ((kStatus_Success == LPUART_ClearStatusFlags(base, (uint32_t)kLPUART_FramingErrorFlag)) ?
950  }
951 
952  if (0U != (statusFlag & (uint32_t)kLPUART_NoiseErrorFlag))
953  {
954  status = ((kStatus_Success == LPUART_ClearStatusFlags(base, (uint32_t)kLPUART_NoiseErrorFlag)) ?
957  }
958  if (kStatus_Success != status)
959  {
960  break;
961  }
962  }
963 
964  if (kStatus_Success == status)
965  {
966 #if defined(FSL_FEATURE_LPUART_HAS_7BIT_DATA_SUPPORT) && FSL_FEATURE_LPUART_HAS_7BIT_DATA_SUPPORT
967  if (isSevenDataBits)
968  {
969  *(dataAddress) = (uint8_t)(base->DATA & 0x7FU);
970  dataAddress++;
971  }
972  else
973  {
974  *(dataAddress) = (uint8_t)base->DATA;
975  dataAddress++;
976  }
977 #else
978  *(dataAddress) = (uint8_t)base->DATA;
979  dataAddress++;
980 #endif
981  }
982  else
983  {
984  break;
985  }
986  }
987 
988  return status;
989 }
990 
1010  lpuart_handle_t *handle,
1011  lpuart_transfer_callback_t callback,
1012  void *userData)
1013 {
1014  assert(NULL != handle);
1015 
1016  uint32_t instance;
1017 
1018 #if defined(FSL_FEATURE_LPUART_HAS_7BIT_DATA_SUPPORT) && FSL_FEATURE_LPUART_HAS_7BIT_DATA_SUPPORT
1019  uint32_t ctrl = base->CTRL;
1020  bool isSevenDataBits = (((ctrl & LPUART_CTRL_M7_MASK) != 0U) ||
1021  (((ctrl & LPUART_CTRL_M_MASK) == 0U) && ((ctrl & LPUART_CTRL_PE_MASK) != 0U)));
1022 #endif
1023 
1024  /* Zero the handle. */
1025  (void)memset(handle, 0, sizeof(lpuart_handle_t));
1026 
1027  /* Set the TX/RX state. */
1028  handle->rxState = (uint8_t)kLPUART_RxIdle;
1029  handle->txState = (uint8_t)kLPUART_TxIdle;
1030 
1031  /* Set the callback and user data. */
1032  handle->callback = callback;
1033  handle->userData = userData;
1034 
1035 #if defined(FSL_FEATURE_LPUART_HAS_7BIT_DATA_SUPPORT) && FSL_FEATURE_LPUART_HAS_7BIT_DATA_SUPPORT
1036  /* Initial seven data bits flag */
1037  handle->isSevenDataBits = isSevenDataBits;
1038 #endif
1039 
1040  /* Get instance from peripheral base address. */
1041  instance = LPUART_GetInstance(base);
1042 
1043  /* Save the handle in global variables to support the double weak mechanism. */
1044  s_lpuartHandle[instance] = handle;
1045 
1047 
1048 /* Enable interrupt in NVIC. */
1049 #if defined(FSL_FEATURE_LPUART_HAS_SEPARATE_RX_TX_IRQ) && FSL_FEATURE_LPUART_HAS_SEPARATE_RX_TX_IRQ
1050  (void)EnableIRQ(s_lpuartRxIRQ[instance]);
1051  (void)EnableIRQ(s_lpuartTxIRQ[instance]);
1052 #else
1053  (void)EnableIRQ(s_lpuartIRQ[instance]);
1054 #endif
1055 }
1056 
1075  lpuart_handle_t *handle,
1076  uint8_t *ringBuffer,
1077  size_t ringBufferSize)
1078 {
1079  assert(NULL != handle);
1080  assert(NULL != ringBuffer);
1081 
1082  /* Setup the ring buffer address */
1083  handle->rxRingBuffer = ringBuffer;
1084  handle->rxRingBufferSize = ringBufferSize;
1085  handle->rxRingBufferHead = 0U;
1086  handle->rxRingBufferTail = 0U;
1087 
1088  /* Enable the interrupt to accept the data when user need the ring buffer. */
1091 }
1092 
1102 {
1103  assert(NULL != handle);
1104 
1105  if (handle->rxState == (uint8_t)kLPUART_RxIdle)
1106  {
1109  }
1110 
1111  handle->rxRingBuffer = NULL;
1112  handle->rxRingBufferSize = 0U;
1113  handle->rxRingBufferHead = 0U;
1114  handle->rxRingBufferTail = 0U;
1115 }
1116 
1137 {
1138  assert(NULL != handle);
1139  assert(NULL != xfer);
1140  assert(NULL != xfer->data);
1141  assert(0U != xfer->dataSize);
1142 
1143  status_t status;
1144 
1145  /* Return error if current TX busy. */
1146  if ((uint8_t)kLPUART_TxBusy == handle->txState)
1147  {
1148  status = kStatus_LPUART_TxBusy;
1149  }
1150  else
1151  {
1152  handle->txData = xfer->data;
1153  handle->txDataSize = xfer->dataSize;
1154  handle->txDataSizeAll = xfer->dataSize;
1155  handle->txState = (uint8_t)kLPUART_TxBusy;
1156 
1157  /* Enable transmitter interrupt. */
1159 
1160  status = kStatus_Success;
1161  }
1162 
1163  return status;
1164 }
1165 
1176 {
1177  assert(NULL != handle);
1178 
1181 
1182  handle->txDataSize = 0;
1183  handle->txState = (uint8_t)kLPUART_TxIdle;
1184 }
1185 
1199 {
1200  assert(NULL != handle);
1201  assert(NULL != count);
1202 
1203  status_t status = kStatus_Success;
1204  size_t tmptxDataSize = handle->txDataSize;
1205 
1206  if ((uint8_t)kLPUART_TxIdle == handle->txState)
1207  {
1209  }
1210  else
1211  {
1212 #if defined(FSL_FEATURE_LPUART_HAS_FIFO) && FSL_FEATURE_LPUART_HAS_FIFO
1213  *count = handle->txDataSizeAll - tmptxDataSize -
1215 #else
1216  if ((base->STAT & (uint32_t)kLPUART_TxDataRegEmptyFlag) != 0U)
1217  {
1218  *count = handle->txDataSizeAll - tmptxDataSize;
1219  }
1220  else
1221  {
1222  *count = handle->txDataSizeAll - tmptxDataSize - 1U;
1223  }
1224 #endif
1225  }
1226 
1227  return status;
1228 }
1229 
1257  lpuart_handle_t *handle,
1258  lpuart_transfer_t *xfer,
1259  size_t *receivedBytes)
1260 {
1261  assert(NULL != handle);
1262  assert(NULL != xfer);
1263  assert(NULL != xfer->data);
1264  assert(0U != xfer->dataSize);
1265 
1266  uint32_t i;
1267  status_t status;
1268  /* How many bytes to copy from ring buffer to user memory. */
1269  size_t bytesToCopy = 0U;
1270  /* How many bytes to receive. */
1271  size_t bytesToReceive;
1272  /* How many bytes currently have received. */
1273  size_t bytesCurrentReceived;
1274 
1275  /* How to get data:
1276  1. If RX ring buffer is not enabled, then save xfer->data and xfer->dataSize
1277  to lpuart handle, enable interrupt to store received data to xfer->data. When
1278  all data received, trigger callback.
1279  2. If RX ring buffer is enabled and not empty, get data from ring buffer first.
1280  If there are enough data in ring buffer, copy them to xfer->data and return.
1281  If there are not enough data in ring buffer, copy all of them to xfer->data,
1282  save the xfer->data remained empty space to lpuart handle, receive data
1283  to this empty space and trigger callback when finished. */
1284 
1285  if ((uint8_t)kLPUART_RxBusy == handle->rxState)
1286  {
1287  status = kStatus_LPUART_RxBusy;
1288  }
1289  else
1290  {
1291  bytesToReceive = xfer->dataSize;
1292  bytesCurrentReceived = 0;
1293 
1294  /* If RX ring buffer is used. */
1295  if (NULL != handle->rxRingBuffer)
1296  {
1297  /* Disable LPUART RX IRQ, protect ring buffer. */
1299 
1300  /* How many bytes in RX ring buffer currently. */
1301  bytesToCopy = LPUART_TransferGetRxRingBufferLength(base, handle);
1302 
1303  if (0U != bytesToCopy)
1304  {
1305  bytesToCopy = MIN(bytesToReceive, bytesToCopy);
1306 
1307  bytesToReceive -= bytesToCopy;
1308 
1309  /* Copy data from ring buffer to user memory. */
1310  for (i = 0U; i < bytesToCopy; i++)
1311  {
1312  xfer->data[bytesCurrentReceived] = handle->rxRingBuffer[handle->rxRingBufferTail];
1313  bytesCurrentReceived++;
1314 
1315  /* Wrap to 0. Not use modulo (%) because it might be large and slow. */
1316  if (((uint32_t)handle->rxRingBufferTail + 1U) == handle->rxRingBufferSize)
1317  {
1318  handle->rxRingBufferTail = 0U;
1319  }
1320  else
1321  {
1322  handle->rxRingBufferTail++;
1323  }
1324  }
1325  }
1326 
1327  /* If ring buffer does not have enough data, still need to read more data. */
1328  if (0U != bytesToReceive)
1329  {
1330  /* No data in ring buffer, save the request to LPUART handle. */
1331  handle->rxData = xfer->data + bytesCurrentReceived;
1332  handle->rxDataSize = bytesToReceive;
1333  handle->rxDataSizeAll = bytesToReceive;
1334  handle->rxState = (uint8_t)kLPUART_RxBusy;
1335  }
1336  /* Enable LPUART RX IRQ if previously enabled. */
1338 
1339  /* Call user callback since all data are received. */
1340  if (0U == bytesToReceive)
1341  {
1342  if (NULL != handle->callback)
1343  {
1344  handle->callback(base, handle, kStatus_LPUART_RxIdle, handle->userData);
1345  }
1346  }
1347  }
1348  /* Ring buffer not used. */
1349  else
1350  {
1351  handle->rxData = xfer->data + bytesCurrentReceived;
1352  handle->rxDataSize = bytesToReceive;
1353  handle->rxDataSizeAll = bytesToReceive;
1354  handle->rxState = (uint8_t)kLPUART_RxBusy;
1355 
1356  /* Enable RX interrupt. */
1360  }
1361 
1362  /* Return the how many bytes have read. */
1363  if (NULL != receivedBytes)
1364  {
1365  *receivedBytes = bytesCurrentReceived;
1366  }
1367 
1368  status = kStatus_Success;
1369  }
1370 
1371  return status;
1372 }
1373 
1384 {
1385  assert(NULL != handle);
1386 
1387  /* Only abort the receive to handle->rxData, the RX ring buffer is still working. */
1388  if (NULL == handle->rxRingBuffer)
1389  {
1390  /* Disable RX interrupt. */
1394  }
1395 
1396  handle->rxDataSize = 0U;
1397  handle->rxState = (uint8_t)kLPUART_RxIdle;
1398 }
1399 
1413 {
1414  assert(NULL != handle);
1415  assert(NULL != count);
1416 
1417  status_t status = kStatus_Success;
1418  size_t tmprxDataSize = handle->rxDataSize;
1419 
1420  if ((uint8_t)kLPUART_RxIdle == handle->rxState)
1421  {
1423  }
1424  else
1425  {
1426  *count = handle->rxDataSizeAll - tmprxDataSize;
1427  }
1428 
1429  return status;
1430 }
1431 
1441 {
1442  assert(NULL != handle);
1443 
1444  uint8_t count;
1445  uint8_t tempCount;
1446  uint32_t status = LPUART_GetStatusFlags(base);
1447  uint32_t enabledInterrupts = LPUART_GetEnabledInterrupts(base);
1448  uint16_t tpmRxRingBufferHead;
1449  uint32_t tpmData;
1450 
1451  /* If RX overrun. */
1452  if ((uint32_t)kLPUART_RxOverrunFlag == ((uint32_t)kLPUART_RxOverrunFlag & status))
1453  {
1454  /* Clear overrun flag, otherwise the RX does not work. */
1455  base->STAT = ((base->STAT & 0x3FE00000U) | LPUART_STAT_OR_MASK);
1456 
1457  /* Trigger callback. */
1458  if (NULL != (handle->callback))
1459  {
1460  handle->callback(base, handle, kStatus_LPUART_RxHardwareOverrun, handle->userData);
1461  }
1462  }
1463 
1464  /* If IDLE flag is set and the IDLE interrupt is enabled. */
1465  if ((0U != ((uint32_t)kLPUART_IdleLineFlag & status)) &&
1466  (0U != ((uint32_t)kLPUART_IdleLineInterruptEnable & enabledInterrupts)))
1467  {
1468 #if defined(FSL_FEATURE_LPUART_HAS_FIFO) && FSL_FEATURE_LPUART_HAS_FIFO
1470 
1471  while ((0U != handle->rxDataSize) && (0U != count))
1472  {
1473  tempCount = (uint8_t)MIN(handle->rxDataSize, count);
1474 
1475  /* Using non block API to read the data from the registers. */
1476  LPUART_ReadNonBlocking(base, handle->rxData, tempCount);
1477  handle->rxData += tempCount;
1478  handle->rxDataSize -= tempCount;
1479  count -= tempCount;
1480 
1481  /* If rxDataSize is 0, disable idle line interrupt.*/
1482  if (0U == (handle->rxDataSize))
1483  {
1484  handle->rxState = (uint8_t)kLPUART_RxIdle;
1485 
1488  if (NULL != handle->callback)
1489  {
1490  handle->callback(base, handle, kStatus_LPUART_RxIdle, handle->userData);
1491  }
1492  }
1493  }
1494 #endif
1495  /* Clear IDLE flag.*/
1496  base->STAT |= LPUART_STAT_IDLE_MASK;
1497 
1498  /* If rxDataSize is 0, disable idle line interrupt.*/
1499  if (0U != (handle->rxDataSize))
1500  {
1502  }
1503  /* If callback is not NULL and rxDataSize is not 0. */
1504  if ((0U != handle->rxDataSize) && (NULL != handle->callback))
1505  {
1506  handle->callback(base, handle, kStatus_LPUART_IdleLineDetected, handle->userData);
1507  }
1508  }
1509  /* Receive data register full */
1510  if ((0U != ((uint32_t)kLPUART_RxDataRegFullFlag & status)) &&
1511  (0U != ((uint32_t)kLPUART_RxDataRegFullInterruptEnable & enabledInterrupts)))
1512  {
1513 /* Get the size that can be stored into buffer for this interrupt. */
1514 #if defined(FSL_FEATURE_LPUART_HAS_FIFO) && FSL_FEATURE_LPUART_HAS_FIFO
1516 #else
1517  count = 1;
1518 #endif
1519 
1520  /* If handle->rxDataSize is not 0, first save data to handle->rxData. */
1521  while ((0U != handle->rxDataSize) && (0U != count))
1522  {
1523 #if defined(FSL_FEATURE_LPUART_HAS_FIFO) && FSL_FEATURE_LPUART_HAS_FIFO
1524  tempCount = (uint8_t)MIN(handle->rxDataSize, count);
1525 #else
1526  tempCount = 1;
1527 #endif
1528 
1529  /* Using non block API to read the data from the registers. */
1530  LPUART_ReadNonBlocking(base, handle->rxData, tempCount);
1531  handle->rxData += tempCount;
1532  handle->rxDataSize -= tempCount;
1533  count -= tempCount;
1534 
1535  /* If all the data required for upper layer is ready, trigger callback. */
1536  if (0U == handle->rxDataSize)
1537  {
1538  handle->rxState = (uint8_t)kLPUART_RxIdle;
1539 
1540  if (NULL != handle->callback)
1541  {
1542  handle->callback(base, handle, kStatus_LPUART_RxIdle, handle->userData);
1543  }
1544  }
1545  }
1546 
1547  /* If use RX ring buffer, receive data to ring buffer. */
1548  if (NULL != handle->rxRingBuffer)
1549  {
1550  while (0U != count--)
1551  {
1552  /* If RX ring buffer is full, trigger callback to notify over run. */
1553  if (LPUART_TransferIsRxRingBufferFull(base, handle))
1554  {
1555  if (NULL != handle->callback)
1556  {
1557  handle->callback(base, handle, kStatus_LPUART_RxRingBufferOverrun, handle->userData);
1558  }
1559  }
1560 
1561  /* If ring buffer is still full after callback function, the oldest data is overridden. */
1562  if (LPUART_TransferIsRxRingBufferFull(base, handle))
1563  {
1564  /* Increase handle->rxRingBufferTail to make room for new data. */
1565  if (((uint32_t)handle->rxRingBufferTail + 1U) == handle->rxRingBufferSize)
1566  {
1567  handle->rxRingBufferTail = 0U;
1568  }
1569  else
1570  {
1571  handle->rxRingBufferTail++;
1572  }
1573  }
1574 
1575  /* Read data. */
1576  tpmRxRingBufferHead = handle->rxRingBufferHead;
1577  tpmData = base->DATA;
1578 #if defined(FSL_FEATURE_LPUART_HAS_7BIT_DATA_SUPPORT) && FSL_FEATURE_LPUART_HAS_7BIT_DATA_SUPPORT
1579  if (handle->isSevenDataBits)
1580  {
1581  handle->rxRingBuffer[tpmRxRingBufferHead] = (uint8_t)(tpmData & 0x7FU);
1582  }
1583  else
1584  {
1585  handle->rxRingBuffer[tpmRxRingBufferHead] = (uint8_t)tpmData;
1586  }
1587 #else
1588  handle->rxRingBuffer[tpmRxRingBufferHead] = (uint8_t)tpmData;
1589 #endif
1590 
1591  /* Increase handle->rxRingBufferHead. */
1592  if (((uint32_t)handle->rxRingBufferHead + 1U) == handle->rxRingBufferSize)
1593  {
1594  handle->rxRingBufferHead = 0U;
1595  }
1596  else
1597  {
1598  handle->rxRingBufferHead++;
1599  }
1600  }
1601  }
1602  /* If no receive requst pending, stop RX interrupt. */
1603  else if (0U == handle->rxDataSize)
1604  {
1607  }
1608  else
1609  {
1610  }
1611  }
1612 
1613  /* Send data register empty and the interrupt is enabled. */
1614  if ((0U != ((uint32_t)kLPUART_TxDataRegEmptyFlag & status)) &&
1615  (0U != ((uint32_t)kLPUART_TxDataRegEmptyInterruptEnable & enabledInterrupts)))
1616  {
1617 /* Get the bytes that available at this moment. */
1618 #if defined(FSL_FEATURE_LPUART_HAS_FIFO) && FSL_FEATURE_LPUART_HAS_FIFO
1619  count = (uint8_t)FSL_FEATURE_LPUART_FIFO_SIZEn(base) -
1621 #else
1622  count = 1;
1623 #endif
1624 
1625  while ((0U != handle->txDataSize) && (0U != count))
1626  {
1627 #if defined(FSL_FEATURE_LPUART_HAS_FIFO) && FSL_FEATURE_LPUART_HAS_FIFO
1628  tempCount = (uint8_t)MIN(handle->txDataSize, count);
1629 #else
1630  tempCount = 1;
1631 #endif
1632 
1633  /* Using non block API to write the data to the registers. */
1634  LPUART_WriteNonBlocking(base, handle->txData, tempCount);
1635  handle->txData += tempCount;
1636  handle->txDataSize -= tempCount;
1637  count -= tempCount;
1638 
1639  /* If all the data are written to data register, notify user with the callback, then TX finished. */
1640  if (0U == handle->txDataSize)
1641  {
1642  /* Disable TX register empty interrupt. */
1643  base->CTRL = (base->CTRL & ~LPUART_CTRL_TIE_MASK);
1644  /* Enable transmission complete interrupt. */
1646  }
1647  }
1648  }
1649 
1650  /* Transmission complete and the interrupt is enabled. */
1651  if ((0U != ((uint32_t)kLPUART_TransmissionCompleteFlag & status)) &&
1652  (0U != ((uint32_t)kLPUART_TransmissionCompleteInterruptEnable & enabledInterrupts)))
1653  {
1654  /* Set txState to idle only when all data has been sent out to bus. */
1655  handle->txState = (uint8_t)kLPUART_TxIdle;
1656  /* Disable transmission complete interrupt. */
1658 
1659  /* Trigger callback. */
1660  if (NULL != handle->callback)
1661  {
1662  handle->callback(base, handle, kStatus_LPUART_TxIdle, handle->userData);
1663  }
1664  }
1665 }
1666 
1676 {
1677  /* To be implemented by User. */
1678 }
1679 #if defined(FSL_FEATURE_LPUART_HAS_SHARED_IRQ0_IRQ1) && FSL_FEATURE_LPUART_HAS_SHARED_IRQ0_IRQ1
1680 #if defined(FSL_FEATURE_LPUART_HAS_SEPARATE_RX_TX_IRQ) && FSL_FEATURE_LPUART_HAS_SEPARATE_RX_TX_IRQ
1681 void LPUART0_LPUART1_RX_DriverIRQHandler(void)
1682 {
1683  uint32_t stat = 0U;
1684  uint32_t ctrl = 0U;
1685 
1686  if (CLOCK_isEnabledClock(s_lpuartClock[0]))
1687  {
1688  stat = LPUART0->STAT;
1689  ctrl = LPUART0->CTRL;
1690  if ((LPUART_STAT_OR_MASK & stat) || ((LPUART_STAT_RDRF_MASK & stat) && (LPUART_CTRL_RIE_MASK & ctrl)))
1691  {
1692  s_lpuartIsr(LPUART0, s_lpuartHandle[0]);
1693  }
1694  }
1695  if (CLOCK_isEnabledClock(s_lpuartClock[1]))
1696  {
1697  stat = LPUART1->STAT;
1698  ctrl = LPUART1->CTRL;
1699  if ((LPUART_STAT_OR_MASK & stat) || ((LPUART_STAT_RDRF_MASK & stat) && (LPUART_CTRL_RIE_MASK & ctrl)))
1700  {
1702  }
1703  }
1705 }
1706 void LPUART0_LPUART1_TX_DriverIRQHandler(void)
1707 {
1708  uint32_t stat = 0U;
1709  uint32_t ctrl = 0U;
1710 
1711  if (CLOCK_isEnabledClock(s_lpuartClock[0]))
1712  {
1713  stat = LPUART0->STAT;
1714  ctrl = LPUART0->CTRL;
1715  if ((LPUART_STAT_OR_MASK & stat) || ((stat & LPUART_STAT_TDRE_MASK) && (ctrl & LPUART_CTRL_TIE_MASK)))
1716  {
1717  s_lpuartIsr(LPUART0, s_lpuartHandle[0]);
1718  }
1719  }
1720  if (CLOCK_isEnabledClock(s_lpuartClock[1]))
1721  {
1722  stat = LPUART1->STAT;
1723  ctrl = LPUART1->CTRL;
1724  if ((LPUART_STAT_OR_MASK & stat) || ((stat & LPUART_STAT_TDRE_MASK) && (ctrl & LPUART_CTRL_TIE_MASK)))
1725  {
1727  }
1728  }
1730 }
1731 #else
1732 void LPUART0_LPUART1_DriverIRQHandler(void)
1733 {
1734  uint32_t stat = 0U;
1735  uint32_t ctrl = 0U;
1736 
1737  if (CLOCK_isEnabledClock(s_lpuartClock[0]))
1738  {
1739  stat = LPUART0->STAT;
1740  ctrl = LPUART0->CTRL;
1741  if ((0U != (LPUART_STAT_OR_MASK & stat)) ||
1742  ((0U != (LPUART_STAT_RDRF_MASK & stat)) && (0U != (LPUART_CTRL_RIE_MASK & ctrl))) ||
1743  ((0U != (stat & LPUART_STAT_TDRE_MASK)) && (0U != (ctrl & LPUART_CTRL_TIE_MASK))))
1744  {
1745  s_lpuartIsr(LPUART0, s_lpuartHandle[0]);
1746  }
1747  }
1748  if (CLOCK_isEnabledClock(s_lpuartClock[1]))
1749  {
1750  stat = LPUART1->STAT;
1751  ctrl = LPUART1->CTRL;
1752  if ((0U != (LPUART_STAT_OR_MASK & stat)) ||
1753  ((0U != (LPUART_STAT_RDRF_MASK & stat)) && (0U != (LPUART_CTRL_RIE_MASK & ctrl))) ||
1754  ((0U != (stat & LPUART_STAT_TDRE_MASK)) && (0U != (ctrl & LPUART_CTRL_TIE_MASK))))
1755  {
1757  }
1758  }
1760 }
1761 #endif
1762 #endif
1763 
1764 #if defined(LPUART0)
1765 #if !(defined(FSL_FEATURE_LPUART_HAS_SHARED_IRQ0_IRQ1) && FSL_FEATURE_LPUART_HAS_SHARED_IRQ0_IRQ1)
1766 #if defined(FSL_FEATURE_LPUART_HAS_SEPARATE_RX_TX_IRQ) && FSL_FEATURE_LPUART_HAS_SEPARATE_RX_TX_IRQ
1767 void LPUART0_TX_DriverIRQHandler(void)
1768 {
1769  s_lpuartIsr(LPUART0, s_lpuartHandle[0]);
1771 }
1772 void LPUART0_RX_DriverIRQHandler(void)
1773 {
1774  s_lpuartIsr(LPUART0, s_lpuartHandle[0]);
1776 }
1777 #else
1778 void LPUART0_DriverIRQHandler(void)
1779 {
1780  s_lpuartIsr(LPUART0, s_lpuartHandle[0]);
1782 }
1783 #endif
1784 #endif
1785 #endif
1786 
1787 #if defined(LPUART1)
1788 #if !(defined(FSL_FEATURE_LPUART_HAS_SHARED_IRQ0_IRQ1) && FSL_FEATURE_LPUART_HAS_SHARED_IRQ0_IRQ1)
1789 #if defined(FSL_FEATURE_LPUART_HAS_SEPARATE_RX_TX_IRQ) && FSL_FEATURE_LPUART_HAS_SEPARATE_RX_TX_IRQ
1790 void LPUART1_TX_DriverIRQHandler(void)
1791 {
1794 }
1795 void LPUART1_RX_DriverIRQHandler(void)
1796 {
1799 }
1800 #else
1801 void LPUART1_DriverIRQHandler(void)
1802 {
1805 }
1806 #endif
1807 #endif
1808 #endif
1809 
1810 #if defined(LPUART2)
1811 #if defined(FSL_FEATURE_LPUART_HAS_SEPARATE_RX_TX_IRQ) && FSL_FEATURE_LPUART_HAS_SEPARATE_RX_TX_IRQ
1812 void LPUART2_TX_DriverIRQHandler(void)
1813 {
1816 }
1817 void LPUART2_RX_DriverIRQHandler(void)
1818 {
1821 }
1822 #else
1823 void LPUART2_DriverIRQHandler(void)
1824 {
1827 }
1828 #endif
1829 #endif
1830 
1831 #if defined(LPUART3)
1832 #if defined(FSL_FEATURE_LPUART_HAS_SEPARATE_RX_TX_IRQ) && FSL_FEATURE_LPUART_HAS_SEPARATE_RX_TX_IRQ
1833 void LPUART3_TX_DriverIRQHandler(void)
1834 {
1837 }
1838 void LPUART3_RX_DriverIRQHandler(void)
1839 {
1842 }
1843 #else
1844 void LPUART3_DriverIRQHandler(void)
1845 {
1848 }
1849 #endif
1850 #endif
1851 
1852 #if defined(LPUART4)
1853 #if defined(FSL_FEATURE_LPUART_HAS_SEPARATE_RX_TX_IRQ) && FSL_FEATURE_LPUART_HAS_SEPARATE_RX_TX_IRQ
1854 void LPUART4_TX_DriverIRQHandler(void)
1855 {
1858 }
1859 void LPUART4_RX_DriverIRQHandler(void)
1860 {
1863 }
1864 #else
1865 void LPUART4_DriverIRQHandler(void)
1866 {
1869 }
1870 #endif
1871 #endif
1872 
1873 #if defined(LPUART5)
1874 #if defined(FSL_FEATURE_LPUART_HAS_SEPARATE_RX_TX_IRQ) && FSL_FEATURE_LPUART_HAS_SEPARATE_RX_TX_IRQ
1875 void LPUART5_TX_DriverIRQHandler(void)
1876 {
1879 }
1880 void LPUART5_RX_DriverIRQHandler(void)
1881 {
1884 }
1885 #else
1886 void LPUART5_DriverIRQHandler(void)
1887 {
1890 }
1891 #endif
1892 #endif
1893 
1894 #if defined(LPUART6)
1895 #if defined(FSL_FEATURE_LPUART_HAS_SEPARATE_RX_TX_IRQ) && FSL_FEATURE_LPUART_HAS_SEPARATE_RX_TX_IRQ
1896 void LPUART6_TX_DriverIRQHandler(void)
1897 {
1900 }
1901 void LPUART6_RX_DriverIRQHandler(void)
1902 {
1905 }
1906 #else
1907 void LPUART6_DriverIRQHandler(void)
1908 {
1911 }
1912 #endif
1913 #endif
1914 
1915 #if defined(LPUART7)
1916 #if defined(FSL_FEATURE_LPUART_HAS_SEPARATE_RX_TX_IRQ) && FSL_FEATURE_LPUART_HAS_SEPARATE_RX_TX_IRQ
1917 void LPUART7_TX_DriverIRQHandler(void)
1918 {
1921 }
1922 void LPUART7_RX_DriverIRQHandler(void)
1923 {
1926 }
1927 #else
1928 void LPUART7_DriverIRQHandler(void)
1929 {
1932 }
1933 #endif
1934 #endif
1935 
1936 #if defined(LPUART8)
1937 #if defined(FSL_FEATURE_LPUART_HAS_SEPARATE_RX_TX_IRQ) && FSL_FEATURE_LPUART_HAS_SEPARATE_RX_TX_IRQ
1938 void LPUART8_TX_DriverIRQHandler(void)
1939 {
1942 }
1943 void LPUART8_RX_DriverIRQHandler(void)
1944 {
1947 }
1948 #else
1949 void LPUART8_DriverIRQHandler(void)
1950 {
1953 }
1954 #endif
1955 #endif
1956 
1957 #if defined(CM4_0__LPUART)
1958 void M4_0_LPUART_DriverIRQHandler(void)
1959 {
1960  s_lpuartIsr(CM4_0__LPUART, s_lpuartHandle[LPUART_GetInstance(CM4_0__LPUART)]);
1962 }
1963 #endif
1964 
1965 #if defined(CM4_1__LPUART)
1966 void M4_1_LPUART_DriverIRQHandler(void)
1967 {
1968  s_lpuartIsr(CM4_1__LPUART, s_lpuartHandle[LPUART_GetInstance(CM4_1__LPUART)]);
1970 }
1971 #endif
1972 
1973 #if defined(CM4__LPUART)
1974 void M4_LPUART_DriverIRQHandler(void)
1975 {
1976  s_lpuartIsr(CM4__LPUART, s_lpuartHandle[LPUART_GetInstance(CM4__LPUART)]);
1978 }
1979 #endif
1980 
1981 #if defined(DMA__LPUART0)
1982 void DMA_UART0_INT_DriverIRQHandler(void)
1983 {
1984  s_lpuartIsr(DMA__LPUART0, s_lpuartHandle[LPUART_GetInstance(DMA__LPUART0)]);
1986 }
1987 #endif
1988 
1989 #if defined(DMA__LPUART1)
1990 void DMA_UART1_INT_DriverIRQHandler(void)
1991 {
1992  s_lpuartIsr(DMA__LPUART1, s_lpuartHandle[LPUART_GetInstance(DMA__LPUART1)]);
1994 }
1995 #endif
1996 
1997 #if defined(DMA__LPUART2)
1998 void DMA_UART2_INT_DriverIRQHandler(void)
1999 {
2000  s_lpuartIsr(DMA__LPUART2, s_lpuartHandle[LPUART_GetInstance(DMA__LPUART2)]);
2002 }
2003 #endif
2004 
2005 #if defined(DMA__LPUART3)
2006 void DMA_UART3_INT_DriverIRQHandler(void)
2007 {
2008  s_lpuartIsr(DMA__LPUART3, s_lpuartHandle[LPUART_GetInstance(DMA__LPUART3)]);
2010 }
2011 #endif
2012 
2013 #if defined(DMA__LPUART4)
2014 void DMA_UART4_INT_DriverIRQHandler(void)
2015 {
2016  s_lpuartIsr(DMA__LPUART4, s_lpuartHandle[LPUART_GetInstance(DMA__LPUART4)]);
2018 }
2019 #endif
2020 
2021 #if defined(ADMA__LPUART0)
2022 void ADMA_UART0_INT_DriverIRQHandler(void)
2023 {
2024  s_lpuartIsr(ADMA__LPUART0, s_lpuartHandle[LPUART_GetInstance(ADMA__LPUART0)]);
2026 }
2027 #endif
2028 
2029 #if defined(ADMA__LPUART1)
2030 void ADMA_UART1_INT_DriverIRQHandler(void)
2031 {
2032  s_lpuartIsr(ADMA__LPUART1, s_lpuartHandle[LPUART_GetInstance(ADMA__LPUART1)]);
2034 }
2035 #endif
2036 
2037 #if defined(ADMA__LPUART2)
2038 void ADMA_UART2_INT_DriverIRQHandler(void)
2039 {
2040  s_lpuartIsr(ADMA__LPUART2, s_lpuartHandle[LPUART_GetInstance(ADMA__LPUART2)]);
2042 }
2043 #endif
2044 
2045 #if defined(ADMA__LPUART3)
2046 void ADMA_UART3_INT_DriverIRQHandler(void)
2047 {
2048  s_lpuartIsr(ADMA__LPUART3, s_lpuartHandle[LPUART_GetInstance(ADMA__LPUART3)]);
2050 }
2051 #endif
LPUART_TransferGetRxRingBufferLength
size_t LPUART_TransferGetRxRingBufferLength(LPUART_Type *base, lpuart_handle_t *handle)
Get the length of received data in RX ring buffer.
Definition: fsl_lpuart.c:137
kLPUART_TransmissionCompleteInterruptEnable
@ kLPUART_TransmissionCompleteInterruptEnable
Definition: fsl_lpuart.h:131
kStatus_LPUART_FramingError
@ kStatus_LPUART_FramingError
Definition: fsl_lpuart.h:48
kLPUART_TxBusy
@ kLPUART_TxBusy
Definition: fsl_lpuart.c:24
kLPUART_EightDataBits
@ kLPUART_EightDataBits
Definition: fsl_lpuart.h:67
kStatus_LPUART_NoiseError
@ kStatus_LPUART_NoiseError
Definition: fsl_lpuart.h:47
LPUART_BAUD_LBKDIE_MASK
#define LPUART_BAUD_LBKDIE_MASK
Definition: MIMXRT1052.h:26875
LPUART_CTRL_IDLECFG
#define LPUART_CTRL_IDLECFG(x)
Definition: MIMXRT1052.h:27191
s_lpuartClock
static const clock_ip_name_t s_lpuartClock[]
Definition: fsl_lpuart.c:88
_lpuart_handle::rxDataSizeAll
size_t rxDataSizeAll
Definition: fsl_lpuart.h:240
LPUART_TransferHandleIRQ
void LPUART_TransferHandleIRQ(LPUART_Type *base, lpuart_handle_t *handle)
LPUART IRQ handle function.
Definition: fsl_lpuart.c:1440
LPUART_GetInstance
uint32_t LPUART_GetInstance(LPUART_Type *base)
Get the LPUART instance from peripheral base address.
Definition: fsl_lpuart.c:113
UART_RETRY_TIMES
#define UART_RETRY_TIMES
Retry times for waiting flag.
Definition: fsl_lpuart.h:30
LPUART_TransferIsRxRingBufferFull
static bool LPUART_TransferIsRxRingBufferFull(LPUART_Type *base, lpuart_handle_t *handle)
Check whether the RX ring buffer is full.
Definition: fsl_lpuart.c:158
LPUART_STAT_OR_MASK
#define LPUART_STAT_OR_MASK
Definition: MIMXRT1052.h:27023
kLPUART_RxIdle
@ kLPUART_RxIdle
Definition: fsl_lpuart.c:25
LPUART_SetBaudRate
status_t LPUART_SetBaudRate(LPUART_Type *base, uint32_t baudRate_Bps, uint32_t srcClock_Hz)
Sets the LPUART instance baudrate.
Definition: fsl_lpuart.c:564
s_lpuartHandle
static lpuart_handle_t * s_lpuartHandle[ARRAY_SIZE(s_lpuartBases)]
Definition: fsl_lpuart.c:78
LPUART8
#define LPUART8
Definition: MIMXRT1052.h:27675
NULL
#define NULL
Definition: porcupine/demo/c/dr_libs/tests/external/miniaudio/extras/speex_resampler/thirdparty/resample.c:92
LPUART_MODIR_TXCTSE_MASK
#define LPUART_MODIR_TXCTSE_MASK
Definition: MIMXRT1052.h:27428
kStatus_LPUART_RxBusy
@ kStatus_LPUART_RxBusy
Definition: fsl_lpuart.h:37
LPUART_CTRL_RIE_MASK
#define LPUART_CTRL_RIE_MASK
Definition: MIMXRT1052.h:27248
LPUART_FIFO_TXFE_MASK
#define LPUART_FIFO_TXFE_MASK
Definition: MIMXRT1052.h:27535
kStatus_LPUART_TxIdle
@ kStatus_LPUART_TxIdle
Definition: fsl_lpuart.h:38
LPUART_CTRL_PE_MASK
#define LPUART_CTRL_PE_MASK
Definition: MIMXRT1052.h:27130
_lpuart_handle::rxRingBufferTail
volatile uint16_t rxRingBufferTail
Definition: fsl_lpuart.h:245
LPUART_TransferReceiveNonBlocking
status_t LPUART_TransferReceiveNonBlocking(LPUART_Type *base, lpuart_handle_t *handle, lpuart_transfer_t *xfer, size_t *receivedBytes)
Receives a buffer of data using the interrupt method.
Definition: fsl_lpuart.c:1256
kStatus_NoTransferInProgress
@ kStatus_NoTransferInProgress
Definition: fsl_common.h:185
_lpuart_handle::txData
uint8_t *volatile txData
Definition: fsl_lpuart.h:235
_lpuart_handle::userData
void * userData
Definition: fsl_lpuart.h:248
kLPUART_TxDataRegEmptyFlag
@ kLPUART_TxDataRegEmptyFlag
Definition: fsl_lpuart.h:151
LPUART_CTRL_TIE_MASK
#define LPUART_CTRL_TIE_MASK
Definition: MIMXRT1052.h:27262
FSL_FEATURE_LPUART_HAS_LIN_BREAK_DETECT
#define FSL_FEATURE_LPUART_HAS_LIN_BREAK_DETECT
Definition: MIMXRT1052_features.h:455
_lpuart_transfer
LPUART transfer structure.
Definition: fsl_lpuart.h:220
LPUART_EnableInterrupts
void LPUART_EnableInterrupts(LPUART_Type *base, uint32_t mask)
Enables LPUART interrupts according to a provided mask.
Definition: fsl_lpuart.c:657
LPUART_CTRL_ILT_MASK
#define LPUART_CTRL_ILT_MASK
Definition: MIMXRT1052.h:27137
LPUART_TransferStopRingBuffer
void LPUART_TransferStopRingBuffer(LPUART_Type *base, lpuart_handle_t *handle)
Aborts the background transfer and uninstalls the ring buffer.
Definition: fsl_lpuart.c:1101
LPUART_BAUD_SBR
#define LPUART_BAUD_SBR(x)
Definition: MIMXRT1052.h:26860
_lpuart_transfer::dataSize
size_t dataSize
Definition: fsl_lpuart.h:223
LPUART_TransferAbortReceive
void LPUART_TransferAbortReceive(LPUART_Type *base, lpuart_handle_t *handle)
Aborts the interrupt-driven data receiving.
Definition: fsl_lpuart.c:1383
s_lpuartBases
static LPUART_Type *const s_lpuartBases[]
Definition: fsl_lpuart.c:76
LPUART_STAT_LBKDIF_MASK
#define LPUART_STAT_LBKDIF_MASK
Definition: MIMXRT1052.h:27112
kLPUART_OneStopBit
@ kLPUART_OneStopBit
Definition: fsl_lpuart.h:76
LPUART_ReadBlocking
status_t LPUART_ReadBlocking(LPUART_Type *base, uint8_t *data, size_t length)
Reads the receiver data register using a blocking method.
Definition: fsl_lpuart.c:890
_lpuart_transfer::data
uint8_t * data
Definition: fsl_lpuart.h:222
FSL_FEATURE_LPUART_FIFO_SIZEn
#define FSL_FEATURE_LPUART_FIFO_SIZEn(x)
Definition: MIMXRT1052_features.h:433
kLPUART_IdleTypeStartBit
@ kLPUART_IdleTypeStartBit
Definition: fsl_lpuart.h:99
LPUART_DisableInterrupts
void LPUART_DisableInterrupts(LPUART_Type *base, uint32_t mask)
Disables LPUART interrupts according to a provided mask.
Definition: fsl_lpuart.c:681
LPUART_Type::FIFO
__IO uint32_t FIFO
Definition: MIMXRT1052.h:26782
LPUART_CTRL_IDLECFG_MASK
#define LPUART_CTRL_IDLECFG_MASK
Definition: MIMXRT1052.h:27179
kLPUART_ParityErrorFlag
@ kLPUART_ParityErrorFlag
Definition: fsl_lpuart.h:164
kStatus_LPUART_TxBusy
@ kStatus_LPUART_TxBusy
Definition: fsl_lpuart.h:36
LPUART_GetDefaultConfig
void LPUART_GetDefaultConfig(lpuart_config_t *config)
Gets the default configuration structure.
Definition: fsl_lpuart.c:519
LPUART_STAT_IDLE_MASK
#define LPUART_STAT_IDLE_MASK
Definition: MIMXRT1052.h:27030
kLPUART_TxIdle
@ kLPUART_TxIdle
Definition: fsl_lpuart.c:23
LPUART_CTRL_ILT
#define LPUART_CTRL_ILT(x)
Definition: MIMXRT1052.h:27143
lpuart_isr_t
void(* lpuart_isr_t)(LPUART_Type *base, lpuart_handle_t *handle)
Definition: fsl_lpuart.c:30
lpuart_transfer_callback_t
void(* lpuart_transfer_callback_t)(LPUART_Type *base, lpuart_handle_t *handle, status_t status, void *userData)
LPUART transfer callback function.
Definition: fsl_lpuart.h:230
LPUART_MODIR_TXCTSC
#define LPUART_MODIR_TXCTSC(x)
Definition: MIMXRT1052.h:27469
LPUART_Type::DATA
__IO uint32_t DATA
Definition: MIMXRT1052.h:26779
LPUART_WATER_RXCOUNT_MASK
#define LPUART_WATER_RXCOUNT_MASK
Definition: MIMXRT1052.h:27630
LPUART_FIFO_TXOFE_MASK
#define LPUART_FIFO_TXOFE_MASK
Definition: MIMXRT1052.h:27549
LPUART3
#define LPUART3
Definition: MIMXRT1052.h:27655
_lpuart_handle::callback
lpuart_transfer_callback_t callback
Definition: fsl_lpuart.h:247
LPUART_TransferHandleErrorIRQ
void LPUART_TransferHandleErrorIRQ(LPUART_Type *base, lpuart_handle_t *handle)
LPUART Error IRQ handle function.
Definition: fsl_lpuart.c:1675
LPUART_STAT_FE_MASK
#define LPUART_STAT_FE_MASK
Definition: MIMXRT1052.h:27009
LPUART_CLOCKS
#define LPUART_CLOCKS
Clock ip name array for LPUART.
Definition: fsl_clock.h:289
LPUART_WATER_RXCOUNT_SHIFT
#define LPUART_WATER_RXCOUNT_SHIFT
Definition: MIMXRT1052.h:27631
SDK_ISR_EXIT_BARRIER
#define SDK_ISR_EXIT_BARRIER
Definition: fsl_common.h:250
kStatus_LPUART_RxIdle
@ kStatus_LPUART_RxIdle
Definition: fsl_lpuart.h:39
LPUART4
#define LPUART4
Definition: MIMXRT1052.h:27659
kLPUART_TxDataRegEmptyInterruptEnable
@ kLPUART_TxDataRegEmptyInterruptEnable
Definition: fsl_lpuart.h:130
LPUART_TransferGetSendCount
status_t LPUART_TransferGetSendCount(LPUART_Type *base, lpuart_handle_t *handle, uint32_t *count)
Gets the number of bytes that have been sent out to bus.
Definition: fsl_lpuart.c:1198
LPUART_STAT_MSBF_MASK
#define LPUART_STAT_MSBF_MASK
Definition: MIMXRT1052.h:27095
kStatus_LPUART_RxHardwareOverrun
@ kStatus_LPUART_RxHardwareOverrun
Definition: fsl_lpuart.h:46
kLPUART_ParityDisabled
@ kLPUART_ParityDisabled
Definition: fsl_lpuart.h:59
LPUART_STAT_TDRE_MASK
#define LPUART_STAT_TDRE_MASK
Definition: MIMXRT1052.h:27051
LPUART_CTRL_RE_MASK
#define LPUART_CTRL_RE_MASK
Definition: MIMXRT1052.h:27227
LPUART_BAUD_SBNS_MASK
#define LPUART_BAUD_SBNS_MASK
Definition: MIMXRT1052.h:26861
ARRAY_SIZE
#define ARRAY_SIZE(x)
Computes the number of elements in an array.
Definition: fsl_common.h:211
_lpuart_handle::txState
volatile uint8_t txState
Definition: fsl_lpuart.h:250
LPUART_CTRL_TE_MASK
#define LPUART_CTRL_TE_MASK
Definition: MIMXRT1052.h:27234
_lpuart_handle::rxRingBuffer
uint8_t * rxRingBuffer
Definition: fsl_lpuart.h:242
_lpuart_handle::rxData
uint8_t *volatile rxData
Definition: fsl_lpuart.h:238
LPUART_BAUD_OSR
#define LPUART_BAUD_OSR(x)
Definition: MIMXRT1052.h:26962
LPUART1
#define LPUART1
Definition: MIMXRT1052.h:27647
_lpuart_handle
LPUART handle structure.
Definition: fsl_lpuart.h:233
IRQn_Type
IRQn_Type
STM32F4XX Interrupt Number Definition, according to the selected device in Library_configuration_sect...
Definition: stm32f407xx.h:66
LPUART_FIFO_RXUFE_MASK
#define LPUART_FIFO_RXUFE_MASK
Definition: MIMXRT1052.h:27542
_lpuart_handle::rxRingBufferSize
size_t rxRingBufferSize
Definition: fsl_lpuart.h:243
count
size_t count
Definition: porcupine/demo/c/dr_libs/tests/external/miniaudio/tests/test_common/ma_test_common.c:31
LPUART_STAT_TC_MASK
#define LPUART_STAT_TC_MASK
Definition: MIMXRT1052.h:27044
LPUART_TransferStartRingBuffer
void LPUART_TransferStartRingBuffer(LPUART_Type *base, lpuart_handle_t *handle, uint8_t *ringBuffer, size_t ringBufferSize)
Sets up the RX ring buffer.
Definition: fsl_lpuart.c:1074
LPUART_STAT_PF_MASK
#define LPUART_STAT_PF_MASK
Definition: MIMXRT1052.h:27002
LPUART_BAUD_BOTHEDGE_MASK
#define LPUART_BAUD_BOTHEDGE_MASK
Definition: MIMXRT1052.h:26889
LPUART_GetEnabledInterrupts
uint32_t LPUART_GetEnabledInterrupts(LPUART_Type *base)
Gets enabled LPUART interrupts.
Definition: fsl_lpuart.c:712
LPUART_BASE_PTRS
#define LPUART_BASE_PTRS
Definition: MIMXRT1052.h:27679
LPUART_FIFO_RXEMPT_MASK
#define LPUART_FIFO_RXEMPT_MASK
Definition: MIMXRT1052.h:27597
LPUART7
#define LPUART7
Definition: MIMXRT1052.h:27671
LPUART_MODIR_RXRTSE_MASK
#define LPUART_MODIR_RXRTSE_MASK
Definition: MIMXRT1052.h:27454
LPUART_Type::CTRL
__IO uint32_t CTRL
Definition: MIMXRT1052.h:26778
_lpuart_handle::rxDataSize
volatile size_t rxDataSize
Definition: fsl_lpuart.h:239
LPUART2
#define LPUART2
Definition: MIMXRT1052.h:27651
CLOCK_EnableClock
static void CLOCK_EnableClock(clock_ip_name_t name)
Enable the clock for specific IP.
Definition: fsl_clock.h:1059
LPUART_ReadNonBlocking
static void LPUART_ReadNonBlocking(LPUART_Type *base, uint8_t *data, size_t length)
Read RX register using non-blocking method.
Definition: fsl_lpuart.c:189
LPUART_WATER_TXCOUNT_MASK
#define LPUART_WATER_TXCOUNT_MASK
Definition: MIMXRT1052.h:27620
LPUART_Type::BAUD
__IO uint32_t BAUD
Definition: MIMXRT1052.h:26776
LPUART_CTRL_M7_MASK
#define LPUART_CTRL_M7_MASK
Definition: MIMXRT1052.h:27192
LPUART_WriteBlocking
status_t LPUART_WriteBlocking(LPUART_Type *base, const uint8_t *data, size_t length)
Writes to the transmitter register using a blocking method.
Definition: fsl_lpuart.c:825
kLPUART_RxDataRegFullFlag
@ kLPUART_RxDataRegFullFlag
Definition: fsl_lpuart.h:155
_lpuart_config
LPUART configuration structure.
Definition: fsl_lpuart.h:194
LPUART_BAUD_OSR_MASK
#define LPUART_BAUD_OSR_MASK
Definition: MIMXRT1052.h:26926
kStatus_LPUART_ParityError
@ kStatus_LPUART_ParityError
Definition: fsl_lpuart.h:49
kLPUART_NoiseErrorFlag
@ kLPUART_NoiseErrorFlag
Definition: fsl_lpuart.h:160
LPUART_FIFO_TXFLUSH_MASK
#define LPUART_FIFO_TXFLUSH_MASK
Definition: MIMXRT1052.h:27576
kLPUART_RxBusy
@ kLPUART_RxBusy
Definition: fsl_lpuart.c:26
LPUART_Init
status_t LPUART_Init(LPUART_Type *base, const lpuart_config_t *config, uint32_t srcClock_Hz)
Initializes an LPUART instance with the user configuration structure and the peripheral clock.
Definition: fsl_lpuart.c:243
LPUART_BAUD_M10_MASK
#define LPUART_BAUD_M10_MASK
Definition: MIMXRT1052.h:26963
LPUART_STAT_NF_MASK
#define LPUART_STAT_NF_MASK
Definition: MIMXRT1052.h:27016
LPUART_TransferSendNonBlocking
status_t LPUART_TransferSendNonBlocking(LPUART_Type *base, lpuart_handle_t *handle, lpuart_transfer_t *xfer)
Transmits a buffer of data using the interrupt method.
Definition: fsl_lpuart.c:1136
kLPUART_RxOverrunInterruptEnable
@ kLPUART_RxOverrunInterruptEnable
Definition: fsl_lpuart.h:134
kLPUART_IdleLineFlag
@ kLPUART_IdleLineFlag
Definition: fsl_lpuart.h:157
LPUART6
#define LPUART6
Definition: MIMXRT1052.h:27667
kStatus_LPUART_RxRingBufferOverrun
@ kStatus_LPUART_RxRingBufferOverrun
Definition: fsl_lpuart.h:44
kLPUART_FramingErrorFlag
@ kLPUART_FramingErrorFlag
Definition: fsl_lpuart.h:162
LPUART_FIFO_RXUF_MASK
#define LPUART_FIFO_RXUF_MASK
Definition: MIMXRT1052.h:27583
EnableIRQ
static status_t EnableIRQ(IRQn_Type interrupt)
Enable specific interrupt.
Definition: fsl_common.h:484
LPUART_STAT_MA2F_MASK
#define LPUART_STAT_MA2F_MASK
Definition: MIMXRT1052.h:26988
kStatus_LPUART_BaudrateNotSupport
@ kStatus_LPUART_BaudrateNotSupport
Definition: fsl_lpuart.h:50
LPUART_Type::WATER
__IO uint32_t WATER
Definition: MIMXRT1052.h:26783
LPUART_FIFO_RXFE_MASK
#define LPUART_FIFO_RXFE_MASK
Definition: MIMXRT1052.h:27515
LPUART_CTRL_PT_MASK
#define LPUART_CTRL_PT_MASK
Definition: MIMXRT1052.h:27123
LPUART_ClearStatusFlags
status_t LPUART_ClearStatusFlags(LPUART_Type *base, uint32_t mask)
Clears status flags with a provided mask.
Definition: fsl_lpuart.c:772
LPUART_CTRL_M_MASK
#define LPUART_CTRL_M_MASK
Definition: MIMXRT1052.h:27151
CLOCK_DisableClock
static void CLOCK_DisableClock(clock_ip_name_t name)
Disable the clock for specific IP.
Definition: fsl_clock.h:1069
LPUART_FIFO_RXFLUSH_MASK
#define LPUART_FIFO_RXFLUSH_MASK
Definition: MIMXRT1052.h:27569
LPUART_STAT_MA1F_MASK
#define LPUART_STAT_MA1F_MASK
Definition: MIMXRT1052.h:26995
LPUART_FIFO_TXEMPT_MASK
#define LPUART_FIFO_TXEMPT_MASK
Definition: MIMXRT1052.h:27604
_lpuart_handle::rxState
volatile uint8_t rxState
Definition: fsl_lpuart.h:251
kStatus_LPUART_IdleLineDetected
@ kStatus_LPUART_IdleLineDetected
Definition: fsl_lpuart.h:52
kLPUART_RxOverrunFlag
@ kLPUART_RxOverrunFlag
Definition: fsl_lpuart.h:158
LPUART_MODIR_TXCTSSRC
#define LPUART_MODIR_TXCTSSRC(x)
Definition: MIMXRT1052.h:27476
LPUART_FIFO_TXOF_MASK
#define LPUART_FIFO_TXOF_MASK
Definition: MIMXRT1052.h:27590
kStatus_LPUART_Timeout
@ kStatus_LPUART_Timeout
Definition: fsl_lpuart.h:53
LPUART_WATER_TXWATER_SHIFT
#define LPUART_WATER_TXWATER_SHIFT
Definition: MIMXRT1052.h:27616
_lpuart_handle::rxRingBufferHead
volatile uint16_t rxRingBufferHead
Definition: fsl_lpuart.h:244
s_lpuartIsr
static lpuart_isr_t s_lpuartIsr
Definition: fsl_lpuart.c:101
config
static sai_transceiver_t config
Definition: imxrt1050/imxrt1050-evkb/source/pv_audio_rec.c:75
LPUART_Type::STAT
__IO uint32_t STAT
Definition: MIMXRT1052.h:26777
clock_ip_name_t
enum _clock_ip_name clock_ip_name_t
CCM CCGR gate control for each module independently.
LPUART_TransferGetReceiveCount
status_t LPUART_TransferGetReceiveCount(LPUART_Type *base, lpuart_handle_t *handle, uint32_t *count)
Gets the number of bytes that have been received.
Definition: fsl_lpuart.c:1412
LPUART_GetStatusFlags
uint32_t LPUART_GetStatusFlags(LPUART_Type *base)
Gets LPUART status flags.
Definition: fsl_lpuart.c:741
LPUART5
#define LPUART5
Definition: MIMXRT1052.h:27663
kStatus_LPUART_FlagCannotClearManually
@ kStatus_LPUART_FlagCannotClearManually
Definition: fsl_lpuart.h:42
kLPUART_TransmissionCompleteFlag
@ kLPUART_TransmissionCompleteFlag
Definition: fsl_lpuart.h:153
LPUART_Type
Definition: MIMXRT1052.h:26771
LPUART_BAUD_SBNS
#define LPUART_BAUD_SBNS(x)
Definition: MIMXRT1052.h:26867
LPUART_STAT_RXEDGIF_MASK
#define LPUART_STAT_RXEDGIF_MASK
Definition: MIMXRT1052.h:27105
_lpuart_handle::txDataSize
volatile size_t txDataSize
Definition: fsl_lpuart.h:236
s_lpuartIRQ
static const IRQn_Type s_lpuartIRQ[]
Definition: fsl_lpuart.c:84
status_t
int32_t status_t
Type used for all status and error return values.
Definition: fsl_common.h:189
LPUART_WATER_TXCOUNT_SHIFT
#define LPUART_WATER_TXCOUNT_SHIFT
Definition: MIMXRT1052.h:27621
LPUART_TransferCreateHandle
void LPUART_TransferCreateHandle(LPUART_Type *base, lpuart_handle_t *handle, lpuart_transfer_callback_t callback, void *userData)
Initializes the LPUART handle.
Definition: fsl_lpuart.c:1009
_lpuart_handle::txDataSizeAll
size_t txDataSizeAll
Definition: fsl_lpuart.h:237
LPUART_TransferAbortSend
void LPUART_TransferAbortSend(LPUART_Type *base, lpuart_handle_t *handle)
Aborts the interrupt-driven data transmit.
Definition: fsl_lpuart.c:1175
LPUART_Type::MODIR
__IO uint32_t MODIR
Definition: MIMXRT1052.h:26781
kStatus_Success
@ kStatus_Success
Definition: fsl_common.h:179
LPUART_WriteNonBlocking
static void LPUART_WriteNonBlocking(LPUART_Type *base, const uint8_t *data, size_t length)
Write to TX register using non-blocking method.
Definition: fsl_lpuart.c:175
LPUART_RX_TX_IRQS
#define LPUART_RX_TX_IRQS
Definition: MIMXRT1052.h:27681
kLPUART_RxDataRegFullInterruptEnable
@ kLPUART_RxDataRegFullInterruptEnable
Definition: fsl_lpuart.h:132
kLPUART_IdleLineInterruptEnable
@ kLPUART_IdleLineInterruptEnable
Definition: fsl_lpuart.h:133
LPUART_Deinit
void LPUART_Deinit(LPUART_Type *base)
Deinitializes a LPUART instance.
Definition: fsl_lpuart.c:455
LPUART_BAUD_RXEDGIE_MASK
#define LPUART_BAUD_RXEDGIE_MASK
Definition: MIMXRT1052.h:26868
LPUART_STAT_RDRF_MASK
#define LPUART_STAT_RDRF_MASK
Definition: MIMXRT1052.h:27037
fsl_lpuart.h
kLPUART_IdleCharacter1
@ kLPUART_IdleCharacter1
Definition: fsl_lpuart.h:109
LPUART_BAUD_SBR_MASK
#define LPUART_BAUD_SBR_MASK
Definition: MIMXRT1052.h:26856
MIN
#define MIN(a, b)
Definition: fsl_common.h:201


picovoice_driver
Author(s):
autogenerated on Fri Apr 1 2022 02:13:56