S32 SDK
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 
81 #include "lpuart_driver.h"
82 
83 /*******************************************************************************
84  * Variables
85  ******************************************************************************/
86 
87 /* Pointer to lpuart runtime state structure */
89 
92 
93 /*******************************************************************************
94  * Private Functions
95  ******************************************************************************/
96 static status_t LPUART_DRV_StartSendDataUsingInt(uint32_t instance,
97  const uint8_t * txBuff,
98  uint32_t txSize);
99 #if FEATURE_LPUART_HAS_DMA_ENABLE
100 static status_t LPUART_DRV_StartSendDataUsingDma(uint32_t instance,
101  const uint8_t * txBuff,
102  uint32_t txSize);
103 #endif
104 static void LPUART_DRV_CompleteSendDataUsingInt(uint32_t instance);
105 #if FEATURE_LPUART_HAS_DMA_ENABLE
106 static void LPUART_DRV_CompleteSendDataUsingDma(void * parameter, edma_chn_status_t status);
107 #endif
108 static status_t LPUART_DRV_StartReceiveDataUsingInt(uint32_t instance,
109  uint8_t * rxBuff,
110  uint32_t rxSize);
111 #if FEATURE_LPUART_HAS_DMA_ENABLE
112 static status_t LPUART_DRV_StartReceiveDataUsingDma(uint32_t instance,
113  uint8_t * rxBuff,
114  uint32_t rxSize);
115 #endif
116 static void LPUART_DRV_CompleteReceiveDataUsingInt(uint32_t instance);
117 #if FEATURE_LPUART_HAS_DMA_ENABLE
118 static void LPUART_DRV_CompleteReceiveDataUsingDma(void * parameter, edma_chn_status_t status);
119 #endif
120 static void LPUART_DRV_PutData(uint32_t instance);
121 static void LPUART_DRV_GetData(uint32_t instance);
122 
123 /*******************************************************************************
124  * Code
125  ******************************************************************************/
126 /*FUNCTION**********************************************************************
127  *
128  * Function Name : LPUART_DRV_Init
129  * Description : This function initializes a LPUART instance for operation.
130  * This function will initialize the run-time state structure to keep track of
131  * the on-going transfers, ungate the clock to the LPUART module, initialize the
132  * module to user defined settings and default settings, configure the IRQ state
133  * structure and enable the module-level interrupt to the core, and enable the
134  * LPUART module transmitter and receiver.
135  * The following is an example of how to set up the lpuart_state_t and the
136  * lpuart_user_config_t parameters and how to call the LPUART_DRV_Init function
137  * by passing in these parameters:
138  * lpuart_user_config_t lpuartConfig;
139  * lpuartConfig.baudRate = 9600;
140  * lpuartConfig.bitCountPerChar = LPUART_8_BITS_PER_CHAR;
141  * lpuartConfig.parityMode = LPUART_PARITY_DISABLED;
142  * lpuartConfig.stopBitCount = LPUART_ONE_STOP_BIT;
143  * lpuartConfig.transferType = LPUART_USING_INTERRUPTS;
144  * lpuart_state_t lpuartState;
145  * LPUART_DRV_Init(instance, &lpuartState, &lpuartConfig);
146  *
147  * Implements : LPUART_DRV_Init_Activity
148  *END**************************************************************************/
149 status_t LPUART_DRV_Init(uint32_t instance, lpuart_state_t * lpuartStatePtr,
150  const lpuart_user_config_t * lpuartUserConfig)
151 {
152  DEV_ASSERT(instance < LPUART_INSTANCE_COUNT);
153  DEV_ASSERT(lpuartStatePtr != NULL);
154  DEV_ASSERT(lpuartUserConfig != NULL);
155 
156  status_t lpuartStatus;
157  status_t osStatusRxSem;
158  status_t osStatusTxSem;
159  uint32_t lpuartSourceClock;
160  clock_names_t instanceClkName = g_lpuartClkNames[instance];
161  LPUART_Type * base = g_lpuartBase[instance];
162  uint32_t idx;
163 
164  /* Get the LPUART clock as configured in the clock manager */
165  (void)CLOCK_SYS_GetFreq(instanceClkName, &lpuartSourceClock);
166 
167  /* Check if current instance is clock gated off. */
168  DEV_ASSERT(lpuartSourceClock > 0U);
169 
170  /* Check if current instance is already initialized. */
171  DEV_ASSERT(g_lpuartStatePtr[instance] == NULL);
172 
173 #if FEATURE_LPUART_HAS_DMA_ENABLE
174  /* In DMA mode, only 8-bits chars are supported */
175  DEV_ASSERT((lpuartUserConfig->transferType != LPUART_USING_DMA) ||
176  (lpuartUserConfig->bitCountPerChar == LPUART_8_BITS_PER_CHAR));
177 #endif
178 
179  /* Clear the state struct for this instance. */
180  uint8_t *clearStructPtr = (uint8_t *)lpuartStatePtr;
181  for (idx = 0; idx < sizeof(lpuart_state_t); idx++)
182  {
183  clearStructPtr[idx] = 0;
184  }
185 
186  /* Save runtime structure pointer.*/
187  g_lpuartStatePtr[instance] = lpuartStatePtr;
188 
189  /* Save the transfer information for runtime retrieval */
190  lpuartStatePtr->transferType = lpuartUserConfig->transferType;
191  lpuartStatePtr->bitCountPerChar = lpuartUserConfig->bitCountPerChar;
192 #if FEATURE_LPUART_HAS_DMA_ENABLE
193  lpuartStatePtr->rxDMAChannel = lpuartUserConfig->rxDMAChannel;
194  lpuartStatePtr->txDMAChannel = lpuartUserConfig->txDMAChannel;
195 #endif
196 
197  /* initialize the LPUART instance */
198  LPUART_HAL_Init(base);
199 
200  /* initialize the parameters of the LPUART config structure with desired data */
201  lpuartStatus = LPUART_HAL_SetBaudRate(base, lpuartSourceClock, lpuartUserConfig->baudRate);
202  if (lpuartStatus != STATUS_SUCCESS)
203  {
204  return STATUS_ERROR;
205  }
206  LPUART_HAL_SetBitCountPerChar(base, lpuartUserConfig->bitCountPerChar);
207  LPUART_HAL_SetParityMode(base, lpuartUserConfig->parityMode);
208  LPUART_HAL_SetStopBitCount(base, lpuartUserConfig->stopBitCount);
209 
210  /* initialize last driver operation status */
211  lpuartStatePtr->transmitStatus = STATUS_SUCCESS;
212  lpuartStatePtr->receiveStatus = STATUS_SUCCESS;
213 
214  /* finally, enable the LPUART transmitter and receiver */
215  LPUART_HAL_SetTransmitterCmd(base, true);
216  LPUART_HAL_SetReceiverCmd(base, true);
217 
218  /* Create the synchronization objects */
219  osStatusRxSem = OSIF_SemaCreate(&lpuartStatePtr->rxComplete, 0);
220  osStatusTxSem = OSIF_SemaCreate(&lpuartStatePtr->txComplete, 0);
221  if ((osStatusRxSem == STATUS_ERROR) || (osStatusTxSem == STATUS_ERROR))
222  {
223  return STATUS_ERROR;
224  }
225 
226  /* Install LPUART irq handler */
227  INT_SYS_InstallHandler(g_lpuartRxTxIrqId[instance], g_lpuartIsr[instance], (isr_t*) 0);
228 
229  /* Enable LPUART interrupt. */
231 
232  return STATUS_SUCCESS;
233 }
234 
235 /*FUNCTION**********************************************************************
236  *
237  * Function Name : LPUART_DRV_Deinit
238  * Description : This function shuts down the UART by disabling interrupts and
239  * transmitter/receiver.
240  *
241  * Implements : LPUART_DRV_Deinit_Activity
242  *END**************************************************************************/
243 status_t LPUART_DRV_Deinit(uint32_t instance)
244 {
245  DEV_ASSERT(instance < LPUART_INSTANCE_COUNT);
246 
247  clock_names_t instanceClkName = g_lpuartClkNames[instance];
248  uint32_t lpuartSourceClock;
249  LPUART_Type * base = g_lpuartBase[instance];
250  const lpuart_state_t * lpuartState = (lpuart_state_t *)g_lpuartStatePtr[instance];
251 
252  (void)CLOCK_SYS_GetFreq(instanceClkName, &lpuartSourceClock);
253 
254  /* Check if current instance is already de-initialized or is gated.*/
255  DEV_ASSERT(g_lpuartStatePtr[instance] != NULL);
256  DEV_ASSERT(lpuartSourceClock > 0U);
257 
258  /* Wait until the data is completely shifted out of shift register */
260 
261  /* Destroy the synchronization objects */
262  (void)OSIF_SemaDestroy(&lpuartState->rxComplete);
263  (void)OSIF_SemaDestroy(&lpuartState->txComplete);
264 
265  /* Disable LPUART interrupt. */
267 
268  /* Restore default handler. */
270 
271  /* disable tx and rx */
272  LPUART_HAL_SetTransmitterCmd(base, false);
273  LPUART_HAL_SetReceiverCmd(base, false);
274 
275  /* Clear our saved pointer to the state structure */
276  g_lpuartStatePtr[instance] = NULL;
277 
278  return STATUS_SUCCESS;
279 }
280 
281 /*FUNCTION**********************************************************************
282  *
283  * Function Name : LPUART_DRV_InstallRxCallback
284  * Description : Install receive data callback function.
285  *
286  * Implements : LPUART_DRV_InstallRxCallback_Activity
287  *END**************************************************************************/
289  lpuart_rx_callback_t function,
290  void * callbackParam)
291 {
292  DEV_ASSERT(instance < LPUART_INSTANCE_COUNT);
293 
294  lpuart_state_t * lpuartState = (lpuart_state_t *)g_lpuartStatePtr[instance];
295 
296  lpuart_rx_callback_t currentCallback = lpuartState->rxCallback;
297  lpuartState->rxCallback = function;
298  lpuartState->rxCallbackParam = callbackParam;
299 
300  return currentCallback;
301 }
302 
303 /*FUNCTION**********************************************************************
304  *
305  * Function Name : LPUART_DRV_InstallTxCallback
306  * Description : Install transmit data callback function, pass in NULL pointer
307  * as callback will uninstall.
308  *
309  * Implements : LPUART_DRV_InstallTxCallback_Activity
310  *END**************************************************************************/
312  lpuart_tx_callback_t function,
313  void * callbackParam)
314 {
315  DEV_ASSERT(instance < LPUART_INSTANCE_COUNT);
316 
317  lpuart_state_t * lpuartState = (lpuart_state_t *)g_lpuartStatePtr[instance];
318 
319  lpuart_tx_callback_t currentCallback = lpuartState->txCallback;
320  lpuartState->txCallback = function;
321  lpuartState->txCallbackParam = callbackParam;
322 
323  return currentCallback;
324 }
325 
326 /*FUNCTION**********************************************************************
327  *
328  * Function Name : LPUART_DRV_SendDataBlocking
329  * Description : This function sends data out through the LPUART module using
330  * blocking method. The function does not return until the transmit is complete.
331  *
332  * Implements : LPUART_DRV_SendDataBlocking_Activity
333  *END**************************************************************************/
335  const uint8_t * txBuff,
336  uint32_t txSize,
337  uint32_t timeout)
338 {
339  DEV_ASSERT(instance < LPUART_INSTANCE_COUNT);
340  DEV_ASSERT(txBuff != NULL);
341 
342  lpuart_state_t * lpuartState = (lpuart_state_t *)g_lpuartStatePtr[instance];
343  status_t retVal = STATUS_SUCCESS;
344  status_t syncStatus;
345 
346  /* Indicates this is a blocking transaction. */
347  lpuartState->isTxBlocking = true;
348 
349  DEV_ASSERT((lpuartState->transferType == LPUART_USING_INTERRUPTS) ||
350  (lpuartState->transferType == LPUART_USING_DMA));
351 
352  if (lpuartState->transferType == LPUART_USING_INTERRUPTS)
353  {
354  /* Start the transmission process using interrupts */
355  retVal = LPUART_DRV_StartSendDataUsingInt(instance, txBuff, txSize);
356  }
357 #if FEATURE_LPUART_HAS_DMA_ENABLE
358  else
359  {
360  /* Start the transmission process using DMA */
361  retVal = LPUART_DRV_StartSendDataUsingDma(instance, txBuff, txSize);
362  }
363 #endif
364 
365  if (retVal == STATUS_SUCCESS)
366  {
367  /* Wait until the transmit is complete. */
368  syncStatus = OSIF_SemaWait(&lpuartState->txComplete, timeout);
369 
370  /* Finish the transmission if timeout expired */
371  if (syncStatus == STATUS_TIMEOUT)
372  {
373  lpuartState->isTxBlocking = false;
374  if (lpuartState->transferType == LPUART_USING_INTERRUPTS)
375  {
377  }
378 #if FEATURE_LPUART_HAS_DMA_ENABLE
379  else
380  {
381  LPUART_DRV_CompleteSendDataUsingDma(((void *)instance), EDMA_CHN_NORMAL);
382  }
383 #endif
384 
385  lpuartState->transmitStatus = STATUS_TIMEOUT;
386  retVal = STATUS_TIMEOUT;
387  }
388  }
389 
390  return retVal;
391 }
392 
393 /*FUNCTION**********************************************************************
394  *
395  * Function Name : LPUART_DRV_SendData
396  * Description : This function sends data out through the LPUART module using
397  * non-blocking method. The function will return immediately after calling this
398  * function.
399  *
400  * Implements : LPUART_DRV_SendData_Activity
401  *END**************************************************************************/
402 status_t LPUART_DRV_SendData(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  status_t retVal = STATUS_SUCCESS;
410  lpuart_state_t * lpuartState = (lpuart_state_t *)g_lpuartStatePtr[instance];
411 
412  /* Indicates this is a non-blocking transaction. */
413  lpuartState->isTxBlocking = false;
414 
415  DEV_ASSERT((lpuartState->transferType == LPUART_USING_INTERRUPTS) ||
416  (lpuartState->transferType == LPUART_USING_DMA));
417 
418  if (lpuartState->transferType == LPUART_USING_INTERRUPTS)
419  {
420  /* Start the transmission process using interrupts */
421  retVal = LPUART_DRV_StartSendDataUsingInt(instance, txBuff, txSize);
422  }
423 #if FEATURE_LPUART_HAS_DMA_ENABLE
424  else
425  {
426  /* Start the transmission process using DMA */
427  retVal = LPUART_DRV_StartSendDataUsingDma(instance, txBuff, txSize);
428  }
429 #endif
430 
431  return retVal;
432 }
433 
434 /*FUNCTION**********************************************************************
435  *
436  * Function Name : LPUART_DRV_GetTransmitStatus
437  * Description : This function returns whether the previous LPUART transmit has
438  * finished. When performing non-blocking transmit, the user can call this
439  * function to ascertain the state of the current transmission:
440  * in progress (or busy) or complete (success). In addition, if the transmission
441  * is still in progress, the user can obtain the number of words that have been
442  * currently transferred.
443  *
444  * Implements : LPUART_DRV_GetTransmitStatus_Activity
445  *END**************************************************************************/
446 status_t LPUART_DRV_GetTransmitStatus(uint32_t instance, uint32_t * bytesRemaining)
447 {
448  DEV_ASSERT(instance < LPUART_INSTANCE_COUNT);
449  DEV_ASSERT(bytesRemaining != NULL);
450 
451  const lpuart_state_t * lpuartState = (lpuart_state_t *)g_lpuartStatePtr[instance];
452  const DMA_Type * edmaBase = g_edmaBase[0U];
453 
454  if (lpuartState->isTxBusy)
455  {
456  /* Fill in the bytes not transferred yet. */
457  if (lpuartState->transferType == LPUART_USING_INTERRUPTS)
458  {
459  /* In interrupt-based communication, the remaining bytes are retrieved
460  * from the state structure
461  */
462  *bytesRemaining = lpuartState->txSize;;
463  }
464 #if FEATURE_LPUART_HAS_DMA_ENABLE
465  else
466  {
467  /* In DMA-based communication, the remaining bytes are retrieved
468  * from the current DMA major loop count
469  */
470  *bytesRemaining = EDMA_HAL_TCDGetCurrentMajorCount(edmaBase, lpuartState->txDMAChannel);
471  }
472 #endif
473  }
474  else
475  {
476  *bytesRemaining = 0;
477  }
478 
479  return lpuartState->transmitStatus;
480 }
481 
482 /*FUNCTION**********************************************************************
483  *
484  * Function Name : LPUART_DRV_AbortSendingData
485  * Description : This function terminates an non-blocking LPUART transmission
486  * early. During a non-blocking LPUART transmission, the user has the option to
487  * terminate the transmission early if the transmission is still in progress.
488  *
489  * Implements : LPUART_DRV_AbortSendingData_Activity
490  *END**************************************************************************/
492 {
493  DEV_ASSERT(instance < LPUART_INSTANCE_COUNT);
494 
495  lpuart_state_t * lpuartState = (lpuart_state_t *)g_lpuartStatePtr[instance];
496 
497  /* Check if a transfer is running. */
498  if (!lpuartState->isTxBusy)
499  {
500  return STATUS_SUCCESS;
501  }
502 
503  /* Stop the running transfer. */
504  if (lpuartState->transferType == LPUART_USING_INTERRUPTS)
505  {
506  lpuartState->transmitStatus = STATUS_UART_ABORTED;
508  }
509 #if FEATURE_LPUART_HAS_DMA_ENABLE
510  else
511  {
512  lpuartState->transmitStatus = STATUS_UART_ABORTED;
513  LPUART_DRV_CompleteSendDataUsingDma(((void *)instance), EDMA_CHN_NORMAL);
514  }
515 #endif
516 
517  return STATUS_SUCCESS;
518 }
519 
520 /*FUNCTION**********************************************************************
521  *
522  * Function Name : LPUART_DRV_ReceiveDataBlocking
523  * Description : This function receives data from LPUART module using blocking
524  * method, the function does not return until the receive is complete.
525  *
526  * Implements : LPUART_DRV_ReceiveDataBlocking_Activity
527  *END**************************************************************************/
529  uint8_t * rxBuff,
530  uint32_t rxSize,
531  uint32_t timeout)
532 {
533  DEV_ASSERT(instance < LPUART_INSTANCE_COUNT);
534  DEV_ASSERT(rxBuff != NULL);
535 
536  lpuart_state_t * lpuartState = (lpuart_state_t *)g_lpuartStatePtr[instance];
537  status_t retVal = STATUS_SUCCESS;
538  status_t syncStatus;
539 
540  /* Indicates this is a blocking transaction. */
541  lpuartState->isRxBlocking = true;
542 
543  DEV_ASSERT((lpuartState->transferType == LPUART_USING_INTERRUPTS) ||
544  (lpuartState->transferType == LPUART_USING_DMA));
545 
546  if (lpuartState->transferType == LPUART_USING_INTERRUPTS)
547  {
548  /* Start the reception process using interrupts */
549  retVal = LPUART_DRV_StartReceiveDataUsingInt(instance, rxBuff, rxSize);
550  }
551 #if FEATURE_LPUART_HAS_DMA_ENABLE
552  else
553  {
554  /* Start the reception process using DMA */
555  retVal = LPUART_DRV_StartReceiveDataUsingDma(instance, rxBuff, rxSize);
556  }
557 #endif
558 
559  if (retVal == STATUS_SUCCESS)
560  {
561  /* Wait until the receive is complete. */
562  syncStatus = OSIF_SemaWait(&lpuartState->rxComplete, timeout);
563 
564  /* Finish the reception if timeout expired */
565  if (syncStatus == STATUS_TIMEOUT)
566  {
567  lpuartState->isRxBlocking = false;
568  if (lpuartState->transferType == LPUART_USING_INTERRUPTS)
569  {
571  }
572 #if FEATURE_LPUART_HAS_DMA_ENABLE
573  else
574  {
575  LPUART_DRV_CompleteReceiveDataUsingDma(((void *)instance), EDMA_CHN_NORMAL);
576  }
577 #endif
578 
579  lpuartState->receiveStatus = STATUS_TIMEOUT;
580  retVal = STATUS_TIMEOUT;
581  }
582  }
583 
584  return retVal;
585 }
586 
587 /*FUNCTION**********************************************************************
588  *
589  * Function Name : LPUART_DRV_ReceiveData
590  * Description : This function receives data from LPUART module using
591  * non-blocking method. This function returns immediately after initiating the
592  * receive function. The application has to get the receive status to see when
593  * the receive is complete. In other words, after calling non-blocking get
594  * function, the application must get the receive status to check if receive
595  * is completed or not.
596  *
597  * Implements : LPUART_DRV_ReceiveData_Activity
598  *END**************************************************************************/
600  uint8_t * rxBuff,
601  uint32_t rxSize)
602 {
603  DEV_ASSERT(instance < LPUART_INSTANCE_COUNT);
604  DEV_ASSERT(rxBuff != NULL);
605 
606  status_t retVal = STATUS_SUCCESS;
607  lpuart_state_t * lpuartState = (lpuart_state_t *)g_lpuartStatePtr[instance];
608 
609  /* Indicates this is a non-blocking transaction. */
610  lpuartState->isRxBlocking = false;
611 
612  DEV_ASSERT((lpuartState->transferType == LPUART_USING_INTERRUPTS) ||
613  (lpuartState->transferType == LPUART_USING_DMA));
614 
615  if (lpuartState->transferType == LPUART_USING_INTERRUPTS)
616  {
617  /* Start the reception process using interrupts */
618  retVal = LPUART_DRV_StartReceiveDataUsingInt(instance, rxBuff, rxSize);
619  }
620 #if FEATURE_LPUART_HAS_DMA_ENABLE
621  else
622  {
623  /* Start the reception process using DMA */
624  retVal = LPUART_DRV_StartReceiveDataUsingDma(instance, rxBuff, rxSize);
625  }
626 #endif
627 
628  return retVal;
629 }
630 
631 /*FUNCTION**********************************************************************
632  *
633  * Function Name : LPUART_DRV_GetReceiveStatus
634  * Description : This function returns whether the previous LPUART receive is
635  * complete. When performing a non-blocking receive, the user can call this
636  * function to ascertain the state of the current receive progress: in progress
637  * or complete. In addition, if the receive is still in progress, the user can
638  * obtain the number of words that have been currently received.
639  *
640  * Implements : LPUART_DRV_GetReceiveStatus_Activity
641  *END**************************************************************************/
643  uint32_t * bytesRemaining)
644 {
645  DEV_ASSERT(instance < LPUART_INSTANCE_COUNT);
646  DEV_ASSERT(bytesRemaining != NULL);
647 
648  const lpuart_state_t * lpuartState = (lpuart_state_t *)g_lpuartStatePtr[instance];
649  const DMA_Type * edmaBase = g_edmaBase[0U];
650 
651  if (lpuartState->isRxBusy)
652  {
653  /* Fill in the bytes transferred. */
654  if (lpuartState->transferType == LPUART_USING_INTERRUPTS)
655  {
656  /* In interrupt-based communication, the remaining bytes are retrieved
657  * from the state structure
658  */
659  *bytesRemaining = lpuartState->rxSize;
660  }
661 #if FEATURE_LPUART_HAS_DMA_ENABLE
662  else
663  {
664  /* In DMA-based communication, the remaining bytes are retrieved
665  * from the current DMA major loop count
666  */
667  *bytesRemaining = EDMA_HAL_TCDGetCurrentMajorCount(edmaBase, lpuartState->rxDMAChannel);
668  }
669 #endif
670  }
671  else
672  {
673  *bytesRemaining = 0;
674  }
675 
676  return lpuartState->receiveStatus;
677 }
678 
679 /*FUNCTION**********************************************************************
680  *
681  * Function Name : LPUART_DRV_AbortReceivingData
682  * Description : Terminates a non-blocking receive early.
683  *
684  * Implements : LPUART_DRV_AbortReceivingData_Activity
685  *END**************************************************************************/
687 {
688  DEV_ASSERT(instance < LPUART_INSTANCE_COUNT);
689 
690  lpuart_state_t * lpuartState = (lpuart_state_t *)g_lpuartStatePtr[instance];
691 
692  /* Check if a transfer is running. */
693  if (!lpuartState->isRxBusy)
694  {
695  return STATUS_SUCCESS;
696  }
697 
698  /* Stop the running transfer. */
699  if (lpuartState->transferType == LPUART_USING_INTERRUPTS)
700  {
701  lpuartState->receiveStatus = STATUS_UART_ABORTED;
703  }
704 #if FEATURE_LPUART_HAS_DMA_ENABLE
705  else
706  {
707  lpuartState->receiveStatus = STATUS_UART_ABORTED;
708  LPUART_DRV_CompleteReceiveDataUsingDma(((void *)instance), EDMA_CHN_NORMAL);
709  }
710 #endif
711 
712  return STATUS_SUCCESS;
713 }
714 
715 /*FUNCTION**********************************************************************
716  *
717  * Function Name : LPUART_DRV_IRQHandler
718  * Description : Interrupt handler for LPUART.
719  * This handler uses the buffers stored in the lpuart_state_t structs to transfer
720  * data. This is not a public API as it is called by IRQ whenever an interrupt
721  * occurs.
722  *
723  *END**************************************************************************/
724 void LPUART_DRV_IRQHandler(uint32_t instance)
725 {
726  DEV_ASSERT(instance < LPUART_INSTANCE_COUNT);
727 
728  lpuart_state_t * lpuartState = (lpuart_state_t *)g_lpuartStatePtr[instance];
729  LPUART_Type * base = g_lpuartBase[instance];
730 
731  /* Exit the ISR if no transfer is happening for this instance. */
732  if (!lpuartState->isTxBusy)
733  {
734  if (!lpuartState->isRxBusy)
735  {
736  return;
737  }
738  }
739 
740  /* Handle receive data full interrupt */
742  {
744  {
745  /* Invoke callback if there is one */
746  if (lpuartState->rxCallback != NULL)
747  {
748  lpuartState->rxCallback(instance, lpuartState->rxCallbackParam);
749  }
750  else
751  {
752  /* Get data and put in receive buffer */
753  LPUART_DRV_GetData(instance);
754 
755  /* Update the internal state */
756  if (lpuartState->bitCountPerChar == LPUART_8_BITS_PER_CHAR)
757  {
758  ++lpuartState->rxBuff;
759  --lpuartState->rxSize;
760  }
761  else
762  {
763  ++lpuartState->rxBuff;
764  ++lpuartState->rxBuff;
765  lpuartState->rxSize -= 2U;
766  }
767 
768  /* Finish reception if this was the last byte received */
769  if (lpuartState->rxSize == 0U)
770  {
771  /* Complete transfer, will disable rx interrupt */
773  }
774  }
775  }
776  }
777 
778  /* Handle transmitter data register empty interrupt */
780  {
782  {
783  /* Check if there are any more bytes to send */
784  if (lpuartState->txSize > 0U)
785  {
786  /* Invoke callback if there is one */
787  if (lpuartState->txCallback != NULL)
788  {
789  lpuartState->txCallback(instance, lpuartState->txCallbackParam);
790  }
791  else
792  {
793  /* Transmit the data */
794  LPUART_DRV_PutData(instance);
795 
796  /* Update the internal state */
797  if (lpuartState->bitCountPerChar == LPUART_8_BITS_PER_CHAR)
798  {
799  ++lpuartState->txBuff;
800  --lpuartState->txSize;
801  }
802  else
803  {
804  ++lpuartState->txBuff;
805  ++lpuartState->txBuff;
806  lpuartState->txSize -= 2U;
807  }
808 
809  /* Finish the transmission if this was the last byte */
810  if (lpuartState->txSize == 0U)
811  {
812  /* Complete transfer, will disable tx interrupt */
814  }
815  }
816  }
817  }
818  }
819 
820  /* Handle receive overrun interrupt */
822  {
823  lpuartState->receiveStatus = STATUS_UART_RX_OVERRUN;
824  /* Clear the flag, OR the rxDataRegFull will not be set any more */
826  }
827 }
828 
829 /*FUNCTION**********************************************************************
830  *
831  * Function Name : LPUART_DRV_StartSendDataUsingInt
832  * Description : Initiate (start) a transmit by beginning the process of
833  * sending data and enabling the interrupt.
834  * This is not a public API as it is called from other driver functions.
835  *
836  *END**************************************************************************/
838  const uint8_t * txBuff,
839  uint32_t txSize)
840 {
841  DEV_ASSERT(instance < LPUART_INSTANCE_COUNT);
842  DEV_ASSERT(txBuff != NULL);
843 
844  LPUART_Type * base = g_lpuartBase[instance];
845  lpuart_state_t * lpuartState = (lpuart_state_t *)g_lpuartStatePtr[instance];
846 
847  /* Check it's not busy transmitting data from a previous function call */
848  if (lpuartState->isTxBusy)
849  {
850  return STATUS_BUSY;
851  }
852 
853  /* Check the validity of the parameters */
854  DEV_ASSERT(txSize > 0U);
856  ((txSize & 1U) == 0U));
857 
858  /* initialize the module driver state structure */
859  lpuartState->txBuff = txBuff;
860  lpuartState->txSize = txSize;
861  lpuartState->isTxBusy = true;
862  lpuartState->transmitStatus = STATUS_BUSY;
863 
864  /* enable transmission complete interrupt */
866 
867  return STATUS_SUCCESS;
868 }
869 
870 #if FEATURE_LPUART_HAS_DMA_ENABLE
871 /*FUNCTION**********************************************************************
872  *
873  * Function Name : LPUART_DRV_StartSendDataUsingDma
874  * Description : Initiate (start) a transmit by beginning the process of
875  * sending data using DMA transfers.
876  * This is not a public API as it is called from other driver functions.
877  *
878  *END**************************************************************************/
879 static status_t LPUART_DRV_StartSendDataUsingDma(uint32_t instance,
880  const uint8_t * txBuff,
881  uint32_t txSize)
882 {
883  DEV_ASSERT(instance < LPUART_INSTANCE_COUNT);
884  DEV_ASSERT(txBuff != NULL);
885 
886  LPUART_Type * base = g_lpuartBase[instance];
887  DMA_Type * edmaBase = g_edmaBase[0U];
888  lpuart_state_t * lpuartState = (lpuart_state_t *)g_lpuartStatePtr[instance];
889 
890  /* Check it's not busy transmitting data from a previous function call */
891  if (lpuartState->isTxBusy)
892  {
893  return STATUS_BUSY;
894  }
895 
896  DEV_ASSERT(txSize > 0U);
897 
898  /* Update state structure */
899  lpuartState->txBuff = txBuff;
900  lpuartState->isTxBusy = true;
901  lpuartState->transmitStatus = STATUS_BUSY;
902 
903  /* Configure the transfer control descriptor for the previously allocated channel */
904  (void)EDMA_DRV_ConfigSingleBlockTransfer(lpuartState->txDMAChannel, EDMA_TRANSFER_MEM2PERIPH, (uint32_t)txBuff,
905  (uint32_t)(&(base->DATA)), EDMA_TRANSFER_SIZE_1B, 1U);
906  EDMA_HAL_TCDSetMajorCount(edmaBase, lpuartState->txDMAChannel, txSize);
908 
909  /* Call driver function to end the transmission when the DMA transfer is done */
910  (void)EDMA_DRV_InstallCallback(lpuartState->txDMAChannel,
911  (edma_callback_t)(LPUART_DRV_CompleteSendDataUsingDma),
912  (void*)(instance));
913 
914  /* Start the DMA channel */
915  (void)EDMA_DRV_StartChannel(lpuartState->txDMAChannel);
916 
917  /* Enable tx DMA requests for the current instance */
918  LPUART_HAL_SetTxDmaCmd(base, true);
919 
920  return STATUS_SUCCESS;
921 }
922 #endif
923 
924 /*FUNCTION**********************************************************************
925  *
926  * Function Name : LPUART_DRV_CompleteSendDataUsingInt
927  * Description : Finish up a transmit by completing the process of sending
928  * data and disabling the interrupt.
929  * This is not a public API as it is called from other driver functions.
930  *
931  *END**************************************************************************/
932 static void LPUART_DRV_CompleteSendDataUsingInt(uint32_t instance)
933 {
934  DEV_ASSERT(instance < LPUART_INSTANCE_COUNT);
935 
936  LPUART_Type * base = g_lpuartBase[instance];
937  lpuart_state_t * lpuartState = (lpuart_state_t *)g_lpuartStatePtr[instance];
938 
939  /* Disable transmission complete interrupt */
941 
942  /* Signal the synchronous completion object. */
943  if (lpuartState->isTxBlocking)
944  {
945  (void)OSIF_SemaPost(&lpuartState->txComplete);
946  }
947 
948  /* Update the information of the module driver state */
949  lpuartState->isTxBusy = false;
950  lpuartState->transmitStatus = STATUS_SUCCESS;
951 }
952 
953 #if FEATURE_LPUART_HAS_DMA_ENABLE
954 /*FUNCTION**********************************************************************
955  *
956  * Function Name : LPUART_DRV_CompleteSendDataUsingDma
957  * Description : Finish up a transmit by completing the process of sending
958  * data and disabling the DMA requests. This is a callback for DMA major loop
959  * completion, so it must match the DMA callback signature.
960  * This is not a public API as it is called from other driver functions.
961  *
962  *END**************************************************************************/
963 static void LPUART_DRV_CompleteSendDataUsingDma(void * parameter, edma_chn_status_t status)
964 {
965  if (status != EDMA_CHN_NORMAL)
966  {
967  return;
968  }
969 
970  uint32_t instance = ((uint32_t)parameter);
971  LPUART_Type * base = g_lpuartBase[instance];
972  lpuart_state_t * lpuartState = (lpuart_state_t *)g_lpuartStatePtr[instance];
973 
974  /* Disable tx DMA requests for the current instance */
975  LPUART_HAL_SetTxDmaCmd(base, false);
976 
977  /* Release the DMA channel */
978  (void)EDMA_DRV_StopChannel(lpuartState->txDMAChannel);
979 
980  /* Invoke callback if there is one */
981  if (lpuartState->txCallback != NULL)
982  {
983  /* Pass the state structure as parameter for internal information retrieval */
984  lpuartState->txCallback(instance, lpuartState->txCallbackParam);
985  }
986 
987  /* Signal the synchronous completion object. */
988  if (lpuartState->isTxBlocking)
989  {
990  (void)OSIF_SemaPost(&lpuartState->txComplete);
991  }
992 
993  /* Update the information of the module driver state */
994  lpuartState->isTxBusy = false;
995  lpuartState->transmitStatus = STATUS_SUCCESS;
996 }
997 #endif
998 
999 /*FUNCTION**********************************************************************
1000  *
1001  * Function Name : LPUART_DRV_StartReceiveDataUsingInt
1002  * Description : Initiate (start) a receive by beginning the process of
1003  * receiving data and enabling the interrupt.
1004  * This is not a public API as it is called from other driver functions.
1005  *
1006  *END**************************************************************************/
1008  uint8_t * rxBuff,
1009  uint32_t rxSize)
1010 {
1011  DEV_ASSERT(instance < LPUART_INSTANCE_COUNT);
1012  DEV_ASSERT(rxBuff != NULL);
1013 
1014  lpuart_state_t * lpuartState = (lpuart_state_t *)g_lpuartStatePtr[instance];
1015  LPUART_Type * base = g_lpuartBase[instance];
1016 
1017  /* Check it's not busy receiving data from a previous function call */
1018  if ((lpuartState->isRxBusy) && (!lpuartState->rxCallback))
1019  {
1020  return STATUS_BUSY;
1021  }
1022 
1023  /* Check the validity of the parameters */
1024  DEV_ASSERT(rxSize > 0U);
1026  ((rxSize & 1U) == 0U));
1027 
1028  /* Initialize the module driver state struct to indicate transfer in progress
1029  * and with the buffer and byte count data. */
1030  lpuartState->isRxBusy = true;
1031  lpuartState->rxBuff = rxBuff;
1032  lpuartState->rxSize = rxSize;
1033  lpuartState->receiveStatus = STATUS_BUSY;
1034 
1035  /* Enable the receive data overrun interrupt */
1037 
1038  /* Enable receive data full interrupt */
1040 
1041  return STATUS_SUCCESS;
1042 }
1043 
1044 #if FEATURE_LPUART_HAS_DMA_ENABLE
1045 /*FUNCTION**********************************************************************
1046  *
1047  * Function Name : LPUART_DRV_StartReceiveDataUsingDma
1048  * Description : Initiate (start) a receive by beginning the process of
1049  * receiving data using DMA transfers.
1050  * This is not a public API as it is called from other driver functions.
1051  *
1052  *END**************************************************************************/
1053 static status_t LPUART_DRV_StartReceiveDataUsingDma(uint32_t instance,
1054  uint8_t * rxBuff,
1055  uint32_t rxSize)
1056 {
1057  DEV_ASSERT(instance < LPUART_INSTANCE_COUNT);
1058  DEV_ASSERT(rxBuff != NULL);
1059 
1060  LPUART_Type * base = g_lpuartBase[instance];
1061  DMA_Type * edmaBase = g_edmaBase[0U];
1062  lpuart_state_t * lpuartState = (lpuart_state_t *)g_lpuartStatePtr[instance];
1063 
1064  /* Check it's not busy transmitting data from a previous function call */
1065  if (lpuartState->isRxBusy)
1066  {
1067  return STATUS_BUSY;
1068  }
1069 
1070  DEV_ASSERT(rxSize > 0U);
1071 
1072  /* Configure the transfer control descriptor for the previously allocated channel */
1074  (uint32_t)(&(base->DATA)), (uint32_t)rxBuff, EDMA_TRANSFER_SIZE_1B, 1U);
1075  EDMA_HAL_TCDSetMajorCount(edmaBase, lpuartState->rxDMAChannel, rxSize);
1076  EDMA_HAL_TCDSetDisableDmaRequestAfterTCDDoneCmd(edmaBase, lpuartState->rxDMAChannel, true);
1077 
1078  /* Call driver function to end the reception when the DMA transfer is done */
1079  (void)EDMA_DRV_InstallCallback(lpuartState->rxDMAChannel,
1080  (edma_callback_t)(LPUART_DRV_CompleteReceiveDataUsingDma),
1081  (void*)(instance));
1082 
1083  /* Start the DMA channel */
1084  (void)EDMA_DRV_StartChannel(lpuartState->rxDMAChannel);
1085 
1086  /* Enable rx DMA requests for the current instance */
1087  LPUART_HAL_SetRxDmaCmd(base, true);
1088 
1089  /* Update the state structure */
1090  lpuartState->rxBuff = rxBuff;
1091  lpuartState->isRxBusy = true;
1092  lpuartState->receiveStatus = STATUS_BUSY;
1093 
1094  /* Enable rx overrun interrupt, so the irq handler can clear the flag;
1095  * otherwise the receiver state machine may freeze on overrun condition
1096  */
1098 
1099  return STATUS_SUCCESS;
1100 }
1101 #endif
1102 
1103 /*FUNCTION**********************************************************************
1104  *
1105  * Function Name : LPUART_DRV_CompleteReceiveDataUsingInt
1106  * Description : Finish up a receive by completing the process of receiving data
1107  * and disabling the interrupt.
1108  * This is not a public API as it is called from other driver functions.
1109  *
1110  *END**************************************************************************/
1111 static void LPUART_DRV_CompleteReceiveDataUsingInt(uint32_t instance)
1112 {
1113  DEV_ASSERT(instance < LPUART_INSTANCE_COUNT);
1114 
1115  lpuart_state_t * lpuartState = (lpuart_state_t *)g_lpuartStatePtr[instance];
1116  LPUART_Type * base = g_lpuartBase[instance];
1117 
1118  /* disable receive data full and rx overrun interrupt. */
1121 
1122  /* Signal the synchronous completion object. */
1123  if (lpuartState->isRxBlocking)
1124  {
1125  (void)OSIF_SemaPost(&lpuartState->rxComplete);
1126  }
1127 
1128  /* Update the information of the module driver state */
1129  lpuartState->isRxBusy = false;
1130  lpuartState->receiveStatus = STATUS_SUCCESS;
1131 }
1132 
1133 #if FEATURE_LPUART_HAS_DMA_ENABLE
1134 /*FUNCTION**********************************************************************
1135  *
1136  * Function Name : LPUART_DRV_CompleteReceiveDataUsingDma
1137  * Description : Finish up a receive by completing the process of receiving data
1138  * and disabling the DMA requests. This is a callback for DMA major loop
1139  * completion, so it must match the DMA callback signature.
1140  * This is not a public API as it is called from other driver functions.
1141  *
1142  *END**************************************************************************/
1143 static void LPUART_DRV_CompleteReceiveDataUsingDma(void * parameter, edma_chn_status_t status)
1144 {
1145  if (status != EDMA_CHN_NORMAL)
1146  {
1147  return;
1148  }
1149 
1150  uint32_t instance = ((uint32_t)parameter);
1151  LPUART_Type * base = g_lpuartBase[instance];
1152  lpuart_state_t * lpuartState = (lpuart_state_t *)g_lpuartStatePtr[instance];
1153 
1154  /* Disable rx DMA requests for the current instance */
1155  LPUART_HAL_SetRxDmaCmd(base, false);
1156 
1157  /* Release the DMA channel */
1158  (void)EDMA_DRV_StopChannel(lpuartState->rxDMAChannel);
1160 
1161  /* Invoke callback if there is one */
1162  if (lpuartState->rxCallback != NULL)
1163  {
1164  lpuartState->rxCallback(instance, lpuartState->rxCallbackParam);
1165  }
1166 
1167  /* Signal the synchronous completion object. */
1168  if (lpuartState->isRxBlocking)
1169  {
1170  (void)OSIF_SemaPost(&lpuartState->rxComplete);
1171  }
1172 
1173  /* Update the information of the module driver state */
1174  lpuartState->isRxBusy = false;
1175  lpuartState->receiveStatus = STATUS_SUCCESS;
1176 }
1177 #endif
1178 
1179 /*FUNCTION**********************************************************************
1180  *
1181  * Function Name : LPUART_DRV_PutData
1182  * Description : Write data to the buffer register, according to configured
1183  * word length.
1184  * This is not a public API as it is called from other driver functions.
1185  *
1186  *END**************************************************************************/
1187 static void LPUART_DRV_PutData(uint32_t instance)
1188 {
1189  const lpuart_state_t * lpuartState = (lpuart_state_t *)g_lpuartStatePtr[instance];
1190  LPUART_Type * base = g_lpuartBase[instance];
1191  uint16_t data;
1192  const uint8_t *txBuff = lpuartState->txBuff;
1193 
1194  if (lpuartState->bitCountPerChar == LPUART_8_BITS_PER_CHAR)
1195  {
1196  /* Transmit the data */
1197  LPUART_HAL_Putchar(base, *txBuff);
1198  }
1199  else if (lpuartState->bitCountPerChar == LPUART_9_BITS_PER_CHAR)
1200  {
1201  /* Create a 16-bits integer from two bytes */
1202  data = (uint16_t)(*txBuff);
1203  ++txBuff;
1204  data |= (uint16_t)(((uint16_t)(*txBuff)) << 8U);
1205 
1206  /* Transmit the data */
1207  LPUART_HAL_Putchar9(base, data);
1208  }
1209  else
1210  {
1211  /* Create a 16-bits integer from two bytes */
1212  data = (uint16_t)(*txBuff);
1213  ++txBuff;
1214  data |= (uint16_t)(((uint16_t)(*txBuff)) << 8U);
1215 
1216  /* Transmit the data */
1217  LPUART_HAL_Putchar10(base, data);
1218  }
1219 }
1220 
1221 /*FUNCTION**********************************************************************
1222  *
1223  * Function Name : LPUART_DRV_GetData
1224  * Description : Read data from the buffer register, according to configured
1225  * word length.
1226  * This is not a public API as it is called from other driver functions.
1227  *
1228  *END**************************************************************************/
1229 static void LPUART_DRV_GetData(uint32_t instance)
1230 {
1231  const lpuart_state_t * lpuartState = (lpuart_state_t *)g_lpuartStatePtr[instance];
1232  const LPUART_Type * base = g_lpuartBase[instance];
1233  uint16_t data;
1234  uint8_t *rxBuff = lpuartState->rxBuff;
1235 
1236  if (lpuartState->bitCountPerChar == LPUART_8_BITS_PER_CHAR)
1237  {
1238  /* Receive the data */
1239  LPUART_HAL_Getchar(base, rxBuff);
1240  }
1241  else if (lpuartState->bitCountPerChar == LPUART_9_BITS_PER_CHAR)
1242  {
1243  /* Receive the data */
1244  LPUART_HAL_Getchar9(base, &data);
1245 
1246  /* Write the least significant bits to the receive buffer */
1247  *rxBuff = (uint8_t)(data & 0xFFU);
1248  ++rxBuff;
1249  /* Write the ninth bit to the subsequent byte in the rx buffer */
1250  *rxBuff = (uint8_t)(data >> 8U);
1251  }
1252  else
1253  {
1254  /* Receive the data */
1255  LPUART_HAL_Getchar10(base, &data);
1256 
1257  /* Write the least significant bits to the receive buffer */
1258  *rxBuff = (uint8_t)(data & 0xFFU);
1259  ++rxBuff;
1260  /* Write the ninth and tenth bits to the subsequent byte in the rx buffer */
1261  *rxBuff = (uint8_t)(data >> 8U);
1262  }
1263 }
1264 
1265 /*******************************************************************************
1266  * EOF
1267  ******************************************************************************/
status_t LPUART_DRV_AbortSendingData(uint32_t instance)
Terminates a non-blocking transmission early.
static void LPUART_DRV_CompleteReceiveDataUsingInt(uint32_t instance)
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)
const isr_t g_lpuartIsr[LPUART_INSTANCE_COUNT]
Table to save LPUART ISRs.
Definition: lpuart_common.c:98
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.
void LPUART_HAL_Putchar9(LPUART_Type *base, uint16_t data)
Sends the LPUART 9-bit character.
Definition: lpuart_hal.c:226
const clock_names_t g_lpuartClkNames[LPUART_INSTANCE_COUNT]
Table to save LPUART indexes in PCC register map for clock configuration.
Definition: lpuart_common.c:93
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
Definition: lpuart_driver.h:93
void DefaultISR(void)
Default ISR.
void * txCallbackParam
status_t LPUART_DRV_AbortReceivingData(uint32_t instance)
Terminates a non-blocking receive early.
void(* lpuart_rx_callback_t)(uint32_t instance, void *lpuartState)
LPUART receive callback function type.
Definition: lpuart_driver.h:45
lpuart_tx_callback_t LPUART_DRV_InstallTxCallback(uint32_t instance, lpuart_tx_callback_t function, void *callbackParam)
Installs callback function for the LPUART transmit.
uint8_t txDMAChannel
void(* lpuart_tx_callback_t)(uint32_t instance, void *lpuartState)
LPUART transmit callback function type.
Definition: lpuart_driver.h:51
status_t EDMA_DRV_StopChannel(uint8_t channel)
Stops the eDMA channel.
Definition: edma_driver.c:790
lpuart_tx_callback_t txCallback
void EDMA_HAL_TCDSetMajorCount(DMA_Type *base, uint32_t channel, uint32_t count)
Sets the major iteration count according to minor loop channel link setting.
Definition: edma_hal.c:388
uint32_t EDMA_HAL_TCDGetCurrentMajorCount(const DMA_Type *base, uint32_t channel)
Returns the current major iteration count.
Definition: edma_hal.c:454
volatile bool isRxBusy
Definition: lpuart_driver.h:91
status_t OSIF_SemaCreate(semaphore_t *const pSem, const uint8_t initValue)
Creates a semaphore with a given value.
semaphore_t rxComplete
static void LPUART_DRV_CompleteSendDataUsingInt(uint32_t instance)
void LPUART_HAL_SetParityMode(LPUART_Type *base, lpuart_parity_mode_t parityModeType)
Configures parity mode in the LPUART controller.
Definition: lpuart_hal.c:213
void * rxCallbackParam
lpuart_bit_count_per_char_t bitCountPerChar
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:78
lpuart_rx_callback_t LPUART_DRV_InstallRxCallback(uint32_t instance, lpuart_rx_callback_t function, void *callbackParam)
Installs callback function for the LPUART receive.
edma_chn_status_t
Channel status for eDMA channel.
Definition: edma_driver.h:125
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...
bool LPUART_HAL_GetIntMode(const LPUART_Type *base, lpuart_interrupt_t intSrc)
Returns LPUART module interrupts state.
Definition: lpuart_hal.c:418
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)
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:31
uint8_t * rxBuff
Definition: lpuart_driver.h:87
uint8_t rxDMAChannel
__IO uint32_t DATA
Definition: S32K144.h:6675
const uint8_t * txBuff
Definition: lpuart_driver.h:86
static void LPUART_HAL_SetTxDmaCmd(LPUART_Type *base, bool enable)
Configures DMA requests.
Definition: lpuart_hal.h:641
status_t LPUART_DRV_Init(uint32_t instance, lpuart_state_t *lpuartStatePtr, const lpuart_user_config_t *lpuartUserConfig)
Initializes an LPUART operation instance.
lpuart_state_t * g_lpuartStatePtr[LPUART_INSTANCE_COUNT]
Definition: lpuart_driver.c:88
lpuart_rx_callback_t rxCallback
Definition: lpuart_driver.h:95
static status_t LPUART_DRV_StartReceiveDataUsingInt(uint32_t instance, uint8_t *rxBuff, uint32_t rxSize)
static void EDMA_HAL_TCDSetDisableDmaRequestAfterTCDDoneCmd(DMA_Type *base, uint32_t channel, bool disable)
Disables/Enables the DMA request after the major loop completes for the TCD.
Definition: edma_hal.h:1117
status_t OSIF_SemaWait(semaphore_t *const pSem, const uint32_t timeout)
Decrement a semaphore with timeout.
status_t EDMA_DRV_StartChannel(uint8_t channel)
Starts an eDMA channel.
Definition: edma_driver.c:765
LPUART_Type *const g_lpuartBase[LPUART_INSTANCE_COUNT]
Table of base addresses for LPUART instances.
Definition: lpuart_common.c:87
const IRQn_Type g_lpuartRxTxIrqId[LPUART_INSTANCE_COUNT]
Table to save LPUART IRQ enumeration numbers defined in the CMSIS header file.
Definition: lpuart_common.c:90
volatile status_t transmitStatus
clock_names_t
Clock names.
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_HAL_SetTransmitterCmd(LPUART_Type *base, bool enable)
Enable/Disable the LPUART transmitter.
Definition: lpuart_hal.h:363
static void LPUART_HAL_Putchar(LPUART_Type *base, uint8_t data)
Sends the LPUART 8-bit character.
Definition: lpuart_hal.h:710
volatile uint32_t txSize
Definition: lpuart_driver.h:88
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.
volatile bool isTxBlocking
Definition: lpuart_driver.h:92
status_t LPUART_HAL_ClearStatusFlag(LPUART_Type *base, lpuart_status_flag_t statusFlag)
LPUART clears an individual status flag.
Definition: lpuart_hal.c:684
LPUART configuration structure.
void LPUART_HAL_Getchar9(const LPUART_Type *base, uint16_t *readData)
Gets the LPUART 9-bit character.
Definition: lpuart_hal.c:274
DMA_Type *const g_edmaBase[DMA_INSTANCE_COUNT]
Array for the eDMA module register base address.
Definition: edma_common.c:47
#define LPUART_INSTANCE_COUNT
Definition: S32K144.h:6683
void INT_SYS_EnableIRQ(IRQn_Type irqNumber)
Enables an interrupt for a given IRQ number.
void LPUART_HAL_Getchar10(const LPUART_Type *base, uint16_t *readData)
Gets the LPUART 10-bit character.
Definition: lpuart_hal.c:293
status_t LPUART_HAL_SetBaudRate(LPUART_Type *base, uint32_t sourceClockInHz, uint32_t desiredBaudRate)
Configures the LPUART baud rate.
Definition: lpuart_hal.c:95
volatile uint32_t rxSize
Definition: lpuart_driver.h:89
static void LPUART_HAL_SetReceiverCmd(LPUART_Type *base, bool enable)
Enable/Disable the LPUART receiver.
Definition: lpuart_hal.h:397
void(* edma_callback_t)(void *parameter, edma_chn_status_t status)
Definition for the eDMA channel callback function.
Definition: edma_driver.h:137
void LPUART_HAL_Putchar10(LPUART_Type *base, uint16_t data)
Sends the LPUART 10-bit character (Note: Feature available on select LPUART instances).
Definition: lpuart_hal.c:248
status_t EDMA_DRV_ConfigSingleBlockTransfer(uint8_t channel, edma_transfer_type_t type, uint32_t srcAddr, uint32_t destAddr, edma_transfer_size_t transferSize, uint32_t dataBufferSize)
Configures a simple single block data transfer with DMA.
Definition: edma_driver.c:487
void LPUART_HAL_SetBitCountPerChar(LPUART_Type *base, lpuart_bit_count_per_char_t bitCountPerChar)
Configures the number of bits per character in the LPUART controller.
Definition: lpuart_hal.c:187
status_t LPUART_DRV_GetTransmitStatus(uint32_t instance, uint32_t *bytesRemaining)
Returns whether the previous transmit is complete.
lpuart_transfer_type_t transferType
void LPUART_HAL_SetIntMode(LPUART_Type *base, lpuart_interrupt_t intSrc, bool enable)
Configures the LPUART module interrupts.
Definition: lpuart_hal.c:371
void(* isr_t)(void)
Interrupt handler type.
bool LPUART_HAL_GetStatusFlag(const LPUART_Type *base, lpuart_status_flag_t statusFlag)
LPUART get status flag.
Definition: lpuart_hal.c:636
lpuart_bit_count_per_char_t bitCountPerChar
Definition: lpuart_driver.h:94
volatile status_t receiveStatus
static void LPUART_HAL_SetRxDmaCmd(LPUART_Type *base, bool enable)
Configures DMA requests.
Definition: lpuart_hal.h:656
Runtime state of the LPUART driver.
Definition: lpuart_driver.h:84
static void LPUART_HAL_SetStopBitCount(LPUART_Type *base, lpuart_stop_bit_count_t stopBitCount)
Configures the number of stop bits in the LPUART controller.
Definition: lpuart_hal.h:579
status_t LPUART_DRV_GetReceiveStatus(uint32_t instance, uint32_t *bytesRemaining)
Returns whether the previous receive is complete.
status_t EDMA_DRV_InstallCallback(uint8_t channel, edma_callback_t callback, void *parameter)
Registers the callback function and the parameter for eDMA channel.
Definition: edma_driver.c:285
volatile bool isTxBusy
Definition: lpuart_driver.h:90
void LPUART_HAL_Init(LPUART_Type *base)
Initializes the LPUART controller.
Definition: lpuart_hal.c:62
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
static void LPUART_HAL_Getchar(const LPUART_Type *base, uint8_t *readData)
Gets the LPUART 8-bit character.
Definition: lpuart_hal.h:748