![]() |
MCUXpresso SDK API Reference Manual
Rev. 0
NXP Semiconductors
|
The MCUXpresso SDK provides a peripheral driver for the Universal Asynchronous Receiver/Transmitter (LPSCI) module of MCUXpresso SDK devices.
The LPSCI driver can be split into 2 parts: functional APIs and transactional APIs.
Functional APIs are feature/property target low level APIs. Functional APIs can be used for the LPSCI initialization/configuration/operation for optimization/customization purpose. Using the functional API requires knowledge of the LPSCI peripheral and how to organize functional APIs to meet the application requirements. All functional APIs use the peripheral base address as the first parameter. The LPSCI functional operation groups provide the functional APIs set.
The transactional APIs are transaction target high level APIs. Transactional APIs can be used to enable the peripheral quickly and also in the user's application if the code size and performance of transactional APIs can satisfy the user's requirements. If there are special requirements for the code size and performance, see the transactional API implementation and write custom code. All transactional APIs use the lpsci_handle_t as the second parameter. Initialize the handle by calling the LPSCI_TransferCreateHandle() API.
Transactional APIs support queue feature for both transmit/receive. Whenever the user calls the LPSCI_TransferSendNonBlocking() or LPSCI_TransferReceiveNonBlocking(), the transfer structure is queued into the internally maintained software queue. The driver automatically continues the transmit/receive if the queue is not empty. When a transfer is finished, the callback is called to inform the user about the completion.
The LPSCI transactional APIs support the background receive. Provide the ringbuffer address and size while calling the LPSCI_TransferCreateHandle() API. The driver automatically starts receiving the data from the receive buffer into the ringbuffer. When the user makes subsequent calls to the LPSCI_ReceiveDataIRQ(), the driver provides the received data in the ringbuffer for user buffer directly and queues the left buffer into the receive queue.
This function group implements the LPSCI functional API. Functional APIs are feature-oriented.
This function group implements the LPSCI transactional API.
This function group implements the LPSCI DMA transactional API.
Refer to the driver examples codes located at <SDK_ROOT>/boards/<BOARD>/driver_examples/lpsci
Data Structures | |
struct | lpsci_config_t |
LPSCI configure structure. More... | |
struct | lpsci_transfer_t |
LPSCI transfer structure. More... | |
Driver version | |
enum | _lpsci_status { kStatus_LPSCI_TxBusy = MAKE_STATUS(kStatusGroup_LPSCI, 0), kStatus_LPSCI_RxBusy = MAKE_STATUS(kStatusGroup_LPSCI, 1), kStatus_LPSCI_TxIdle = MAKE_STATUS(kStatusGroup_LPSCI, 2), kStatus_LPSCI_RxIdle = MAKE_STATUS(kStatusGroup_LPSCI, 3), kStatus_LPSCI_FlagCannotClearManually, kStatus_LPSCI_BaudrateNotSupport, kStatus_LPSCI_Error = MAKE_STATUS(kStatusGroup_LPSCI, 6), kStatus_LPSCI_RxRingBufferOverrun, kStatus_LPSCI_RxHardwareOverrun = MAKE_STATUS(kStatusGroup_LPSCI, 8), kStatus_LPSCI_NoiseError = MAKE_STATUS(kStatusGroup_LPSCI, 9), kStatus_LPSCI_FramingError = MAKE_STATUS(kStatusGroup_LPSCI, 10), kStatus_LPSCI_ParityError = MAKE_STATUS(kStatusGroup_LPSCI, 11), kStatus_LPSCI_IdleLineDetected = MAKE_STATUS(kStatusGroup_LPSCI, 12) } |
Error codes for the LPSCI driver. More... | |
enum | lpsci_parity_mode_t { kLPSCI_ParityDisabled = 0x0U, kLPSCI_ParityEven = 0x2U, kLPSCI_ParityOdd = 0x3U } |
LPSCI parity mode. More... | |
enum | lpsci_stop_bit_count_t { kLPSCI_OneStopBit = 0U, kLPSCI_TwoStopBit = 1U } |
LPSCI stop bit count. More... | |
enum | lpsci_idle_line_type_t { kLPSCI_IdleLineStartBit = 0U, kLPSCI_IdleLineStopBit = 1U } |
LPSCI stop bit count. More... | |
enum | _lpsci_interrupt_enable_t { kLPSCI_LinBreakInterruptEnable = (UART0_BDH_LBKDIE_MASK), kLPSCI_RxActiveEdgeInterruptEnable = (UART0_BDH_RXEDGIE_MASK), kLPSCI_TxDataRegEmptyInterruptEnable = (UART0_C2_TIE_MASK << 8), kLPSCI_TransmissionCompleteInterruptEnable = (UART0_C2_TCIE_MASK << 8), kLPSCI_RxDataRegFullInterruptEnable = (UART0_C2_RIE_MASK << 8), kLPSCI_IdleLineInterruptEnable = (UART0_C2_ILIE_MASK << 8), kLPSCI_RxOverrunInterruptEnable = (UART0_C3_ORIE_MASK << 16), kLPSCI_NoiseErrorInterruptEnable = (UART0_C3_NEIE_MASK << 16), kLPSCI_FramingErrorInterruptEnable = (UART0_C3_FEIE_MASK << 16), kLPSCI_ParityErrorInterruptEnable = (UART0_C3_PEIE_MASK << 16) } |
LPSCI interrupt configuration structure, default settings all disabled. More... | |
enum | _lpsci_status_flag_t { kLPSCI_TxDataRegEmptyFlag = (UART0_S1_TDRE_MASK), kLPSCI_TransmissionCompleteFlag, kLPSCI_RxDataRegFullFlag, kLPSCI_IdleLineFlag = (UART0_S1_IDLE_MASK), kLPSCI_RxOverrunFlag, kLPSCI_NoiseErrorFlag = (UART0_S1_NF_MASK), kLPSCI_FramingErrorFlag, kLPSCI_ParityErrorFlag = (UART0_S1_PF_MASK), kLPSCI_LinBreakFlag, kLPSCI_RxActiveEdgeFlag, kLPSCI_RxActiveFlag } |
LPSCI status flags. More... | |
typedef void(* | lpsci_transfer_callback_t )(UART0_Type *base, lpsci_handle_t *handle, status_t status, void *userData) |
LPSCI transfer callback function. More... | |
#define | FSL_LPSCI_DRIVER_VERSION (MAKE_VERSION(2, 0, 4)) |
LPSCI driver version 2.0.4. More... | |
Initialization and deinitialization | |
status_t | LPSCI_Init (UART0_Type *base, const lpsci_config_t *config, uint32_t srcClock_Hz) |
Initializes an LPSCI instance with the user configuration structure and the peripheral clock. More... | |
void | LPSCI_Deinit (UART0_Type *base) |
Deinitializes an LPSCI instance. More... | |
void | LPSCI_GetDefaultConfig (lpsci_config_t *config) |
Gets the default configuration structure and saves the configuration to a user-provided pointer. More... | |
status_t | LPSCI_SetBaudRate (UART0_Type *base, uint32_t baudRate_Bps, uint32_t srcClock_Hz) |
Sets the LPSCI instance baudrate. More... | |
Status | |
uint32_t | LPSCI_GetStatusFlags (UART0_Type *base) |
Gets LPSCI status flags. More... | |
status_t | LPSCI_ClearStatusFlags (UART0_Type *base, uint32_t mask) |
Interrupts | |
void | LPSCI_EnableInterrupts (UART0_Type *base, uint32_t mask) |
Enables an LPSCI interrupt according to a provided mask. More... | |
void | LPSCI_DisableInterrupts (UART0_Type *base, uint32_t mask) |
Disables the LPSCI interrupt according to a provided mask. More... | |
uint32_t | LPSCI_GetEnabledInterrupts (UART0_Type *base) |
Gets the enabled LPSCI interrupts. More... | |
DMA Control | |
static uint32_t | LPSCI_GetDataRegisterAddress (UART0_Type *base) |
Gets the LPSCI data register address. More... | |
static void | LPSCI_EnableTxDMA (UART0_Type *base, bool enable) |
Enables or disable LPSCI transmitter DMA request. More... | |
static void | LPSCI_EnableRxDMA (UART0_Type *base, bool enable) |
Enables or disables the LPSCI receiver DMA. More... | |
Bus Operations | |
uint32_t | LPSCI_GetInstance (UART0_Type *base) |
Get the LPSCI instance from peripheral base address. More... | |
static void | LPSCI_EnableTx (UART0_Type *base, bool enable) |
Enables or disables the LPSCI transmitter. More... | |
static void | LPSCI_EnableRx (UART0_Type *base, bool enable) |
Enables or disables the LPSCI receiver. More... | |
static void | LPSCI_WriteByte (UART0_Type *base, uint8_t data) |
Writes to the TX register. More... | |
static uint8_t | LPSCI_ReadByte (UART0_Type *base) |
Reads the RX data register. More... | |
void | LPSCI_WriteBlocking (UART0_Type *base, const uint8_t *data, size_t length) |
Writes to the TX register using a blocking method. More... | |
status_t | LPSCI_ReadBlocking (UART0_Type *base, uint8_t *data, size_t length) |
Reads the RX register using a blocking method. More... | |
Transactional | |
void | LPSCI_TransferCreateHandle (UART0_Type *base, lpsci_handle_t *handle, lpsci_transfer_callback_t callback, void *userData) |
Initializes the LPSCI handle. More... | |
void | LPSCI_TransferStartRingBuffer (UART0_Type *base, lpsci_handle_t *handle, uint8_t *ringBuffer, size_t ringBufferSize) |
Sets up the RX ring buffer. More... | |
void | LPSCI_TransferStopRingBuffer (UART0_Type *base, lpsci_handle_t *handle) |
Aborts the background transfer and uninstalls the ring buffer. More... | |
size_t | LPSCI_TransferGetRxRingBufferLength (lpsci_handle_t *handle) |
Get the length of received data in RX ring buffer. More... | |
status_t | LPSCI_TransferSendNonBlocking (UART0_Type *base, lpsci_handle_t *handle, lpsci_transfer_t *xfer) |
Transmits a buffer of data using the interrupt method. More... | |
void | LPSCI_TransferAbortSend (UART0_Type *base, lpsci_handle_t *handle) |
Aborts the interrupt-driven data transmit. More... | |
status_t | LPSCI_TransferGetSendCount (UART0_Type *base, lpsci_handle_t *handle, uint32_t *count) |
Get the number of bytes that have been written to LPSCI TX register. More... | |
status_t | LPSCI_TransferReceiveNonBlocking (UART0_Type *base, lpsci_handle_t *handle, lpsci_transfer_t *xfer, size_t *receivedBytes) |
Receives buffer of data using the interrupt method. More... | |
void | LPSCI_TransferAbortReceive (UART0_Type *base, lpsci_handle_t *handle) |
Aborts interrupt driven data receiving. More... | |
status_t | LPSCI_TransferGetReceiveCount (UART0_Type *base, lpsci_handle_t *handle, uint32_t *count) |
Get the number of bytes that have been received. More... | |
void | LPSCI_TransferHandleIRQ (UART0_Type *base, lpsci_handle_t *handle) |
LPSCI IRQ handle function. More... | |
void | LPSCI_TransferHandleErrorIRQ (UART0_Type *base, lpsci_handle_t *handle) |
LPSCI Error IRQ handle function. More... | |
struct lpsci_config_t |
Data Fields | |
uint32_t | baudRate_Bps |
LPSCI baud rate. | |
lpsci_parity_mode_t | parityMode |
Parity mode, disabled (default), even, odd. | |
lpsci_stop_bit_count_t | stopBitCount |
Number of stop bits, 1 stop bit (default) or 2 stop bits. | |
lpsci_idle_line_type_t | idleLineType |
IDLE line type. More... | |
bool | enableTx |
Enable TX. | |
bool | enableRx |
Enable RX. | |
lpsci_idle_line_type_t lpsci_config_t::idleLineType |
struct lpsci_transfer_t |
#define FSL_LPSCI_DRIVER_VERSION (MAKE_VERSION(2, 0, 4)) |
typedef void(* lpsci_transfer_callback_t)(UART0_Type *base, lpsci_handle_t *handle, status_t status, void *userData) |
enum _lpsci_status |
enum lpsci_parity_mode_t |
This structure contains the settings for all LPSCI interrupt configurations.
enum _lpsci_status_flag_t |
This provides constants for the LPSCI status flags for use in the LPSCI functions.
status_t LPSCI_Init | ( | UART0_Type * | base, |
const lpsci_config_t * | config, | ||
uint32_t | srcClock_Hz | ||
) |
This function configures the LPSCI module with user-defined settings. The user can configure the configuration structure and can also get the default configuration by calling the LPSCI_GetDefaultConfig() function. Example below shows how to use this API to configure the LPSCI.
base | LPSCI peripheral base address. |
config | Pointer to user-defined configuration structure. |
srcClock_Hz | LPSCI clock source frequency in HZ. |
kStatus_LPSCI_BaudrateNotSupport | Baudrate is not support in current clock source. |
kStatus_Success | LPSCI initialize succeed |
void LPSCI_Deinit | ( | UART0_Type * | base | ) |
This function waits for TX complete, disables TX and RX, and disables the LPSCI clock.
base | LPSCI peripheral base address. |
void LPSCI_GetDefaultConfig | ( | lpsci_config_t * | config | ) |
This function initializes the LPSCI configure structure to default value. the default value are: lpsciConfig->baudRate_Bps = 115200U; lpsciConfig->parityMode = kLPSCI_ParityDisabled; lpsciConfig->stopBitCount = kLPSCI_OneStopBit; lpsciConfig->idleLineType = kLPSCI_IdleLineStartBit; lpsciConfig->enableTx = false; lpsciConfig->enableRx = false;
config | Pointer to configuration structure. |
status_t LPSCI_SetBaudRate | ( | UART0_Type * | base, |
uint32_t | baudRate_Bps, | ||
uint32_t | srcClock_Hz | ||
) |
This function configures the LPSCI module baudrate. This function is used to update the LPSCI module baudrate after the LPSCI module is initialized with the LPSCI_Init.
base | LPSCI peripheral base address. |
baudRate_Bps | LPSCI baudrate to be set. |
srcClock_Hz | LPSCI clock source frequency in HZ. |
kStatus_LPSCI_BaudrateNotSupport | Baudrate is not supported in the current clock source. |
kStatus_Success | Set baudrate succeed |
uint32_t LPSCI_GetStatusFlags | ( | UART0_Type * | base | ) |
This function gets all LPSCI status flags. The flags are returned as the logical OR value of the enumerators _lpsci_flags. To check a specific status, compare the return value to the enumerators in _LPSCI_flags. For example, to check whether the TX is empty:
base | LPSCI peripheral base address. |
void LPSCI_EnableInterrupts | ( | UART0_Type * | base, |
uint32_t | mask | ||
) |
This function enables the LPSCI interrupts according to a provided mask. The mask is a logical OR of enumeration members. See _lpsci_interrupt_enable. For example, to enable the TX empty interrupt and RX full interrupt:
base | LPSCI peripheral base address. |
mask | The interrupts to enable. Logical OR of _lpsci_interrupt_enable. |
void LPSCI_DisableInterrupts | ( | UART0_Type * | base, |
uint32_t | mask | ||
) |
This function disables the LPSCI interrupts according to a provided mask. The mask is a logical OR of enumeration members. See _lpsci_interrupt_enable. For example, to disable TX empty interrupt and RX full interrupt:
base | LPSCI peripheral base address. |
mask | The interrupts to disable. Logical OR of _LPSCI_interrupt_enable. |
uint32_t LPSCI_GetEnabledInterrupts | ( | UART0_Type * | base | ) |
This function gets the enabled LPSCI interrupts, which are returned as the logical OR value of the enumerators _lpsci_interrupt_enable. To check a specific interrupts enable status, compare the return value to the enumerators in _LPSCI_interrupt_enable. For example, to check whether TX empty interrupt is enabled:
base | LPSCI peripheral base address. |
|
inlinestatic |
This function returns the LPSCI data register address, which is mainly used by DMA/eDMA case.
base | LPSCI peripheral base address. |
|
inlinestatic |
This function enables or disables the transmit data register empty flag, S1[TDRE], to generate DMA requests.
base | LPSCI peripheral base address. |
enable | True to enable, false to disable. |
|
inlinestatic |
This function enables or disables the receiver data register full flag, S1[RDRF], to generate DMA requests.
base | LPSCI peripheral base address. |
enable | True to enable, false to disable. |
uint32_t LPSCI_GetInstance | ( | UART0_Type * | base | ) |
base | LPSCI peripheral base address. |
|
inlinestatic |
This function enables or disables the LPSCI transmitter.
base | LPSCI peripheral base address. |
enable | True to enable, false to disable. |
|
inlinestatic |
This function enables or disables the LPSCI receiver.
base | LPSCI peripheral base address. |
enable | True to enable, false to disable. |
|
inlinestatic |
This function writes data to the TX register directly. The upper layer must ensure that the TX register is empty before calling this function.
base | LPSCI peripheral base address. |
data | Data write to TX register. |
|
inlinestatic |
This function reads data from the RX register directly. The upper layer must ensure that the RX register is full before calling this function.
base | LPSCI peripheral base address. |
void LPSCI_WriteBlocking | ( | UART0_Type * | base, |
const uint8_t * | data, | ||
size_t | length | ||
) |
This function polls the TX register, waits for the TX register empty, and writes data to the TX buffer.
base | LPSCI peripheral base address. |
data | Start address of the data to write. |
length | Size of the data to write. |
status_t LPSCI_ReadBlocking | ( | UART0_Type * | base, |
uint8_t * | data, | ||
size_t | length | ||
) |
This function polls the RX register, waits for the RX register to be full, and reads data from the RX register.
base | LPSCI peripheral base address. |
data | Start address of the buffer to store the received data. |
length | Size of the buffer. |
kStatus_LPSCI_RxHardwareOverrun | Receiver overrun happened while receiving data. |
kStatus_LPSCI_NoiseError | Noise error happened while receiving data. |
kStatus_LPSCI_FramingError | Framing error happened while receiving data. |
kStatus_LPSCI_ParityError | Parity error happened while receiving data. |
kStatus_Success | Successfully received all data. |
void LPSCI_TransferCreateHandle | ( | UART0_Type * | base, |
lpsci_handle_t * | handle, | ||
lpsci_transfer_callback_t | callback, | ||
void * | userData | ||
) |
This function initializes the LPSCI handle, which can be used for other LPSCI transactional APIs. Usually, for a specified LPSCI instance, call this API once to get the initialized handle.
LPSCI driver supports the "background" receiving, which means that the user can set up an RX ring buffer optionally. Data received are stored into the ring buffer even when the user doesn't call the LPSCI_TransferReceiveNonBlocking() API. If there is already data received in the ring buffer, get the received data from the ring buffer directly. The ring buffer is disabled if pass NULL as ringBuffer
.
handle | LPSCI handle pointer. |
base | LPSCI peripheral base address. |
ringBuffer | Start address of ring buffer for background receiving. Pass NULL to disable the ring buffer. |
ringBufferSize | size of the ring buffer. |
void LPSCI_TransferStartRingBuffer | ( | UART0_Type * | base, |
lpsci_handle_t * | handle, | ||
uint8_t * | ringBuffer, | ||
size_t | ringBufferSize | ||
) |
This function sets up the RX ring buffer to a specific LPSCI handle.
When the RX ring buffer is used, data received is stored into the ring buffer even when the user doesn't call the LPSCI_TransferReceiveNonBlocking() API. If there is already data received in the ring buffer, the user can get the received data from the ring buffer directly.
ringBufferSize
is 32, only 31 bytes are used for saving data.base | LPSCI peripheral base address. |
handle | LPSCI handle pointer. |
ringBuffer | Start address of ring buffer for background receiving. Pass NULL to disable the ring buffer. |
ringBufferSize | size of the ring buffer. |
void LPSCI_TransferStopRingBuffer | ( | UART0_Type * | base, |
lpsci_handle_t * | handle | ||
) |
This function aborts the background transfer and uninstalls the ringbuffer.
base | LPSCI peripheral base address. |
handle | LPSCI handle pointer. |
size_t LPSCI_TransferGetRxRingBufferLength | ( | lpsci_handle_t * | handle | ) |
handle LPSCI handle pointer.
status_t LPSCI_TransferSendNonBlocking | ( | UART0_Type * | base, |
lpsci_handle_t * | handle, | ||
lpsci_transfer_t * | xfer | ||
) |
This function sends data using the interrupt method. This is a non-blocking function, which returns directly without waiting for all data to be written to the TX register. When all data is written to the TX register in ISR, LPSCI driver calls the callback function and passes the kStatus_LPSCI_TxIdle as status parameter.
handle | LPSCI handle pointer. |
xfer | LPSCI transfer structure, refer to #LPSCI_transfer_t. |
kStatus_Success | Successfully start the data transmission. |
kStatus_LPSCI_TxBusy | Previous transmission still not finished, data not all written to the TX register. |
kStatus_InvalidArgument | Invalid argument. |
void LPSCI_TransferAbortSend | ( | UART0_Type * | base, |
lpsci_handle_t * | handle | ||
) |
This function aborts the interrupt driven data send.
handle | LPSCI handle pointer. |
status_t LPSCI_TransferGetSendCount | ( | UART0_Type * | base, |
lpsci_handle_t * | handle, | ||
uint32_t * | count | ||
) |
This function gets the number of bytes that have been written to LPSCI TX register by interrupt method.
base | LPSCI peripheral base address. |
handle | LPSCI handle pointer. |
count | Send bytes count. |
kStatus_NoTransferInProgress | No send in progress. |
kStatus_InvalidArgument | Parameter is invalid. |
kStatus_Success | Get successfully through the parameter count ; |
status_t LPSCI_TransferReceiveNonBlocking | ( | UART0_Type * | base, |
lpsci_handle_t * | handle, | ||
lpsci_transfer_t * | xfer, | ||
size_t * | receivedBytes | ||
) |
This function receives data using the interrupt method. This is a non-blocking function which returns without waiting for all data to be received. If the RX ring buffer is used and not empty, the data in ring buffer is copied and the parameter receivedBytes
shows how many bytes are copied from the ring buffer. After copying, if the data in ring buffer is not enough to read, the receive request is saved by the LPSCI driver. When new data arrives, the receive request is serviced first. When all data is received, the LPSCI driver notifies the upper layer through a callback function and passes the status parameter kStatus_LPSCI_RxIdle. For example, the upper layer needs 10 bytes but there are only 5 bytes in the ring buffer. The 5 bytes are copied to the xfer->data and the function returns with the parameter receivedBytes
set to 5. For the remaining 5 bytes, newly arrived data is saved from the xfer->data[5]. When 5 bytes are received, the LPSCI driver notifies the upper layer. If the RX ring buffer is not enabled, this function enables the RX and RX interrupt to receive data to the xfer->data. When all data is received, the upper layer is notified.
handle | LPSCI handle pointer. |
xfer | lpsci transfer structure. See lpsci_transfer_t. |
receivedBytes | Bytes received from the ring buffer directly. |
kStatus_Success | Successfully queue the transfer into transmit queue. |
kStatus_LPSCI_RxBusy | Previous receive request is not finished. |
kStatus_InvalidArgument | Invalid argument. |
void LPSCI_TransferAbortReceive | ( | UART0_Type * | base, |
lpsci_handle_t * | handle | ||
) |
This function aborts interrupt driven data receiving.
handle | LPSCI handle pointer. |
status_t LPSCI_TransferGetReceiveCount | ( | UART0_Type * | base, |
lpsci_handle_t * | handle, | ||
uint32_t * | count | ||
) |
This function gets the number of bytes that have been received.
base | LPSCI peripheral base address. |
handle | LPSCI handle pointer. |
count | Receive bytes count. |
kStatus_NoTransferInProgress | No receive in progress. |
kStatus_InvalidArgument | Parameter is invalid. |
kStatus_Success | Get successfully through the parameter count ; |
void LPSCI_TransferHandleIRQ | ( | UART0_Type * | base, |
lpsci_handle_t * | handle | ||
) |
This function handles the LPSCI transmit and receive IRQ request.
handle | LPSCI handle pointer. |
void LPSCI_TransferHandleErrorIRQ | ( | UART0_Type * | base, |
lpsci_handle_t * | handle | ||
) |
This function handle the LPSCI error IRQ request.
handle | LPSCI handle pointer. |