![]() |
S32 SDK
|
This module covers the functionality of the Low Power Universal Asynchronous Receiver-Transmitter (LPUART) peripheral driver.
The LPUART driver implements serial communication using the LPUART module in the S32144K processor.
In order to use the LPUART driver it must be first initialized, using LPUART_DRV_Init() function. Once initialized, it cannot be initialized again for the same LPUART module instance until it is de-initialized, using LPUART_DRV_Deinit(). The initialization function does the following operations:
After initialization, a serial communication can be triggered by calling LPUART_DRV_SendData function; this will save the reference of the data buffer received as parameter in the internal tx buffer pointer, then copy the first byte to the data register. The hw tranceiver then automatically shifts the data and triggers a 'Transmit buffer empty' interrupt when all bits are shifted. The drivers interrupt handler takes care of transmitting the next byte in the buffer, by increasing the data pointer and decreasing the data size. The same sequence of operations is executed until all bytes in the tx buffer have been transmitted.
Similarly, data reception is triggered by calling LPUART_DRV_ReceiveData function, passing the rx buffer as parameter. When the tranceiver copies the received bits in the data register, the 'Receive buffer full' interrupt is triggered; the driver irq handler clears the flag by reading the received byte, saves it in the rx buffer, then increments the data pointer and decrements the data size. This is repeated untill all bytes are received.
The workflow applies to send/receive operations using blocking method (triggered by LPUART_DRV_SendDataBlocking and LPUART_DRV_ReceiveDataBlocking), with the single difference that the send/receive function will not return until the send/receive operation is complete (all bytes are successfully transferred or a timeout occured). The timeout for the blocking method is passed as parameter by the user.
If a user callback is installed for rx/tx, the callback has to take care of data handling and aborting the transfer when complete; the driver irq handler does not manipulate the buffers in this case. A target usecase here would be receiving an indefinite number of bytes; the user rx callback will be called by the driver each time a character is received and the application needs to call LPUART_DRV_AbortReceivingData in order to stop the reception.
In DMA operation, both blocking and non-blocking transmission methods confiure a DMA channel to copy data from the buffer to the data register (for tx), or viceversa (for rx). The driver assumes the DMA channel is already allocated and the proper requests are routed to it via DMAMUX. After configuring the DMA channel, the driver enables DMA requests for rx/tx, then the DMA engine takes care of moving data to/from the data buffer. In this scenario, the callback is only called when the full transmission is done, that is when the DMA channel finishes the number of loops configured in the transfer descriptor.
Data Structures | |
struct | lpuart_state_t |
Runtime state of the LPUART driver. More... | |
struct | lpuart_user_config_t |
LPUART configuration structure. More... | |
Typedefs | |
typedef void(* | lpuart_rx_callback_t) (uint32_t instance, void *lpuartState) |
LPUART receive callback function type. More... | |
typedef void(* | lpuart_tx_callback_t) (uint32_t instance, void *lpuartState) |
LPUART transmit callback function type. More... | |
Enumerations | |
enum | lpuart_transfer_type_t { LPUART_USING_DMA = 0, LPUART_USING_INTERRUPTS } |
Type of LPUART transfer (based on interrupts or DMA). More... | |
Variables | |
LPUART_Type *const | g_lpuartBase [LPUART_INSTANCE_COUNT] |
Table of base addresses for LPUART instances. More... | |
const IRQn_Type | g_lpuartRxTxIrqId [LPUART_INSTANCE_COUNT] |
Table to save LPUART IRQ enumeration numbers defined in the CMSIS header file. More... | |
const clock_names_t | g_lpuartClkNames [LPUART_INSTANCE_COUNT] |
Table to save LPUART indexes in PCC register map for clock configuration. More... | |
LPUART Driver | |
status_t | LPUART_DRV_Init (uint32_t instance, lpuart_state_t *lpuartStatePtr, const lpuart_user_config_t *lpuartUserConfig) |
Initializes an LPUART operation instance. More... | |
status_t | LPUART_DRV_Deinit (uint32_t instance) |
Shuts down the LPUART by disabling interrupts and transmitter/receiver. More... | |
lpuart_rx_callback_t | LPUART_DRV_InstallRxCallback (uint32_t instance, lpuart_rx_callback_t function, void *callbackParam) |
Installs callback function for the LPUART receive. More... | |
lpuart_tx_callback_t | LPUART_DRV_InstallTxCallback (uint32_t instance, lpuart_tx_callback_t function, void *callbackParam) |
Installs callback function for the LPUART transmit. More... | |
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. More... | |
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 for transmitting data. When used with a non-blocking receive, the LPUART can perform a full duplex operation. Non-blocking means that the function returns immediately. The application has to get the transmit status to know when the transmit is complete. More... | |
status_t | LPUART_DRV_GetTransmitStatus (uint32_t instance, uint32_t *bytesRemaining) |
Returns whether the previous transmit is complete. More... | |
status_t | LPUART_DRV_AbortSendingData (uint32_t instance) |
Terminates a non-blocking transmission early. More... | |
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 not return until the receive is complete. More... | |
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 receiving data. When used with a non-blocking transmission, the LPUART can perform a full duplex operation. Non-blocking means that the function returns immediately. The application has to get the receive status to know when the receive is complete. More... | |
status_t | LPUART_DRV_GetReceiveStatus (uint32_t instance, uint32_t *bytesRemaining) |
Returns whether the previous receive is complete. More... | |
status_t | LPUART_DRV_AbortReceivingData (uint32_t instance) |
Terminates a non-blocking receive early. More... | |
typedef void(* lpuart_rx_callback_t) (uint32_t instance, void *lpuartState) |
LPUART receive callback function type.
Implements : lpuart_rx_callback_t_Class
Definition at line 45 of file lpuart_driver.h.
typedef void(* lpuart_tx_callback_t) (uint32_t instance, void *lpuartState) |
LPUART transmit callback function type.
Implements : lpuart_tx_callback_t_Class
Definition at line 51 of file lpuart_driver.h.
Type of LPUART transfer (based on interrupts or DMA).
Implements : lpuart_transfer_type_t_Class
Enumerator | |
---|---|
LPUART_USING_DMA |
The driver will use DMA to perform UART transfer |
LPUART_USING_INTERRUPTS |
The driver will use interrupts to perform UART transfer |
Definition at line 70 of file lpuart_driver.h.
status_t LPUART_DRV_AbortReceivingData | ( | uint32_t | instance | ) |
Terminates a non-blocking receive early.
instance | LPUART instance number |
Definition at line 686 of file lpuart_driver.c.
status_t LPUART_DRV_AbortSendingData | ( | uint32_t | instance | ) |
Terminates a non-blocking transmission early.
instance | LPUART instance number |
Definition at line 491 of file lpuart_driver.c.
status_t LPUART_DRV_Deinit | ( | uint32_t | instance | ) |
Shuts down the LPUART by disabling interrupts and transmitter/receiver.
instance | LPUART instance number |
Definition at line 243 of file lpuart_driver.c.
status_t LPUART_DRV_GetReceiveStatus | ( | uint32_t | instance, |
uint32_t * | bytesRemaining | ||
) |
Returns whether the previous receive is complete.
instance | LPUART instance number |
bytesRemaining | pointer to value that is filled with the number of bytes that still need to be received in the active transfer. |
STATUS_SUCCESS | the receive has completed successfully. |
STATUS_BUSY | the receive is still in progress. bytesReceived will be filled with the number of bytes that have been received so far. |
STATUS_UART_ABORTED | The receive was aborted. |
STATUS_TIMEOUT | A timeout was reached. |
STATUS_ERROR | An error occured. |
Definition at line 642 of file lpuart_driver.c.
status_t LPUART_DRV_GetTransmitStatus | ( | uint32_t | instance, |
uint32_t * | bytesRemaining | ||
) |
Returns whether the previous transmit is complete.
instance | LPUART instance number |
bytesRemaining | Pointer to value that is populated with the number of bytes that have been sent in the active transfer |
STATUS_SUCCESS | The transmit has completed successfully. |
STATUS_BUSY | The transmit is still in progress. bytesTransmitted will be filled with the number of bytes that have been transmitted so far. |
STATUS_UART_ABORTED | The transmit was aborted. |
STATUS_TIMEOUT | A timeout was reached. |
STATUS_ERROR | An error occured. |
Definition at line 446 of file lpuart_driver.c.
status_t LPUART_DRV_Init | ( | uint32_t | instance, |
lpuart_state_t * | lpuartStatePtr, | ||
const lpuart_user_config_t * | lpuartUserConfig | ||
) |
Initializes an LPUART operation instance.
The caller provides memory for the driver state structures during initialization. The user must select the LPUART clock source in the application to initialize the LPUART.
instance | LPUART instance number |
lpuartUserConfig | user configuration structure of type lpuart_user_config_t |
lpuartStatePtr | pointer to the LPUART driver state structure |
Definition at line 149 of file lpuart_driver.c.
lpuart_rx_callback_t LPUART_DRV_InstallRxCallback | ( | uint32_t | instance, |
lpuart_rx_callback_t | function, | ||
void * | callbackParam | ||
) |
Installs callback function for the LPUART receive.
instance | The LPUART instance number. |
function | The LPUART receive callback function. |
rxBuff | The receive buffer used inside IRQHandler. This buffer must be kept as long as the callback is alive. |
callbackParam | The LPUART receive callback parameter pointer. |
Definition at line 288 of file lpuart_driver.c.
lpuart_tx_callback_t LPUART_DRV_InstallTxCallback | ( | uint32_t | instance, |
lpuart_tx_callback_t | function, | ||
void * | callbackParam | ||
) |
Installs callback function for the LPUART transmit.
instance | The LPUART instance number. |
function | The LPUART transmit callback function. |
txBuff | The transmit buffer used inside IRQHandler. This buffer must be kept as long as the callback is alive. |
callbackParam | The LPUART transmit callback parameter pointer. |
Definition at line 311 of file lpuart_driver.c.
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 receiving data. When used with a non-blocking transmission, the LPUART can perform a full duplex operation. Non-blocking means that the function returns immediately. The application has to get the receive status to know when the receive is complete.
instance | LPUART instance number |
rxBuff | buffer containing 8-bit read data chars received |
rxSize | the number of bytes to receive |
Definition at line 599 of file lpuart_driver.c.
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 not return until the receive is complete.
instance | LPUART instance number |
rxBuff | buffer containing 8-bit read data chars received |
rxSize | the number of bytes to receive |
timeout | timeout value in milliseconds |
Definition at line 528 of file lpuart_driver.c.
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 for transmitting data. When used with a non-blocking receive, the LPUART can perform a full duplex operation. Non-blocking means that the function returns immediately. The application has to get the transmit status to know when the transmit is complete.
instance | LPUART instance number |
txBuff | source buffer containing 8-bit data chars to send |
txSize | the number of bytes to send |
Definition at line 402 of file lpuart_driver.c.
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.
Blocking means that the function does not return until the transmission is complete.
instance | LPUART instance number |
txBuff | source buffer containing 8-bit data chars to send |
txSize | the number of bytes to send |
timeout | timeout value in milliseconds |
Definition at line 334 of file lpuart_driver.c.
LPUART_Type* const g_lpuartBase[LPUART_INSTANCE_COUNT] |
Table of base addresses for LPUART instances.
Definition at line 87 of file lpuart_common.c.
const clock_names_t g_lpuartClkNames[LPUART_INSTANCE_COUNT] |
Table to save LPUART indexes in PCC register map for clock configuration.
Definition at line 93 of file lpuart_common.c.
const IRQn_Type g_lpuartRxTxIrqId[LPUART_INSTANCE_COUNT] |
Table to save LPUART IRQ enumeration numbers defined in the CMSIS header file.
Definition at line 90 of file lpuart_common.c.