rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Typedefs | Enumerations | Functions | Variables
fsl_lpspi.c File Reference

Typedefs

typedef void(* lpspi_master_isr_t) (LPSPI_Type *base, lpspi_master_handle_t *handle)
 Typedef for master interrupt handler.
 
typedef void(* lpspi_slave_isr_t) (LPSPI_Type *base, lpspi_slave_handle_t *handle)
 Typedef for slave interrupt handler.
 

Enumerations

enum  _lpspi_default_watermarks { kLpspiDefaultTxWatermark = 0 , kLpspiDefaultRxWatermark = 0 }
 Default watermark values. More...
 

Functions

uint32_t LPSPI_GetInstance (LPSPI_Type *base)
 Get instance number for LPSPI module.
 
static void LPSPI_SetOnePcsPolarity (LPSPI_Type *base, lpspi_which_pcs_t pcs, lpspi_pcs_polarity_config_t activeLowOrHigh)
 Configures the LPSPI peripheral chip select polarity.
 
static uint32_t LPSPI_CombineWriteData (uint8_t *txData, uint32_t bytesEachWrite, bool isByteSwap)
 Combine the write data for 1 byte to 4 bytes. This is not a public API.
 
static void LPSPI_SeparateReadData (uint8_t *rxData, uint32_t readData, uint32_t bytesEachRead, bool isByteSwap)
 Separate the read data for 1 byte to 4 bytes. This is not a public API.
 
static void LPSPI_MasterTransferFillUpTxFifo (LPSPI_Type *base, lpspi_master_handle_t *handle)
 Master fill up the TX FIFO with data. This is not a public API.
 
static void LPSPI_MasterTransferComplete (LPSPI_Type *base, lpspi_master_handle_t *handle)
 Master finish up a transfer. It would call back if there is callback function and set the state to idle. This is not a public API.
 
static void LPSPI_SlaveTransferFillUpTxFifo (LPSPI_Type *base, lpspi_slave_handle_t *handle)
 Slave fill up the TX FIFO with data. This is not a public API.
 
static void LPSPI_SlaveTransferComplete (LPSPI_Type *base, lpspi_slave_handle_t *handle)
 Slave finish up a transfer. It would call back if there is callback function and set the state to idle. This is not a public API.
 
static void LPSPI_CommonIRQHandler (LPSPI_Type *base, void *param)
 LPSPI common interrupt handler.
 
void LPSPI_SetDummyData (LPSPI_Type *base, uint8_t dummyData)
 Set up the dummy data.
 
void LPSPI_MasterInit (LPSPI_Type *base, const lpspi_master_config_t *masterConfig, uint32_t srcClock_Hz)
 Initializes the LPSPI master.
 
void LPSPI_MasterGetDefaultConfig (lpspi_master_config_t *masterConfig)
 Sets the lpspi_master_config_t structure to default values.
 
void LPSPI_SlaveInit (LPSPI_Type *base, const lpspi_slave_config_t *slaveConfig)
 LPSPI slave configuration.
 
void LPSPI_SlaveGetDefaultConfig (lpspi_slave_config_t *slaveConfig)
 Sets the lpspi_slave_config_t structure to default values.
 
void LPSPI_Reset (LPSPI_Type *base)
 Restores the LPSPI peripheral to reset state. Note that this function sets all registers to reset state. As a result, the LPSPI module can't work after calling this API.
 
void LPSPI_Deinit (LPSPI_Type *base)
 De-initializes the LPSPI peripheral. Call this API to disable the LPSPI clock.
 
uint32_t LPSPI_MasterSetBaudRate (LPSPI_Type *base, uint32_t baudRate_Bps, uint32_t srcClock_Hz, uint32_t *tcrPrescaleValue)
 Sets the LPSPI baud rate in bits per second.
 
void LPSPI_MasterSetDelayScaler (LPSPI_Type *base, uint32_t scaler, lpspi_delay_type_t whichDelay)
 Manually configures a specific LPSPI delay parameter (module must be disabled to change the delay values).
 
uint32_t LPSPI_MasterSetDelayTimes (LPSPI_Type *base, uint32_t delayTimeInNanoSec, lpspi_delay_type_t whichDelay, uint32_t srcClock_Hz)
 Calculates the delay based on the desired delay input in nanoseconds (module must be disabled to change the delay values).
 
void LPSPI_MasterTransferCreateHandle (LPSPI_Type *base, lpspi_master_handle_t *handle, lpspi_master_transfer_callback_t callback, void *userData)
 Initializes the LPSPI master handle.
 
bool LPSPI_CheckTransferArgument (lpspi_transfer_t *transfer, uint32_t bitsPerFrame, uint32_t bytesPerFrame)
 Check the argument for transfer .
 
