1.1.7.4.1 DRV_SDSPI_Initialize Function
C
SYS_MODULE_OBJ DRV_SDSPI_Initialize ( const SYS_MODULE_INDEX drvIndex, const SYS_MODULE_INIT * const init )
Summary
Initializes the SD Card driver.
Description
This routine initializes the SD Card driver, making it ready for clients to open and use the driver.
Precondition
None.
Parameters
Param | Description |
---|---|
drvIndex | Index for the driver instance to be initialized |
init | Pointer to a data structure containing any data necessary to initialize the driver. |
Returns
If successful, returns a valid handle to a driver object. Otherwise, it returns SYS_MODULE_OBJ_INVALID.
Example
DRV_SDSPI_INIT drvSDSPI0InitData; SYS_MODULE_OBJ objectHandle; DRV_SDSPI_PLIB_INTERFACE drvSDSPI0PlibAPI = { // SPI PLIB WriteRead function .writeRead = (DRV_SDSPI_WRITEREAD)SPI0_WriteRead, // SPI PLIB Write function .write = (DRV_SDSPI_WRITE)SPI0_Write, // SPI PLIB Read function .read = (DRV_SDSPI_READ)SPI0_Read, // SPI PLIB Transfer Status function .isBusy = (DRV_SDSPI_IS_BUSY)SPI0_IsBusy, // SPI PLIB Transfer Setup function .transferSetup = (DRV_SDSPI_SETUP)SPI0_TransferSetup, // SPI PLIB Callback Register .callbackRegister = (DRV_SDSPI_CALLBACK_REGISTER)SPI0_CallbackRegister, }; DRV_SDSPI_INIT drvSDSPI0InitData = { // SD Card SPI PLIB API interface .spiPlib = &drvSDSPI0PlibAPI, .remapDataBits = drvSDSPI0remapDataBits, .remapClockPolarity = drvSDSPI0remapClockPolarity, .remapClockPhase = drvSDSPI0remapClockPhase, // SDSPI Number of clients .numClients = DRV_SDSPI_CLIENTS_NUMBER_IDX0, // SDSPI Client Objects Pool .clientObjPool = (uintptr_t)&drvSDSPI0ClientObjPool[0], .chipSelectPin = DRV_SDSPI_CHIP_SELECT_PIN_IDX0, .SDSPISpeedHz = DRV_SDSPI_SPEED_HZ_IDX0, .writeProtectPin = SYS_PORT_PIN_NONE, .isFsEnabled = DRV_SDSPI_REGISTER_WITH_FS_IDX0, // DMA Channel for Transmit .txDMAChannel = DRV_SDSPI_XMIT_DMA_CH_IDX0, // DMA Channel for Receive .rxDMAChannel = DRV_SDSPI_RCV_DMA_CH_IDX0, // SPI Transmit Register .txAddress = (void *)&(SPI0_REGS->SPI_TDR), // SPI Receive Register .rxAddress = (void *)&(SPI0_REGS->SPI_RDR), }; objectHandle = DRV_SDSPI_Initialize(DRV_SDSPI_INDEX_0, (SYS_MODULE_INIT *)&drvSDSPI0InitData); if (objectHandle == SYS_MODULE_OBJ_INVALID) { // Handle error }
Remarks
This routine must be called before any other SD Card routine is called.
This routine should only be called once during system initialization.
The system must use DRV_SDSPI_Status to find out when the driver is in the ready state.