lpuart_driver.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
3  * Copyright 2016-2017 NXP
4  * All rights reserved.
5  *
6  * THIS SOFTWARE IS PROVIDED BY NXP "AS IS" AND ANY EXPRESSED OR
7  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
8  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
9  * IN NO EVENT SHALL NXP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
10  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
11  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
12  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
13  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
14  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
15  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
16  * THE POSSIBILITY OF SUCH DAMAGE.
17  */
18 
84 #include <stddef.h>
85 #include <stdbool.h>
86 #include "lpuart_hw_access.h"
87 #include "lpuart_irq.h"
88 #include "clock_manager.h"
89 
90 /*******************************************************************************
91  * Variables
92  ******************************************************************************/
93 
94 /* Pointer to lpuart runtime state structure */
96 
97 /* Table of base addresses for lpuart instances. */
99 
100 /* Table to save LPUART enum numbers defined in CMSIS files. */
102 
103 /* Table to save LPUART clock names as defined in clock manager. */
105 
106 /*******************************************************************************
107  * Private Functions
108  ******************************************************************************/
109 static status_t LPUART_DRV_StartSendDataUsingInt(uint32_t instance,
110  const uint8_t * txBuff,
111  uint32_t txSize);
112 static void LPUART_DRV_CompleteSendDataUsingInt(uint32_t instance);
113 static status_t LPUART_DRV_StartReceiveDataUsingInt(uint32_t instance,
114  uint8_t * rxBuff,
115  uint32_t rxSize);
116 static void LPUART_DRV_CompleteReceiveDataUsingInt(uint32_t instance);
117 #if FEATURE_LPUART_HAS_DMA_ENABLE
118 static void LPUART_DRV_StopTxDma(uint32_t instance);
119 static void LPUART_DRV_StopRxDma(uint32_t instance);
120 static status_t LPUART_DRV_StartSendDataUsingDma(uint32_t instance,
121  const uint8_t * txBuff,
122  uint32_t txSize);
123 static void LPUART_DRV_TxDmaCallback(void * parameter, edma_chn_status_t status);
124 static status_t LPUART_DRV_StartReceiveDataUsingDma(uint32_t instance,
125  uint8_t * rxBuff,
126  uint32_t rxSize);
127 static void LPUART_DRV_RxDmaCallback(void * parameter, edma_chn_status_t status);
128 #endif
129 static void LPUART_DRV_PutData(uint32_t instance);
130 static void LPUART_DRV_GetData(uint32_t instance);
131 
132 /*******************************************************************************
133  * Code
134  ******************************************************************************/
135 /*FUNCTION**********************************************************************
136  *
137  * Function Name : LPUART_DRV_Init
138  * Description : This function initializes a LPUART instance for operation.
139  * This function will initialize the run-time state structure to keep track of
140  * the on-going transfers, ungate the clock to the LPUART module, initialize the
141  * module to user defined settings and default settings, configure the IRQ state
142  * structure and enable the module-level interrupt to the core, and enable the
143  * LPUART module transmitter and receiver.
144  * The following is an example of how to set up the lpuart_state_t and the
145  * lpuart_user_config_t parameters and how to call the LPUART_DRV_Init function
146  * by passing in these parameters:
147  * lpuart_user_config_t lpuartConfig;
148  * lpuartConfig.baudRate = 9600;
149  * lpuartConfig.bitCountPerChar = LPUART_8_BITS_PER_CHAR;
150  * lpuartConfig.parityMode = LPUART_PARITY_DISABLED;
151  * lpuartConfig.stopBitCount = LPUART_ONE_STOP_BIT;
152  * lpuartConfig.transferType = LPUART_USING_INTERRUPTS;
153  * lpuart_state_t lpuartState;
154  * LPUART_DRV_Init(instance, &lpuartState, &lpuartConfig);
155  *
156  * Implements : LPUART_DRV_Init_Activity
157  *END**************************************************************************/
158 status_t LPUART_DRV_Init(uint32_t instance, lpuart_state_t * lpuartStatePtr,
159  const lpuart_user_config_t * lpuartUserConfig)
160 {
161  DEV_ASSERT(instance < LPUART_INSTANCE_COUNT);
162  DEV_ASSERT(lpuartStatePtr != NULL);
163  DEV_ASSERT(lpuartUserConfig != NULL);
164 
165  status_t lpuartStatus;
166  status_t osStatusRxSem;
167  status_t osStatusTxSem;
168  LPUART_Type * base = s_lpuartBase[instance];
169  uint32_t idx;
170  uint32_t lpuartSourceClock;
171  clock_names_t instanceClkName = s_lpuartClkNames[instance];
172 
173  /* Get the LPUART clock as configured in the clock manager */
174  (void)CLOCK_SYS_GetFreq(instanceClkName, &lpuartSourceClock);
175 
176  /* Check if current instance is clock gated off. */
177  DEV_ASSERT(lpuartSourceClock > 0U);
178 
179  /* Check if current instance is already initialized. */
180  DEV_ASSERT(s_lpuartStatePtr[instance] == NULL);
181 
182 #if FEATURE_LPUART_HAS_DMA_ENABLE
183  /* In DMA mode, only 8-bits chars are supported */
184  DEV_ASSERT((lpuartUserConfig->transferType != LPUART_USING_DMA) ||
185  (lpuartUserConfig->bitCountPerChar == LPUART_8_BITS_PER_CHAR));
186 #endif
187 
188  /* Clear the state struct for this instance. */
189  uint8_t *clearStructPtr = (uint8_t *)lpuartStatePtr;
190  for (idx = 0; idx < sizeof(lpuart_state_t); idx++)
191  {
192  clearStructPtr[idx] = 0;
193  }
194 
195  /* Save runtime structure pointer.*/
196  s_lpuartStatePtr[instance] = lpuartStatePtr;
197 
198  /* Save the transfer information for runtime retrieval */
199  lpuartStatePtr->transferType = lpuartUserConfig->transferType;
200  lpuartStatePtr->bitCountPerChar = lpuartUserConfig->bitCountPerChar;
201 #if FEATURE_LPUART_HAS_DMA_ENABLE
202  lpuartStatePtr->rxDMAChannel = lpuartUserConfig->rxDMAChannel;
203  lpuartStatePtr->txDMAChannel = lpuartUserConfig->txDMAChannel;
204 #endif
205 
206  /* initialize the LPUART instance */
207  LPUART_Init(base);
208 
209  /* initialize the parameters of the LPUART config structure with desired data */
210  lpuartStatus = LPUART_DRV_SetBaudRate(instance, lpuartUserConfig->baudRate);
211  if (lpuartStatus != STATUS_SUCCESS)
212  {
213  return STATUS_ERROR;
214  }
215  LPUART_SetBitCountPerChar(base, lpuartUserConfig->bitCountPerChar);
216  LPUART_SetParityMode(base, lpuartUserConfig->parityMode);
217  LPUART_SetStopBitCount(base, lpuartUserConfig->stopBitCount);
218 
219  /* initialize last driver operation status */
220  lpuartStatePtr->transmitStatus = STATUS_SUCCESS;
221  lpuartStatePtr->receiveStatus = STATUS_SUCCESS;
222 
223  /* Create the synchronization objects */
224  osStatusRxSem = OSIF_SemaCreate(&lpuartStatePtr->rxComplete, 0);
225  osStatusTxSem = OSIF_SemaCreate(&lpuartStatePtr->txComplete, 0);
226  if ((osStatusRxSem == STATUS_ERROR) || (osStatusTxSem == STATUS_ERROR))
227  {
228  return STATUS_ERROR;
229  }
230 
231  /* Install LPUART irq handler */
232  INT_SYS_InstallHandler(s_lpuartRxTxIrqId[instance], g_lpuartIsr[instance], (isr_t*) 0);
233 
234  /* Enable LPUART interrupt. */
236 
237  return STATUS_SUCCESS;
238 }
239 
240 /*FUNCTION**********************************************************************
241  *
242  * Function Name : LPUART_DRV_Deinit
243  * Description : This function shuts down the UART by disabling interrupts and
244  * transmitter/receiver.
245  *
246  * Implements : LPUART_DRV_Deinit_Activity
247  *END**************************************************************************/
248 status_t LPUART_DRV_Deinit(uint32_t instance)
249 {
250  DEV_ASSERT(instance < LPUART_INSTANCE_COUNT);
251 
252  clock_names_t instanceClkName = s_lpuartClkNames[instance];
253  uint32_t lpuartSourceClock;
254  const LPUART_Type * base = s_lpuartBase[instance];
255  const lpuart_state_t * lpuartState = (lpuart_state_t *)s_lpuartStatePtr[instance];
256 
257  (void)CLOCK_SYS_GetFreq(instanceClkName, &lpuartSourceClock);
258 
259  /* Check if current instance is already de-initialized or is gated.*/
260  DEV_ASSERT(s_lpuartStatePtr[instance] != NULL);
261  DEV_ASSERT(lpuartSourceClock > 0U);
262 
263  /* Wait until the data is completely shifted out of shift register */
264  while (!LPUART_GetStatusFlag(base, LPUART_TX_COMPLETE)) {}
265 
266  /* Destroy the synchronization objects */
267  (void)OSIF_SemaDestroy(&lpuartState->rxComplete);
268  (void)OSIF_SemaDestroy(&lpuartState->txComplete);
269 
270  /* Disable LPUART interrupt. */
272 
273  /* Restore default handler. */
275 
276  /* Clear our saved pointer to the state structure */
277  s_lpuartStatePtr[instance] = NULL;
278 
279  return STATUS_SUCCESS;
280 }
281 
282 /*FUNCTION**********************************************************************
283  *
284  * Function Name : LPUART_DRV_InstallRxCallback
285  * Description : Install receive data callback function.
286  *
287  * Implements : LPUART_DRV_InstallRxCallback_Activity
288  *END**************************************************************************/
290  uart_callback_t function,
291  void * callbackParam)
292 {
293  DEV_ASSERT(instance < LPUART_INSTANCE_COUNT);
294 
295  lpuart_state_t * lpuartState = (lpuart_state_t *)s_lpuartStatePtr[instance];
296 
297  uart_callback_t currentCallback = lpuartState->rxCallback;
298  lpuartState->rxCallback = function;
299  lpuartState->rxCallbackParam = callbackParam;
300 
301  return currentCallback;
302 }
303 
304 /*FUNCTION**********************************************************************
305  *
306  * Function Name : LPUART_DRV_InstallTxCallback
307  * Description : Install transmit data callback function, pass in NULL pointer
308  * as callback will uninstall.
309  *
310  * Implements : LPUART_DRV_InstallTxCallback_Activity
311  *END**************************************************************************/
313  uart_callback_t function,
314  void * callbackParam)
315 {
316  DEV_ASSERT(instance < LPUART_INSTANCE_COUNT);
317 
318  lpuart_state_t * lpuartState = (lpuart_state_t *)s_lpuartStatePtr[instance];
319 
320  uart_callback_t currentCallback = lpuartState->txCallback;
321  lpuartState->txCallback = function;
322  lpuartState->txCallbackParam = callbackParam;
323 
324  return currentCallback;
325 }
326 
327 /*FUNCTION**********************************************************************
328  *
329  * Function Name : LPUART_DRV_SendDataBlocking
330  * Description : This function sends data out through the LPUART module using
331  * blocking method. The function does not return until the transmit is complete.
332  *
333  * Implements : LPUART_DRV_SendDataBlocking_Activity
334  *END**************************************************************************/
336  const uint8_t * txBuff,
337  uint32_t txSize,
338  uint32_t timeout)
339 {
340  DEV_ASSERT(instance < LPUART_INSTANCE_COUNT);
341  DEV_ASSERT(txBuff != NULL);
342 
343  lpuart_state_t * lpuartState = (lpuart_state_t *)s_lpuartStatePtr[instance];
344  status_t retVal = STATUS_SUCCESS;
345  status_t syncStatus;
346 
347  /* Indicates this is a blocking transaction. */
348  lpuartState->isTxBlocking = true;
349 
350  DEV_ASSERT((lpuartState->transferType == LPUART_USING_INTERRUPTS) ||
351  (lpuartState->transferType == LPUART_USING_DMA));
352 
353  if (lpuartState->transferType == LPUART_USING_INTERRUPTS)
354  {
355  /* Start the transmission process using interrupts */
356  retVal = LPUART_DRV_StartSendDataUsingInt(instance, txBuff, txSize);
357  }
358 #if FEATURE_LPUART_HAS_DMA_ENABLE
359  else
360  {
361  /* Start the transmission process using DMA */
362  retVal = LPUART_DRV_StartSendDataUsingDma(instance, txBuff, txSize);
363  }
364 #endif
365 
366  if (retVal == STATUS_SUCCESS)
367  {
368  /* Wait until the transmit is complete. */
369  syncStatus = OSIF_SemaWait(&lpuartState->txComplete, timeout);
370 
371  /* Finish the transmission if timeout expired */
372  if (syncStatus == STATUS_TIMEOUT)
373  {
374  lpuartState->isTxBlocking = false;
375  lpuartState->transmitStatus = STATUS_TIMEOUT;
376 
377  if (lpuartState->transferType == LPUART_USING_INTERRUPTS)
378  {
380  }
381 #if FEATURE_LPUART_HAS_DMA_ENABLE
382  else
383  {
384  LPUART_DRV_StopTxDma(instance);
385  }
386 #endif
387 
388  retVal = STATUS_TIMEOUT;
389  }
390  }
391 
392  return retVal;
393 }
394 
395 /*FUNCTION**********************************************************************
396  *
397  * Function Name : LPUART_DRV_SendDataPolling
398  * Description : Send out multiple bytes of data using polling method.
399  *
400  * Implements : LPUART_DRV_SendDataPolling_Activity
401  *END**************************************************************************/
402 void LPUART_DRV_SendDataPolling(uint32_t instance,
403  const uint8_t *txBuff,
404  uint32_t txSize)
405 {
406  DEV_ASSERT(instance < LPUART_INSTANCE_COUNT);
407  DEV_ASSERT(txBuff != NULL);
408 
409  LPUART_Type * base = s_lpuartBase[instance];
410  lpuart_state_t * lpuartState = (lpuart_state_t *)s_lpuartStatePtr[instance];
411 
412  /* Check the validity of the parameters */
413  DEV_ASSERT(txSize > 0U);
415  ((txSize & 1U) == 0U));
416 
417  /* Enable the LPUART transmitter */
418  LPUART_SetTransmitterCmd(base, true);
419 
420  while (txSize > 0U)
421  {
422  while (!LPUART_GetStatusFlag(base, LPUART_TX_DATA_REG_EMPTY))
423  {}
424 
425  lpuartState->txBuff = txBuff;
426  LPUART_DRV_PutData(instance);
427 
428  if (lpuartState->bitCountPerChar == LPUART_8_BITS_PER_CHAR)
429  {
430  ++txBuff;
431  --txSize;
432  }
433  else
434  {
435  ++txBuff;
436  ++txBuff;
437  txSize -= 2U;
438  }
439  }
440 
441  /* Disable the LPUART transmitter */
442  LPUART_SetTransmitterCmd(base, false);
443 }
444 
445 /*FUNCTION**********************************************************************
446  *
447  * Function Name : LPUART_DRV_SendData
448  * Description : This function sends data out through the LPUART module using
449  * non-blocking method. The function will return immediately after calling this
450  * function.
451  *
452  * Implements : LPUART_DRV_SendData_Activity
453  *END**************************************************************************/
454 status_t LPUART_DRV_SendData(uint32_t instance,
455  const uint8_t * txBuff,
456  uint32_t txSize)
457 {
458  DEV_ASSERT(instance < LPUART_INSTANCE_COUNT);
459  DEV_ASSERT(txBuff != NULL);
460 
461  status_t retVal = STATUS_SUCCESS;
462  lpuart_state_t * lpuartState = (lpuart_state_t *)s_lpuartStatePtr[instance];
463 
464  /* Indicates this is a non-blocking transaction. */
465  lpuartState->isTxBlocking = false;
466 
467  DEV_ASSERT((lpuartState->transferType == LPUART_USING_INTERRUPTS) ||
468  (lpuartState->transferType == LPUART_USING_DMA));
469 
470  if (lpuartState->transferType == LPUART_USING_INTERRUPTS)
471  {
472  /* Start the transmission process using interrupts */
473  retVal = LPUART_DRV_StartSendDataUsingInt(instance, txBuff, txSize);
474  }
475 #if FEATURE_LPUART_HAS_DMA_ENABLE
476  else
477  {
478  /* Start the transmission process using DMA */
479  retVal = LPUART_DRV_StartSendDataUsingDma(instance, txBuff, txSize);
480  }
481 #endif
482 
483  return retVal;
484 }
485 
486 /*FUNCTION**********************************************************************
487  *
488  * Function Name : LPUART_DRV_GetTransmitStatus
489  * Description : This function returns whether the previous LPUART transmit has
490  * finished. When performing non-blocking transmit, the user can call this
491  * function to ascertain the state of the current transmission:
492  * in progress (or busy) or complete (success). In addition, if the transmission
493  * is still in progress, the user can obtain the number of words that have been
494  * currently transferred.
495  *
496  * Implements : LPUART_DRV_GetTransmitStatus_Activity
497  *END**************************************************************************/
498 status_t LPUART_DRV_GetTransmitStatus(uint32_t instance, uint32_t * bytesRemaining)
499 {
500  DEV_ASSERT(instance < LPUART_INSTANCE_COUNT);
501 
502  const lpuart_state_t * lpuartState = (lpuart_state_t *)s_lpuartStatePtr[instance];
503 
504  if (bytesRemaining != NULL)
505  {
506  if (lpuartState->isTxBusy)
507  {
508  /* Fill in the bytes not transferred yet. */
509  if (lpuartState->transferType == LPUART_USING_INTERRUPTS)
510  {
511  /* In interrupt-based communication, the remaining bytes are retrieved
512  * from the state structure
513  */
514  *bytesRemaining = lpuartState->txSize;;
515  }
516 #if FEATURE_LPUART_HAS_DMA_ENABLE
517  else
518  {
519  /* In DMA-based communication, the remaining bytes are retrieved
520  * from the current DMA major loop count
521  */
522  *bytesRemaining = EDMA_DRV_GetRemainingMajorIterationsCount(lpuartState->txDMAChannel);
523  }
524 #endif
525  }
526  else
527  {
528  *bytesRemaining = 0;
529  }
530  }
531 
532  return lpuartState->transmitStatus;
533 }
534 
535 /*FUNCTION**********************************************************************
536  *
537  * Function Name : LPUART_DRV_AbortSendingData
538  * Description : This function terminates an non-blocking LPUART transmission
539  * early. During a non-blocking LPUART transmission, the user has the option to
540  * terminate the transmission early if the transmission is still in progress.
541  *
542  * Implements : LPUART_DRV_AbortSendingData_Activity
543  *END**************************************************************************/
545 {
546  DEV_ASSERT(instance < LPUART_INSTANCE_COUNT);
547 
548  lpuart_state_t * lpuartState = (lpuart_state_t *)s_lpuartStatePtr[instance];
549 
550  /* Check if a transfer is running. */
551  if (!lpuartState->isTxBusy)
552  {
553  return STATUS_SUCCESS;
554  }
555 
556  /* Update the tx status */
557  lpuartState->transmitStatus = STATUS_UART_ABORTED;
558 
559  /* Stop the running transfer. */
560  if (lpuartState->transferType == LPUART_USING_INTERRUPTS)
561  {
563  }
564 #if FEATURE_LPUART_HAS_DMA_ENABLE
565  else
566  {
567  LPUART_DRV_StopTxDma(instance);
568  }
569 #endif
570 
571  return STATUS_SUCCESS;
572 }
573 
574 /*FUNCTION**********************************************************************
575  *
576  * Function Name : LPUART_DRV_ReceiveDataBlocking
577  * Description : This function receives data from LPUART module using blocking
578  * method, the function does not return until the receive is complete.
579  *
580  * Implements : LPUART_DRV_ReceiveDataBlocking_Activity
581  *END**************************************************************************/
583  uint8_t * rxBuff,
584  uint32_t rxSize,
585  uint32_t timeout)
586 {
587  DEV_ASSERT(instance < LPUART_INSTANCE_COUNT);
588  DEV_ASSERT(rxBuff != NULL);
589 
590  lpuart_state_t * lpuartState = (lpuart_state_t *)s_lpuartStatePtr[instance];
591  status_t retVal = STATUS_SUCCESS;
592  status_t syncStatus;
593 
594  /* Indicates this is a blocking transaction. */
595  lpuartState->isRxBlocking = true;
596 
597  DEV_ASSERT((lpuartState->transferType == LPUART_USING_INTERRUPTS) ||
598  (lpuartState->transferType == LPUART_USING_DMA));
599 
600  if (lpuartState->transferType == LPUART_USING_INTERRUPTS)
601  {
602  /* Start the reception process using interrupts */
603  retVal = LPUART_DRV_StartReceiveDataUsingInt(instance, rxBuff, rxSize);
604  }
605 #if FEATURE_LPUART_HAS_DMA_ENABLE
606  else
607  {
608  /* Start the reception process using DMA */
609  retVal = LPUART_DRV_StartReceiveDataUsingDma(instance, rxBuff, rxSize);
610  }
611 #endif
612 
613  if (retVal == STATUS_SUCCESS)
614  {
615  /* Wait until the receive is complete. */
616  syncStatus = OSIF_SemaWait(&lpuartState->rxComplete, timeout);
617 
618  /* Finish the reception if timeout expired */
619  if (syncStatus == STATUS_TIMEOUT)
620  {
621  lpuartState->isRxBlocking = false;
622  lpuartState->receiveStatus = STATUS_TIMEOUT;
623 
624  if (lpuartState->transferType == LPUART_USING_INTERRUPTS)
625  {
627  }
628 #if FEATURE_LPUART_HAS_DMA_ENABLE
629  else
630  {
631  LPUART_DRV_StopRxDma(instance);
632  }
633 #endif
634  retVal = STATUS_TIMEOUT;
635  }
636  }
637 
638  return retVal;
639 }
640 
641 /*FUNCTION**********************************************************************
642  *
643  * Function Name : LPUART_DRV_ReceiveDataPolling
644  * Description : Receive multiple bytes of data using polling method.
645  *
646  * Implements : LPUART_DRV_ReceiveDataPolling_Activity
647  *END**************************************************************************/
649  uint8_t *rxBuff,
650  uint32_t rxSize)
651 {
652  DEV_ASSERT(instance < LPUART_INSTANCE_COUNT);
653  DEV_ASSERT(rxBuff != NULL);
654 
655  status_t retVal = STATUS_SUCCESS;
656  LPUART_Type * base = s_lpuartBase[instance];
657  lpuart_state_t * lpuartState = (lpuart_state_t *)s_lpuartStatePtr[instance];
658 
659  /* Check the validity of the parameters */
660  DEV_ASSERT(rxSize > 0U);
662  ((rxSize & 1U) == 0U));
663 
664  /* Enable the LPUART receiver */
665  LPUART_SetReceiverCmd((LPUART_Type *)base, true);
666 
667  while (rxSize > 0U)
668  {
669  while (!LPUART_GetStatusFlag(base, LPUART_RX_DATA_REG_FULL))
670  {}
671 
672  lpuartState->rxBuff = rxBuff;
673  LPUART_DRV_GetData(instance);
674 
675  if (lpuartState->bitCountPerChar == LPUART_8_BITS_PER_CHAR)
676  {
677  ++rxBuff;
678  --rxSize;
679  }
680  else
681  {
682  ++rxBuff;
683  ++rxBuff;
684  rxSize -= 2U;
685  }
686 
687  /* Check for errors on received data */
688  if (LPUART_GetStatusFlag(base, LPUART_RX_OVERRUN))
689  {
690  retVal = STATUS_UART_RX_OVERRUN;
691  /* Clear the flag */
692  (void)LPUART_ClearStatusFlag(base, LPUART_RX_OVERRUN);
693  break;
694  }
695  else if (LPUART_GetStatusFlag(base, LPUART_FRAME_ERR))
696  {
697  retVal = STATUS_UART_FRAMING_ERROR;
698  /* Clear the flag */
699  (void)LPUART_ClearStatusFlag(base, LPUART_FRAME_ERR);
700  break;
701  }
702  else if (LPUART_GetStatusFlag(base, LPUART_NOISE_DETECT))
703  {
704  retVal = STATUS_UART_NOISE_ERROR;
705  /* Clear the flag */
706  (void)LPUART_ClearStatusFlag(base, LPUART_NOISE_DETECT);
707  break;
708  }
709  else if (LPUART_GetStatusFlag(base, LPUART_PARITY_ERR))
710  {
711  retVal = STATUS_UART_PARITY_ERROR;
712  /* Clear the flag */
713  (void)LPUART_ClearStatusFlag(base, LPUART_PARITY_ERR);
714  break;
715  }
716  else
717  {
718  /* No error condition - avoid MISRA violation */
719  }
720  }
721 
722  /* Disable the LPUART receiver */
723  LPUART_SetReceiverCmd((LPUART_Type *)base, false);
724 
725  return retVal;
726 }
727 
728 /*FUNCTION**********************************************************************
729  *
730  * Function Name : LPUART_DRV_ReceiveData
731  * Description : This function receives data from LPUART module using
732  * non-blocking method. This function returns immediately after initiating the
733  * receive function. The application has to get the receive status to see when
734  * the receive is complete. In other words, after calling non-blocking get
735  * function, the application must get the receive status to check if receive
736  * is completed or not.
737  *
738  * Implements : LPUART_DRV_ReceiveData_Activity
739  *END**************************************************************************/
741  uint8_t * rxBuff,
742  uint32_t rxSize)
743 {
744  DEV_ASSERT(instance < LPUART_INSTANCE_COUNT);
745  DEV_ASSERT(rxBuff != NULL);
746 
747  status_t retVal = STATUS_SUCCESS;
748  lpuart_state_t * lpuartState = (lpuart_state_t *)s_lpuartStatePtr[instance];
749 
750  /* Indicates this is a non-blocking transaction. */
751  lpuartState->isRxBlocking = false;
752 
753  DEV_ASSERT((lpuartState->transferType == LPUART_USING_INTERRUPTS) ||
754  (lpuartState->transferType == LPUART_USING_DMA));
755 
756  if (lpuartState->transferType == LPUART_USING_INTERRUPTS)
757  {
758  /* Start the reception process using interrupts */
759  retVal = LPUART_DRV_StartReceiveDataUsingInt(instance, rxBuff, rxSize);
760  }
761 #if FEATURE_LPUART_HAS_DMA_ENABLE
762  else
763  {
764  /* Start the reception process using DMA */
765  retVal = LPUART_DRV_StartReceiveDataUsingDma(instance, rxBuff, rxSize);
766  }
767 #endif
768 
769  return retVal;
770 }
771 
772 /*FUNCTION**********************************************************************
773  *
774  * Function Name : LPUART_DRV_GetReceiveStatus
775  * Description : This function returns whether the previous LPUART receive is
776  * complete. When performing a non-blocking receive, the user can call this
777  * function to ascertain the state of the current receive progress: in progress
778  * or complete. In addition, if the receive is still in progress, the user can
779  * obtain the number of words that have been currently received.
780  *
781  * Implements : LPUART_DRV_GetReceiveStatus_Activity
782  *END**************************************************************************/
784  uint32_t * bytesRemaining)
785 {
786  DEV_ASSERT(instance < LPUART_INSTANCE_COUNT);
787 
788  const lpuart_state_t * lpuartState = (lpuart_state_t *)s_lpuartStatePtr[instance];
789 
790  if (bytesRemaining != NULL)
791  {
792  if (lpuartState->isRxBusy)
793  {
794  /* Fill in the bytes transferred. */
795  if (lpuartState->transferType == LPUART_USING_INTERRUPTS)
796  {
797  /* In interrupt-based communication, the remaining bytes are retrieved
798  * from the state structure
799  */
800  *bytesRemaining = lpuartState->rxSize;
801  }
802 #if FEATURE_LPUART_HAS_DMA_ENABLE
803  else
804  {
805  /* In DMA-based communication, the remaining bytes are retrieved
806  * from the current DMA major loop count
807  */
808  *bytesRemaining = EDMA_DRV_GetRemainingMajorIterationsCount(lpuartState->rxDMAChannel);
809  }
810 #endif
811  }
812  else
813  {
814  *bytesRemaining = 0;
815  }
816  }
817 
818  return lpuartState->receiveStatus;
819 }
820 
821 /*FUNCTION**********************************************************************
822  *
823  * Function Name : LPUART_DRV_AbortReceivingData
824  * Description : Terminates a non-blocking receive early.
825  *
826  * Implements : LPUART_DRV_AbortReceivingData_Activity
827  *END**************************************************************************/
829 {
830  DEV_ASSERT(instance < LPUART_INSTANCE_COUNT);
831 
832  lpuart_state_t * lpuartState = (lpuart_state_t *)s_lpuartStatePtr[instance];
833 
834  /* Check if a transfer is running. */
835  if (!lpuartState->isRxBusy)
836  {
837  return STATUS_SUCCESS;
838  }
839 
840  /* Update the rx status */
841  lpuartState->receiveStatus = STATUS_UART_ABORTED;
842 
843  /* Stop the running transfer. */
844  if (lpuartState->transferType == LPUART_USING_INTERRUPTS)
845  {
847  }
848 #if FEATURE_LPUART_HAS_DMA_ENABLE
849  else
850  {
851  LPUART_DRV_StopRxDma(instance);
852  }
853 #endif
854 
855  return STATUS_SUCCESS;
856 }
857 
858 /*FUNCTION**********************************************************************
859  *
860  * Function Name : LPUART_DRV_SetBaudRate
861  * Description : Configures the LPUART baud rate.
862  * In some LPUART instances the user must disable the transmitter/receiver
863  * before calling this function.
864  * Generally, this may be applied to all LPUARTs to ensure safe operation.
865  *
866  * Implements : LPUART_DRV_SetBaudRate_Activity
867  *END**************************************************************************/
868 status_t LPUART_DRV_SetBaudRate(uint32_t instance, uint32_t desiredBaudRate)
869 {
870  DEV_ASSERT(instance < LPUART_INSTANCE_COUNT);
871 
872  uint16_t sbr, sbrTemp, i;
873  uint32_t osr, tempDiff, calculatedBaud, baudDiff;
874  uint32_t lpuartSourceClock;
875  clock_names_t instanceClkName = s_lpuartClkNames[instance];
876  LPUART_Type * base = s_lpuartBase[instance];
877  const lpuart_state_t * lpuartState;
878  lpuartState = (lpuart_state_t *)s_lpuartStatePtr[instance];
879 
880  if (lpuartState != NULL)
881  {
882  /* Check if there is an ongoing transfer */
883  if (lpuartState->isTxBusy == true)
884  {
885  return STATUS_BUSY;
886  }
887  if (lpuartState->isRxBusy == true)
888  {
889  return STATUS_BUSY;
890  }
891  }
892 
893  /* Get the LPUART clock as configured in the clock manager */
894  (void)CLOCK_SYS_GetFreq(instanceClkName, &lpuartSourceClock);
895 
896  /* Check if current instance is clock gated off. */
897  DEV_ASSERT(lpuartSourceClock > 0U);
898  /* Check if the desired baud rate can be configured with the current protocol clock. */
899  DEV_ASSERT(lpuartSourceClock >= (desiredBaudRate * 4U));
900 
901  /* This lpuart instantiation uses a slightly different baud rate calculation
902  * The idea is to use the best OSR (over-sampling rate) possible
903  * Note, osr is typically hard-set to 16 in other lpuart instantiations
904  * First calculate the baud rate using the minimum OSR possible (4) */
905  osr = 4;
906  sbr = (uint16_t)(lpuartSourceClock / (desiredBaudRate * osr));
907  calculatedBaud = (lpuartSourceClock / (osr * sbr));
908 
909  if (calculatedBaud > desiredBaudRate)
910  {
911  baudDiff = calculatedBaud - desiredBaudRate;
912  }
913  else
914  {
915  baudDiff = desiredBaudRate - calculatedBaud;
916  }
917 
918  /* loop to find the best osr value possible, one that generates minimum baudDiff
919  * iterate through the rest of the supported values of osr */
920  for (i = 5U; i <= 32U; i++)
921  {
922  /* calculate the temporary sbr value */
923  sbrTemp = (uint16_t)(lpuartSourceClock / (desiredBaudRate * i));
924  /* calculate the baud rate based on the temporary osr and sbr values */
925  calculatedBaud = (lpuartSourceClock / (i * sbrTemp));
926 
927  if (calculatedBaud > desiredBaudRate)
928  {
929  tempDiff = calculatedBaud - desiredBaudRate;
930  }
931  else
932  {
933  tempDiff = desiredBaudRate - calculatedBaud;
934  }
935 
936  if (tempDiff <= baudDiff)
937  {
938  baudDiff = tempDiff;
939  osr = i; /* update and store the best osr value calculated */
940  sbr = sbrTemp; /* update store the best sbr value calculated */
941  }
942  }
943 
944  /* Check if osr is between 4x and 7x oversampling.
945  * If so, then "BOTHEDGE" sampling must be turned on */
946  if ((osr > 3U) && (osr < 8U))
947  {
948  LPUART_SetBothEdgeSamplingCmd(base, true);
949  }
950 
951  /* program the osr value (bit value is one less than actual value) */
952  LPUART_SetOversamplingRatio(base, (osr - 1U));
953 
954  /* write the sbr value to the BAUD registers */
955  LPUART_SetBaudRateDivisor(base, sbr);
956 
957  return STATUS_SUCCESS;
958 }
959 
960 /*FUNCTION**********************************************************************
961  *
962  * Function Name : LPUART_DRV_GetBaudRate
963  * Description : Returns the LPUART configured baud rate.
964  *
965  * Implements : LPUART_DRV_GetBaudRate_Activity
966  *END**************************************************************************/
967 void LPUART_DRV_GetBaudRate(uint32_t instance, uint32_t * configuredBaudRate)
968 {
969  DEV_ASSERT(instance < LPUART_INSTANCE_COUNT);
970  DEV_ASSERT(configuredBaudRate != NULL);
971 
972  uint8_t osr;
973  uint16_t sbr;
974  uint32_t lpuartSourceClock;
975  clock_names_t instanceClkName = s_lpuartClkNames[instance];
976  const LPUART_Type * base = s_lpuartBase[instance];
977 
978  /* Get the LPUART clock as configured in the clock manager */
979  (void)CLOCK_SYS_GetFreq(instanceClkName, &lpuartSourceClock);
980 
981  osr = LPUART_GetOversamplingRatio(base);
982  sbr = LPUART_GetBaudRateDivisor(base);
983 
984  *configuredBaudRate = (lpuartSourceClock / ((osr + 1UL) * sbr));
985 }
986 
987 /*FUNCTION**********************************************************************
988  *
989  * Function Name : LPUART_DRV_SetTxBuffer
990  * Description : Sets the driver internal reference to the tx buffer.
991  * Can be called from the tx callback to provide a different
992  * buffer for continuous transmission.
993  *
994  * Implements : LPUART_DRV_SetTxBuffer_Activity
995  *END**************************************************************************/
997  const uint8_t * txBuff,
998  uint32_t txSize)
999 {
1000  DEV_ASSERT(instance < LPUART_INSTANCE_COUNT);
1001  DEV_ASSERT(txBuff != NULL);
1002  DEV_ASSERT(txSize > 0U);
1003 
1004  lpuart_state_t * lpuartState = (lpuart_state_t *)s_lpuartStatePtr[instance];
1005  lpuartState->txBuff = txBuff;
1006  lpuartState->txSize = txSize;
1007 
1008  return STATUS_SUCCESS;
1009 }
1010 
1011 /*FUNCTION**********************************************************************
1012  *
1013  * Function Name : LPUART_DRV_SetRxBuffer
1014  * Description : Sets the driver internal reference to the rx buffer.
1015  * Can be called from the rx callback to provide a different
1016  * buffer for continuous reception.
1017  *
1018  * Implements : LPUART_DRV_SetRxBuffer_Activity
1019  *END**************************************************************************/
1021  uint8_t * rxBuff,
1022  uint32_t rxSize)
1023 {
1024  DEV_ASSERT(instance < LPUART_INSTANCE_COUNT);
1025  DEV_ASSERT(rxBuff != NULL);
1026  DEV_ASSERT(rxSize > 0U);
1027 
1028  lpuart_state_t * lpuartState = (lpuart_state_t *)s_lpuartStatePtr[instance];
1029  lpuartState->rxBuff = rxBuff;
1030  lpuartState->rxSize = rxSize;
1031 
1032  return STATUS_SUCCESS;
1033 }
1034 
1035 /*FUNCTION**********************************************************************
1036  *
1037  * Function Name : LPUART_DRV_IRQHandler
1038  * Description : Interrupt handler for LPUART.
1039  * This handler uses the buffers stored in the lpuart_state_t structs to transfer
1040  * data. This is not a public API as it is called by IRQ whenever an interrupt
1041  * occurs.
1042  *
1043  *END**************************************************************************/
1044 void LPUART_DRV_IRQHandler(uint32_t instance)
1045 {
1046  DEV_ASSERT(instance < LPUART_INSTANCE_COUNT);
1047 
1048  lpuart_state_t * lpuartState = (lpuart_state_t *)s_lpuartStatePtr[instance];
1049  LPUART_Type * base = s_lpuartBase[instance];
1050 
1051  /* Exit the ISR if no transfer is happening for this instance. */
1052  if (!lpuartState->isTxBusy)
1053  {
1054  if (!lpuartState->isRxBusy)
1055  {
1056  return;
1057  }
1058  }
1059 
1060  /* Handle receive data full interrupt */
1061  if (LPUART_GetIntMode(base, LPUART_INT_RX_DATA_REG_FULL))
1062  {
1063  if (LPUART_GetStatusFlag(base, LPUART_RX_DATA_REG_FULL))
1064  {
1065  /* Get data and put in receive buffer */
1066  LPUART_DRV_GetData(instance);
1067 
1068  /* Update the internal state */
1069  if (lpuartState->bitCountPerChar == LPUART_8_BITS_PER_CHAR)
1070  {
1071  ++lpuartState->rxBuff;
1072  --lpuartState->rxSize;
1073  }
1074  else
1075  {
1076  lpuartState->rxBuff = &lpuartState->rxBuff[2];
1077  lpuartState->rxSize -= 2U;
1078  }
1079 
1080  /* Check if this was the last byte in the current buffer */
1081  if (lpuartState->rxSize == 0U)
1082  {
1083  /* Invoke callback if there is one (callback may reset the rx buffer for continuous reception) */
1084  if (lpuartState->rxCallback != NULL)
1085  {
1086  lpuartState->rxCallback(lpuartState, UART_EVENT_RX_FULL, lpuartState->rxCallbackParam);
1087  }
1088  }
1089 
1090  /* Finish reception if this was the last byte received */
1091  if (lpuartState->rxSize == 0U)
1092  {
1093  /* Complete transfer (disable rx logic) */
1095 
1096  /* Invoke callback if there is one */
1097  if (lpuartState->rxCallback != NULL)
1098  {
1099  lpuartState->rxCallback(lpuartState, UART_EVENT_END_TRANSFER, lpuartState->rxCallbackParam);
1100  }
1101  }
1102  }
1103  }
1104 
1105  /* Handle transmitter data register empty interrupt */
1106  if (LPUART_GetIntMode(base, LPUART_INT_TX_DATA_REG_EMPTY))
1107  {
1108  if (LPUART_GetStatusFlag(base, LPUART_TX_DATA_REG_EMPTY))
1109  {
1110  /* Check if there are any more bytes to send */
1111  if (lpuartState->txSize > 0U)
1112  {
1113  /* Transmit the data */
1114  LPUART_DRV_PutData(instance);
1115 
1116  /* Update the internal state */
1117  if (lpuartState->bitCountPerChar == LPUART_8_BITS_PER_CHAR)
1118  {
1119  ++lpuartState->txBuff;
1120  --lpuartState->txSize;
1121  }
1122  else
1123  {
1124  lpuartState->txBuff = &lpuartState->txBuff[2];
1125  lpuartState->txSize -= 2U;
1126  }
1127 
1128  /* Check if this was the last byte in the current buffer */
1129  if (lpuartState->txSize == 0U)
1130  {
1131  /* Invoke callback if there is one (callback may reset the tx buffer for continuous transmission)*/
1132  if (lpuartState->txCallback != NULL)
1133  {
1134  lpuartState->txCallback(lpuartState, UART_EVENT_TX_EMPTY, lpuartState->txCallbackParam);
1135  }
1136 
1137  /* If there's no new data, disable tx empty interrupt */
1138  if (lpuartState->txSize == 0U)
1139  {
1140  LPUART_SetIntMode(base, LPUART_INT_TX_DATA_REG_EMPTY, false);
1141  }
1142  }
1143  }
1144  }
1145  }
1146 
1147  /* Handle transmission complete interrupt */
1148  if (LPUART_GetIntMode(base, LPUART_INT_TX_COMPLETE))
1149  {
1150  if (LPUART_GetStatusFlag(base, LPUART_TX_COMPLETE))
1151  {
1152  if (lpuartState->txSize == 0U)
1153  {
1154  if (lpuartState->transferType == LPUART_USING_INTERRUPTS)
1155  {
1156  /* Complete the interrupt based transfer */
1158  }
1159 #if FEATURE_LPUART_HAS_DMA_ENABLE
1160  else
1161  {
1162  /* Complete the DMA based transfer */
1163  LPUART_DRV_StopTxDma(instance);
1164  }
1165 #endif
1166  /* Invoke callback if there is one */
1167  if (lpuartState->txCallback != NULL)
1168  {
1169  lpuartState->txCallback(lpuartState, UART_EVENT_END_TRANSFER, lpuartState->txCallbackParam);
1170  }
1171  }
1172  }
1173  }
1174 
1175  /* Handle receive overrun interrupt */
1176  if (LPUART_GetStatusFlag(base, LPUART_RX_OVERRUN))
1177  {
1178  /* Update the internal status */
1179  lpuartState->receiveStatus = STATUS_UART_RX_OVERRUN;
1180  if (lpuartState->transferType == LPUART_USING_INTERRUPTS)
1181  {
1182  /* Complete the transfer (disable rx logic) */
1184  }
1185 #if FEATURE_LPUART_HAS_DMA_ENABLE
1186  else
1187  {
1188  /* Complete the transfer (stop DMA channel) */
1189  LPUART_DRV_StopRxDma(instance);
1190  }
1191 #endif
1192  /* Invoke callback if there is one */
1193  if (lpuartState->rxCallback != NULL)
1194  {
1195  lpuartState->rxCallback(lpuartState, UART_EVENT_ERROR, lpuartState->rxCallbackParam);
1196  }
1197 
1198  /* Clear the flag */
1199  (void)LPUART_ClearStatusFlag(base, LPUART_RX_OVERRUN);
1200  }
1201  /* Handle framing error interrupt */
1202  else if (LPUART_GetStatusFlag(base, LPUART_FRAME_ERR))
1203  {
1204  /* Update the internal status */
1206  if (lpuartState->transferType == LPUART_USING_INTERRUPTS)
1207  {
1208  /* Complete the transfer (disable rx logic) */
1210  }
1211 #if FEATURE_LPUART_HAS_DMA_ENABLE
1212  else
1213  {
1214  /* Complete the transfer (stop DMA channel) */
1215  LPUART_DRV_StopRxDma(instance);
1216  }
1217 #endif
1218  /* Invoke callback if there is one */
1219  if (lpuartState->rxCallback != NULL)
1220  {
1221  lpuartState->rxCallback(lpuartState, UART_EVENT_ERROR, lpuartState->rxCallbackParam);
1222  }
1223 
1224  /* Clear the flag */
1225  (void)LPUART_ClearStatusFlag(base, LPUART_FRAME_ERR);
1226  }
1227  /* Handle parity error interrupt */
1228  else if (LPUART_GetStatusFlag(base, LPUART_PARITY_ERR))
1229  {
1230  /* Update the internal status */
1231  lpuartState->receiveStatus = STATUS_UART_PARITY_ERROR;
1232  if (lpuartState->transferType == LPUART_USING_INTERRUPTS)
1233  {
1234  /* Complete the transfer (disable rx logic) */
1236  }
1237 #if FEATURE_LPUART_HAS_DMA_ENABLE
1238  else
1239  {
1240  /* Complete the transfer (stop DMA channel) */
1241  LPUART_DRV_StopRxDma(instance);
1242  }
1243 #endif
1244  /* Invoke callback if there is one */
1245  if (lpuartState->rxCallback != NULL)
1246  {
1247  lpuartState->rxCallback(lpuartState, UART_EVENT_ERROR, lpuartState->rxCallbackParam);
1248  }
1249 
1250  /* Clear the flag */
1251  (void)LPUART_ClearStatusFlag(base, LPUART_PARITY_ERR);
1252  }
1253  /* Handle noise error interrupt */
1254  else if (LPUART_GetStatusFlag(base, LPUART_NOISE_DETECT))
1255  {
1256  /* Update the internal status */
1257  lpuartState->receiveStatus = STATUS_UART_NOISE_ERROR;
1258  if (lpuartState->transferType == LPUART_USING_INTERRUPTS)
1259  {
1260  /* Complete transfer (disable rx logic) */
1262  }
1263 #if FEATURE_LPUART_HAS_DMA_ENABLE
1264  else
1265  {
1266  /* Complete the transfer (stop DMA channel) */
1267  LPUART_DRV_StopRxDma(instance);
1268  }
1269 #endif
1270  /* Invoke callback if there is one */
1271  if (lpuartState->rxCallback != NULL)
1272  {
1273  lpuartState->rxCallback(lpuartState, UART_EVENT_ERROR, lpuartState->rxCallbackParam);
1274  }
1275 
1276  /* Clear the flag */
1277  (void)LPUART_ClearStatusFlag(base, LPUART_NOISE_DETECT);
1278  }
1279  else
1280  {
1281  /* Do nothing - avoid MISRA violation; program will never run through this branch */
1282  }
1283 }
1284 
1285 /*FUNCTION**********************************************************************
1286  *
1287  * Function Name : LPUART_DRV_StartSendDataUsingInt
1288  * Description : Initiate (start) a transmit by beginning the process of
1289  * sending data and enabling the interrupt.
1290  * This is not a public API as it is called from other driver functions.
1291  *
1292  *END**************************************************************************/
1294  const uint8_t * txBuff,
1295  uint32_t txSize)
1296 {
1297  DEV_ASSERT(instance < LPUART_INSTANCE_COUNT);
1298  DEV_ASSERT(txBuff != NULL);
1299 
1300  LPUART_Type * base = s_lpuartBase[instance];
1301  lpuart_state_t * lpuartState = (lpuart_state_t *)s_lpuartStatePtr[instance];
1302 
1303  /* Check it's not busy transmitting data from a previous function call */
1304  if (lpuartState->isTxBusy)
1305  {
1306  return STATUS_BUSY;
1307  }
1308 
1309  /* Check the validity of the parameters */
1310  DEV_ASSERT(txSize > 0U);
1312  ((txSize & 1U) == 0U));
1313 
1314  /* initialize the module driver state structure */
1315  lpuartState->txBuff = txBuff;
1316  lpuartState->txSize = txSize;
1317  lpuartState->isTxBusy = true;
1318  lpuartState->transmitStatus = STATUS_BUSY;
1319 
1320  /* Enable the LPUART transmitter */
1321  LPUART_SetTransmitterCmd(base, true);
1322 
1323  /* Enable tx empty and transmission complete interrupt */
1324  LPUART_SetIntMode(base, LPUART_INT_TX_DATA_REG_EMPTY, true);
1325  LPUART_SetIntMode(base, LPUART_INT_TX_COMPLETE, true);
1326 
1327  return STATUS_SUCCESS;
1328 }
1329 
1330 #if FEATURE_LPUART_HAS_DMA_ENABLE
1331 /*FUNCTION**********************************************************************
1332  *
1333  * Function Name : LPUART_DRV_StartSendDataUsingDma
1334  * Description : Initiate (start) a transmit by beginning the process of
1335  * sending data using DMA transfers.
1336  * This is not a public API as it is called from other driver functions.
1337  *
1338  *END**************************************************************************/
1340  const uint8_t * txBuff,
1341  uint32_t txSize)
1342 {
1343  DEV_ASSERT(instance < LPUART_INSTANCE_COUNT);
1344  DEV_ASSERT(txBuff != NULL);
1345 
1346  LPUART_Type * base = s_lpuartBase[instance];
1347  lpuart_state_t * lpuartState = (lpuart_state_t *)s_lpuartStatePtr[instance];
1348 
1349  /* Check it's not busy transmitting data from a previous function call */
1350  if (lpuartState->isTxBusy)
1351  {
1352  return STATUS_BUSY;
1353  }
1354 
1355  DEV_ASSERT(txSize > 0U);
1356 
1357  /* Update state structure */
1358  lpuartState->txBuff = txBuff;
1359  lpuartState->txSize = 0U;
1360  lpuartState->isTxBusy = true;
1361  lpuartState->transmitStatus = STATUS_BUSY;
1362 
1363  /* Configure the transfer control descriptor for the previously allocated channel */
1364  (void)EDMA_DRV_ConfigMultiBlockTransfer(lpuartState->txDMAChannel, EDMA_TRANSFER_MEM2PERIPH, (uint32_t)txBuff,
1365  (uint32_t)(&(base->DATA)), EDMA_TRANSFER_SIZE_1B, 1U, txSize, true);
1366 
1367  /* Call driver function to end the transmission when the DMA transfer is done */
1368  (void)EDMA_DRV_InstallCallback(lpuartState->txDMAChannel,
1370  (void*)(instance));
1371 
1372  /* Start the DMA channel */
1373  (void)EDMA_DRV_StartChannel(lpuartState->txDMAChannel);
1374 
1375  /* Enable the LPUART transmitter */
1376  LPUART_SetTransmitterCmd(base, true);
1377 
1378  /* Enable tx DMA requests for the current instance */
1379  LPUART_SetTxDmaCmd(base, true);
1380 
1381  /* Enable transmission complete interrupt */
1382  LPUART_SetIntMode(base, LPUART_INT_TX_COMPLETE, true);
1383 
1384  return STATUS_SUCCESS;
1385 }
1386 #endif
1387 
1388 /*FUNCTION**********************************************************************
1389  *
1390  * Function Name : LPUART_DRV_CompleteSendDataUsingInt
1391  * Description : Finish up a transmit by completing the process of sending
1392  * data and disabling the interrupt.
1393  * This is not a public API as it is called from other driver functions.
1394  *
1395  *END**************************************************************************/
1396 static void LPUART_DRV_CompleteSendDataUsingInt(uint32_t instance)
1397 {
1398  DEV_ASSERT(instance < LPUART_INSTANCE_COUNT);
1399 
1400  LPUART_Type * base = s_lpuartBase[instance];
1401  lpuart_state_t * lpuartState = (lpuart_state_t *)s_lpuartStatePtr[instance];
1402 
1403  if (lpuartState->transmitStatus == STATUS_BUSY)
1404  {
1405  /* If the transfer is completed, update the transmit status */
1406  lpuartState->transmitStatus = STATUS_SUCCESS;
1407  }
1408  else
1409  {
1410  /* If the transfer is aborted or timed out, disable tx empty interrupt */
1411  LPUART_SetIntMode(base, LPUART_INT_TX_DATA_REG_EMPTY, false);
1412  }
1413 
1414  /* Disable transmission complete interrupt */
1415  LPUART_SetIntMode(base, LPUART_INT_TX_COMPLETE, false);
1416 
1417  /* Disable transmitter */
1418  LPUART_SetTransmitterCmd(base, false);
1419 
1420  /* Update the internal busy flag */
1421  lpuartState->isTxBusy = false;
1422 
1423  /* Signal the synchronous completion object. */
1424  if (lpuartState->isTxBlocking)
1425  {
1426  (void)OSIF_SemaPost(&lpuartState->txComplete);
1427  }
1428 }
1429 
1430 #if FEATURE_LPUART_HAS_DMA_ENABLE
1431 /*FUNCTION**********************************************************************
1432  *
1433  * Function Name : LPUART_DRV_TxDmaCallback
1434  * Description : Finish up a transmit by completing the process of sending
1435  * data and disabling the DMA requests. This is a callback for DMA major loop
1436  * completion, so it must match the DMA callback signature.
1437  * This is not a public API as it is called from other driver functions.
1438  *
1439  *END**************************************************************************/
1440 static void LPUART_DRV_TxDmaCallback(void * parameter, edma_chn_status_t status)
1441 {
1442  if (status != EDMA_CHN_NORMAL)
1443  {
1444  return;
1445  }
1446 
1447  uint32_t instance = ((uint32_t)parameter);
1448  lpuart_state_t * lpuartState = (lpuart_state_t *)s_lpuartStatePtr[instance];
1449 
1450  /* Invoke callback if there is one */
1451  if (lpuartState->txCallback != NULL)
1452  {
1453  /* Allow the user to provide a new buffer, for continuous transmission */
1454  lpuartState->txCallback(lpuartState, UART_EVENT_TX_EMPTY, lpuartState->txCallbackParam);
1455  }
1456 
1457  /* If the callback has updated the tx buffer, update the DMA descriptor to continue the transfer;
1458  * otherwise, stop the current transfer.
1459  */
1460  if (lpuartState->txSize > 0U)
1461  {
1462  /* Set the source address and the number of minor loops (bytes to be transfered) */
1463  EDMA_DRV_SetSrcAddr(lpuartState->txDMAChannel, (uint32_t)(lpuartState->txBuff));
1464  EDMA_DRV_SetMajorLoopIterationCount(lpuartState->txDMAChannel, lpuartState->txSize);
1465 
1466  /* Now that this tx is set up, clear remaining bytes count */
1467  lpuartState->txSize = 0U;
1468 
1469  /* Re-start the channel */
1470  (void)EDMA_DRV_StartChannel(lpuartState->txDMAChannel);
1471  }
1472 }
1473 #endif
1474 
1475 /*FUNCTION**********************************************************************
1476  *
1477  * Function Name : LPUART_DRV_StartReceiveDataUsingInt
1478  * Description : Initiate (start) a receive by beginning the process of
1479  * receiving data and enabling the interrupt.
1480  * This is not a public API as it is called from other driver functions.
1481  *
1482  *END**************************************************************************/
1484  uint8_t * rxBuff,
1485  uint32_t rxSize)
1486 {
1487  DEV_ASSERT(instance < LPUART_INSTANCE_COUNT);
1488  DEV_ASSERT(rxBuff != NULL);
1489 
1490  lpuart_state_t * lpuartState = (lpuart_state_t *)s_lpuartStatePtr[instance];
1491  LPUART_Type * base = s_lpuartBase[instance];
1492 
1493  /* Check it's not busy receiving data from a previous function call */
1494  if (lpuartState->isRxBusy)
1495  {
1496  return STATUS_BUSY;
1497  }
1498 
1499  /* Check the validity of the parameters */
1500  DEV_ASSERT(rxSize > 0U);
1502  ((rxSize & 1U) == 0U));
1503 
1504  /* Initialize the module driver state struct to indicate transfer in progress
1505  * and with the buffer and byte count data. */
1506  lpuartState->isRxBusy = true;
1507  lpuartState->rxBuff = rxBuff;
1508  lpuartState->rxSize = rxSize;
1509  lpuartState->receiveStatus = STATUS_BUSY;
1510 
1511  /* Enable the receiver */
1512  LPUART_SetReceiverCmd(base, true);
1513 
1514  /* Enable error interrupts */
1515  LPUART_SetErrorInterrupts(base, true);
1516 
1517  /* Enable receive data full interrupt */
1518  LPUART_SetIntMode(base, LPUART_INT_RX_DATA_REG_FULL, true);
1519 
1520  return STATUS_SUCCESS;
1521 }
1522 
1523 #if FEATURE_LPUART_HAS_DMA_ENABLE
1524 /*FUNCTION**********************************************************************
1525  *
1526  * Function Name : LPUART_DRV_StartReceiveDataUsingDma
1527  * Description : Initiate (start) a receive by beginning the process of
1528  * receiving data using DMA transfers.
1529  * This is not a public API as it is called from other driver functions.
1530  *
1531  *END**************************************************************************/
1533  uint8_t * rxBuff,
1534  uint32_t rxSize)
1535 {
1536  DEV_ASSERT(instance < LPUART_INSTANCE_COUNT);
1537  DEV_ASSERT(rxBuff != NULL);
1538 
1539  LPUART_Type * base = s_lpuartBase[instance];
1540  lpuart_state_t * lpuartState = (lpuart_state_t *)s_lpuartStatePtr[instance];
1541 
1542  /* Check it's not busy transmitting data from a previous function call */
1543  if (lpuartState->isRxBusy)
1544  {
1545  return STATUS_BUSY;
1546  }
1547 
1548  DEV_ASSERT(rxSize > 0U);
1549 
1550  /* Configure the transfer control descriptor for the previously allocated channel */
1552  (uint32_t)(&(base->DATA)), (uint32_t)rxBuff, EDMA_TRANSFER_SIZE_1B,
1553  1U, rxSize, true);
1554 
1555  /* Call driver function to end the reception when the DMA transfer is done */
1556  (void)EDMA_DRV_InstallCallback(lpuartState->rxDMAChannel,
1558  (void*)(instance));
1559 
1560  /* Start the DMA channel */
1561  (void)EDMA_DRV_StartChannel(lpuartState->rxDMAChannel);
1562 
1563  /* Update the state structure */
1564  lpuartState->rxBuff = rxBuff;
1565  lpuartState->rxSize = 0U;
1566  lpuartState->isRxBusy = true;
1567  lpuartState->receiveStatus = STATUS_BUSY;
1568 
1569  /* Enable the receiver */
1570  LPUART_SetReceiverCmd(base, true);
1571 
1572  /* Enable error interrupts */
1573  LPUART_SetErrorInterrupts(base, true);
1574 
1575  /* Enable rx DMA requests for the current instance */
1576  LPUART_SetRxDmaCmd(base, true);
1577 
1578  return STATUS_SUCCESS;
1579 }
1580 #endif
1581 
1582 /*FUNCTION**********************************************************************
1583  *
1584  * Function Name : LPUART_DRV_CompleteReceiveDataUsingInt
1585  * Description : Finish up a receive by completing the process of receiving data
1586  * and disabling the interrupt.
1587  * This is not a public API as it is called from other driver functions.
1588  *
1589  *END**************************************************************************/
1590 static void LPUART_DRV_CompleteReceiveDataUsingInt(uint32_t instance)
1591 {
1592  DEV_ASSERT(instance < LPUART_INSTANCE_COUNT);
1593 
1594  uint8_t tmpByte;
1595  lpuart_state_t * lpuartState = (lpuart_state_t *)s_lpuartStatePtr[instance];
1596  LPUART_Type * base = s_lpuartBase[instance];
1597 
1598  /* Disable receiver */
1599  LPUART_SetReceiverCmd(base, false);
1600 
1601  /* Disable error interrupts */
1602  LPUART_SetErrorInterrupts(base, false);
1603 
1604  /* Read dummy to clear RDRF flag */
1605  LPUART_Getchar(base, &tmpByte);
1606 
1607  /* Disable receive data full and rx overrun interrupt. */
1608  LPUART_SetIntMode(base, LPUART_INT_RX_DATA_REG_FULL, false);
1609 
1610  /* Signal the synchronous completion object. */
1611  if (lpuartState->isRxBlocking)
1612  {
1613  (void)OSIF_SemaPost(&lpuartState->rxComplete);
1614  }
1615 
1616  /* Update the information of the module driver state */
1617  lpuartState->isRxBusy = false;
1618  if (lpuartState->receiveStatus == STATUS_BUSY)
1619  {
1620  lpuartState->receiveStatus = STATUS_SUCCESS;
1621  }
1622 }
1623 
1624 #if FEATURE_LPUART_HAS_DMA_ENABLE
1625 /*FUNCTION**********************************************************************
1626  *
1627  * Function Name : LPUART_DRV_RxDmaCallback
1628  * Description : Finish up a receive by completing the process of receiving data
1629  * and disabling the DMA requests. This is a callback for DMA major loop
1630  * completion, so it must match the DMA callback signature.
1631  * This is not a public API as it is called from other driver functions.
1632  *
1633  *END**************************************************************************/
1634 static void LPUART_DRV_RxDmaCallback(void * parameter, edma_chn_status_t status)
1635 {
1636  if (status != EDMA_CHN_NORMAL)
1637  {
1638  return;
1639  }
1640 
1641  uint32_t instance = ((uint32_t)parameter);
1642  lpuart_state_t * lpuartState = (lpuart_state_t *)s_lpuartStatePtr[instance];
1643 
1644  /* Return if an error occurred; error cases are treated by the interrupt handler */
1645  if (lpuartState->receiveStatus != STATUS_BUSY)
1646  {
1647  return;
1648  }
1649 
1650  /* Invoke callback if there is one */
1651  if (lpuartState->rxCallback != NULL)
1652  {
1653  /* Allow the user to provide a new buffer inside the callback, to continue the reception */
1654  lpuartState->rxCallback(lpuartState, UART_EVENT_RX_FULL, lpuartState->rxCallbackParam);
1655  }
1656 
1657  /* If the callback has updated the rx buffer, update the DMA descriptor to continue the transfer;
1658  * otherwise, stop the current transfer.
1659  */
1660  if (lpuartState->rxSize > 0U)
1661  {
1662  /* Set the source address and the number of minor loops (bytes to be transfered) */
1663  EDMA_DRV_SetDestAddr(lpuartState->rxDMAChannel, (uint32_t)(lpuartState->rxBuff));
1664  EDMA_DRV_SetMajorLoopIterationCount(lpuartState->rxDMAChannel, lpuartState->rxSize);
1665 
1666  /* Now that this rx is set up, clear remaining bytes count */
1667  lpuartState->rxSize = 0U;
1668 
1669  /* Re-start the channel */
1670  (void)EDMA_DRV_StartChannel(lpuartState->rxDMAChannel);
1671  }
1672  else
1673  {
1674  /* Stop the reception */
1675  LPUART_DRV_StopRxDma(instance);
1676 
1677  /* Invoke the callback to notify the end of the transfer */
1678  if (lpuartState->rxCallback != NULL)
1679  {
1680  lpuartState->rxCallback(lpuartState, UART_EVENT_END_TRANSFER, lpuartState->rxCallbackParam);
1681  }
1682  }
1683 }
1684 #endif
1685 
1686 /*FUNCTION**********************************************************************
1687  *
1688  * Function Name : LPUART_DRV_PutData
1689  * Description : Write data to the buffer register, according to configured
1690  * word length.
1691  * This is not a public API as it is called from other driver functions.
1692  *
1693  *END**************************************************************************/
1694 static void LPUART_DRV_PutData(uint32_t instance)
1695 {
1696  const lpuart_state_t * lpuartState = (lpuart_state_t *)s_lpuartStatePtr[instance];
1697  LPUART_Type * base = s_lpuartBase[instance];
1698  uint16_t data;
1699  const uint8_t *txBuff = lpuartState->txBuff;
1700 
1701  if (lpuartState->bitCountPerChar == LPUART_8_BITS_PER_CHAR)
1702  {
1703  /* Transmit the data */
1704  LPUART_Putchar(base, *txBuff);
1705  }
1706  else if (lpuartState->bitCountPerChar == LPUART_9_BITS_PER_CHAR)
1707  {
1708  /* Create a 16-bits integer from two bytes */
1709  data = (uint16_t)(*txBuff);
1710  ++txBuff;
1711  data |= (uint16_t)(((uint16_t)(*txBuff)) << 8U);
1712 
1713  /* Transmit the data */
1714  LPUART_Putchar9(base, data);
1715  }
1716  else
1717  {
1718  /* Create a 16-bits integer from two bytes */
1719  data = (uint16_t)(*txBuff);
1720  ++txBuff;
1721  data |= (uint16_t)(((uint16_t)(*txBuff)) << 8U);
1722 
1723  /* Transmit the data */
1724  LPUART_Putchar10(base, data);
1725  }
1726 }
1727 
1728 /*FUNCTION**********************************************************************
1729  *
1730  * Function Name : LPUART_DRV_GetData
1731  * Description : Read data from the buffer register, according to configured
1732  * word length.
1733  * This is not a public API as it is called from other driver functions.
1734  *
1735  *END**************************************************************************/
1736 static void LPUART_DRV_GetData(uint32_t instance)
1737 {
1738  const lpuart_state_t * lpuartState = (lpuart_state_t *)s_lpuartStatePtr[instance];
1739  const LPUART_Type * base = s_lpuartBase[instance];
1740  uint16_t data;
1741  uint8_t *rxBuff = lpuartState->rxBuff;
1742 
1743  if (lpuartState->bitCountPerChar == LPUART_8_BITS_PER_CHAR)
1744  {
1745  /* Receive the data */
1746  LPUART_Getchar(base, rxBuff);
1747  }
1748  else if (lpuartState->bitCountPerChar == LPUART_9_BITS_PER_CHAR)
1749  {
1750  /* Receive the data */
1751  LPUART_Getchar9(base, &data);
1752 
1753  /* Write the least significant bits to the receive buffer */
1754  *rxBuff = (uint8_t)(data & 0xFFU);
1755  ++rxBuff;
1756  /* Write the ninth bit to the subsequent byte in the rx buffer */
1757  *rxBuff = (uint8_t)(data >> 8U);
1758  }
1759  else
1760  {
1761  /* Receive the data */
1762  LPUART_Getchar10(base, &data);
1763 
1764  /* Write the least significant bits to the receive buffer */
1765  *rxBuff = (uint8_t)(data & 0xFFU);
1766  ++rxBuff;
1767  /* Write the ninth and tenth bits to the subsequent byte in the rx buffer */
1768  *rxBuff = (uint8_t)(data >> 8U);
1769  }
1770 }
1771 
1772 #if FEATURE_LPUART_HAS_DMA_ENABLE
1773 /*FUNCTION**********************************************************************
1774  *
1775  * Function Name : LPUART_DRV_StopTxDma
1776  * Description : Finish up a DMA transmission by disabling the DMA requests,
1777  * transmission complete interrupt and tx logic. This function also resets the
1778  * internal driver state (busy flag/tx semaphore).
1779  * This is not a public API as it is called from other driver functions.
1780  *
1781  *END**************************************************************************/
1782 static void LPUART_DRV_StopTxDma(uint32_t instance)
1783 {
1784  LPUART_Type * base = s_lpuartBase[instance];
1785  lpuart_state_t * lpuartState = (lpuart_state_t *)s_lpuartStatePtr[instance];
1786 
1787  /* Disable tx DMA requests for the current instance */
1788  LPUART_SetTxDmaCmd(base, false);
1789 
1790  /* Stop the dma channel */
1791  (void)EDMA_DRV_StopChannel(lpuartState->txDMAChannel);
1792 
1793  /* Disable transmission complete interrupt */
1794  LPUART_SetIntMode(base, LPUART_INT_TX_COMPLETE, false);
1795 
1796  /* Disable transmitter */
1797  LPUART_SetTransmitterCmd(base, false);
1798 
1799  /* Signal the synchronous completion object. */
1800  if (lpuartState->isTxBlocking)
1801  {
1802  (void)OSIF_SemaPost(&lpuartState->txComplete);
1803  }
1804 
1805  if (lpuartState->transmitStatus == STATUS_BUSY)
1806  {
1807  /* If the transfer is completed, update the transmit status */
1808  lpuartState->transmitStatus = STATUS_SUCCESS;
1809  }
1810 
1811  /* Update the internal busy flag */
1812  lpuartState->isTxBusy = false;
1813 }
1814 
1815 /*FUNCTION**********************************************************************
1816  *
1817  * Function Name : LPUART_DRV_StopRxDma
1818  * Description : Finish up a DMA reception by disabling the DMA requests,
1819  * error interrupts and rx logic. This function also resets the internal driver
1820  * state (busy flag/rx semaphore).
1821  * This is not a public API as it is called from other driver functions.
1822  *
1823  *END**************************************************************************/
1824 static void LPUART_DRV_StopRxDma(uint32_t instance)
1825 {
1826  LPUART_Type * base = s_lpuartBase[instance];
1827  lpuart_state_t * lpuartState = (lpuart_state_t *)s_lpuartStatePtr[instance];
1828 
1829  /* Disable receiver */
1830  LPUART_SetReceiverCmd(base, false);
1831 
1832  /* Disable error interrupts */
1833  LPUART_SetErrorInterrupts(base, false);
1834 
1835  /* Disable rx DMA requests for the current instance */
1836  LPUART_SetRxDmaCmd(base, false);
1837 
1838  /* Stop the DMA channel */
1839  (void)EDMA_DRV_StopChannel(lpuartState->rxDMAChannel);
1840 
1841  /* Signal the synchronous completion object. */
1842  if (lpuartState->isRxBlocking)
1843  {
1844  (void)OSIF_SemaPost(&lpuartState->rxComplete);
1845  }
1846 
1847  /* Update the internal driver status */
1848  if (lpuartState->receiveStatus == STATUS_BUSY)
1849  {
1850  lpuartState->receiveStatus = STATUS_SUCCESS;
1851  }
1852 
1853  /* Update the information of the module driver state */
1854  lpuartState->isRxBusy = false;
1855 }
1856 #endif
1857 
1858 /*******************************************************************************
1859  * EOF
1860  ******************************************************************************/
status_t LPUART_DRV_AbortSendingData(uint32_t instance)
Terminates a non-blocking transmission early.
void EDMA_DRV_SetMajorLoopIterationCount(uint8_t virtualChannel, uint32_t majorLoopCount)
Configures the number of major loop iterations.
Definition: edma_driver.c:1316
static void LPUART_DRV_CompleteReceiveDataUsingInt(uint32_t instance)
static status_t LPUART_DRV_StartReceiveDataUsingDma(uint32_t instance, uint8_t *rxBuff, uint32_t rxSize)
uint32_t EDMA_DRV_GetRemainingMajorIterationsCount(uint8_t virtualChannel)
Returns the remaining major loop iteration count.
Definition: edma_driver.c:1346
#define LPUART_BASE_PTRS
Definition: S32K118.h:6549
status_t EDMA_DRV_InstallCallback(uint8_t virtualChannel, edma_callback_t callback, void *parameter)
Registers the callback function and the parameter for eDMA channel.
Definition: edma_driver.c:336
status_t LPUART_DRV_SendDataBlocking(uint32_t instance, const uint8_t *txBuff, uint32_t txSize, uint32_t timeout)
Sends data out through the LPUART module using a blocking method.
static void LPUART_DRV_GetData(uint32_t instance)
uart_callback_t LPUART_DRV_InstallTxCallback(uint32_t instance, uart_callback_t function, void *callbackParam)
Installs callback function for the LPUART transmit.
void LPUART_DRV_SendDataPolling(uint32_t instance, const uint8_t *txBuff, uint32_t txSize)
Send out multiple bytes of data using polling method.
status_t OSIF_SemaDestroy(const semaphore_t *const pSem)
Destroys a previously created semaphore.
status_t LPUART_DRV_Deinit(uint32_t instance)
Shuts down the LPUART by disabling interrupts and transmitter/receiver.
status_t LPUART_DRV_SendData(uint32_t instance, const uint8_t *txBuff, uint32_t txSize)
Sends data out through the LPUART module using a non-blocking method. This enables an a-sync method f...
volatile bool isRxBlocking
void DefaultISR(void)
Default ISR.
status_t EDMA_DRV_ConfigMultiBlockTransfer(uint8_t virtualChannel, edma_transfer_type_t type, uint32_t srcAddr, uint32_t destAddr, edma_transfer_size_t transferSize, uint32_t blockSize, uint32_t blockCount, bool disableReqOnCompletion)
Configures a multiple block data transfer with DMA.
Definition: edma_driver.c:662
static lpuart_state_t * s_lpuartStatePtr[(2u)]
Definition: lpuart_driver.c:95
void * txCallbackParam
status_t LPUART_DRV_AbortReceivingData(uint32_t instance)
Terminates a non-blocking receive early.
isr_t g_lpuartIsr[(2u)]
Definition: lpuart_irq.c:72
static const IRQn_Type s_lpuartRxTxIrqId[(2u)]
uint8_t txDMAChannel
uart_callback_t rxCallback
status_t LPUART_DRV_ReceiveDataPolling(uint32_t instance, uint8_t *rxBuff, uint32_t rxSize)
Receive multiple bytes of data using polling method.
volatile bool isRxBusy
Definition: lpuart_driver.h:99
status_t OSIF_SemaCreate(semaphore_t *const pSem, const uint8_t initValue)
Creates a semaphore with a given value.
semaphore_t rxComplete
#define LPUART_CLOCK_NAMES
static void LPUART_DRV_CompleteSendDataUsingInt(uint32_t instance)
static status_t LPUART_DRV_StartSendDataUsingDma(uint32_t instance, const uint8_t *txBuff, uint32_t txSize)
void * rxCallbackParam
lpuart_bit_count_per_char_t bitCountPerChar
status_t EDMA_DRV_StopChannel(uint8_t virtualChannel)
Stops the eDMA channel.
Definition: edma_driver.c:952
void INT_SYS_DisableIRQ(IRQn_Type irqNumber)
Disables an interrupt for a given IRQ number.
lpuart_transfer_type_t transferType
lpuart_parity_mode_t parityMode
#define DEV_ASSERT(x)
Definition: devassert.h:77
edma_chn_status_t
Channel status for eDMA channel.
Definition: edma_driver.h:255
status_t LPUART_DRV_ReceiveData(uint32_t instance, uint8_t *rxBuff, uint32_t rxSize)
Gets data from the LPUART module by using a non-blocking method. This enables an a-sync method for re...
void EDMA_DRV_SetDestAddr(uint8_t virtualChannel, uint32_t address)
Configures the destination address for the eDMA channel.
Definition: edma_driver.c:1196
status_t CLOCK_SYS_GetFreq(clock_names_t clockName, uint32_t *frequency)
Gets the clock frequency for a specific clock name.
static void LPUART_DRV_PutData(uint32_t instance)
void LPUART_DRV_IRQHandler(uint32_t instance)
uart_callback_t LPUART_DRV_InstallRxCallback(uint32_t instance, uart_callback_t function, void *callbackParam)
Installs callback function for the LPUART receive.
semaphore_t txComplete
status_t
Status return codes. Common error codes will be a unified enumeration (C enum) that will contain all ...
Definition: status.h:44
IRQn_Type
Defines the Interrupt Numbers definitions.
Definition: S32K118.h:188
uint8_t * rxBuff
Definition: lpuart_driver.h:95
uint8_t rxDMAChannel
status_t LPUART_DRV_SetBaudRate(uint32_t instance, uint32_t desiredBaudRate)
Configures the LPUART baud rate.
const uint8_t * txBuff
Definition: lpuart_driver.h:94
static void LPUART_DRV_StopTxDma(uint32_t instance)
status_t LPUART_DRV_Init(uint32_t instance, lpuart_state_t *lpuartStatePtr, const lpuart_user_config_t *lpuartUserConfig)
Initializes an LPUART operation instance.
status_t LPUART_DRV_SetTxBuffer(uint32_t instance, const uint8_t *txBuff, uint32_t txSize)
Sets the internal driver reference to the tx buffer.
uart_callback_t txCallback
static status_t LPUART_DRV_StartReceiveDataUsingInt(uint32_t instance, uint8_t *rxBuff, uint32_t rxSize)
void EDMA_DRV_SetSrcAddr(uint8_t virtualChannel, uint32_t address)
Configures the source address for the eDMA channel.
Definition: edma_driver.c:1046
static void LPUART_DRV_TxDmaCallback(void *parameter, edma_chn_status_t status)
status_t OSIF_SemaWait(semaphore_t *const pSem, const uint32_t timeout)
Decrement a semaphore with timeout.
volatile status_t transmitStatus
status_t LPUART_DRV_ReceiveDataBlocking(uint32_t instance, uint8_t *rxBuff, uint32_t rxSize, uint32_t timeout)
Gets data from the LPUART module by using a blocking method. Blocking means that the function does no...
static void LPUART_DRV_RxDmaCallback(void *parameter, edma_chn_status_t status)
volatile uint32_t txSize
Definition: lpuart_driver.h:96
static status_t LPUART_DRV_StartSendDataUsingInt(uint32_t instance, const uint8_t *txBuff, uint32_t txSize)
status_t OSIF_SemaPost(semaphore_t *const pSem)
Increment a semaphore.
static LPUART_Type *const s_lpuartBase[(2u)]
Definition: lpuart_driver.c:98
volatile bool isTxBlocking
status_t EDMA_DRV_StartChannel(uint8_t virtualChannel)
Starts an eDMA channel.
Definition: edma_driver.c:921
LPUART configuration structure.
#define LPUART_INSTANCE_COUNT
Definition: S32K118.h:6534
void INT_SYS_EnableIRQ(IRQn_Type irqNumber)
Enables an interrupt for a given IRQ number.
volatile uint32_t DATA
Definition: S32K118.h:6526
void(* uart_callback_t)(void *driverState, uart_event_t event, void *userData)
Callback for all peripherals which support UART features.
Definition: callbacks.h:103
volatile uint32_t rxSize
Definition: lpuart_driver.h:97
void(* edma_callback_t)(void *parameter, edma_chn_status_t status)
Definition for the eDMA channel callback function.
Definition: edma_driver.h:266
void LPUART_DRV_GetBaudRate(uint32_t instance, uint32_t *configuredBaudRate)
Returns the LPUART baud rate.
clock_names_t
Clock names.
status_t LPUART_DRV_GetTransmitStatus(uint32_t instance, uint32_t *bytesRemaining)
Returns whether the previous transmit is complete.
lpuart_transfer_type_t transferType
void(* isr_t)(void)
Interrupt handler type.
lpuart_bit_count_per_char_t bitCountPerChar
volatile status_t receiveStatus
Runtime state of the LPUART driver.
Definition: lpuart_driver.h:92
status_t LPUART_DRV_GetReceiveStatus(uint32_t instance, uint32_t *bytesRemaining)
Returns whether the previous receive is complete.
volatile bool isTxBusy
Definition: lpuart_driver.h:98
#define LPUART_RX_TX_IRQS
Definition: S32K118.h:6555
status_t LPUART_DRV_SetRxBuffer(uint32_t instance, uint8_t *rxBuff, uint32_t rxSize)
Sets the internal driver reference to the rx buffer.
static void LPUART_DRV_StopRxDma(uint32_t instance)
static const clock_names_t s_lpuartClkNames[(2u)]
void INT_SYS_InstallHandler(IRQn_Type irqNumber, const isr_t newHandler, isr_t *const oldHandler)
Installs an interrupt handler routine for a given IRQ number.
lpuart_stop_bit_count_t stopBitCount