status_t LPSPI_MasterTransferBlocking (LPSPI_Type *base, lpspi_transfer_t *transfer)
 LPSPI master transfer data using a polling method.
 
status_t LPSPI_MasterTransferNonBlocking (LPSPI_Type *base, lpspi_master_handle_t *handle, lpspi_transfer_t *transfer)
 LPSPI master transfer data using an interrupt method.
 
status_t LPSPI_MasterTransferGetCount (LPSPI_Type *base, lpspi_master_handle_t *handle, size_t *count)
 Gets the master transfer remaining bytes.
 
void LPSPI_MasterTransferAbort (LPSPI_Type *base, lpspi_master_handle_t *handle)
 LPSPI master abort transfer which uses an interrupt method.
 
void LPSPI_MasterTransferHandleIRQ (LPSPI_Type *base, lpspi_master_handle_t *handle)
 LPSPI Master IRQ handler function.
 
void LPSPI_SlaveTransferCreateHandle (LPSPI_Type *base, lpspi_slave_handle_t *handle, lpspi_slave_transfer_callback_t callback, void *userData)
 Initializes the LPSPI slave handle.
 
status_t LPSPI_SlaveTransferNonBlocking (LPSPI_Type *base, lpspi_slave_handle_t *handle, lpspi_transfer_t *transfer)
 LPSPI slave transfer data using an interrupt method.
 
status_t LPSPI_SlaveTransferGetCount (LPSPI_Type *base, lpspi_slave_handle_t *handle, size_t *count)
 Gets the slave transfer remaining bytes.
 
void LPSPI_SlaveTransferAbort (LPSPI_Type *base, lpspi_slave_handle_t *handle)
 LPSPI slave aborts a transfer which uses an interrupt method.
 
void LPSPI_SlaveTransferHandleIRQ (LPSPI_Type *base, lpspi_slave_handle_t *handle)
 LPSPI Slave IRQ handler function.
 
void LPSPI0_DriverIRQHandler (void)
 
void LPSPI1_DriverIRQHandler (void)
 
void LPSPI2_DriverIRQHandler (void)
 
void LPSPI3_DriverIRQHandler (void)
 
void LPSPI4_DriverIRQHandler (void)
 
void LPSPI5_DriverIRQHandler (void)
 
void DMA_SPI0_INT_DriverIRQHandler (void)
 
void DMA_SPI1_INT_DriverIRQHandler (void)
 
void DMA_SPI2_INT_DriverIRQHandler (void)
 
void DMA_SPI3_INT_DriverIRQHandler (void)
 
void ADMA_SPI0_INT_DriverIRQHandler (void)
 
void ADMA_SPI1_INT_DriverIRQHandler (void)
 
void ADMA_SPI2_INT_DriverIRQHandler (void)
 
void ADMA_SPI3_INT_DriverIRQHandler (void)
 

Variables

static const uint8_t s_baudratePrescaler [] = {1, 2, 4, 8, 16, 32, 64, 128}
 
static LPSPI_Type *const s_lpspiBases [] = LPSPI_BASE_PTRS
 Pointers to lpspi bases for each instance.
 
static const IRQn_Type s_lpspiIRQ [] = LPSPI_IRQS
 Pointers to lpspi IRQ number for each instance.
 
static const clock_ip_name_t s_lpspiClocks [] = LPSPI_CLOCKS
 Pointers to lpspi clocks for each instance.
 
static const clock_ip_name_t s_LpspiPeriphClocks [] = LPSPI_PERIPH_CLOCKS
 
static void * s_lpspiHandle [ARRAY_SIZE(s_lpspiBases)] = {NULL}
 Pointers to lpspi handles for each instance.
 
static lpspi_master_isr_t s_lpspiMasterIsr
 Pointer to master IRQ handler for each instance.
 
static lpspi_slave_isr_t s_lpspiSlaveIsr
 Pointer to slave IRQ handler for each instance.
 
volatile uint8_t g_lpspiDummyData [ARRAY_SIZE(s_lpspiBases)] = {0}
 Global variable for dummy data value setting.
 

Typedef Documentation

◆ lpspi_master_isr_t

typedef void(* lpspi_master_isr_t) (LPSPI_Type *base, lpspi_master_handle_t *handle)

Typedef for master interrupt handler.

Definition at line 33 of file fsl_lpspi.c.

◆ lpspi_slave_isr_t

typedef void(* lpspi_slave_isr_t) (LPSPI_Type *base, lpspi_slave_handle_t *handle)

Typedef for slave interrupt handler.

Definition at line 36 of file fsl_lpspi.c.

Enumeration Type Documentation

