![]() |
S32 SDK
|
Low Power Serial Peripheral Interface Peripheral Driver.
Data Structures | |
struct | lpspi_master_config_t |
Data structure containing information about a device on the SPI bus. More... | |
struct | lpspi_state_t |
Runtime state structure for the LPSPI master driver. More... | |
struct | lpspi_slave_config_t |
User configuration structure for the SPI slave driver. Implements : lpspi_slave_config_t_Class. More... | |
Enumerations | |
enum | lpspi_transfer_type { LPSPI_USING_DMA = 0, LPSPI_USING_INTERRUPTS } |
Type of LPSPI transfer (based on interrupts or DMA). Implements : lpspi_transfer_type_Class. More... | |
enum | transfer_status_t { LPSPI_TRANSFER_OK = 0U, LPSPI_TRANSMIT_FAIL, LPSPI_RECEIVE_FAIL } |
Functions | |
void | LPSPI_DRV_IRQHandler (uint32_t instance) |
The function LPSPI_DRV_IRQHandler passes IRQ control to either the master or slave driver. More... | |
void | LPSPI_DRV_FillupTxBuffer (uint32_t instance) |
The function LPSPI_DRV_FillupTxBuffer writes data in TX hardware buffer depending on driver state and number of bytes remained to send. More... | |
void | LPSPI_DRV_ReadRXBuffer (uint32_t instance) |
The function LPSPI_DRV_ReadRXBuffer reads data from RX hardware buffer and writes this data in RX software buffer. More... | |
void | LPSPI_DRV_DisableTEIEInterrupts (uint32_t instance) |
Disable the TEIE interrupts at the end of a transfer. Disable the interrupts and clear the status for transmit/receive errors. More... | |
void | LPSPI0_IRQHandler (void) |
This function is the implementation of LPSPI0 handler named in startup code. More... | |
void | LPSPI1_IRQHandler (void) |
This function is the implementation of LPSPI1 handler named in startup code. More... | |
void | LPSPI2_IRQHandler (void) |
This function is the implementation of LPSPI2 handler named in startup code. More... | |
Variables | |
LPSPI_Type * | g_lpspiBase [LPSPI_INSTANCE_COUNT] |
Table of base pointers for SPI instances. More... | |
IRQn_Type | g_lpspiIrqId [LPSPI_INSTANCE_COUNT] |
Table to save LPSPI IRQ enumeration numbers defined in the CMSIS header file. More... | |
lpspi_state_t * | g_lpspiStatePtr [LPSPI_INSTANCE_COUNT] |
Initialization and shutdown | |
status_t | LPSPI_DRV_MasterInit (uint32_t instance, lpspi_state_t *lpspiState, const lpspi_master_config_t *spiConfig) |
Initializes a LPSPI instance for interrupt driven master mode operation. More... | |
status_t | LPSPI_DRV_MasterDeinit (uint32_t instance) |
Shuts down a LPSPI instance. More... | |
status_t | LPSPI_DRV_MasterSetDelay (uint32_t instance, uint32_t delayBetwenTransfers, uint32_t delaySCKtoPCS, uint32_t delayPCStoSCK) |
Configures the LPSPI master mode bus timing delay options. More... | |
Bus configuration | |
status_t | LPSPI_DRV_MasterConfigureBus (uint32_t instance, const lpspi_master_config_t *spiConfig, uint32_t *calculatedBaudRate) |
Configures the LPSPI port physical parameters to access a device on the bus when the LSPI instance is configured for interrupt operation. More... | |
Blocking transfers | |
status_t | LPSPI_DRV_MasterTransferBlocking (uint32_t instance, const uint8_t *sendBuffer, uint8_t *receiveBuffer, uint16_t transferByteCount, uint32_t timeout) |
Performs an interrupt driven blocking SPI master mode transfer. More... | |
Non-blocking transfers | |
status_t | LPSPI_DRV_MasterTransfer (uint32_t instance, const uint8_t *sendBuffer, uint8_t *receiveBuffer, uint16_t transferByteCount) |
Performs an interrupt driven non-blocking SPI master mode transfer. More... | |
status_t | LPSPI_DRV_MasterGetTransferStatus (uint32_t instance, uint32_t *bytesRemained) |
Returns whether the previous interrupt driven transfer is completed. More... | |
status_t | LPSPI_DRV_MasterAbortTransfer (uint32_t instance) |
Terminates an interrupt driven asynchronous transfer early. More... | |
void | LPSPI_DRV_MasterIRQHandler (uint32_t instance) |
Interrupt handler for LPSPI master mode. This handler uses the buffers stored in the lpspi_master_state_t structs to transfer data. More... | |
Initialization and shutdown | |
status_t | LPSPI_DRV_SlaveInit (uint32_t instance, lpspi_state_t *lpspiState, const lpspi_slave_config_t *slaveConfig) |
Initializes a LPSPI instance for a slave mode operation, using interrupt mechanism. More... | |
status_t | LPSPI_DRV_SlaveDeinit (uint32_t instance) |
Shuts down an LPSPI instance interrupt mechanism. More... | |
Blocking transfers | |
status_t | LPSPI_DRV_SlaveTransferBlocking (uint32_t instance, const uint8_t *sendBuffer, uint8_t *receiveBuffer, uint16_t transferByteCount, uint32_t timeout) |
Transfers data on LPSPI bus using interrupt and a blocking call. More... | |
Non-blocking transfers | |
void | LPSPI_DRV_SlaveIRQHandler (uint32_t instance) |
Interrupt handler for LPSPI slave mode. This handler uses the buffers stored in the lpspi_master_state_t structs to transfer data. More... | |
status_t | LPSPI_DRV_SlaveTransfer (uint32_t instance, const uint8_t *sendBuffer, uint8_t *receiveBuffer, uint16_t transferByteCount) |
Starts the transfer data on LPSPI bus using an interrupt and a non-blocking call. More... | |
status_t | LPSPI_DRV_SlaveAbortTransfer (uint32_t instance) |
Aborts the transfer that started by a non-blocking call transfer function. More... | |
status_t | LPSPI_DRV_SlaveGetTransferStatus (uint32_t instance, uint32_t *bytesRemained) |
Returns whether the previous transfer is finished. More... | |
enum lpspi_transfer_type |
Type of LPSPI transfer (based on interrupts or DMA). Implements : lpspi_transfer_type_Class.
Enumerator | |
---|---|
LPSPI_USING_DMA |
The driver will use DMA to perform SPI transfer |
LPSPI_USING_INTERRUPTS |
The driver will use interrupts to perform SPI transfer |
Definition at line 62 of file lpspi_shared_function.h.
enum transfer_status_t |
Enumerator | |
---|---|
LPSPI_TRANSFER_OK |
Transfer OK |
LPSPI_TRANSMIT_FAIL |
Error during transmission |
LPSPI_RECEIVE_FAIL |
Error during reception |
Definition at line 68 of file lpspi_shared_function.h.
void LPSPI0_IRQHandler | ( | void | ) |
This function is the implementation of LPSPI0 handler named in startup code.
It passes the instance to the shared LPSPI IRQ handler.
Definition at line 109 of file lpspi_irq.c.
void LPSPI1_IRQHandler | ( | void | ) |
This function is the implementation of LPSPI1 handler named in startup code.
It passes the instance to the shared LPSPI IRQ handler.
Definition at line 119 of file lpspi_irq.c.
void LPSPI2_IRQHandler | ( | void | ) |
This function is the implementation of LPSPI2 handler named in startup code.
It passes the instance to the shared LPSPI IRQ handler.
Definition at line 129 of file lpspi_irq.c.
void LPSPI_DRV_DisableTEIEInterrupts | ( | uint32_t | instance | ) |
Disable the TEIE interrupts at the end of a transfer. Disable the interrupts and clear the status for transmit/receive errors.
Definition at line 261 of file lpspi_shared_function.c.
void LPSPI_DRV_FillupTxBuffer | ( | uint32_t | instance | ) |
The function LPSPI_DRV_FillupTxBuffer writes data in TX hardware buffer depending on driver state and number of bytes remained to send.
The function LPSPI_DRV_FillupTxBuffer writes data in TX hardware buffer depending on driver state and number of bytes remained to send.
Definition at line 122 of file lpspi_shared_function.c.
void LPSPI_DRV_IRQHandler | ( | uint32_t | instance | ) |
The function LPSPI_DRV_IRQHandler passes IRQ control to either the master or slave driver.
The address of the IRQ handlers are checked to make sure they are non-zero before they are called. If the IRQ handler's address is zero, it means that driver was not present in the link (because the IRQ handlers are marked as weak). This would actually be a program error, because it means the master/slave config for the IRQ was set incorrectly.
Definition at line 99 of file lpspi_shared_function.c.
status_t LPSPI_DRV_MasterAbortTransfer | ( | uint32_t | instance | ) |
Terminates an interrupt driven asynchronous transfer early.
During an a-sync (non-blocking) transfer, the user has the option to terminate the transfer early if the transfer is still in progress.
instance | The instance number of the LPSPI peripheral. |
Definition at line 563 of file lpspi_master_driver.c.
status_t LPSPI_DRV_MasterConfigureBus | ( | uint32_t | instance, |
const lpspi_master_config_t * | spiConfig, | ||
uint32_t * | calculatedBaudRate | ||
) |
Configures the LPSPI port physical parameters to access a device on the bus when the LSPI instance is configured for interrupt operation.
In this function, the term "spiConfig" is used to indicate the SPI device for which the LPSPI master is communicating. This is an optional function as the spiConfig parameters are normally configured in the initialization function or the transfer functions, where these various functions would call the configure bus function. This is an example to set up the lpspi_master_config_t structure to call the LPSPI_DRV_MasterConfigureBus function by passing in these parameters:
instance | The instance number of the LPSPI peripheral. |
spiConfig | Pointer to the spiConfig structure. This structure contains the settings for the SPI bus configuration. The SPI device parameters are the desired baud rate (in bits-per-sec), bits-per-frame, chip select attributes, clock attributes, and data shift direction. |
calculatedBaudRate | The calculated baud rate passed back to the user to determine if the calculated baud rate is close enough to meet the needs. The baud rate never exceeds the desired baud rate. |
Definition at line 311 of file lpspi_master_driver.c.
status_t LPSPI_DRV_MasterDeinit | ( | uint32_t | instance | ) |
Shuts down a LPSPI instance.
This function resets the LPSPI peripheral, gates its clock, and disables the interrupt to the core. It first checks to see if a transfer is in progress and if so returns an error status.
instance | The instance number of the LPSPI peripheral. |
Definition at line 191 of file lpspi_master_driver.c.
status_t LPSPI_DRV_MasterGetTransferStatus | ( | uint32_t | instance, |
uint32_t * | bytesRemained | ||
) |
Returns whether the previous interrupt driven transfer is completed.
When performing an a-sync (non-blocking) transfer, the user can call this function to ascertain the state of the current transfer: in progress (or busy) or complete (success). In addition, if the transfer is still in progress, the user can get the number of words that have been transferred up to now.
instance | The instance number of the LPSPI peripheral. |
bytesRemained | Pointer to a value that is filled in with the number of bytes that must be received. |
Definition at line 535 of file lpspi_master_driver.c.
status_t LPSPI_DRV_MasterInit | ( | uint32_t | instance, |
lpspi_state_t * | lpspiState, | ||
const lpspi_master_config_t * | spiConfig | ||
) |
Initializes a LPSPI instance for interrupt driven master mode operation.
This function uses an interrupt-driven method for transferring data. In this function, the term "spiConfig" is used to indicate the SPI device for which the LPSPI master is communicating. This function initializes the run-time state structure to track the ongoing transfers, un-gates the clock to the LPSPI module, resets the LPSPI module, configures the IRQ state structure, enables the module-level interrupt to the core, and enables the LPSPI module. This is an example to set up the lpspi_master_state_t and call the LPSPI_DRV_MasterInit function by passing in these parameters:
instance | The instance number of the LPSPI peripheral. |
lpspiState | The pointer to the LPSPI master driver state structure. The user passes the memory for this run-time state structure. The LPSPI master driver populates the members. This run-time state structure keeps track of the transfer in progress. |
spiConfig | The data structure containing information about a device on the SPI bus |
Definition at line 140 of file lpspi_master_driver.c.
void LPSPI_DRV_MasterIRQHandler | ( | uint32_t | instance | ) |
Interrupt handler for LPSPI master mode. This handler uses the buffers stored in the lpspi_master_state_t structs to transfer data.
instance | The instance number of the LPSPI peripheral. |
Interrupt handler for LPSPI master mode. This handler uses the buffers stored in the lpspi_master_state_t structs to transfer data.
Definition at line 799 of file lpspi_master_driver.c.
status_t LPSPI_DRV_MasterSetDelay | ( | uint32_t | instance, |
uint32_t | delayBetwenTransfers, | ||
uint32_t | delaySCKtoPCS, | ||
uint32_t | delayPCStoSCK | ||
) |
Configures the LPSPI master mode bus timing delay options.
This function involves the LPSPI module's delay options to "fine tune" some of the signal timings and match the timing needs of a slower peripheral device. This is an optional function that can be called after the LPSPI module has been initialized for master mode. The timings are adjusted in terms of cycles of the baud rate clock. The bus timing delays that can be adjusted are listed below:
SCK to PCS Delay: Adjustable delay option between the last edge of SCK to the de-assertion of the PCS signal.
PCS to SCK Delay: Adjustable delay option between the assertion of the PCS signal to the first SCK edge.
Delay between Transfers: Adjustable delay option between the de-assertion of the PCS signal for a frame to the assertion of the PCS signal for the next frame.
instance | The instance number of the LPSPI peripheral. |
delayBetwenTransfers | Minimum delay between 2 transfers in microseconds |
delaySCKtoPCS | Minimum delay between SCK and PCS |
delayPCStoSCK | Minimum delay between PCS and SCK |
Definition at line 237 of file lpspi_master_driver.c.
status_t LPSPI_DRV_MasterTransfer | ( | uint32_t | instance, |
const uint8_t * | sendBuffer, | ||
uint8_t * | receiveBuffer, | ||
uint16_t | transferByteCount | ||
) |
Performs an interrupt driven non-blocking SPI master mode transfer.
This function simultaneously sends and receives data on the SPI bus, as SPI is naturally a full-duplex bus. The function returns immediately after initiating the transfer. The user needs to check whether the transfer is complete using the LPSPI_DRV_MasterGetTransferStatus function. This function allows the user to optionally pass in a SPI configuration structure which allows the user to change the SPI bus attributes in conjunction with initiating a SPI transfer. The difference between passing in the SPI configuration structure here as opposed to the configure bus function is that the configure bus function returns the calculated baud rate where this function does not. The user can also call the configure bus function prior to the transfer in which case the user would simply pass in a NULL to the transfer function's device structure parameter.
instance | The instance number of the LPSPI peripheral. |
spiConfig | Pointer to the SPI configuration structure. This structure contains the settings for the SPI bus configuration in this transfer. You may pass NULL for this parameter, in which case the current bus configuration is used unmodified. The device can be configured separately by calling the LPSPI_DRV_MasterConfigureBus function. |
sendBuffer | The pointer to the data buffer of the data to send. You may pass NULL for this parameter and bytes with a value of 0 (zero) is sent. |
receiveBuffer | Pointer to the buffer where the received bytes are stored. If you pass NULL for this parameter, the received bytes are ignored. |
transferByteCount | The number of bytes to send and receive. |
Definition at line 498 of file lpspi_master_driver.c.
status_t LPSPI_DRV_MasterTransferBlocking | ( | uint32_t | instance, |
const uint8_t * | sendBuffer, | ||
uint8_t * | receiveBuffer, | ||
uint16_t | transferByteCount, | ||
uint32_t | timeout | ||
) |
Performs an interrupt driven blocking SPI master mode transfer.
This function simultaneously sends and receives data on the SPI bus, as SPI is naturally a full-duplex bus. The function does not return until the transfer is complete. This function allows the user to optionally pass in a SPI configuration structure which allows the user to change the SPI bus attributes in conjunction with initiating a SPI transfer. The difference between passing in the SPI configuration structure here as opposed to the configure bus function is that the configure bus function returns the calculated baud rate where this function does not. The user can also call the configure bus function prior to the transfer in which case the user would simply pass in a NULL to the transfer function's device structure parameter.
instance | The instance number of the LPSPI peripheral. |
sendBuffer | The pointer to the data buffer of the data to send. You may pass NULL for this parameter and bytes with a value of 0 (zero) is sent. |
receiveBuffer | Pointer to the buffer where the received bytes are stored. If you pass NULL for this parameter, the received bytes are ignored. |
transferByteCount | The number of bytes to send and receive. |
timeout | A timeout for the transfer in milliseconds. If the transfer takes longer than this amount of time, the transfer is aborted and a STATUS_TIMEOUT error returned. |
Definition at line 420 of file lpspi_master_driver.c.
void LPSPI_DRV_ReadRXBuffer | ( | uint32_t | instance | ) |
The function LPSPI_DRV_ReadRXBuffer reads data from RX hardware buffer and writes this data in RX software buffer.
The function LPSPI_DRV_ReadRXBuffer reads data from RX hardware buffer and writes this data in RX software buffer.
Definition at line 200 of file lpspi_shared_function.c.
status_t LPSPI_DRV_SlaveAbortTransfer | ( | uint32_t | instance | ) |
Aborts the transfer that started by a non-blocking call transfer function.
This function stops the transfer which was started by the calling the SPI_DRV_SlaveTransfer() function.
instance | The instance number of SPI peripheral |
Definition at line 430 of file lpspi_slave_driver.c.
status_t LPSPI_DRV_SlaveDeinit | ( | uint32_t | instance | ) |
Shuts down an LPSPI instance interrupt mechanism.
Disables the LPSPI module, gates its clock, and changes the LPSPI slave driver state to NonInit for the LPSPI slave module which is initialized with interrupt mechanism. After de-initialization, the user can re-initialize the LPSPI slave module with other mechanisms.
instance | The instance number of the LPSPI peripheral. |
Definition at line 172 of file lpspi_slave_driver.c.
status_t LPSPI_DRV_SlaveGetTransferStatus | ( | uint32_t | instance, |
uint32_t * | bytesRemained | ||
) |
Returns whether the previous transfer is finished.
When performing an a-sync transfer, the user can call this function to ascertain the state of the current transfer: in progress (or busy) or complete (success). In addition, if the transfer is still in progress, the user can get the number of words that have been transferred up to now.
instance | The instance number of the LPSPI peripheral. |
bytesRemained | Pointer to value that is filled in with the number of frames that have been sent in the active transfer. A frame is defined as the number of bits per frame. |
Definition at line 466 of file lpspi_slave_driver.c.
status_t LPSPI_DRV_SlaveInit | ( | uint32_t | instance, |
lpspi_state_t * | lpspiState, | ||
const lpspi_slave_config_t * | slaveConfig | ||
) |
Initializes a LPSPI instance for a slave mode operation, using interrupt mechanism.
This function un-gates the clock to the LPSPI module, initializes the LPSPI for slave mode. After it is initialized, the LPSPI module is configured in slave mode and the user can start transmitting and receiving data by calling send, receive, and transfer functions. This function indicates LPSPI slave uses an interrupt mechanism.
instance | The instance number of the LPSPI peripheral. |
lpspiState | The pointer to the LPSPI slave driver state structure. |
slaveConfig | The configuration structure lpspi_slave_user_config_t which configures the data bus format. |
Definition at line 103 of file lpspi_slave_driver.c.
void LPSPI_DRV_SlaveIRQHandler | ( | uint32_t | instance | ) |
Interrupt handler for LPSPI slave mode. This handler uses the buffers stored in the lpspi_master_state_t structs to transfer data.
instance | The instance number of the LPSPI peripheral. |
Definition at line 373 of file lpspi_slave_driver.c.
status_t LPSPI_DRV_SlaveTransfer | ( | uint32_t | instance, |
const uint8_t * | sendBuffer, | ||
uint8_t * | receiveBuffer, | ||
uint16_t | transferByteCount | ||
) |
Starts the transfer data on LPSPI bus using an interrupt and a non-blocking call.
instance | The instance number of LPSPI peripheral |
sendBuffer | The pointer to data that user wants to transmit. |
receiveBuffer | The pointer to data that user wants to store received data. |
transferByteCount | The number of bytes to send and receive. |
Definition at line 238 of file lpspi_slave_driver.c.
status_t LPSPI_DRV_SlaveTransferBlocking | ( | uint32_t | instance, |
const uint8_t * | sendBuffer, | ||
uint8_t * | receiveBuffer, | ||
uint16_t | transferByteCount, | ||
uint32_t | timeout | ||
) |
Transfers data on LPSPI bus using interrupt and a blocking call.
This function checks the driver status and mechanism, and transmits/receives data through the LPSPI bus. If the sendBuffer is NULL, the transmit process is ignored. If the receiveBuffer is NULL, the receive process is ignored. If both the receiveBuffer and the sendBuffer are available, the transmit and the receive progress is processed. If only the receiveBuffer is available, the receive is processed. Otherwise, the transmit is processed. This function only returns when the processes are completed. This function uses an interrupt mechanism.
instance | The instance number of LPSPI peripheral |
sendBuffer | The pointer to data that user wants to transmit. |
receiveBuffer | The pointer to data that user wants to store received data. |
transferByteCount | The number of bytes to send and receive. |
timeout | The maximum number of milliseconds that function waits before timed out reached. |
Definition at line 200 of file lpspi_slave_driver.c.
LPSPI_Type* g_lpspiBase[LPSPI_INSTANCE_COUNT] |
Table of base pointers for SPI instances.
Definition at line 77 of file lpspi_shared_function.c.
IRQn_Type g_lpspiIrqId[LPSPI_INSTANCE_COUNT] |
Table to save LPSPI IRQ enumeration numbers defined in the CMSIS header file.
Definition at line 80 of file lpspi_shared_function.c.
lpspi_state_t* g_lpspiStatePtr[LPSPI_INSTANCE_COUNT] |
Definition at line 83 of file lpspi_shared_function.c.