/* ** This function will Assert the Chip select line before transmission, will ** enable the Edma events for Tx/Rx of McSPI peripheral, will De-assert the ** Chip select once communication is complete. */ static void McSPITransfer(unsigned short length) { /* Set the word count field with the data length to be transferred.*/ McSPIWordCountSet(SOC_SPI_0_REGS, length); /* Force the SPIEN to low state.*/ McSPICSAssert(SOC_SPI_0_REGS, MCSPI_CH_NUM); /* Enable the Tx/Rx DMA events for McSPI. */ McSPIDMAEnable(SOC_SPI_0_REGS, (MCSPI_DMA_RX_EVENT | MCSPI_DMA_TX_EVENT), MCSPI_CH_NUM); /* Enable the McSPI channel for communication.*/ McSPIChannelEnable(SOC_SPI_0_REGS, MCSPI_CH_NUM); /* Wait for control to return from ISR.*/ while((0 == flagTx) || (flagRx == 0)); flagTx = 0; flagRx = 0; /* Force the SPIEN to high state.*/ McSPICSDeAssert(SOC_SPI_0_REGS, MCSPI_CH_NUM); /* Disable the McSPI channel for communication.*/ McSPIChannelDisable(SOC_SPI_0_REGS, MCSPI_CH_NUM); }
/* ** This function will activate/deactivate CS line and also enable Tx and Rx ** interrupts of McSPI peripheral. */ static void McSPITransfer(void) { p_tx = txBuffer; p_rx = rxBuffer; /* SPIEN line is forced to low state.*/ McSPICSAssert(SOC_SPI_0_REGS, chNum); /* Enable the Tx/Rx interrupts of McSPI.*/ McSPIIntEnable(SOC_SPI_0_REGS, MCSPI_INT_TX_EMPTY(chNum) | MCSPI_INT_RX_FULL(chNum)); /* Enable the McSPI channel for communication.*/ McSPIChannelEnable(SOC_SPI_0_REGS, chNum); /* Wait until control returns back from McSPI ISR.*/ while(flag); flag = 1; /* Force SPIEN line to the inactive state.*/ McSPICSDeAssert(SOC_SPI_0_REGS, chNum); /* Disable the McSPI channel.*/ McSPIChannelDisable(SOC_SPI_0_REGS, chNum); }
/* ** This function will activate/deactivate CS line and also enable Tx and Rx ** interrupts of McSPI peripheral. */ void _mcspi_transfer(Mcspi_t *McspiStruct) { McspiStruct->BuffTmp = McspiStruct->Buff; /* SPIEN line is forced to low state.*/ McSPICSAssert(McspiStruct->BaseAddr, McspiStruct->Channel); /* Enable the Tx/Rx interrupts of McSPI.*/ McSPIIntEnable(McspiStruct->BaseAddr, MCSPI_INT_TX_EMPTY(McspiStruct->Channel) | MCSPI_INT_RX_FULL(McspiStruct->Channel)); /* Enable the McSPI channel for communication.*/ McSPIChannelEnable(McspiStruct->BaseAddr, McspiStruct->Channel); /* Wait until control returns back from McSPI ISR.*/ while(McspiStruct->flag); McspiStruct->flag = 1; /* Force SPIEN line to the inactive state.*/ McSPICSDeAssert(McspiStruct->BaseAddr, McspiStruct->Channel); /* Disable the McSPI channel.*/ McSPIChannelDisable(McspiStruct->BaseAddr, McspiStruct->Channel); }