◆ _lpspi_default_watermarks

Default watermark values.

The default watermarks are set to zero.

Enumerator
kLpspiDefaultTxWatermark 
kLpspiDefaultRxWatermark 

Definition at line 26 of file fsl_lpspi.c.

27{
30};
@ kLpspiDefaultTxWatermark
Definition fsl_lpspi.c:28
@ kLpspiDefaultRxWatermark
Definition fsl_lpspi.c:29

Function Documentation

◆ ADMA_SPI0_INT_DriverIRQHandler()

void ADMA_SPI0_INT_DriverIRQHandler ( void  )

Definition at line 2073 of file fsl_lpspi.c.

2074{
2075 assert(s_lpspiHandle[LPSPI_GetInstance(ADMA__LPSPI0)]);
2076 LPSPI_CommonIRQHandler(ADMA__LPSPI0, s_lpspiHandle[LPSPI_GetInstance(ADMA__LPSPI0)]);
2077}
static void * s_lpspiHandle[ARRAY_SIZE(s_lpspiBases)]
Pointers to lpspi handles for each instance.
Definition fsl_lpspi.c:135
uint32_t LPSPI_GetInstance(LPSPI_Type *base)
Get instance number for LPSPI module.
Definition fsl_lpspi.c:146
static void LPSPI_CommonIRQHandler(LPSPI_Type *base, void *param)
LPSPI common interrupt handler.
Definition fsl_lpspi.c:1976
Here is the call graph for this function:

◆ ADMA_SPI1_INT_DriverIRQHandler()

void ADMA_SPI1_INT_DriverIRQHandler ( void  )

Definition at line 2081 of file fsl_lpspi.c.

2082{
2083 assert(s_lpspiHandle[LPSPI_GetInstance(ADMA__LPSPI1)]);
2084 LPSPI_CommonIRQHandler(ADMA__LPSPI1, s_lpspiHandle[LPSPI_GetInstance(ADMA__LPSPI1)]);
2085}
Here is the call graph for this function:

◆ ADMA_SPI2_INT_DriverIRQHandler()

void ADMA_SPI2_INT_DriverIRQHandler ( void  )

Definition at line 2088 of file fsl_lpspi.c.

2089{
2090 assert(s_lpspiHandle[LPSPI_GetInstance(ADMA__LPSPI2)]);
2091 LPSPI_CommonIRQHandler(ADMA__LPSPI2, s_lpspiHandle[LPSPI_GetInstance(ADMA__LPSPI2)]);
2092}
Here is the call graph for this function:

◆ ADMA_SPI3_INT_DriverIRQHandler()

void ADMA_SPI3_INT_DriverIRQHandler ( void  )

Definition at line 2096 of file fsl_lpspi.c.

2097{
2098 assert(s_lpspiHandle[LPSPI_GetInstance(ADMA__LPSPI3)]);
2099 LPSPI_CommonIRQHandler(ADMA__LPSPI3, s_lpspiHandle[LPSPI_GetInstance(ADMA__LPSPI3)]);
2100}
Here is the call graph for this function:

◆ DMA_SPI0_INT_DriverIRQHandler()

void DMA_SPI0_INT_DriverIRQHandler ( void  )

Definition at line 2042 of file fsl_lpspi.c.

2043{
2044 assert(s_lpspiHandle[LPSPI_GetInstance(DMA__LPSPI0)]);
2045 LPSPI_CommonIRQHandler(DMA__LPSPI0, s_lpspiHandle[LPSPI_GetInstance(DMA__LPSPI0)]);
2046}
Here is the call graph for this function:

◆ DMA_SPI1_INT_DriverIRQHandler()

void DMA_SPI1_INT_DriverIRQHandler ( void  )

Definition at line 2050 of file fsl_lpspi.c.

2051{
2052 assert(s_lpspiHandle[LPSPI_GetInstance(DMA__LPSPI1)]);
2053 LPSPI_CommonIRQHandler(DMA__LPSPI1, s_lpspiHandle[LPSPI_GetInstance(DMA__LPSPI1)]);
2054}
Here is the call graph for this function:

◆ DMA_SPI2_INT_DriverIRQHandler()

void DMA_SPI2_INT_DriverIRQHandler ( void  )

Definition at line 2057 of file fsl_lpspi.c.

2058{
2059 assert(s_lpspiHandle[LPSPI_GetInstance(DMA__LPSPI2)]);
2060 LPSPI_CommonIRQHandler(DMA__LPSPI2, s_lpspiHandle[LPSPI_GetInstance(DMA__LPSPI2)]);
2061}
Here is the call graph for this function:

◆ DMA_SPI3_INT_DriverIRQHandler()

