The section describes the programming interface of the LPSCI Peripheral driver. The LPSCI peripheral driver transfers data to and from external devices on the Universal Asynchronous Receiver/Transmitter (LPSCI) serial bus with a single function call.
LPSCI Device structures
The driver uses an instantiation of the lpsci_state_t structure to maintain the current state of a particular LPSCI instance module driver. This structure holds data used by the LPSCI Peripheral driver to communicate between the transmit and receive transfer functions and the interrupt handler. The interrupt handler also uses this information to keep track of its progress. Because the driver itself does not statically allocate memory, the caller provides memory for the driver state structure during initialization. The user is required to pass in the memory for the run-time state structure. The LPSCI driver populates the structure members.
LPSCI User configuration structures
The LPSCI driver uses instances of the user configuration structure, lpsci_user_config_t, for the LPSCI driver. As a result, the most common settings of the LPSCI are configured with a single function call. Settings include: LPSCI baud rate; LPSCI parity mode: disabled (default), or even or odd; the number of stop bits; the number of bits per data word.
LPSCI Initialization
-
To initialize the LPSCI driver, call the LPSCI_DRV_Init() function and pass the instance number of the relevant LPSCI peripheral, memory for the run-time state structure, and a pointer to the user configuration structure. For example, to use LPSCI0 pass a value of 0 to the initialization function.
-
Then, pass the memory for the run-time state structure and, finally, pass a user configuration structure of the type lpsci_user_config_t as shown here:
typedef struct LpsciUserConfig {
uint32_t baudRate;
Typically, the lpsci_user_config_t instantiation is configured as a 8-bit-character, no-parity, 1-stop-bit (8-n-1) with a 9600 bps baud rate. The lpsci_user_config_t instantiation can be easily modified to configure the LPSCI Peripheral driver either to a different baud rate or character transfer features. This is an example code to set up a user LPSCI configuration instantiation:
This example shows how to call the LPSCI_DRV_Init() function given the user configuration structure and the LPSCI instance 0.
uint32_t lpsciInstance = 0;
LPSCI Transfers
The driver implements transmit and receive functions to transfer buffers of data. The driver also supports two different modes for transferring data: blocking and non-blocking.
The non-blocking transmit and receive functions include the LPSCI_DRV_SendData() and LPSCI_DRV_ReceiveData() functions.
The blocking (async) transmit and receive functions include the LPSCI_DRV_SendDataBlocking() and LPSCI_DRV_ReceiveDataBlocking() functions.
In all cases mentioned here, the functions are interrupt-driven.
These code examples show how to use previously mentioned functions and assume that the LPSCI module has been initialized as described previously in the Initialization Section.
For blocking transfer functions transmit and receive:
uint8_t sourceBuff[26] ={0};
uint8_t readBuffer[10] = {0};
uint32_t byteCount = sizeof(sourceBuff);
uint32_t rxRemainingSize = sizeof(readBuffer);
For non-blocking (async) transfer functions transmit and receive:
uint8_t *pTxBuff;
uint8_t rxBuff[10];
uint32_t txBytesRemaining, rxBytesRemaining;
|
file | fsl_lpsci_driver.h |
| This driver is for UART0 if UART0 is a separate chapter in the chip reference manual.
|
|
|
typedef void(* | lpsci_rx_callback_t )(uint32_t instance, void *lpsciState) |
| LPSCI receive callback function type. More...
|
|
typedef void(* | lpsci_tx_callback_t )(uint32_t instance, void *lpsciState) |
| LPSCI transmit callback function type.
|
|
|
UART0_Type *const | g_lpsciBase [UART0_INSTANCE_COUNT] |
| Table of base addresses for LPSCI instances. More...
|
|
UART0_Type *const | g_lpsciBase [UART0_INSTANCE_COUNT] |
| Table of base addresses for LPSCI instances. More...
|
|
const IRQn_Type | g_lpsciRxTxIrqId [UART0_INSTANCE_COUNT] |
| Table to save LPSCI IRQ enumeration numbers defined in CMSIS header file.
|
|
|
lpsci_status_t | LPSCI_DRV_DmaInit (uint32_t instance, lpsci_dma_state_t *lpsciDmaStatePtr, const lpsci_dma_user_config_t *lpsciUserConfig) |
| Initializes an LPSCI instance to work with DMA. More...
|
|
lpsci_status_t | LPSCI_DRV_DmaDeinit (uint32_t instance) |
| Shuts down the LPSCI. More...
|
|
lpsci_status_t | LPSCI_DRV_DmaSendDataBlocking (uint32_t instance, const uint8_t *txBuff, uint32_t txSize, uint32_t timeout) |
| Sends (transmits) data out through the LPSCI-DMA module using blocking method. More...
|
|
lpsci_status_t | LPSCI_DRV_DmaSendData (uint32_t instance, const uint8_t *txBuff, uint32_t txSize) |
| Sends (transmits) data through the LPSCI-DMA module using a non-blocking method. More...
|
|
lpsci_status_t | LPSCI_DRV_DmaGetTransmitStatus (uint32_t instance, uint32_t *bytesRemaining) |
| Returns whether the previous LPSCI-DMA transmit has finished. More...
|
|
lpsci_status_t | LPSCI_DRV_DmaAbortSendingData (uint32_t instance) |
| Terminates a non-blocking LPSCI-DMA transmission early. More...
|
|
lpsci_status_t | LPSCI_DRV_DmaReceiveDataBlocking (uint32_t instance, uint8_t *rxBuff, uint32_t rxSize, uint32_t timeout) |
| Gets (receives) data from the LPSCI-DMA module using a blocking method. More...
|
|
lpsci_status_t | LPSCI_DRV_DmaReceiveData (uint32_t instance, uint8_t *rxBuff, uint32_t rxSize) |
| Gets (receives) data from the LPSCI-DMA module using a non-blocking method. More...
|
|
lpsci_status_t | LPSCI_DRV_DmaGetReceiveStatus (uint32_t instance, uint32_t *bytesRemaining) |
| Returns whether the previous LPSCI-DMA receive is complete. More...
|
|
lpsci_status_t | LPSCI_DRV_DmaAbortReceivingData (uint32_t instance) |
| Terminates a non-blocking LPSCI-DMA receive early. More...
|
|
|
lpsci_status_t | LPSCI_DRV_Init (uint32_t instance, lpsci_state_t *lpsciStatePtr, const lpsci_user_config_t *lpsciUserConfig) |
| Initializes an LPSCI instance for operation. More...
|
|
lpsci_status_t | LPSCI_DRV_Deinit (uint32_t instance) |
| Shuts down the LPSCI by disabling interrupts and the transmitter/receiver. More...
|
|
lpsci_rx_callback_t | LPSCI_DRV_InstallRxCallback (uint32_t instance, lpsci_rx_callback_t function, uint8_t *rxBuff, void *callbackParam, bool alwaysEnableRxIrq) |
| Installs callback function for the LPSCI receive. More...
|
|
lpsci_tx_callback_t | LPSCI_DRV_InstallTxCallback (uint32_t instance, lpsci_tx_callback_t function, uint8_t *txBuff, void *callbackParam) |
| Installs callback function for the LPSCI transmit. More...
|
|
lpsci_status_t | LPSCI_DRV_SendDataBlocking (uint32_t instance, const uint8_t *txBuff, uint32_t txSize, uint32_t timeout) |
| Sends (transmits) data out through the LPSCI module using a blocking method. More...
|
|
lpsci_status_t | LPSCI_DRV_SendData (uint32_t instance, const uint8_t *txBuff, uint32_t txSize) |
| Sends (transmits) data through the LPSCI module using a non-blocking method. More...
|
|
lpsci_status_t | LPSCI_DRV_GetTransmitStatus (uint32_t instance, uint32_t *bytesRemaining) |
| Returns whether the previous LPSCI transmit has finished. More...
|
|
lpsci_status_t | LPSCI_DRV_AbortSendingData (uint32_t instance) |
| Terminates an asynchronous LPSCI transmission early. More...
|
|
lpsci_status_t | LPSCI_DRV_ReceiveDataBlocking (uint32_t instance, uint8_t *rxBuff, uint32_t rxSize, uint32_t timeout) |
| Gets (receives) data from the LPSCI module using a blocking method. More...
|
|
lpsci_status_t | LPSCI_DRV_ReceiveData (uint32_t instance, uint8_t *rxBuff, uint32_t rxSize) |
| Gets (receives) data from the LPSCI module using a non-blocking method. More...
|
|
lpsci_status_t | LPSCI_DRV_GetReceiveStatus (uint32_t instance, uint32_t *bytesRemaining) |
| Returns whether the previous LPSCI receive is complete. More...
|
|
lpsci_status_t | LPSCI_DRV_AbortReceivingData (uint32_t instance) |
| Terminates an asynchronous LPSCI receive early. More...
|
|
volatile bool lpsci_dma_state_t::isTxBusy |
volatile bool lpsci_dma_state_t::isRxBusy |
volatile bool lpsci_dma_state_t::isTxBlocking |
volatile bool lpsci_dma_state_t::isRxBlocking |
struct lpsci_dma_user_config_t |
Use an instance of this structure with the LPSCI_DRV_Init()function. This enables configuration of the most common settings of the LPSCI peripheral with a single function call. Settings include: LPSCI baud rate, LPSCI parity mode: disabled (default), or even or odd, the number of stop bits, and the number of bits per data word.
This structure holds data used by the LPSCI peripheral driver to communicate between the transfer function and the interrupt handler. The interrupt handler also uses this information to keep track of its progress. The user passes in the memory for the run-time state structure. The LPSCI driver populates the members.
const uint8_t* lpsci_state_t::txBuff |
uint8_t* lpsci_state_t::rxBuff |
volatile size_t lpsci_state_t::txSize |
volatile size_t lpsci_state_t::rxSize |
volatile bool lpsci_state_t::isTxBusy |
volatile bool lpsci_state_t::isRxBusy |
volatile bool lpsci_state_t::isTxBlocking |
volatile bool lpsci_state_t::isRxBlocking |
void* lpsci_state_t::rxCallbackParam |
void* lpsci_state_t::txCallbackParam |
struct lpsci_user_config_t |
typedef void(* lpsci_rx_callback_t)(uint32_t instance, void *lpsciState) |
This function initializes the run-time state structure to keep track of the on-going transfers, un-gates the clock to the LPSCI module, initializes the module to user-defined settings and default settings, configures the IRQ state structure, and enables the module-level interrupt to the core, the LPSCI module transmitter and receiver. This example shows how to set up the lpsci_dma_state_t and the lpsci_user_config_t parameters and how to call the LPSCI_DRV_DmaInit function by passing in these parameters:
- Parameters
-
instance | The LPSCI instance number. |
lpsciDmaStatePtr | A pointer to the LPSCI driver state structure memory. The user passes in the memory for the run-time state structure. The LPSCI driver populates the members. This run-time state structure keeps track of the current transfer in progress. |
lpsciUserConfig | The user configuration structure of type lpsci_user_config_t. The user populates the members of this structure and passes the pointer of this structure to this function. |
- Returns
- An error code or kStatus_LPSCI_Success.
This function disables the LPSCI-DMA trigger and disables the transmitter and receiver.
- Parameters
-
instance | The LPSCI instance number. |
- Returns
- An error code or kStatus_LPSCI_Success.
lpsci_status_t LPSCI_DRV_DmaSendDataBlocking |
( |
uint32_t |
instance, |
|
|
const uint8_t * |
txBuff, |
|
|
uint32_t |
txSize, |
|
|
uint32_t |
timeout |
|
) |
| |
- Parameters
-
instance | The LPSCI instance number. |
txBuff | A pointer to the source buffer containing 8-bit data chars to send. |
txSize | The number of bytes to send. |
timeout | A timeout value for RTOS abstraction sync control in milliseconds (ms). |
- Returns
- An error code or kStatus_LPSCI_Success.
lpsci_status_t LPSCI_DRV_DmaSendData |
( |
uint32_t |
instance, |
|
|
const uint8_t * |
txBuff, |
|
|
uint32_t |
txSize |
|
) |
| |
- Parameters
-
instance | The LPSCI module base address. |
txBuff | A pointer to the source buffer containing 8-bit data chars to send. |
txSize | The number of bytes to send. |
- Returns
- An error code or kStatus_LPSCI_Success.
lpsci_status_t LPSCI_DRV_DmaGetTransmitStatus |
( |
uint32_t |
instance, |
|
|
uint32_t * |
bytesRemaining |
|
) |
| |
- Parameters
-
instance | The LPSCI module base address. |
bytesRemaining | A pointer to a value that is populated with the number of bytes that are remaining in the active transfer. |
- Returns
- An error code or kStatus_LPSCI_Success.
- Return values
-
kStatus_LPSCI_Success | The transmit has completed successfully. |
kStatus_LPSCI_TxBusy | The transmit is still in progress. bytesTransmitted is filled with the number of bytes which are transmitted up to that point. |
- Parameters
-
instance | The LPSCI module base address. |
- Returns
- An error code or kStatus_LPSCI_Success.
- Return values
-
kStatus_LPSCI_Success | The transmit was successful. |
kStatus_LPSCI_NoTransmitInProgress | No transmission is currently in progress. |
lpsci_status_t LPSCI_DRV_DmaReceiveDataBlocking |
( |
uint32_t |
instance, |
|
|
uint8_t * |
rxBuff, |
|
|
uint32_t |
rxSize, |
|
|
uint32_t |
timeout |
|
) |
| |
- Parameters
-
instance | The LPSCI module base address. |
rxBuff | A pointer to the buffer containing 8-bit read data chars received. |
rxSize | The number of bytes to receive. |
timeout | A timeout value for RTOS abstraction sync control in milliseconds (ms). |
- Returns
- An error code or kStatus_LPSCI_Success.
lpsci_status_t LPSCI_DRV_DmaReceiveData |
( |
uint32_t |
instance, |
|
|
uint8_t * |
rxBuff, |
|
|
uint32_t |
rxSize |
|
) |
| |
- Parameters
-
instance | The LPSCI module base address. |
rxBuff | A pointer to the buffer containing 8-bit read data chars received. |
rxSize | The number of bytes to receive. |
- Returns
- An error code or kStatus_LPSCI_Success.
lpsci_status_t LPSCI_DRV_DmaGetReceiveStatus |
( |
uint32_t |
instance, |
|
|
uint32_t * |
bytesRemaining |
|
) |
| |
- Parameters
-
instance | The LPSCI module base address. |
bytesRemaining | A pointer to a value that is populated with the number of bytes which still need to be received in the active transfer. |
- Returns
- An error code or kStatus_LPSCI_Success.
- Return values
-
kStatus_LPSCI_Success | The receive has completed successfully. |
kStatus_LPSCI_RxBusy | The receive is still in progress. bytesReceived is filled with the number of bytes which are received up to that point. |
- Parameters
-
instance | The LPSCI module base address. |
- Returns
- An error code or kStatus_LPSCI_Success.
- Return values
-
kStatus_LPSCI_Success | The receive was successful. |
kStatus_LPSCI_NoTransmitInProgress | No receive is currently in progress. |
This function initializes the run-time state structure to keep track of the on-going transfers, un-gates the clock to the LPSCI module, initializes the module to user-defined settings and default settings, configures the IRQ state structure and enables the module-level interrupt to the core, and enables the LPSCI module transmitter and receiver. This example shows how to set up the lpsci_state_t and the lpsci_user_config_t parameters and how to call the LPSCI_DRV_Init function by passing in these parameters:
- Parameters
-
instance | The LPSCI instance number. |
lpsciStatePtr | A pointer to the LPSCI driver state structure memory. The user passes in the memory for the run-time state structure. The LPSCI driver populates the members. The run-time state structure keeps track of the current transfer in progress. |
lpsciUserConfig | The user configuration structure of type lpsci_user_config_t. The user populates the members of this structure and passes the pointer of the structure to the function. |
- Returns
- An error code or kStatus_LPSCI_Success.
This function disables the LPSCI interrupts, disables the transmitter and receiver, and flushes the FIFOs (for modules that support FIFOs).
- Parameters
-
instance | The LPSCI instance number. |
- Returns
- An error code or kStatus_LPSCI_Success.
- Parameters
-
instance | The LPSCI instance number. |
function | The LPSCI receive callback function. |
rxBuff | The receive buffer used inside IRQHandler. This buffer must be kept as long as the callback is functional. |
callbackParam | The LPSCI receive callback parameter pointer. |
alwaysEnableRxIrq | Whether always enable receive IRQ or not. |
- Returns
- Former LPSCI receive callback function pointer.
- Note
- After the callback is installed, it bypasses part of the LPSCI IRQHandler logic. Therefore, the callback needs to handle the indexes of txBuff and txSize.
- Parameters
-
instance | The LPSCI instance number. |
function | The LPSCI transmit callback function. |
txBuff | The transmit buffer used inside IRQHandler. This buffer must be kept as long as the callback is alive. |
callbackParam | The LPSCI transmit callback parameter pointer. |
- Returns
- Former LPSCI transmit callback function pointer.
lpsci_status_t LPSCI_DRV_SendDataBlocking |
( |
uint32_t |
instance, |
|
|
const uint8_t * |
txBuff, |
|
|
uint32_t |
txSize, |
|
|
uint32_t |
timeout |
|
) |
| |
A blocking (also known as synchronous) function means that the function does not return until the transmit is complete. This blocking function sends data through the LPSCI port.
- Parameters
-
instance | The LPSCI instance number. |
txBuff | A pointer to the source buffer containing 8-bit data chars to send. |
txSize | The number of bytes to send. |
timeout | A timeout value for RTOS abstraction sync control in milliseconds (ms). |
- Returns
- An error code or kStatus_LPSCI_Success.
lpsci_status_t LPSCI_DRV_SendData |
( |
uint32_t |
instance, |
|
|
const uint8_t * |
txBuff, |
|
|
uint32_t |
txSize |
|
) |
| |
A non-blocking (also known as synchronous) function means that the function returns immediately after initiating the transmit function. The application has to get the transmit status to see when the transmit is complete. In other words, after calling non-blocking (asynchronous) send function, the application must get the transmit status to check if transmit is complete. The asynchronous method of transmitting and receiving allows the LPSCI to perform a full duplex operation (simultaneously transmit and receive).
- Parameters
-
instance | The LPSCI module base address. |
txBuff | A pointer to the source buffer containing 8-bit data chars to send. |
txSize | The number of bytes to send. |
- Returns
- An error code or kStatus_LPSCI_Success.
lpsci_status_t LPSCI_DRV_GetTransmitStatus |
( |
uint32_t |
instance, |
|
|
uint32_t * |
bytesRemaining |
|
) |
| |
When performing an a-sync transmit, call this function to ascertain the state of the current transmission: in progress (or busy) or complete (success). If the transmission is still in progress, the user can obtain the number of words that have been transferred.
- Parameters
-
instance | The LPSCI module base address. |
bytesRemaining | A pointer to a value that is filled in with the number of bytes that are remaining in the active transfer. |
- Returns
- Current transmission status.
- Return values
-
kStatus_LPSCI_Success | The transmit has completed successfully. |
kStatus_LPSCI_TxBusy | The transmit is still in progress. bytesRemaining is filled with the number of bytes which are transmitted up to that point. |
During an a-sync LPSCI transmission, the user can terminate the transmission early if the transmission is still in progress.
- Parameters
-
instance | The LPSCI module base address. |
- Returns
- Whether the aborting was successful or not.
- Return values
-
kStatus_LPSCI_Success | The transmit was successful. |
kStatus_LPSCI_NoTransmitInProgress | No transmission is currently in progress. |
lpsci_status_t LPSCI_DRV_ReceiveDataBlocking |
( |
uint32_t |
instance, |
|
|
uint8_t * |
rxBuff, |
|
|
uint32_t |
rxSize, |
|
|
uint32_t |
timeout |
|
) |
| |
A blocking (also known as synchronous) function does not return until the receive is complete. This blocking function sends data through the LPSCI port.
- Parameters
-
instance | The LPSCI module base address. |
rxBuff | A pointer to the buffer containing 8-bit read data chars received. |
rxSize | The number of bytes to receive. |
timeout | A timeout value for RTOS abstraction sync control in milliseconds (ms). |
- Returns
- An error code or kStatus_LPSCI_Success.
lpsci_status_t LPSCI_DRV_ReceiveData |
( |
uint32_t |
instance, |
|
|
uint8_t * |
rxBuff, |
|
|
uint32_t |
rxSize |
|
) |
| |
A non-blocking (also known as synchronous) function returns immediately after initiating the receive function. The application has to get the receive status to see when the receive is complete. The asynchronous method of transmitting and receiving allows the LPSCI to perform a full duplex operation (simultaneously transmit and receive).
- Parameters
-
instance | The LPSCI module base address. |
rxBuff | A pointer to the buffer containing 8-bit read data chars received. |
rxSize | The number of bytes to receive. |
- Returns
- An error code or kStatus_LPSCI_Success.
lpsci_status_t LPSCI_DRV_GetReceiveStatus |
( |
uint32_t |
instance, |
|
|
uint32_t * |
bytesRemaining |
|
) |
| |
When performing an a-sync receive, call this function to ascertain the state of the current receive progress: in progress (or busy) or complete (success). If the receive is still in progress, the user can obtain the number of words that have been received.
- Parameters
-
instance | The LPSCI module base address. |
bytesRemaining | A pointer to a value that is filled in with the number of bytes which still need to be received in the active transfer. |
- Returns
- Current receive status.
- Return values
-
kStatus_LPSCI_Success | The receive has completed successfully. |
kStatus_LPSCI_RxBusy | The receive is still in progress. bytesRemaining is filled with the number of bytes which are received up to that point. |
During an a-sync LPSCI receive, the user can terminate the receive early if the receive is still in progress.
- Parameters
-
instance | The LPSCI module base address. |
- Returns
- Whether the action success or not.
- Return values
-
kStatus_LPSCI_Success | The receive was successful. |
kStatus_LPSCI_NoTransmitInProgress | No receive is currently in progress. |
UART0_Type* const g_lpsciBase[UART0_INSTANCE_COUNT] |
UART0_Type* const g_lpsciBase[UART0_INSTANCE_COUNT] |