uart_pal.c
Go to the documentation of this file.
1 /*
2  * Copyright 2017-2018 NXP
3  * All rights reserved.
4  *
5  * THIS SOFTWARE IS PROVIDED BY NXP "AS IS" AND ANY EXPRESSED OR
6  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
7  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
8  * IN NO EVENT SHALL NXP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
9  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
10  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
11  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
12  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
13  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
14  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
15  * THE POSSIBILITY OF SUCH DAMAGE.
16  */
17 
66 #include "uart_pal.h"
67 #include "device_registers.h"
68 
69 /* Include PD files */
70 #if (defined(UART_OVER_LPUART))
71  #include "lpuart_driver.h"
72 #endif
73 
74 #if (defined(UART_OVER_FLEXIO))
75  #include "flexio.h"
76  #include "flexio_uart_driver.h"
77 #endif
78 
79 #if (defined(UART_OVER_LINFLEXD))
80  #include "linflexd_uart_driver.h"
81 #endif
82 
83 /* Define state structures for LPUART */
84 #if (defined(UART_OVER_LPUART))
85 
86  static lpuart_state_t s_lpuartState[NO_OF_LPUART_INSTS_FOR_UART];
88  static uint8_t s_lpuartStateInstanceMapping[NO_OF_LPUART_INSTS_FOR_UART];
90  static bool s_lpuartStateIsAllocated[NO_OF_LPUART_INSTS_FOR_UART];
91 #endif
92 
93 /* Define state structures for UART over FLEXIO */
94 #if (defined(UART_OVER_FLEXIO))
95 
96  static flexio_uart_state_t s_flexioUartTxState[NO_OF_FLEXIO_INSTS_FOR_UART];
98  static flexio_uart_state_t s_flexioUartRxState[NO_OF_FLEXIO_INSTS_FOR_UART];
99  flexio_device_state_t flexioDeviceState;
101  static uint8_t s_flexioUartStateInstanceMapping[NO_OF_FLEXIO_INSTS_FOR_UART];
103  static bool s_flexioUartStateIsAllocated[NO_OF_FLEXIO_INSTS_FOR_UART];
104 #endif
105 
106 /* Define state structures for LinFlexD */
107 #if (defined(UART_OVER_LINFLEXD))
108 
109  static linflexd_uart_state_t s_linFlexDState[NO_OF_LINFLEXD_INSTS_FOR_UART];
111  static uint8_t s_linFlexDStateInstanceMapping[NO_OF_LINFLEXD_INSTS_FOR_UART];
113  static bool s_linFlexDStateIsAllocated[NO_OF_LINFLEXD_INSTS_FOR_UART];
114 #endif
115 
116 /*FUNCTION**********************************************************************
117  *
118  * Function Name : UART_AllocateState
119  * Description : Allocates one of the available state structures.
120  *
121  *END**************************************************************************/
122 static uint8_t UART_AllocateState(bool* isAllocated,
123  uint8_t * instanceMapping,
124  const uart_instance_t* const instance,
125  uint8_t numberOfinstances)
126 {
127  DEV_ASSERT(isAllocated != NULL);
128  DEV_ASSERT(instanceMapping != NULL);
129  DEV_ASSERT(instance != NULL);
130 
131  uint8_t i;
132  uint32_t uartIdx = instance->instIdx;
133 
134  /* Allocate one of the UART state structures for this instance */
135  for (i = 0; i < numberOfinstances; i++)
136  {
137  if (isAllocated[i] == false)
138  {
139  instanceMapping[i] = (uint8_t)uartIdx;
140  isAllocated[i] = true;
141  break;
142  }
143  }
144  return i;
145 }
146 
147 /*FUNCTION**********************************************************************
148  *
149  * Function Name : UART_FreeState
150  * Description : Deallocates one of the available state structures.
151  *
152  *END**************************************************************************/
153 static void UART_FreeState(bool* isAllocated,
154  const uint8_t * instanceMapping,
155  const uart_instance_t * const instance,
156  uint8_t numberOfinstances)
157 {
158  DEV_ASSERT(isAllocated != NULL);
159  DEV_ASSERT(instanceMapping != NULL);
160  DEV_ASSERT(instance != NULL);
161 
162  uint8_t i;
163  uint32_t uartIdx = instance->instIdx;
164 
165  /* Free one of the UART state structures for this instance */
166  for (i = 0;i < numberOfinstances;i++)
167  {
168  if (instanceMapping[i] == (uint8_t)uartIdx)
169  {
170  isAllocated[i] = false;
171  break;
172  }
173  }
174 }
175 
176 #if (defined(UART_OVER_FLEXIO))
177 /*FUNCTION**********************************************************************
178  *
179  * Function Name : UART_FindFlexioState
180  * Description : Search the state structure of the FlexIO instance
181  *
182  *END**************************************************************************/
183 static uint8_t UART_FindFlexioState(const uart_instance_t * const instance)
184 {
185  DEV_ASSERT(instance != NULL);
186 
187  uint8_t i;
188  uint32_t uartIdx = instance->instIdx;
189 
190  for (i = 0; i < NO_OF_FLEXIO_INSTS_FOR_UART; i++)
191  {
192  if (s_flexioUartStateInstanceMapping[i] == (uint8_t)uartIdx)
193  {
194  break;
195  }
196  }
197  return i;
198 }
199 #endif
200 
201 /*FUNCTION**********************************************************************
202  *
203  * Function Name : UART_Init
204  * Description : Configures the UART module
205  *
206  * Implements : UART_Init_Activity
207  *END**************************************************************************/
208 status_t UART_Init(const uart_instance_t * const instance, const uart_user_config_t *config)
209 {
210  DEV_ASSERT(instance != NULL);
211  DEV_ASSERT(config != NULL);
212 
213  status_t status = STATUS_ERROR;
214  uint8_t index = 0;
215 
216  switch (instance->instType)
217  {
218  /* Define UART PAL over LPUART */
219  #if (defined(UART_OVER_LPUART))
222  lpuart_user_config_t lpuartConfig;
223  lpuartConfig.baudRate = config->baudRate;
224 
225  /* LPUART supports only 8, 9 or 10 bits per character */
227  (config->bitCount <= UART_10_BITS_PER_CHAR));
228  switch (config->bitCount)
229  {
232  break;
235  break;
238  break;
239  default:
240  /* Impossible type - do nothing */
241  break;
242  }
243 
244  lpuartConfig.parityMode = (lpuart_parity_mode_t)(config->parityMode);
245  lpuartConfig.stopBitCount = (lpuart_stop_bit_count_t)(config->stopBitCount);
246  lpuartConfig.transferType = (lpuart_transfer_type_t)(config->transferType);
247  lpuartConfig.rxDMAChannel = config->rxDMAChannel;
248  lpuartConfig.txDMAChannel = config->txDMAChannel;
249 
250  /* Allocate one of the LPUART state structure for this instance */
251  index = UART_AllocateState(s_lpuartStateIsAllocated,
252  s_lpuartStateInstanceMapping,
253  instance,
254  NO_OF_LPUART_INSTS_FOR_UART);
255  /* Initialize LPUART instance */
256  status = LPUART_DRV_Init(instance->instIdx, (lpuart_state_t*)(&s_lpuartState[index]), &lpuartConfig);
257 
258  /* Install Rx callback */
259  if (config->rxCallback != NULL)
260  {
261  (void)LPUART_DRV_InstallRxCallback(instance->instIdx,
262  config->rxCallback,
263  config->rxCallbackParam);
264  }
265 
266  /* Install Tx callback */
267  if (config->txCallback != NULL)
268  {
269  (void)LPUART_DRV_InstallTxCallback(instance->instIdx,
270  config->txCallback,
271  config->txCallbackParam);
272  }
273  break;
274  #endif
275  /* Define UART PAL over FLEXIO */
276  #if (defined(UART_OVER_FLEXIO))
279  /* FlexIO driver can be used with parity disabled and one stop bit */
282 
283  flexio_uart_user_config_t flexioUartTxConfig;
284  flexio_uart_user_config_t flexioUartRxConfig;
285 
286  /* Set baud rate for Tx and Rx */
287  flexioUartTxConfig.baudRate = config->baudRate;
288  flexioUartRxConfig.baudRate = config->baudRate;
289 
290  /* Set transfer type for Tx and Rx */
291  switch (config->transferType)
292  {
293  case UART_USING_DMA:
294  flexioUartTxConfig.driverType = FLEXIO_DRIVER_TYPE_DMA;
295  flexioUartRxConfig.driverType = FLEXIO_DRIVER_TYPE_DMA;
296  break;
298  flexioUartTxConfig.driverType = FLEXIO_DRIVER_TYPE_INTERRUPTS;
299  flexioUartRxConfig.driverType = FLEXIO_DRIVER_TYPE_INTERRUPTS;
300  break;
301  default:
302  /* Impossible type - do nothing */
303  break;
304  }
305 
306  /* Set bit count per char for Tx and Rx */
307  switch (config->bitCount)
308  {
310  flexioUartTxConfig.bitCount = 7U;
311  flexioUartRxConfig.bitCount = 7U;
312  break;
314  flexioUartTxConfig.bitCount = 8U;
315  flexioUartRxConfig.bitCount = 8U;
316  break;
318  flexioUartTxConfig.bitCount = 9U;
319  flexioUartRxConfig.bitCount = 9U;
320  break;
322  flexioUartTxConfig.bitCount = 10U;
323  flexioUartRxConfig.bitCount = 10U;
324  break;
326  flexioUartTxConfig.bitCount = 15U;
327  flexioUartRxConfig.bitCount = 15U;
328  break;
330  flexioUartTxConfig.bitCount = 16U;
331  flexioUartRxConfig.bitCount = 16U;
332  break;
333  default:
334  /* Impossible type - do nothing */
335  break;
336  }
337 
338  /* Configure Tx */
339  flexioUartTxConfig.direction = FLEXIO_UART_DIRECTION_TX;
340  flexioUartTxConfig.dmaChannel = config->txDMAChannel;
341  flexioUartTxConfig.dataPin = ((extension_flexio_for_uart_t *)(config->extension))->dataPinTx;
342 
343  /* Configure Rx */
344  flexioUartRxConfig.direction = FLEXIO_UART_DIRECTION_RX;
345  flexioUartRxConfig.dmaChannel = config->rxDMAChannel;
346  flexioUartRxConfig.dataPin = ((extension_flexio_for_uart_t *)(config->extension))->dataPinRx;
347 
348  /* Link Flexio Callbacks to the callbacks defined in PAL */
349  flexioUartRxConfig.callback = config->rxCallback;
350  flexioUartRxConfig.callbackParam = config->rxCallbackParam;
351  flexioUartTxConfig.callback = config->txCallback;
352  flexioUartTxConfig.callbackParam = config->txCallbackParam;
353 
354  status = FLEXIO_DRV_InitDevice(0U, &flexioDeviceState);
355  if (status == STATUS_SUCCESS)
356  {
357  /* Allocate one of the Flexio state structure for this instance */
358  index = UART_AllocateState(s_flexioUartStateIsAllocated,
359  s_flexioUartStateInstanceMapping,
360  instance,
361  NO_OF_FLEXIO_INSTS_FOR_UART);
362  /* Init FlexIO UART driver for Tx */
363  status = FLEXIO_UART_DRV_Init(0U,
364  &flexioUartTxConfig,
365  (flexio_uart_state_t*)&s_flexioUartTxState[index]);
366  /* Init FlexIO UART driver for Rx */
367  status = FLEXIO_UART_DRV_Init(0U,
368  &flexioUartRxConfig,
369  (flexio_uart_state_t*)&s_flexioUartRxState[index]);
370  }
371  break;
372  #endif
373  /* Define UART PAL over LinFlexD */
374  #if (defined(UART_OVER_LINFLEXD))
376  DEV_ASSERT(instance->instIdx < LINFlexD_INSTANCE_COUNT);
377  linflexd_uart_user_config_t linFlexDConfig;
378  linFlexDConfig.baudRate = config->baudRate;
379  /* LinFlexD does not support 9 or 10 bits per character */
381  (config->bitCount != UART_10_BITS_PER_CHAR));
382  switch (config->bitCount)
383  {
385  linFlexDConfig.wordLength = LINFLEXD_UART_7_BITS;
386  break;
388  linFlexDConfig.wordLength = LINFLEXD_UART_8_BITS;
389  break;
391  linFlexDConfig.wordLength = LINFLEXD_UART_15_BITS;
392  break;
394  linFlexDConfig.wordLength = LINFLEXD_UART_16_BITS;
395  break;
396  default:
397  /* Impossible type - do nothing */
398  break;
399  }
400 
401  switch (config->parityMode)
402  {
404  linFlexDConfig.parityCheck = false;
405  break;
406  case UART_PARITY_EVEN:
407  linFlexDConfig.parityCheck = true;
408  linFlexDConfig.parityType = LINFLEXD_UART_PARITY_EVEN;
409  break;
410  case UART_PARITY_ODD:
411  linFlexDConfig.parityCheck = true;
412  linFlexDConfig.parityType = LINFLEXD_UART_PARITY_ODD;
413  break;
414  default:
415  /* Impossible type - do nothing */
416  break;
417  }
418 
419  linFlexDConfig.stopBitsCount = (linflexd_uart_stop_bits_count_t)config->stopBitCount;
420  linFlexDConfig.transferType = (linflexd_uart_transfer_type_t)config->transferType;
421  linFlexDConfig.txDMAChannel = config->txDMAChannel;
422  linFlexDConfig.rxDMAChannel = config->rxDMAChannel;
423 
424  /* Allocate one of the LinFlexD state structures for this instance */
425  index = UART_AllocateState(s_linFlexDStateIsAllocated,
426  s_linFlexDStateInstanceMapping,
427  instance,
428  NO_OF_LINFLEXD_INSTS_FOR_UART);
429  /* Initialize LinFlexD instance */
430  status = LINFLEXD_UART_DRV_Init(instance->instIdx, &s_linFlexDState[index], &linFlexDConfig);
431 
432  /* Install Rx callback */
433  if (config->rxCallback != NULL)
434  {
435  (void)LINFLEXD_UART_DRV_InstallRxCallback(instance->instIdx,
436  config->rxCallback,
437  config->rxCallbackParam);
438  }
439 
440  /* Install Tx callback */
441  if (config->txCallback != NULL)
442  {
443  (void)LINFLEXD_UART_DRV_InstallTxCallback(instance->instIdx,
444  config->txCallback,
445  config->txCallbackParam);
446  }
447  break;
448  #endif
449  default:
450  /* Impossible type - do nothing */
451  break;
452  }
453  return status;
454 }
455 
456 /*FUNCTION**********************************************************************
457  *
458  * Function Name : UART_Deinit
459  * Description : De-initializes the UART module
460  *
461  * Implements : UART_Deinit_Activity
462  *END**************************************************************************/
463 status_t UART_Deinit(const uart_instance_t * const instance)
464 {
465  DEV_ASSERT(instance != NULL);
466  status_t status = STATUS_ERROR;
467 #if (defined(UART_OVER_FLEXIO))
468  uint8_t index = 0;
469 #endif
470 
471  switch (instance->instType)
472  {
473  /* Define UART PAL over LPUART */
474  #if (defined(UART_OVER_LPUART))
477  status = LPUART_DRV_Deinit(instance->instIdx);
478  if (status == STATUS_SUCCESS)
479  {
480  UART_FreeState(s_lpuartStateIsAllocated,
481  s_lpuartStateInstanceMapping,
482  instance,
483  NO_OF_LPUART_INSTS_FOR_UART);
484  }
485  break;
486  #endif
487  /* Define UART PAL over FLEXIO */
488  #if (defined(UART_OVER_FLEXIO))
489  /* Define UART PAL over FLEXIO */
492  index = UART_FindFlexioState(instance);
493  status = FLEXIO_UART_DRV_Deinit(&(s_flexioUartTxState[index]));
494  if (status == STATUS_SUCCESS)
495  {
496  UART_FreeState(s_flexioUartStateIsAllocated,
497  s_flexioUartStateInstanceMapping,
498  instance,
499  NO_OF_FLEXIO_INSTS_FOR_UART);
500  }
501  status = FLEXIO_UART_DRV_Deinit(&(s_flexioUartRxState[index]));
502  if (status == STATUS_SUCCESS)
503  {
504  UART_FreeState(s_flexioUartStateIsAllocated,
505  s_flexioUartStateInstanceMapping,
506  instance,
507  NO_OF_FLEXIO_INSTS_FOR_UART);
508  }
509  break;
510  #endif
511  /* Define UART PAL over LinFlexD */
512  #if (defined(UART_OVER_LINFLEXD))
513  /* Define UART PAL over LinFlexD */
515  DEV_ASSERT(instance->instIdx < LINFlexD_INSTANCE_COUNT);
516  status = LINFLEXD_UART_DRV_Deinit(instance->instIdx);
517  if (status == STATUS_SUCCESS)
518  {
519  UART_FreeState(s_linFlexDStateIsAllocated,
520  s_linFlexDStateInstanceMapping,
521  instance,
522  NO_OF_LINFLEXD_INSTS_FOR_UART);
523  }
524  break;
525  #endif
526  default:
527  /* Impossible type - do nothing */
528  break;
529  }
530  return status;
531 }
532 
533 /*FUNCTION**********************************************************************
534  *
535  * Function Name : UART_SetBaudRate
536  * Description : Configures the UART baud rate.
537  *
538  * Implements : UART_SetBaudRate_Activity
539  *END**************************************************************************/
540 status_t UART_SetBaudRate(const uart_instance_t * const instance, uint32_t desiredBaudRate)
541 {
542  DEV_ASSERT(instance != NULL);
543  status_t status = STATUS_ERROR;
544 #if (defined(UART_OVER_FLEXIO))
545  uint8_t index = 0;
546  uint8_t bitCount = 0;
547 #endif
548 
549  switch (instance->instType)
550  {
551  /* Define UART PAL over LPUART */
552  #if (defined(UART_OVER_LPUART))
555  status = LPUART_DRV_SetBaudRate(instance->instIdx, desiredBaudRate);
556  break;
557  #endif
558  /* Define UART PAL over FLEXIO */
559  #if (defined(UART_OVER_FLEXIO))
562  index = UART_FindFlexioState(instance);
563  bitCount = (s_flexioUartTxState[index]).bitCount;
564  status = FLEXIO_UART_DRV_SetConfig(&(s_flexioUartTxState[index]),
565  desiredBaudRate,
566  bitCount);
567  status = FLEXIO_UART_DRV_SetConfig(&(s_flexioUartRxState[index]),
568  desiredBaudRate,
569  bitCount);
570  break;
571  #endif
572  /* Define UART PAL over LinFlexD */
573  #if (defined(UART_OVER_LINFLEXD))
575  DEV_ASSERT(instance->instIdx < LINFlexD_INSTANCE_COUNT);
576  status = LINFLEXD_UART_DRV_SetBaudRate(instance->instIdx, desiredBaudRate);
577  break;
578  #endif
579  default:
580  /* Impossible type - do nothing */
581  break;
582  }
583  return status;
584 }
585 
586 /*FUNCTION**********************************************************************
587  *
588  * Function Name : UART_GetBaudRate
589  * Description : Returns the UART configured baud rate.
590  *
591  * Implements : UART_GetBaudRate_Activity
592  *END**************************************************************************/
593 status_t UART_GetBaudRate(const uart_instance_t * const instance, uint32_t * configuredBaudRate)
594 {
595  DEV_ASSERT(instance != NULL);
596  status_t status = STATUS_ERROR;
597 
598  switch (instance->instType)
599  {
600  /* Define UART PAL over LPUART */
601  #if (defined(UART_OVER_LPUART))
604  LPUART_DRV_GetBaudRate(instance->instIdx, configuredBaudRate);
605  status = STATUS_SUCCESS;
606  break;
607  #endif
608  /* Define UART PAL over FLEXIO */
609  #if (defined(UART_OVER_FLEXIO))
612  status = FLEXIO_UART_DRV_GetBaudRate(&(s_flexioUartTxState[UART_FindFlexioState(instance)]),
613  configuredBaudRate);
614  break;
615  #endif
616  /* Define UART PAL over LinFlexD */
617  #if (defined(UART_OVER_LINFLEXD))
619  DEV_ASSERT(instance->instIdx < LINFlexD_INSTANCE_COUNT);
620  status = LINFLEXD_UART_DRV_GetBaudRate(instance->instIdx, configuredBaudRate);
621  break;
622  #endif
623  default:
624  /* Impossible type - do nothing */
625  break;
626  }
627 
628  return status;
629 }
630 
631 /*FUNCTION**********************************************************************
632  *
633  * Function Name : UART_SendDataBlocking
634  * Description : Perform a blocking UART transmission
635  *
636  * Implements : UART_SendDataBlocking_Activity
637  *END**************************************************************************/
639  const uart_instance_t * const instance,
640  const uint8_t * txBuff,
641  uint32_t txSize,
642  uint32_t timeout)
643 {
644  DEV_ASSERT(instance != NULL);
645  DEV_ASSERT(txBuff != NULL);
646 
647  status_t status = STATUS_ERROR;
648 
649  switch (instance->instType)
650  {
651  /* Define UART PAL over LPUART */
652  #if (defined(UART_OVER_LPUART))
655  status = LPUART_DRV_SendDataBlocking(instance->instIdx, txBuff, txSize, timeout);
656  break;
657  #endif
658  /* Define UART PAL over FLEXIO */
659  #if (defined(UART_OVER_FLEXIO))
663  &(s_flexioUartTxState[UART_FindFlexioState(instance)]),
664  txBuff,
665  txSize,
666  timeout);
667  break;
668  #endif
669  /* Define UART PAL over LinFlexD */
670  #if (defined(UART_OVER_LINFLEXD))
672  DEV_ASSERT(instance->instIdx < LINFlexD_INSTANCE_COUNT);
673  status = LINFLEXD_UART_DRV_SendDataBlocking(instance->instIdx, txBuff, txSize, timeout);
674  break;
675  #endif
676  default:
677  /* Impossible type - do nothing */
678  break;
679  }
680 
681  return status;
682 }
683 
684 /*FUNCTION**********************************************************************
685  *
686  * Function Name : UART_SendData
687  * Description : Perform a non-blocking UART transmission
688  *
689  * Implements : UART_SendData_Activity
690  *END**************************************************************************/
691 status_t UART_SendData(const uart_instance_t * const instance, const uint8_t * txBuff, uint32_t txSize)
692 {
693  DEV_ASSERT(instance != NULL);
694  DEV_ASSERT(txBuff != NULL);
695  status_t status = STATUS_ERROR;
696 
697  switch (instance->instType)
698  {
699  /* Define UART PAL over LPUART */
700  #if (defined(UART_OVER_LPUART))
703  status = LPUART_DRV_SendData(instance->instIdx, txBuff, txSize);
704  break;
705  #endif
706  /* Define UART PAL over FLEXIO */
707  #if (defined(UART_OVER_FLEXIO))
710  status = FLEXIO_UART_DRV_SendData(
711  &(s_flexioUartTxState[UART_FindFlexioState(instance)]),
712  txBuff,
713  txSize);
714  break;
715  #endif
716  /* Define UART PAL over LinFlexD */
717  #if (defined(UART_OVER_LINFLEXD))
719  DEV_ASSERT(instance->instIdx < LINFlexD_INSTANCE_COUNT);
720  status = LINFLEXD_UART_DRV_SendData(instance->instIdx, txBuff, txSize);
721  break;
722  #endif
723  default:
724  /* Impossible type - do nothing */
725  break;
726  }
727 
728  return status;
729 }
730 
731 /*FUNCTION**********************************************************************
732  *
733  * Function Name : UART_AbortSendingData
734  * Description : This function terminates an non-blocking transmission early.
735  *
736  * Implements : UART_AbortSendingData_Activity
737  *END**************************************************************************/
739 {
740  DEV_ASSERT(instance != NULL);
741  status_t status = STATUS_ERROR;
742 
743  switch (instance->instType)
744  {
745  /* Define UART PAL over LPUART */
746  #if (defined(UART_OVER_LPUART))
749  status = LPUART_DRV_AbortSendingData(instance->instIdx);
750  break;
751  #endif
752  /* Define UART PAL over FLEXIO */
753  #if (defined(UART_OVER_FLEXIO))
756  status = FLEXIO_UART_DRV_TransferAbort(&(s_flexioUartTxState[UART_FindFlexioState(instance)]));
757  break;
758  #endif
759  /* Define UART PAL over LinFlexD */
760  #if (defined(UART_OVER_LINFLEXD))
762  DEV_ASSERT(instance->instIdx < LINFlexD_INSTANCE_COUNT);
763  status = LINFLEXD_UART_DRV_AbortSendingData(instance->instIdx);
764  break;
765  #endif
766  default:
767  /* Impossible type - do nothing */
768  break;
769  }
770 
771  return status;
772 }
773 
774 /*FUNCTION**********************************************************************
775  *
776  * Function Name : UART_GetTransmitStatus
777  * Description : This function returns whether the previous transmission has
778  * finished
779  *
780  * Implements : UART_GetTransmitStatus_Activity
781  *END**************************************************************************/
782 status_t UART_GetTransmitStatus(const uart_instance_t * const instance, uint32_t * bytesRemaining)
783 {
784  DEV_ASSERT(instance != NULL);
785  status_t status = STATUS_ERROR;
786 
787  switch (instance->instType)
788  {
789  /* Define UART PAL over LPUART */
790  #if (defined(UART_OVER_LPUART))
793  status = LPUART_DRV_GetTransmitStatus(instance->instIdx, bytesRemaining);
794  break;
795  #endif
796  /* Define UART PAL over FLEXIO */
797  #if (defined(UART_OVER_FLEXIO))
800  status = FLEXIO_UART_DRV_GetStatus(
801  &(s_flexioUartTxState[UART_FindFlexioState(instance)]),
802  bytesRemaining);
803  break;
804  #endif
805  /* Define UART PAL over LinFlexD */
806  #if (defined(UART_OVER_LINFLEXD))
808  DEV_ASSERT(instance->instIdx < LINFlexD_INSTANCE_COUNT);
809  status = LINFLEXD_UART_DRV_GetTransmitStatus(instance->instIdx, bytesRemaining);
810  break;
811  #endif
812  default:
813  /* Impossible type - do nothing */
814  break;
815  }
816 
817  return status;
818 }
819 
820 /*FUNCTION**********************************************************************
821  *
822  * Function Name : UART_ReceiveDataBlocking
823  * Description : Perform a blocking UART reception
824  *
825  * Implements : UART_ReceiveDataBlocking_Activity
826  *END**************************************************************************/
828  const uart_instance_t * const instance,
829  uint8_t * rxBuff,
830  uint32_t rxSize,
831  uint32_t timeout)
832 {
833  DEV_ASSERT(instance != NULL);
834  status_t status = STATUS_ERROR;
835 
836  switch(instance->instType)
837  {
838  /* Define UART PAL over LPUART */
839  #if (defined(UART_OVER_LPUART))
842  status = LPUART_DRV_ReceiveDataBlocking(instance->instIdx, rxBuff, rxSize, timeout);
843  break;
844  #endif
845  /* Define UART PAL over FLEXIO */
846  #if (defined(UART_OVER_FLEXIO))
850  &(s_flexioUartRxState[UART_FindFlexioState(instance)]),
851  rxBuff,
852  rxSize,
853  timeout);
854  break;
855  #endif
856  /* Define UART PAL over LinFlexD */
857  #if (defined(UART_OVER_LINFLEXD))
859  DEV_ASSERT(instance->instIdx < LINFlexD_INSTANCE_COUNT);
860  status = LINFLEXD_UART_DRV_ReceiveDataBlocking(instance->instIdx, rxBuff, rxSize, timeout);
861  break;
862  #endif
863  default:
864  /* Impossible type - do nothing */
865  break;
866  }
867 
868  return status;
869 }
870 
871 /*FUNCTION**********************************************************************
872  *
873  * Function Name : UART_ReceiveData
874  * Description : Perform a non-blocking UART reception
875  *
876  * Implements : UART_ReceiveData_Activity
877  *END**************************************************************************/
878 status_t UART_ReceiveData(const uart_instance_t * const instance, uint8_t * rxBuff, uint32_t rxSize)
879 {
880  DEV_ASSERT(instance != NULL);
881  status_t status = STATUS_ERROR;
882 
883  switch (instance->instType)
884  {
885  /* Define UART PAL over LPUART */
886  #if (defined(UART_OVER_LPUART))
889  status = LPUART_DRV_ReceiveData(instance->instIdx, rxBuff, rxSize);
890  break;
891  #endif
892  /* Define UART PAL over FLEXIO */
893  #if (defined(UART_OVER_FLEXIO))
897  &(s_flexioUartRxState[UART_FindFlexioState(instance)]),
898  rxBuff,
899  rxSize);
900  break;
901  #endif
902  /* Define UART PAL over LinFlexD */
903  #if (defined(UART_OVER_LINFLEXD))
905  DEV_ASSERT(instance->instIdx < LINFlexD_INSTANCE_COUNT);
906  status = LINFLEXD_UART_DRV_ReceiveData(instance->instIdx, rxBuff, rxSize);
907  break;
908  #endif
909  default:
910  /* Impossible type - do nothing */
911  break;
912  }
913 
914  return status;
915 }
916 
917 /*FUNCTION**********************************************************************
918  *
919  * Function Name : UART_AbortReceivingData
920  * Description : Terminates a non-blocking receive early.
921  *
922  * Implements : UART_AbortReceivingData_Activity
923  *END**************************************************************************/
925 {
926  DEV_ASSERT(instance != NULL);
927  status_t status = STATUS_ERROR;
928 
929  switch (instance->instType)
930  {
931  /* Define UART PAL over LPUART */
932  #if (defined(UART_OVER_LPUART))
935  status = LPUART_DRV_AbortReceivingData(instance->instIdx);
936  break;
937  #endif
938  /* Define UART PAL over FLEXIO */
939  #if (defined(UART_OVER_FLEXIO))
942  status = FLEXIO_UART_DRV_TransferAbort(&(s_flexioUartRxState[UART_FindFlexioState(instance)]));
943  break;
944  #endif
945  /* Define UART PAL over LinFlexD */
946  #if (defined(UART_OVER_LINFLEXD))
948  DEV_ASSERT(instance->instIdx < LINFlexD_INSTANCE_COUNT);
949  status = LINFLEXD_UART_DRV_AbortReceivingData(instance->instIdx);
950  break;
951  #endif
952  default:
953  /* Impossible type - do nothing */
954  break;
955  }
956 
957  return status;
958 }
959 
960 /*FUNCTION**********************************************************************
961  *
962  * Function Name : UART_GetReceiveStatus
963  * Description : This function returns whether the previous reception has
964  * finished
965  *
966  * Implements : UART_GetReceiveStatus_Activity
967  *END**************************************************************************/
968 status_t UART_GetReceiveStatus(const uart_instance_t * const instance, uint32_t * bytesRemaining)
969 {
970  DEV_ASSERT(instance != NULL);
971  status_t status = STATUS_ERROR;
972 
973  switch (instance->instType)
974  {
975  /* Define UART PAL over LPUART */
976  #if (defined(UART_OVER_LPUART))
979  status = LPUART_DRV_GetReceiveStatus(instance->instIdx, bytesRemaining);
980  break;
981  #endif
982  /* Define UART PAL over FLEXIO */
983  #if (defined(UART_OVER_FLEXIO))
986  status = FLEXIO_UART_DRV_GetStatus(&(s_flexioUartRxState[UART_FindFlexioState(instance)]),
987  bytesRemaining);
988  break;
989  #endif
990  /* Define UART PAL over LinFlexD */
991  #if (defined(UART_OVER_LINFLEXD))
993  DEV_ASSERT(instance->instIdx < LINFlexD_INSTANCE_COUNT);
994  status = LINFLEXD_UART_DRV_GetReceiveStatus(instance->instIdx, bytesRemaining);
995  break;
996  #endif
997  default:
998  /* Impossible type - do nothing */
999  break;
1000  }
1001 
1002  return status;
1003 }
1004 
1005 /*FUNCTION**********************************************************************
1006  *
1007  * Function Name : UART_SetRxBuffer
1008  * Description : This function provide a buffer for receiving data.
1009  *
1010  *
1011  * Implements : UART_SetRxBuffer_Activity
1012  *END**************************************************************************/
1013 status_t UART_SetRxBuffer(const uart_instance_t * const instance, uint8_t * rxBuff, uint32_t rxSize)
1014 {
1015  DEV_ASSERT(instance != NULL);
1016  status_t status = STATUS_ERROR;
1017 
1018  switch (instance->instType)
1019  {
1020  /* Define UART PAL over LPUART */
1021  #if (defined(UART_OVER_LPUART))
1022  case UART_INST_TYPE_LPUART:
1024  status = LPUART_DRV_SetRxBuffer(instance->instIdx, rxBuff, rxSize);
1025  break;
1026  #endif
1027  /* Define UART PAL over FLEXIO */
1028  #if (defined(UART_OVER_FLEXIO))
1031  status = FLEXIO_UART_DRV_SetRxBuffer(&(s_flexioUartRxState[UART_FindFlexioState(instance)]), rxBuff, rxSize);
1032  break;
1033  #endif
1034  /* Define UART PAL over LinFlexD */
1035  #if (defined(UART_OVER_LINFLEXD))
1037  DEV_ASSERT(instance->instIdx < LINFlexD_INSTANCE_COUNT);
1038  status = LINFLEXD_UART_DRV_SetRxBuffer(instance->instIdx, rxBuff, rxSize);
1039  break;
1040  #endif
1041  default:
1042  /* Impossible type - do nothing */
1043  break;
1044  }
1045 
1046  return status;
1047 }
1048 
1049 /*FUNCTION**********************************************************************
1050  *
1051  * Function Name : UART_SetTxBuffer
1052  * Description : This function provide a buffer for transmitting data.
1053  *
1054  *
1055  * Implements : UART_SetTxBuffer_Activity
1056  *END**************************************************************************/
1057 status_t UART_SetTxBuffer(const uart_instance_t * const instance, const uint8_t * txBuff, uint32_t txSize)
1058 {
1059  DEV_ASSERT(instance != NULL);
1060  status_t status = STATUS_ERROR;
1061 
1062  switch (instance->instType)
1063  {
1064  /* Define UART PAL over LPUART */
1065  #if (defined(UART_OVER_LPUART))
1066  case UART_INST_TYPE_LPUART:
1068  status = LPUART_DRV_SetTxBuffer(instance->instIdx, txBuff, txSize);
1069  break;
1070  #endif
1071  /* Define UART PAL over FLEXIO */
1072  #if (defined(UART_OVER_FLEXIO))
1075  status = FLEXIO_UART_DRV_SetTxBuffer(&(s_flexioUartTxState[UART_FindFlexioState(instance)]), txBuff, txSize);
1076  break;
1077  #endif
1078  /* Define UART PAL over LinFlexD */
1079  #if (defined(UART_OVER_LINFLEXD))
1081  DEV_ASSERT(instance->instIdx < LINFlexD_INSTANCE_COUNT);
1082  status = LINFLEXD_UART_DRV_SetTxBuffer(instance->instIdx, txBuff, txSize);
1083  break;
1084  #endif
1085  default:
1086  /* Impossible type - do nothing */
1087  break;
1088  }
1089  return status;
1090 }
1091 
1092 /*******************************************************************************
1093  * EOF
1094  ******************************************************************************/
status_t UART_Init(const uart_instance_t *const instance, const uart_user_config_t *config)
Initializes the UART module.
Definition: uart_pal.c:208
status_t LPUART_DRV_AbortSendingData(uint32_t instance)
Terminates a non-blocking transmission early.
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.
uart_callback_t LPUART_DRV_InstallTxCallback(uint32_t instance, uart_callback_t function, void *callbackParam)
Installs callback function for the LPUART transmit.
status_t LPUART_DRV_Deinit(uint32_t instance)
Shuts down the LPUART by disabling interrupts and transmitter/receiver.
uint8_t txDMAChannel
Definition: uart_pal.h:99
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...
status_t FLEXIO_UART_DRV_ReceiveData(flexio_uart_state_t *state, uint8_t *rxBuff, uint32_t rxSize)
Perform a non-blocking UART reception.
status_t LPUART_DRV_AbortReceivingData(uint32_t instance)
Terminates a non-blocking receive early.
status_t UART_SendData(const uart_instance_t *const instance, const uint8_t *txBuff, uint32_t txSize)
Perform a non-blocking UART transmission.
Definition: uart_pal.c:691
uint32_t baudRate
Definition: uart_pal.h:93
status_t FLEXIO_UART_DRV_SetTxBuffer(flexio_uart_state_t *state, const uint8_t *txBuff, uint32_t txSize)
Provide a buffer for transmitting data.
uart_bit_count_per_char_t bitCount
Definition: uart_pal.h:94
static void UART_FreeState(bool *isAllocated, const uint8_t *instanceMapping, const uart_instance_t *const instance, uint8_t numberOfinstances)
Definition: uart_pal.c:153
status_t UART_GetReceiveStatus(const uart_instance_t *const instance, uint32_t *bytesRemaining)
Get the status of the current non-blocking UART reception.
Definition: uart_pal.c:968
status_t UART_GetBaudRate(const uart_instance_t *const instance, uint32_t *configuredBaudRate)
Returns the UART baud rate.
Definition: uart_pal.c:593
status_t FLEXIO_UART_DRV_SetConfig(flexio_uart_state_t *state, uint32_t baudRate, uint8_t bitCount)
Set the baud rate and bit width for any subsequent UART communication.
Structure storing PAL instance information.
status_t UART_SetTxBuffer(const uart_instance_t *const instance, const uint8_t *txBuff, uint32_t txSize)
Provide a buffer for transmitting data.
Definition: uart_pal.c:1057
status_t UART_AbortSendingData(const uart_instance_t *const instance)
Terminates a non-blocking transmission early.
Definition: uart_pal.c:738
lpuart_bit_count_per_char_t bitCountPerChar
status_t FLEXIO_UART_DRV_SendData(flexio_uart_state_t *state, const uint8_t *txBuff, uint32_t txSize)
Perform a non-blocking UART transmission.
lpuart_parity_mode_t parityMode
#define DEV_ASSERT(x)
Definition: devassert.h:77
status_t FLEXIO_UART_DRV_SendDataBlocking(flexio_uart_state_t *state, const uint8_t *txBuff, uint32_t txSize, uint32_t timeout)
Perform a blocking UART transmission.
status_t UART_ReceiveDataBlocking(const uart_instance_t *const instance, uint8_t *rxBuff, uint32_t rxSize, uint32_t timeout)
Perform a blocking UART reception.
Definition: uart_pal.c:827
uart_parity_mode_t parityMode
Definition: uart_pal.h:95
flexio_uart_driver_direction_t direction
status_t FLEXIO_UART_DRV_ReceiveDataBlocking(flexio_uart_state_t *state, uint8_t *rxBuff, uint32_t rxSize, uint32_t timeout)
Perform a blocking UART reception.
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...
lpuart_transfer_type_t
Type of LPUART transfer (based on interrupts or DMA).
Definition: lpuart_driver.h:46
status_t FLEXIO_UART_DRV_GetBaudRate(flexio_uart_state_t *state, uint32_t *baudRate)
Get the currently configured baud rate.
void * rxCallbackParam
Definition: uart_pal.h:101
lpuart_parity_mode_t
LPUART parity mode.
Definition: lpuart_driver.h:67
uart_callback_t LPUART_DRV_InstallRxCallback(uint32_t instance, uart_callback_t function, void *callbackParam)
Installs callback function for the LPUART receive.
status_t
Status return codes. Common error codes will be a unified enumeration (C enum) that will contain all ...
Definition: status.h:44
status_t UART_AbortReceivingData(const uart_instance_t *const instance)
Terminates a non-blocking receive early.
Definition: uart_pal.c:924
status_t FLEXIO_UART_DRV_GetStatus(flexio_uart_state_t *state, uint32_t *bytesRemaining)
Get the status of the current non-blocking UART transfer.
uart_callback_t txCallback
Definition: uart_pal.h:102
status_t FLEXIO_UART_DRV_SetRxBuffer(flexio_uart_state_t *state, uint8_t *rxBuff, uint32_t rxSize)
Provide a buffer for receiving data.
status_t LPUART_DRV_SetBaudRate(uint32_t instance, uint32_t desiredBaudRate)
Configures the LPUART baud rate.
uart_inst_type_t instType
Driver internal context structure.
status_t UART_ReceiveData(const uart_instance_t *const instance, uint8_t *rxBuff, uint32_t rxSize)
Perform a non-blocking UART reception.
Definition: uart_pal.c:878
status_t FLEXIO_UART_DRV_Deinit(flexio_uart_state_t *state)
De-initialize the FLEXIO_UART driver.
uint8_t rxDMAChannel
Definition: uart_pal.h:98
status_t FLEXIO_UART_DRV_TransferAbort(flexio_uart_state_t *state)
Aborts a non-blocking UART transfer.
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.
void * txCallbackParam
Definition: uart_pal.h:103
#define FLEXIO_UART_INSTANCE_COUNT
status_t UART_SetRxBuffer(const uart_instance_t *const instance, uint8_t *rxBuff, uint32_t rxSize)
Provide a buffer for receiving data.
Definition: uart_pal.c:1013
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 uint8_t UART_AllocateState(bool *isAllocated, uint8_t *instanceMapping, const uart_instance_t *const instance, uint8_t numberOfinstances)
Definition: uart_pal.c:122
Defines the UART configuration structure.
Definition: uart_pal.h:91
status_t UART_GetTransmitStatus(const uart_instance_t *const instance, uint32_t *bytesRemaining)
Get the status of the current non-blocking UART transmission.
Definition: uart_pal.c:782
LPUART configuration structure.
#define LPUART_INSTANCE_COUNT
Definition: S32K118.h:6534
lpuart_stop_bit_count_t
LPUART number of stop bits.
Definition: lpuart_driver.h:78
flexio_driver_type_t driverType
void LPUART_DRV_GetBaudRate(uint32_t instance, uint32_t *configuredBaudRate)
Returns the LPUART baud rate.
status_t LPUART_DRV_GetTransmitStatus(uint32_t instance, uint32_t *bytesRemaining)
Returns whether the previous transmit is complete.
Driver configuration structure.
lpuart_transfer_type_t transferType
status_t FLEXIO_UART_DRV_Init(uint32_t instance, const flexio_uart_user_config_t *userConfigPtr, flexio_uart_state_t *state)
Initialize the FLEXIO_UART driver.
Runtime state of the LPUART driver.
Definition: lpuart_driver.h:92
status_t UART_SetBaudRate(const uart_instance_t *const instance, uint32_t desiredBaudRate)
Configures the UART baud rate.
Definition: uart_pal.c:540
status_t UART_Deinit(const uart_instance_t *const instance)
De-initializes the UART module.
Definition: uart_pal.c:463
status_t FLEXIO_DRV_InitDevice(uint32_t instance, flexio_device_state_t *deviceState)
Initializes the FlexIO device.
Definition: flexio_common.c:89
uart_callback_t rxCallback
Definition: uart_pal.h:100
status_t LPUART_DRV_GetReceiveStatus(uint32_t instance, uint32_t *bytesRemaining)
Returns whether the previous receive is complete.
status_t UART_SendDataBlocking(const uart_instance_t *const instance, const uint8_t *txBuff, uint32_t txSize, uint32_t timeout)
Perform a blocking UART transmission.
Definition: uart_pal.c:638
uart_transfer_type_t transferType
Definition: uart_pal.h:97
status_t LPUART_DRV_SetRxBuffer(uint32_t instance, uint8_t *rxBuff, uint32_t rxSize)
Sets the internal driver reference to the rx buffer.
lpuart_stop_bit_count_t stopBitCount
uart_stop_bit_count_t stopBitCount
Definition: uart_pal.h:96