void DMA_SPI3_INT_DriverIRQHandler ( void  )

Definition at line 2065 of file fsl_lpspi.c.

2066{
2067 assert(s_lpspiHandle[LPSPI_GetInstance(DMA__LPSPI3)]);
2068 LPSPI_CommonIRQHandler(DMA__LPSPI3, s_lpspiHandle[LPSPI_GetInstance(DMA__LPSPI3)]);
2069}
Here is the call graph for this function:

◆ LPSPI0_DriverIRQHandler()

void LPSPI0_DriverIRQHandler ( void  )

Definition at line 1994 of file fsl_lpspi.c.

1995{
1996 assert(s_lpspiHandle[0]);
1998}
Here is the call graph for this function:

◆ LPSPI1_DriverIRQHandler()

void LPSPI1_DriverIRQHandler ( void  )

Definition at line 2002 of file fsl_lpspi.c.

2003{
2004 assert(s_lpspiHandle[1]);
2006}
Here is the call graph for this function:

◆ LPSPI2_DriverIRQHandler()

void LPSPI2_DriverIRQHandler ( void  )

Definition at line 2010 of file fsl_lpspi.c.

2011{
2012 assert(s_lpspiHandle[2]);
2014}
Here is the call graph for this function:

◆ LPSPI3_DriverIRQHandler()

void LPSPI3_DriverIRQHandler ( void  )

Definition at line 2018 of file fsl_lpspi.c.

2019{
2020 assert(s_lpspiHandle[3]);
2022}
Here is the call graph for this function:

◆ LPSPI4_DriverIRQHandler()

void LPSPI4_DriverIRQHandler ( void  )

Definition at line 2026 of file fsl_lpspi.c.

2027{
2028 assert(s_lpspiHandle[4]);
2030}
Here is the call graph for this function:

◆ LPSPI5_DriverIRQHandler()

void LPSPI5_DriverIRQHandler ( void  )

Definition at line 2034 of file fsl_lpspi.c.

2035{
2036 assert(s_lpspiHandle[5]);
2038}
Here is the call graph for this function:

◆ LPSPI_CombineWriteData()

static uint32_t LPSPI_CombineWriteData ( uint8_t *  txData,
uint32_t  bytesEachWrite,
bool  isByteSwap 
)
static

Combine the write data for 1 byte to 4 bytes. This is not a public API.

Definition at line 1812 of file fsl_lpspi.c.

1813{
1814 assert(txData);
1815
1816 uint32_t wordToSend = 0;
1817
1818 switch (bytesEachWrite)
1819 {
1820 case 1:
1821 wordToSend = *txData;
1822 ++txData;
1823 break;
1824
1825 case 2:
1826 if (!isByteSwap)
1827 {
1828 wordToSend = *txData;
1829 ++txData;
1830 wordToSend |= (unsigned)(*txData) << 8U;
1831 ++txData;
1832 }
1833 else
1834 {
1835 wordToSend = (unsigned)(*txData) << 8U;
1836 ++txData;
1837 wordToSend |= *txData;
1838 ++txData;
1839 }
1840
1841 break;
1842
1843 case 3:
1844 if (!isByteSwap)
1845 {
1846 wordToSend = *txData;
1847 ++txData;
1848 wordToSend |= (unsigned)(*txData) << 8U;
1849 ++txData;
1850 wordToSend |= (unsigned)(*txData) << 16U;
1851 ++txData;
1852 }
1853 else
1854 {
1855 wordToSend = (unsigned)(*txData) << 16U;
1856 ++txData;
1857 wordToSend |= (unsigned)(*txData) << 8U;
1858 ++txData;
1859 wordToSend |= *txData;
1860 ++txData;
1861 }
1862 break;
1863
1864 case 4:
1865 if (!isByteSwap)
1866 {
1867 wordToSend = *txData;
1868 ++txData;
1869 wordToSend |= (unsigned)(*txData) << 8U;
1870 ++txData;
1871 wordToSend |= (unsigned)(*txData) << 16U;
1872 ++txData;
1873 wordToSend |= (unsigned)(*txData) << 24U;
1874 ++txData;
1875 }
1876 else
1877 {
1878 wordToSend = (unsigned)(*txData) << 24U;
1879 ++txData;
1880 wordToSend |= (unsigned)(*txData) << 16U;
1881 ++txData;
1882 wordToSend |= (unsigned)(*txData) << 8U;
1883 ++txData;
1884 wordToSend |= *txData;
1885 ++txData;
1886 }
1887 break;
1888
1889 default:
1890 assert(false);
1891 break;
1892 }
1893 return wordToSend;
1894}

