![]() |
Kinetis Bootloader
2.0.0
Common bootloader for Kinetis devices
|
Data Structures | |
| struct | lpsci_config_t |
| LPSCI configure structure. More... | |
| struct | lpsci_transfer_t |
| LPSCI transfer structure. More... | |
| struct | lpsci_handle_t |
Typedefs | |
| typedef void(* | lpsci_transfer_callback_t) (UART0_Type *base, lpsci_handle_t *handle, status_t status, void *userData) |
| LPSCI transfer callback function. | |
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 | |
| 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... | |
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... | |
| void | LPSCI_TransferSendBlocking (UART0_Type *base, const uint8_t *data, size_t length) |
| Writes to the TX register using a blocking method. 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_TransferReceiveBlocking (UART0_Type *base, uint8_t *data, size_t length) |
| Reads the RX register using a non-blocking method. 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... | |
The KSDK provides a peripheral driver for the Inter-Integrated Circuit (LPSCI) module of Kinetis devices.
#Overview
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 first parameter. Initialize the handle by calling the LPSCI_CreateHandle() API.
Transactional APIs support queue feature for both transmit/receive. Whenever the user calls the LPSCI_SendDataIRQ() or LPSCI_ReceiveDataIRQ(), 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_CreateHandle() 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.
| struct lpsci_config_t |
LPSCI configure structure.
| Data Fields | ||
|---|---|---|
| uint32_t | baudRate_Bps |
LPSCI baud rate |
| bool | enableRx |
Enable RX |
| bool | enableTx |
Enable TX |
| 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 |
| struct lpsci_transfer_t |
| struct _lpsci_handle |
| Data Fields | ||
|---|---|---|
| lpsci_transfer_callback_t | callback |
Callback function. |
| uint8_t *volatile | rxData |
Address of remaining data to receive. |
| volatile size_t | rxDataSize |
Size of the remaining data to receive. |
| size_t | rxDataSizeAll |
Size of the data to receive. |
| uint8_t * | rxRingBuffer |
Start address of the receiver ring buffer. |
| volatile uint16_t | rxRingBufferHead |
Index for the driver to store received data into ring buffer. |
| size_t | rxRingBufferSize |
Size of the ring buffer. |
| volatile uint16_t | rxRingBufferTail |
Index for the user to get data from the ring buffer. |
| volatile uint8_t | rxState |
RX transfer state |
| uint8_t *volatile | txData |
Address of remaining data to send. |
| volatile size_t | txDataSize |
Size of the remaining data to send. |
| size_t | txDataSizeAll |
Size of the data to send out. |
| volatile uint8_t | txState |
TX transfer state. |
| void * | userData |
LPSCI callback function parameter. |
LPSCI interrupt configuration structure, default settings all disabled.
This structure contains the settings for all LPSCI interrupt configurations.
| enum _lpsci_status |
Error codes for the LPSCI driver.
| enum _lpsci_status_flag_t |
LPSCI status flags.
This provides constants for the LPSCI status flags for use in the LPSCI functions.
| enum lpsci_parity_mode_t |
| void LPSCI_Deinit | ( | UART0_Type * | base | ) |
Deinitializes an LPSCI instance.
This function waits for TX complete, disables TX and RX, and disables the LPSCI clock.
| base | LPSCI peripheral base address. |
| void LPSCI_DisableInterrupts | ( | UART0_Type * | base, |
| uint32_t | mask | ||
| ) |
Disables the LPSCI interrupt according to a provided 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. |
| void LPSCI_EnableInterrupts | ( | UART0_Type * | base, |
| uint32_t | mask | ||
| ) |
Enables an LPSCI interrupt according to a provided 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. |
|
inlinestatic |
Enables or disables the LPSCI receiver.
This function enables or disables the LPSCI receiver.
| base | LPSCI peripheral base address. |
| enable | True to enable, false to disable. |
|
inlinestatic |
Enables or disables the LPSCI receiver DMA.
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. |
|
inlinestatic |
Enables or disables the LPSCI transmitter.
This function enables or disables the LPSCI transmitter.
| base | LPSCI peripheral base address. |
| enable | True to enable, false to disable. |
|
inlinestatic |
Enables or disable LPSCI transmitter DMA request.
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 |
Gets the LPSCI data register address.
This function returns the LPSCI data register address, which is mainly used by DMA/eDMA case.
| base | LPSCI peripheral base address. |
| void LPSCI_GetDefaultConfig | ( | lpsci_config_t * | config | ) |
Gets the default configuration structure and saves the configuration to a user-provided pointer.
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->enableTx = false; lpsciConfig->enableRx = false;
| config | Pointer to configuration structure. |
| uint32_t LPSCI_GetEnabledInterrupts | ( | UART0_Type * | base | ) |
Gets the enabled LPSCI interrupts.
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. |
| uint32_t LPSCI_GetStatusFlags | ( | UART0_Type * | base | ) |
Gets LPSCI status flags.
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. |
| 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.
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 | Status LPSCI initialize succeed |
|
inlinestatic |
Reads the RX data register.
This function polls the RX register, waits for the RX register to be full, and reads data from the TX register.
| base | LPSCI peripheral base address. |
| status_t LPSCI_SetBaudRate | ( | UART0_Type * | base, |
| uint32_t | baudRate_Bps, | ||
| uint32_t | srcClock_Hz | ||
| ) |
Sets the LPSCI instance baudrate.
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 | Status LPSCI initialize succeeded. |
| void LPSCI_TransferAbortReceive | ( | UART0_Type * | base, |
| lpsci_handle_t * | handle | ||
| ) |
Aborts interrupt driven data receiving.
This function aborts interrupt driven data receiving.
| handle | LPSCI handle pointer. |
| void LPSCI_TransferAbortSend | ( | UART0_Type * | base, |
| lpsci_handle_t * | handle | ||
| ) |
Aborts the interrupt-driven data transmit.
This function aborts the interrupt driven data send.
| handle | LPSCI handle pointer. |
| void LPSCI_TransferCreateHandle | ( | UART0_Type * | base, |
| lpsci_handle_t * | handle, | ||
| lpsci_transfer_callback_t | callback, | ||
| void * | userData | ||
| ) |
Initializes the LPSCI handle.
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. |
| status_t LPSCI_TransferGetReceiveCount | ( | UART0_Type * | base, |
| lpsci_handle_t * | handle, | ||
| uint32_t * | count | ||
| ) |
Get the number of bytes that have been received.
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; |
| 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.
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; |
| void LPSCI_TransferHandleErrorIRQ | ( | UART0_Type * | base, |
| lpsci_handle_t * | handle | ||
| ) |
LPSCI Error IRQ handle function.
This function handle the LPSCI error IRQ request.
| handle | LPSCI handle pointer. |
| void LPSCI_TransferHandleIRQ | ( | UART0_Type * | base, |
| lpsci_handle_t * | handle | ||
| ) |
LPSCI IRQ handle function.
This function handles the LPSCI transmit and receive IRQ request.
| handle | LPSCI handle pointer. |
| status_t LPSCI_TransferReceiveBlocking | ( | UART0_Type * | base, |
| uint8_t * | data, | ||
| size_t | length | ||
| ) |
Reads the RX register using a non-blocking method.
This function reads data from the TX register directly. The upper layer must ensure that the RX register is full before calling this function.
| 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. |
| 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.
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_TransferSendBlocking | ( | UART0_Type * | base, |
| const uint8_t * | data, | ||
| size_t | length | ||
| ) |
Writes to the TX register using a blocking method.
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_TransferSendNonBlocking | ( | UART0_Type * | base, |
| lpsci_handle_t * | handle, | ||
| lpsci_transfer_t * | xfer | ||
| ) |
Transmits a buffer of data using the interrupt method.
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_TransferStartRingBuffer | ( | UART0_Type * | base, |
| lpsci_handle_t * | handle, | ||
| uint8_t * | ringBuffer, | ||
| size_t | ringBufferSize | ||
| ) |
Sets up the RX ring buffer.
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 | ||
| ) |
Aborts the background transfer and uninstalls the ring buffer.
This function aborts the background transfer and uninstalls the ringbuffer.
| base | LPSCI peripheral base address. |
| handle | LPSCI handle pointer. |
|
inlinestatic |
Writes to the TX register.
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. |