Hello Alice,
I tried importing the newer SPI driver code, namely the fsl_spi.c and fsl_spi.h files into my project which is using the older SDK libraries. There seems to be a lot of file dependencies from SDK versions. I start including files that are required to support fsl_spi.c and things get messy fast. I need to include too many files I don't see this being feasible. If you think this is feasible could you please provide the changes that are required to make this possible? Importing fsl_spi.c from the latest SDK into lpc5410x_xpresso54102_keil_iar_v3.04.000 version of the SDK.
Instead of trying to import the latest version of the SPI driver into my project perhaps we could make the older spi code non-blocking. Is there a way we could modify the older SDK spim_54102.c file to make the spi code non-blocking. Looking at the driver code it seems that the Chip_SPIM_XferHandler in spim_54102.c is blocking in the the while loop.
/* SPI master transfer state change handler */
void Chip_SPIM_XferHandler(LPC_SPI_T *pSPI, SPIM_XFER_T *xfer)
{
uint32_t data;
uint8_t flen;
/* Get length of a receive value */
flen = (pSPI->TXCTRL >> 24) & 0xF;
/* Master asserts slave */
if ((Chip_SPI_GetStatus(pSPI) & SPI_STAT_SSA) != 0) {
Chip_SPI_ClearStatus(pSPI, SPI_STAT_SSA);
xfer->state = SPIM_XFER_STATE_BUSY;
/* SSEL assertion callback */
if (xfer->cbFunc) {
xfer->cbFunc(SPIM_EVT_SSELASSERT, xfer);
}
}
/* Slave de-assertion */
if ((Chip_SPI_GetStatus(pSPI) & SPI_STAT_SSD) != 0) {
Chip_SPI_ClearStatus(pSPI, SPI_STAT_SSD);
xfer->state = SPIM_XFER_STATE_DONE;
/* SSEL assertion callback */
if (xfer->cbFunc) {
xfer->cbFunc(SPIM_EVT_SSELDEASSERT, xfer);
}
}
/* Data received? */
while ((Chip_SPI_GetStatus(pSPI) & SPI_STAT_RXRDY) != 0 && Chip_SPIM_HandlerRx(pSPI, xfer)) {}
/* Transmit data? */
while (((Chip_SPI_GetStatus(pSPI) & SPI_STAT_TXRDY) != 0)) {
int32_t len = xfer->rxCount > xfer->txCount ? xfer->rxCount : xfer->txCount;
if ((xfer->rxCount <= xfer->rxDoneCount) && (xfer->txCount <= xfer->txDoneCount)) {
xfer->state = SPIM_XFER_STATE_DONE;
/* Transfer is done, this will be last data */
Chip_SPIM_ForceEndOfTransfer(pSPI);
return;
}
data = 0;
if (xfer->txCount > xfer->txDoneCount) {
if (flen > {
data = ((uint16_t *) xfer->txBuff)[xfer->txDoneCount];
}
else {
data = ((uint8_t *) xfer->txBuff)[xfer->txDoneCount];
}
}
/* Check for end of transfer and end the transfer if needed */
if ((len == (xfer->txDoneCount + 1)) && (xfer->options & SPIM_XFER_OPTION_EOT)) {
pSPI->TXDATCTL = pSPI->TXCTRL | SPI_TXDATCTL_EOT | data;
}
else {
Chip_SPI_WriteTXData(pSPI, data);
}
xfer->txDoneCount++;
if ((xfer->txCount == xfer->txDoneCount) && xfer->cbFunc) {
xfer->cbFunc(SPIM_EVT_TXDONE, xfer);
}
/* Check if we have a data ready to receive */
if (Chip_SPI_GetStatus(pSPI) & SPI_STAT_RXRDY) {
Chip_SPIM_HandlerRx(pSPI, xfer);
}
}
}
/* Start non-blocking SPI master transfer */
void Chip_SPIM_Xfer(LPC_SPI_T *pSPI, SPIM_XFER_T *xfer)
{
/* Setup SPI master select, data length, EOT/EOF timing, and RX data ignore */
pSPI->TXCTRL =
((xfer->options <<
16) | SPI_TXDATCTL_DEASSERT_ALL | (xfer->rxBuff ? 0 : SPI_TXDATCTL_RXIGNORE)) & ~SPI_TXDATCTL_EOT;
Chip_SPIM_AssertSSEL(pSPI, xfer->sselNum);
/* Clear initial transfer states */
xfer->txDoneCount = xfer->rxDoneCount = 0;
/* Call main handler to start transfer */
Chip_SPIM_XferHandler(pSPI, xfer);
}