Referenced by LPSPI_MasterTransferBlocking(), LPSPI_MasterTransferFillUpTxFifo(), LPSPI_SlaveTransferFillUpTxFifo(), and LPSPI_SlaveTransferHandleIRQ().

Here is the caller graph for this function:

◆ LPSPI_CommonIRQHandler()

static void LPSPI_CommonIRQHandler ( LPSPI_Type *  base,
void *  param 
)
static

LPSPI common interrupt handler.

Parameters
handlepointer to s_lpspiHandle which stores the transfer state.

Definition at line 1976 of file fsl_lpspi.c.

1977{
1978 if (LPSPI_IsMaster(base))
1979 {
1981 }
1982 else
1983 {
1985 }
1986/* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
1987 exception return operation might vector to incorrect interrupt */
1988#if defined __CORTEX_M && (__CORTEX_M == 4U)
1989 __DSB();
1990#endif
1991}
static lpspi_slave_isr_t s_lpspiSlaveIsr
Pointer to slave IRQ handler for each instance.
Definition fsl_lpspi.c:140
static lpspi_master_isr_t s_lpspiMasterIsr
Pointer to master IRQ handler for each instance.
Definition fsl_lpspi.c:138
static bool LPSPI_IsMaster(LPSPI_Type *base)
Returns whether the LPSPI module is in master mode.
Definition fsl_lpspi.h:731
LPSPI master transfer handle structure used for transactional API.
Definition fsl_lpspi.h:350
LPSPI slave transfer handle structure used for transactional API.
Definition fsl_lpspi.h:383
static tstrWifiInitParam param

Referenced by ADMA_SPI0_INT_DriverIRQHandler(), ADMA_SPI1_INT_DriverIRQHandler(), ADMA_SPI2_INT_DriverIRQHandler(), ADMA_SPI3_INT_DriverIRQHandler(), DMA_SPI0_INT_DriverIRQHandler(), DMA_SPI1_INT_DriverIRQHandler(), DMA_SPI2_INT_DriverIRQHandler(), DMA_SPI3_INT_DriverIRQHandler(), LPSPI0_DriverIRQHandler(), LPSPI1_DriverIRQHandler(), LPSPI2_DriverIRQHandler(), LPSPI3_DriverIRQHandler(), LPSPI4_DriverIRQHandler(), and LPSPI5_DriverIRQHandler().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ LPSPI_GetInstance()

static uint32_t LPSPI_GetInstance ( LPSPI_Type *  base)

Get instance number for LPSPI module.

Parameters
baseLPSPI peripheral base address.
Returns
Return the value of LPSPI instance.

Definition at line 146 of file fsl_lpspi.c.

147{
148 uint8_t instance = 0;
149
150 /* Find the instance index from base address mappings. */
151 for (instance = 0; instance < ARRAY_SIZE(s_lpspiBases); instance++)
152 {
153 if (s_lpspiBases[instance] == base)
154 {
155 break;
156 }
157 }
158
159 assert(instance < ARRAY_SIZE(s_lpspiBases));
160
161 return instance;
162}
static BenchController instance
static LPSPI_Type *const s_lpspiBases[]
Pointers to lpspi bases for each instance.
Definition fsl_lpspi.c:119

Referenced by ADMA_SPI0_INT_DriverIRQHandler(), ADMA_SPI1_INT_DriverIRQHandler(), ADMA_SPI2_INT_DriverIRQHandler(), ADMA_SPI3_INT_DriverIRQHandler(), DMA_SPI0_INT_DriverIRQHandler(), DMA_SPI1_INT_DriverIRQHandler(), DMA_SPI2_INT_DriverIRQHandler(), DMA_SPI3_INT_DriverIRQHandler(), LPSPI_Deinit(), LPSPI_MasterInit(), LPSPI_MasterTransferBlocking(), LPSPI_MasterTransferCreateHandle(), LPSPI_MasterTransferNonBlocking(), LPSPI_SetDummyData(), LPSPI_SlaveInit(), LPSPI_SlaveTransferCreateHandle(), and LPSPI_SlaveTransferNonBlocking().

Here is the caller graph for this function:

◆ LPSPI_MasterTransferComplete()

static void LPSPI_MasterTransferComplete ( LPSPI_Type *  base,
lpspi_master_handle_t handle 
)
static

Master finish up a transfer. It would call back if there is callback function and set the state to idle. This is not a public API.

Definition at line 1170 of file fsl_lpspi.c.

