编写spi底层驱动程序步骤:
1、Spi_Init() 首先是SPI外设模块相关设置初始化
2、Spi_SetupEB()把相关数据放入相关静态存储区保存
3、Spi_AsyncTransmit()把数据传输出去
void Spi_Init(const Spi_ConfigType* const ConfigPtr)
{
uint32 CoreId = 0;
const Spi_CoreConfigType *CoreConfigPtr = NULL_PTR;
uint8 HwMap = 0;
/*Get Core config pointer*/
CoreId = Mcal_GetCpuIndex();
Spi_kGlobalConfigPtr = ConfigPtr;
CoreConfigPtr = Spi_kGlobalConfigPtr->CoreConfigPtr[CoreId];
/* Initialize all the core run-time variables*/
Spi_lCoreInit(CoreId);
for(HwMap = 0; HwMap < SPI_MAX_HW_UNIT; HwMap++)
{
/*QSPIx kernel is configured*/
/*Is QSPI kernel configured*/
if(Spi_lIsQSPIHwConfigured(HwMap) == (uint8)E_OK)
{
#if defined (SPI_INIT_DEINIT_WRITE_PERIP_ENDINIT_PROTREG)
SPI_INIT_DEINIT_WRITE_PERIP_ENDINIT_PROTREG( \
(uint32*)&SPI_HW_MODULE[HwMap].CLC.U, \
CoreConfigPtr->QSPIHwConfigPtr[HwMap]->ClockSetting);
#endif
/* Initialize the QSPI registers to reset values */
Spi_lQSPIHwResetInit(HwMap);
/* Set-up Chip select */
Spi_lQSPIHwInit(HwMap);
/* Set-up async run-time variables */
#if(SPI_LEVEL_DELIVERED != 0U)
/* QSPIx is asynchronous*/
if(Spi_lIsQSPIHwConfiguredAsync(HwMap) == (uint8)E_OK)
{
Spi_lAsyncInitPtrRuntimeVar(HwMap);
Spi_lResetAsyncQueueVar(HwMap);
Spi_lQSPIHwDMAInit(HwMap);
}
#endif
}
}
/* Check for IB buffer assigned to core,Set-up IB buffer for all the IB channels in Core */
if(Spi_lGetTotalIBChannelsInCore(CoreId) != 0U)
{
Spi_lInitIBBuffer();
}
/* Always set default as polling - Applicable for L2 only */
/* Level delivered is 2*/
#if(SPI_LEVEL_DELIVERED == 2U)
/*Set default asynchronous mode as polling */
Spi_RuntimeCoreVar[CoreId]->AsyncMode = SPI_POLLING_MODE;
#endif
/* Set the driver status to IDLE */
#if((SPI_LEVEL_DELIVERED == 0U) || (SPI_LEVEL_DELIVERED == 2U))
Spi_RuntimeCoreVar[CoreId]->SyncStatus = SPI_IDLE;
#endif
#if(SPI_LEVEL_DELIVERED != 0U)
for(HwMap = 0; HwMap < SPI_MAX_HW_UNIT; HwMap++)
{
/* Is QSPI kernel configured */
if(Spi_lIsQSPIHwConfiguredAsync(HwMap) == (uint8)E_OK)
{
Spi_RuntimeKernelVar[HwMap]->BusStatus = SPI_IDLE;
}
}
#endif
} /* ConfigPtr == NULL */
} /* End of function Spi_Init */