![]() |
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... | |
Enumerations | |
enum | lpuart_transfer_type_t { LPUART_USING_DMA = 0, LPUART_USING_INTERRUPTS } |
Type of LPUART transfer (based on interrupts or DMA). More... | |
enum | lpuart_bit_count_per_char_t { LPUART_8_BITS_PER_CHAR = 0x0U, LPUART_9_BITS_PER_CHAR = 0x1U, LPUART_10_BITS_PER_CHAR = 0x2U } |
LPUART number of bits in a character. More... | |
enum | lpuart_parity_mode_t { LPUART_PARITY_DISABLED = 0x0U, LPUART_PARITY_EVEN = 0x2U, LPUART_PARITY_ODD = 0x3U } |
LPUART parity mode. More... | |
enum | lpuart_stop_bit_count_t { LPUART_ONE_STOP_BIT = 0x0U, LPUART_TWO_STOP_BIT = 0x1U } |
LPUART number of stop bits. 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... | |
uart_callback_t | LPUART_DRV_InstallRxCallback (uint32_t instance, uart_callback_t function, void *callbackParam) |
Installs callback function for the LPUART receive. More... | |
uart_callback_t | LPUART_DRV_InstallTxCallback (uint32_t instance, uart_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... | |
void | LPUART_DRV_SendDataPolling (uint32_t instance, const uint8_t *txBuff, uint32_t txSize) |
Send out multiple bytes of data using polling 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_ReceiveDataPolling (uint32_t instance, uint8_t *rxBuff, uint32_t rxSize) |
Receive multiple bytes of data using polling method. 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... | |
status_t | LPUART_DRV_SetBaudRate (uint32_t instance, uint32_t desiredBaudRate) |
Configures the LPUART baud rate. More... | |
void | LPUART_DRV_GetBaudRate (uint32_t instance, uint32_t *configuredBaudRate) |
Returns the LPUART baud rate. More... | |
LPUART number of bits in a character.
Implements : lpuart_bit_count_per_char_t_Class
Enumerator | |
---|---|
LPUART_8_BITS_PER_CHAR |
8-bit data characters |
LPUART_9_BITS_PER_CHAR |
9-bit data characters |
LPUART_10_BITS_PER_CHAR |
10-bit data characters |
Definition at line 56 of file lpuart_driver.h.
enum lpuart_parity_mode_t |
LPUART parity mode.
Implements : lpuart_parity_mode_t_Class
Enumerator | |
---|---|
LPUART_PARITY_DISABLED |
parity disabled |
LPUART_PARITY_EVEN |
parity enabled, type even, bit setting: PE|PT = 10 |
LPUART_PARITY_ODD |
parity enabled, type odd, bit setting: PE|PT = 11 |
Definition at line 67 of file lpuart_driver.h.
LPUART number of stop bits.
Implements : lpuart_stop_bit_count_t_Class
Enumerator | |
---|---|
LPUART_ONE_STOP_BIT |
one stop bit |
LPUART_TWO_STOP_BIT |
two stop bits |
Definition at line 78 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 46 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 780 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 530 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 244 of file lpuart_driver.c.
void LPUART_DRV_GetBaudRate | ( | uint32_t | instance, |
uint32_t * | configuredBaudRate | ||
) |
Returns the LPUART baud rate.
This function returns the LPUART configured baud rate.
instance | LPUART instance number. | |
[out] | configuredBaudRate | LPUART configured baud rate. |
Definition at line 901 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 occurred. |
Definition at line 737 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 occurred. |
Definition at line 486 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 158 of file lpuart_driver.c.
uart_callback_t LPUART_DRV_InstallRxCallback | ( | uint32_t | instance, |
uart_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 289 of file lpuart_driver.c.
uart_callback_t LPUART_DRV_InstallTxCallback | ( | uint32_t | instance, |
uart_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 312 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 694 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 567 of file lpuart_driver.c.
status_t LPUART_DRV_ReceiveDataPolling | ( | uint32_t | instance, |
uint8_t * | rxBuff, | ||
uint32_t | rxSize | ||
) |
Receive multiple bytes of data using polling method.
instance | LPUART instance number. |
rxBuff | The buffer pointer which saves the data to be received. |
rxSize | Size of data need to be received in unit of byte. |
Definition at line 633 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 442 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 335 of file lpuart_driver.c.
void LPUART_DRV_SendDataPolling | ( | uint32_t | instance, |
const uint8_t * | txBuff, | ||
uint32_t | txSize | ||
) |
Send out multiple bytes of data using polling method.
instance | LPUART instance number. |
txBuff | The buffer pointer which saves the data to be sent. |
txSize | Size of data to be sent in unit of byte. |
Definition at line 401 of file lpuart_driver.c.
status_t LPUART_DRV_SetBaudRate | ( | uint32_t | instance, |
uint32_t | desiredBaudRate | ||
) |
Configures the LPUART baud rate.
This function configures the LPUART baud rate. In some LPUART instances the user must disable the transmitter/receiver before calling this function. Generally, this may be applied to all LPUARTs to ensure safe operation.
instance | LPUART instance number. |
desiredBaudRate | LPUART desired baud rate. |
Definition at line 819 of file lpuart_driver.c.