1171{
1172 assert(handle);
1173
1174 /* Disable interrupt requests*/
1176
1177 handle->state = kLPSPI_Idle;
1178
1179 if (handle->callback)
1180 {
1181 handle->callback(base, handle, kStatus_Success, handle->userData);
1182 }
1183}
@ kStatus_Success
Definition fsl_common.h:159
static void LPSPI_DisableInterrupts(LPSPI_Type *base, uint32_t mask)
Disables the LPSPI interrupts.
Definition fsl_lpspi.h:617
@ kLPSPI_Idle
Definition fsl_lpspi.h:249
@ kLPSPI_AllInterruptEnable
Definition fsl_lpspi.h:73
volatile uint8_t state
Definition fsl_lpspi.h:375
lpspi_master_transfer_callback_t callback
Definition fsl_lpspi.h:377

Referenced by LPSPI_MasterTransferHandleIRQ().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ LPSPI_MasterTransferFillUpTxFifo()

static void LPSPI_MasterTransferFillUpTxFifo ( LPSPI_Type *  base,
lpspi_master_handle_t handle 
)
static

Master fill up the TX FIFO with data. This is not a public API.

Definition at line 1110 of file fsl_lpspi.c.

1111{
1112 assert(handle);
1113
1114 uint32_t wordToSend = 0;
1115
1116 /* Make sure the difference in remaining TX and RX byte counts does not exceed FIFO depth
1117 * and that the number of TX FIFO entries does not exceed the FIFO depth.
1118 * But no need to make the protection if there is no rxData.
1119 */
1120 while ((LPSPI_GetTxFifoCount(base) < (handle->fifoSize)) &&
1121 (((handle->readRegRemainingTimes - handle->writeRegRemainingTimes) < handle->fifoSize) ||
1122 (handle->rxData == NULL)))
1123 {
1124 if (handle->txRemainingByteCount < handle->bytesEachWrite)
1125 {
1126 handle->bytesEachWrite = handle->txRemainingByteCount;
1127 }
1128
1129 if (handle->txData)
1130 {
1131 wordToSend = LPSPI_CombineWriteData(handle->txData, handle->bytesEachWrite, handle->isByteSwap);
1132 handle->txData += handle->bytesEachWrite;
1133 }
1134 else
1135 {
1136 wordToSend = handle->txBuffIfNull;
1137 }
1138
1139 /*Write the word to TX register*/
1140 LPSPI_WriteData(base, wordToSend);
1141
1142 /*Decrease the write TX register times.*/
1143 --handle->writeRegRemainingTimes;
1144
1145 /*Decrease the remaining TX byte count.*/
1146 handle->txRemainingByteCount -= handle->bytesEachWrite;
1147
1148 if (handle->txRemainingByteCount == 0)
1149 {
1150 /* If PCS is continuous, update TCR to de-assert PCS */
1151 if (handle->isPcsContinuous)
1152 {
1153 /* Only write to the TCR if the FIFO has room */
1154 if ((LPSPI_GetTxFifoCount(base) < (handle->fifoSize)))
1155 {
1156 base->TCR = (base->TCR & ~(LPSPI_TCR_CONTC_MASK));
1157 handle->writeTcrInIsr = false;
1158 }
1159 /* Else, set a global flag to tell the ISR to do write to the TCR */
1160 else
1161 {
1162 handle->writeTcrInIsr = true;
1163 }
1164 }
1165 break;
1166 }
1167 }
1168}
static uint32_t LPSPI_CombineWriteData(uint8_t *txData, uint32_t bytesEachWrite, bool isByteSwap)
Combine the write data for 1 byte to 4 bytes. This is not a public API.
Definition fsl_lpspi.c:1812
static uint32_t LPSPI_GetTxFifoCount(LPSPI_Type *base)
Gets the LPSPI Tx FIFO count.
Definition fsl_lpspi.h:547
static void LPSPI_WriteData(LPSPI_Type *base, uint32_t data)
Writes data into the transmit data buffer.
Definition fsl_lpspi.h:904
uint8_t *volatile txData
Definition fsl_lpspi.h:363
volatile uint8_t fifoSize
Definition fsl_lpspi.h:356
uint8_t *volatile rxData
Definition fsl_lpspi.h:364
volatile uint32_t writeRegRemainingTimes
Definition fsl_lpspi.h:368
volatile uint32_t readRegRemainingTimes
Definition fsl_lpspi.h:369
volatile size_t txRemainingByteCount
Definition fsl_lpspi.h:365
volatile bool writeTcrInIsr
Definition fsl_lpspi.h:352
volatile uint8_t bytesEachWrite
Definition fsl_lpspi.h:360
volatile bool isByteSwap
Definition fsl_lpspi.h:354
volatile bool isPcsContinuous
Definition fsl_lpspi.h:351

Referenced by LPSPI_MasterTransferHandleIRQ(), and LPSPI_MasterTransferNonBlocking().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ LPSPI_SeparateReadData()

static void LPSPI_SeparateReadData ( uint8_t *  rxData,
uint32_t  readData,
uint32_t  bytesEachRead,
bool  isByteSwap 
)
static

Separate the read data for 1 byte to 4 bytes. This is not a public API.

Definition at line 1896 of file fsl_lpspi.c.

1897{
1898 assert(rxData);
1899
1900 switch (bytesEachRead)
1901 {
1902 case 1:
1903 *rxData = readData;
1904 ++rxData;
1905 break;
1906
1907 case 2:
1908 if (!isByteSwap)
1909 {
1910 *rxData = readData;
1911 ++rxData;
1912 *rxData = readData >> 8;
1913 ++rxData;
1914 }
1915 else
1916 {
1917 *rxData = readData >> 8;
1918 ++rxData;
1919 *rxData = readData;
1920 ++rxData;
1921 }
1922 break;
1923
1924 case 3:
1925 if (!isByteSwap)
1926 {
1927 *rxData = readData;
1928 ++rxData;
1929 *rxData = readData >> 8;
1930 ++rxData;
1931 *rxData = readData >> 16;
1932 ++rxData;
1933 }
1934 else
1935 {
1936 *rxData = readData >> 16;
1937 ++rxData;
1938 *rxData = readData >> 8;
1939 ++rxData;
1940 *rxData = readData;
1941 ++rxData;
1942 }
1943 break;
1944
1945 case 4:
1946 if (!isByteSwap)
1947 {
1948 *rxData = readData;
1949 ++rxData;
1950 *rxData = readData >> 8;
1951 ++rxData;
1952 *rxData = readData >> 16;
1953 ++rxData;
1954 *rxData = readData >> 24;
1955 ++rxData;
1956 }
1957 else
1958 {
1959 *rxData = readData >> 24;
1960 ++rxData;
1961 *rxData = readData >> 16;
1962 ++rxData;
1963 *rxData = readData >> 8;
1964 ++rxData;
1965 *rxData = readData;
1966 ++rxData;
1967 }
1968 break;
1969
1970 default:
1971 assert(false);
1972 break;
1973 }
1974}

Referenced by LPSPI_MasterTransferBlocking(), LPSPI_MasterTransferHandleIRQ(), and LPSPI_SlaveTransferHandleIRQ().

Here is the caller graph for this function:

◆ LPSPI_SetOnePcsPolarity()

static void LPSPI_SetOnePcsPolarity ( LPSPI_Type *  base,
lpspi_which_pcs_t  pcs,
lpspi_pcs_polarity_config_t  activeLowOrHigh 
)
static

Configures the LPSPI peripheral chip select polarity.

This function takes in the desired peripheral chip select (Pcs) and it's corresponding desired polarity and configures the Pcs signal to operate with the desired characteristic.

Parameters
baseLPSPI peripheral address.
pcsThe particular peripheral chip select (parameter value is of type lpspi_which_pcs_t) for which we wish to apply the active high or active low characteristic.
activeLowOrHighThe setting for either "active high, inactive low (0)" or "active low, inactive high(1)" of type lpspi_pcs_polarity_config_t.

Definition at line 385 of file fsl_lpspi.c.

388{
389 uint32_t cfgr1Value = 0;
390 /* Clear the PCS polarity bit */
391 cfgr1Value = base->CFGR1 & ~(1U << (LPSPI_CFGR1_PCSPOL_SHIFT + pcs));
392
393 /* Configure the PCS polarity bit according to the activeLowOrHigh setting */
394 base->CFGR1 = cfgr1Value | ((uint32_t)activeLowOrHigh << (LPSPI_CFGR1_PCSPOL_SHIFT + pcs));
395}

Referenced by LPSPI_MasterInit(), and LPSPI_SlaveInit().

Here is the caller graph for this function:

◆ LPSPI_SlaveTransferComplete()

static void LPSPI_SlaveTransferComplete ( LPSPI_Type *  base,
lpspi_slave_handle_t handle 
)
static

Slave finish up a transfer. It would call back if there is callback function and set the state to idle. This is not a public API.

Definition at line 1593 of file fsl_lpspi.c.

1594{
1595 assert(handle);
1596
1597 status_t status = 0;
1598
1599 /* Disable interrupt requests*/
1601
1602 if (handle->state == kLPSPI_Error)
1603 {
1604 status = kStatus_LPSPI_Error;
1605 }
1606 else
1607 {
1608 status = kStatus_Success;
1609 }
1610
1611 handle->state = kLPSPI_Idle;
1612
1613 if (handle->callback)
1614 {
1615 handle->callback(base, handle, status, handle->userData);
1616 }
1617}
int32_t status_t
Type used for all status and error return values.
Definition fsl_common.h:169
@ kLPSPI_Error
Definition fsl_lpspi.h:251
@ kStatus_LPSPI_Error
Definition fsl_lpspi.h:40
volatile uint8_t state
Definition fsl_lpspi.h:404
lpspi_slave_transfer_callback_t callback
Definition fsl_lpspi.h:408

Referenced by LPSPI_SlaveTransferHandleIRQ().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ LPSPI_SlaveTransferFillUpTxFifo()

static void LPSPI_SlaveTransferFillUpTxFifo ( LPSPI_Type *  base,
lpspi_slave_handle_t handle 
)
static

Slave fill up the TX FIFO with data. This is not a public API.

Definition at line 1564 of file fsl_lpspi.c.

1565{
1566 assert(handle);
1567
1568 uint32_t wordToSend = 0;
1569
1570 while (LPSPI_GetTxFifoCount(base) < (handle->fifoSize))
1571 {
1572 if (handle->txRemainingByteCount < handle->bytesEachWrite)
1573 {
1574 handle->bytesEachWrite = handle->txRemainingByteCount;
1575 }
1576
1577 wordToSend = LPSPI_CombineWriteData(handle->txData, handle->bytesEachWrite, handle->isByteSwap);
1578 handle->txData += handle->bytesEachWrite;
1579
1580 /*Decrease the remaining TX byte count.*/
1581 handle->txRemainingByteCount -= handle->bytesEachWrite;
1582
1583 /*Write the word to TX register*/
1584 LPSPI_WriteData(base, wordToSend);
1585
1586 if (handle->txRemainingByteCount == 0)
1587 {
1588 break;
1589 }
1590 }
1591}
volatile size_t txRemainingByteCount
Definition fsl_lpspi.h:396
volatile uint8_t fifoSize
Definition fsl_lpspi.h:386
volatile uint8_t bytesEachWrite
Definition fsl_lpspi.h:390
uint8_t *volatile txData
Definition fsl_lpspi.h:393
volatile bool isByteSwap
Definition fsl_lpspi.h:384

Referenced by LPSPI_SlaveTransferHandleIRQ(), and LPSPI_SlaveTransferNonBlocking().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ s_baudratePrescaler

const uint8_t s_baudratePrescaler[] = {1, 2, 4, 8, 16, 32, 64, 128}
static

Definition at line 116 of file fsl_lpspi.c.

116{1, 2, 4, 8, 16, 32, 64, 128};

Referenced by LPSPI_MasterSetBaudRate(), and LPSPI_MasterSetDelayTimes().

◆ s_lpspiBases

LPSPI_Type* const s_lpspiBases[] = LPSPI_BASE_PTRS
static

Pointers to lpspi bases for each instance.

Definition at line 119 of file fsl_lpspi.c.

Referenced by LPSPI_GetInstance().

◆ s_lpspiClocks

const clock_ip_name_t s_lpspiClocks[] = LPSPI_CLOCKS
static

Pointers to lpspi clocks for each instance.

Definition at line 126 of file fsl_lpspi.c.

Referenced by LPSPI_Deinit(), LPSPI_MasterInit(), and LPSPI_SlaveInit().

◆ s_lpspiHandle

void* s_lpspiHandle[ARRAY_SIZE(s_lpspiBases)] = {NULL}
static

◆ s_lpspiIRQ

const IRQn_Type s_lpspiIRQ[] = LPSPI_IRQS
static

Pointers to lpspi IRQ number for each instance.

Definition at line 122 of file fsl_lpspi.c.

Referenced by LPSPI_MasterTransferNonBlocking(), and LPSPI_SlaveTransferNonBlocking().

◆ s_lpspiMasterIsr

lpspi_master_isr_t s_lpspiMasterIsr
static

Pointer to master IRQ handler for each instance.

Definition at line 138 of file fsl_lpspi.c.

Referenced by LPSPI_CommonIRQHandler(), and LPSPI_MasterTransferCreateHandle().

◆ s_LpspiPeriphClocks

const clock_ip_name_t s_LpspiPeriphClocks[] = LPSPI_PERIPH_CLOCKS
static

Definition at line 129 of file fsl_lpspi.c.

Referenced by LPSPI_Deinit(), LPSPI_MasterInit(), and LPSPI_SlaveInit().

◆ s_lpspiSlaveIsr

lpspi_slave_isr_t s_lpspiSlaveIsr
static

Pointer to slave IRQ handler for each instance.

Definition at line 140 of file fsl_lpspi.c.

Referenced by LPSPI_CommonIRQHandler(), and LPSPI_SlaveTransferCreateHandle().

Go to the source code of this file.