MCUXpresso SDK API Reference Manual  Rev. 0
NXP Semiconductors
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
SDIF: SD/MMC/SDIO card interface

Overview

The MCUXpresso SDK provides a peripheral driver for the SD/MMC/SDIO card interface (SDIF) module of MCUXpresso SDK devices.

Typical use case

sdif Operation

Refer to the driver examples codes located at <SDK_ROOT>/boards/<BOARD>/driver_examples/sdif

Data Structures

struct  sdif_dma_descriptor_t
 define the internal DMA descriptor More...
 
struct  sdif_dma_config_t
 Defines the internal DMA config structure. More...
 
struct  sdif_data_t
 Card data descriptor. More...
 
struct  sdif_command_t
 Card command descriptor. More...
 
struct  sdif_transfer_t
 Transfer state. More...
 
struct  sdif_config_t
 Data structure to initialize the sdif. More...
 
struct  sdif_capability_t
 SDIF capability information. More...
 
struct  sdif_transfer_callback_t
 sdif callback functions. More...
 
struct  sdif_handle_t
 sdif handle More...
 
struct  sdif_host_t
 sdif host descriptor More...
 

Macros

#define SDIF_CLOCK_RANGE_NEED_DELAY   (50000000U)
 SDIOCLKCTRL setting Below clock delay setting should depend on specific platform, so it can be redefined when timing mismatch issue occur. More...
 
#define SDIF_HIGHSPEED_SAMPLE_DELAY   (0U)
 High speed mode clk_sample fixed delay.
 
#define SDIF_HIGHSPEED_DRV_DELAY   (0x1FU)
 High speed mode clk_drv fixed delay.
 
#define SDIF_HIGHSPEED_SAMPLE_PHASE_SHIFT   (0U)
 High speed mode clk_sample pharse shift.
 
#define SDIF_HIGHSPEED_DRV_PHASE_SHIFT   (1U) /* 90 degrees clk_drv pharse delay */
 High speed mode clk_drv pharse shift.
 
#define SDIF_INTERNAL_DMA_ADDR_ALIGN   (4U)
 SDIF internal DMA descriptor address and the data buffer address align.
 

Typedefs

typedef status_t(* sdif_transfer_function_t )(SDIF_Type *base, sdif_transfer_t *content)
 sdif transfer function. More...
 

Enumerations

enum  _sdif_status {
  kStatus_SDIF_DescriptorBufferLenError = MAKE_STATUS(kStatusGroup_SDIF, 0U),
  kStatue_SDIF_InvalidArgument = MAKE_STATUS(kStatusGroup_SDIF, 1U),
  kStatus_SDIF_SyncCmdTimeout = MAKE_STATUS(kStatusGroup_SDIF, 2U),
  kStatus_SDIF_SendCmdFail = MAKE_STATUS(kStatusGroup_SDIF, 3U),
  kStatus_SDIF_SendCmdErrorBufferFull,
  kStatus_SDIF_DMATransferFailWithFBE,
  kStatus_SDIF_DMATransferDescriptorUnavaliable,
  kStatus_SDIF_DataTransferFail = MAKE_STATUS(kStatusGroup_SDIF, 6U),
  kStatus_SDIF_ResponseError = MAKE_STATUS(kStatusGroup_SDIF, 7U),
  kStatus_SDIF_DMAAddrNotAlign = MAKE_STATUS(kStatusGroup_SDIF, 8U)
}
 SDIF status. More...
 
enum  _sdif_capability_flag {
  kSDIF_SupportHighSpeedFlag = 0x1U,
  kSDIF_SupportDmaFlag = 0x2U,
  kSDIF_SupportSuspendResumeFlag = 0x4U,
  kSDIF_SupportV330Flag = 0x8U,
  kSDIF_Support4BitFlag = 0x10U,
  kSDIF_Support8BitFlag = 0x20U
}
 Host controller capabilities flag mask. More...
 
enum  _sdif_reset_type {
  kSDIF_ResetController,
  kSDIF_ResetFIFO = SDIF_CTRL_FIFO_RESET_MASK,
  kSDIF_ResetDMAInterface = SDIF_CTRL_DMA_RESET_MASK,
  kSDIF_ResetAll
}
 define the reset type More...
 
enum  sdif_bus_width_t {
  kSDIF_Bus1BitWidth = 0U,
  kSDIF_Bus4BitWidth = SDIF_CTYPE_CARD_WIDTH0_MASK,
  kSDIF_Bus8BitWidth = SDIF_CTYPE_CARD_WIDTH1_MASK
}
 define the card bus width type More...
 
enum  _sdif_command_flags {
  kSDIF_CmdResponseExpect = SDIF_CMD_RESPONSE_EXPECT_MASK,
  kSDIF_CmdResponseLengthLong = SDIF_CMD_RESPONSE_LENGTH_MASK,
  kSDIF_CmdCheckResponseCRC = SDIF_CMD_CHECK_RESPONSE_CRC_MASK,
  kSDIF_DataExpect = SDIF_CMD_DATA_EXPECTED_MASK,
  kSDIF_DataWriteToCard = SDIF_CMD_READ_WRITE_MASK,
  kSDIF_DataStreamTransfer = SDIF_CMD_TRANSFER_MODE_MASK,
  kSDIF_DataTransferAutoStop = SDIF_CMD_SEND_AUTO_STOP_MASK,
  kSDIF_WaitPreTransferComplete,
  kSDIF_TransferStopAbort,
  kSDIF_SendInitialization,
  kSDIF_CmdUpdateClockRegisterOnly,
  kSDIF_CmdtoReadCEATADevice = SDIF_CMD_READ_CEATA_DEVICE_MASK,
  kSDIF_CmdExpectCCS = SDIF_CMD_CCS_EXPECTED_MASK,
  kSDIF_BootModeEnable = SDIF_CMD_ENABLE_BOOT_MASK,
  kSDIF_BootModeExpectAck = SDIF_CMD_EXPECT_BOOT_ACK_MASK,
  kSDIF_BootModeDisable = SDIF_CMD_DISABLE_BOOT_MASK,
  kSDIF_BootModeAlternate = SDIF_CMD_BOOT_MODE_MASK,
  kSDIF_CmdVoltageSwitch = SDIF_CMD_VOLT_SWITCH_MASK,
  kSDIF_CmdDataUseHoldReg = SDIF_CMD_USE_HOLD_REG_MASK
}
 define the command flags More...
 
enum  _sdif_command_type {
  kCARD_CommandTypeNormal = 0U,
  kCARD_CommandTypeSuspend = 1U,
  kCARD_CommandTypeResume = 2U,
  kCARD_CommandTypeAbort = 3U
}
 The command type. More...
 
enum  _sdif_response_type {
  kCARD_ResponseTypeNone = 0U,
  kCARD_ResponseTypeR1 = 1U,
  kCARD_ResponseTypeR1b = 2U,
  kCARD_ResponseTypeR2 = 3U,
  kCARD_ResponseTypeR3 = 4U,
  kCARD_ResponseTypeR4 = 5U,
  kCARD_ResponseTypeR5 = 6U,
  kCARD_ResponseTypeR5b = 7U,
  kCARD_ResponseTypeR6 = 8U,
  kCARD_ResponseTypeR7 = 9U
}
 The command response type. More...
 
enum  _sdif_interrupt_mask {
  kSDIF_CardDetect = SDIF_INTMASK_CDET_MASK,
  kSDIF_ResponseError = SDIF_INTMASK_RE_MASK,
  kSDIF_CommandDone = SDIF_INTMASK_CDONE_MASK,
  kSDIF_DataTransferOver = SDIF_INTMASK_DTO_MASK,
  kSDIF_WriteFIFORequest = SDIF_INTMASK_TXDR_MASK,
  kSDIF_ReadFIFORequest = SDIF_INTMASK_RXDR_MASK,
  kSDIF_ResponseCRCError = SDIF_INTMASK_RCRC_MASK,
  kSDIF_DataCRCError = SDIF_INTMASK_DCRC_MASK,
  kSDIF_ResponseTimeout = SDIF_INTMASK_RTO_MASK,
  kSDIF_DataReadTimeout = SDIF_INTMASK_DRTO_MASK,
  kSDIF_DataStarvationByHostTimeout = SDIF_INTMASK_HTO_MASK,
  kSDIF_FIFOError = SDIF_INTMASK_FRUN_MASK,
  kSDIF_HardwareLockError = SDIF_INTMASK_HLE_MASK,
  kSDIF_DataStartBitError = SDIF_INTMASK_SBE_MASK,
  kSDIF_AutoCmdDone = SDIF_INTMASK_ACD_MASK,
  kSDIF_DataEndBitError = SDIF_INTMASK_EBE_MASK,
  kSDIF_SDIOInterrupt = SDIF_INTMASK_SDIO_INT_MASK_MASK,
  kSDIF_CommandTransferStatus,
  kSDIF_DataTransferStatus ,
  kSDIF_AllInterruptStatus = 0x1FFFFU
}
 define the interrupt mask flags More...
 
enum  _sdif_dma_status {
  kSDIF_DMATransFinishOneDescriptor = SDIF_IDSTS_TI_MASK,
  kSDIF_DMARecvFinishOneDescriptor = SDIF_IDSTS_RI_MASK,
  kSDIF_DMAFatalBusError = SDIF_IDSTS_FBE_MASK,
  kSDIF_DMADescriptorUnavailable = SDIF_IDSTS_DU_MASK,
  kSDIF_DMACardErrorSummary = SDIF_IDSTS_CES_MASK,
  kSDIF_NormalInterruptSummary = SDIF_IDSTS_NIS_MASK,
  kSDIF_AbnormalInterruptSummary = SDIF_IDSTS_AIS_MASK
}
 define the internal DMA status flags More...
 
enum  _sdif_dma_descriptor_flag {
  kSDIF_DisableCompleteInterrupt = 0x2U,
  kSDIF_DMADescriptorDataBufferEnd = 0x4U,
  kSDIF_DMADescriptorDataBufferStart = 0x8U,
  kSDIF_DMASecondAddrChained = 0x10U,
  kSDIF_DMADescriptorEnd = 0x20U,
  kSDIF_DMADescriptorOwnByDMA = 0x80000000U
}
 define the internal DMA descriptor flag More...
 
enum  sdif_dma_mode_t
 define the internal DMA mode
 

Functions

void SDIF_Init (SDIF_Type *base, sdif_config_t *config)
 SDIF module initialization function. More...
 
void SDIF_Deinit (SDIF_Type *base)
 SDIF module deinit function. More...
 
bool SDIF_SendCardActive (SDIF_Type *base, uint32_t timeout)
 SDIF send initialize 80 clocks for SD card after initilize. More...
 
static uint32_t SDIF_DetectCardInsert (SDIF_Type *base, bool data3)
 SDIF module detect card insert status function. More...
 
static void SDIF_EnableCardClock (SDIF_Type *base, bool enable)
 SDIF module enable/disable card clock. More...
 
static void SDIF_EnableLowPowerMode (SDIF_Type *base, bool enable)
 SDIF module enable/disable module disable the card clock to enter low power mode when card is idle,for SDIF cards, if interrupts must be detected, clock should not be stopped. More...
 
uint32_t SDIF_SetCardClock (SDIF_Type *base, uint32_t srcClock_Hz, uint32_t target_HZ)
 Sets the card bus clock frequency. More...
 
bool SDIF_Reset (SDIF_Type *base, uint32_t mask, uint32_t timeout)
 reset the different block of the interface. More...
 
static void SDIF_EnableCardPower (SDIF_Type *base, bool enable)
 enable/disable the card power. More...
 
static uint32_t SDIF_GetCardWriteProtect (SDIF_Type *base)
 get the card write protect status More...
 
static void SDIF_SetCardBusWidth (SDIF_Type *base, sdif_bus_width_t type)
 set card data bus width More...
 
static void SDIF_AssertHardwareReset (SDIF_Type *base)
 toggle state on hardware reset PIN This is used which card has a reset PIN typically. More...
 
status_t SDIF_SendCommand (SDIF_Type *base, sdif_command_t *cmd, uint32_t timeout)
 send command to the card More...
 
static void SDIF_EnableGlobalInterrupt (SDIF_Type *base, bool enable)
 SDIF enable/disable global interrupt. More...
 
static void SDIF_EnableInterrupt (SDIF_Type *base, uint32_t mask)
 SDIF enable interrupt. More...
 
static void SDIF_DisableInterrupt (SDIF_Type *base, uint32_t mask)
 SDIF disable interrupt. More...
 
static uint32_t SDIF_GetInterruptStatus (SDIF_Type *base)
 SDIF get interrupt status. More...
 
static void SDIF_ClearInterruptStatus (SDIF_Type *base, uint32_t mask)
 SDIF clear interrupt status. More...
 
void SDIF_TransferCreateHandle (SDIF_Type *base, sdif_handle_t *handle, sdif_transfer_callback_t *callback, void *userData)
 Creates the SDIF handle. More...
 
static void SDIF_EnableDmaInterrupt (SDIF_Type *base, uint32_t mask)
 SDIF enable DMA interrupt. More...
 
static void SDIF_DisableDmaInterrupt (SDIF_Type *base, uint32_t mask)
 SDIF disable DMA interrupt. More...
 
static uint32_t SDIF_GetInternalDMAStatus (SDIF_Type *base)
 SDIF get internal DMA status. More...
 
static void SDIF_ClearInternalDMAStatus (SDIF_Type *base, uint32_t mask)
 SDIF clear internal DMA status. More...
 
status_t SDIF_InternalDMAConfig (SDIF_Type *base, sdif_dma_config_t *config, const uint32_t *data, uint32_t dataSize)
 SDIF internal DMA config function. More...
 
static void SDIF_EnableInternalDMA (SDIF_Type *base, bool enable)
 SDIF internal DMA enable. More...
 
static void SDIF_SendReadWait (SDIF_Type *base)
 SDIF send read wait to SDIF card function. More...
 
bool SDIF_AbortReadData (SDIF_Type *base, uint32_t timeout)
 SDIF abort the read data when SDIF card is in suspend state Once assert this bit,data state machine will be reset which is waiting for the next blocking data,used in SDIO card suspend sequence,should call after suspend cmd send. More...
 
static void SDIF_EnableCEATAInterrupt (SDIF_Type *base, bool enable)
 SDIF enable/disable CE-ATA card interrupt this bit should set together with the card register. More...
 
status_t SDIF_TransferNonBlocking (SDIF_Type *base, sdif_handle_t *handle, sdif_dma_config_t *dmaConfig, sdif_transfer_t *transfer)
 SDIF transfer function data/cmd in a non-blocking way this API should be use in interrupt mode, when use this API user must call SDIF_TransferCreateHandle first, all status check through interrupt. More...
 
status_t SDIF_TransferBlocking (SDIF_Type *base, sdif_dma_config_t *dmaConfig, sdif_transfer_t *transfer)
 SDIF transfer function data/cmd in a blocking way. More...
 
status_t SDIF_ReleaseDMADescriptor (SDIF_Type *base, sdif_dma_config_t *dmaConfig)
 SDIF release the DMA descriptor to DMA engine this function should be called when DMA descriptor unavailable status occurs. More...
 
void SDIF_GetCapability (SDIF_Type *base, sdif_capability_t *capability)
 SDIF return the controller capability. More...
 
static uint32_t SDIF_GetControllerStatus (SDIF_Type *base)
 SDIF return the controller status. More...
 
static void SDIF_SendCCSD (SDIF_Type *base, bool withAutoStop)
 SDIF send command complete signal disable to CE-ATA card. More...
 
void SDIF_ConfigClockDelay (uint32_t target_HZ, uint32_t divider)
 SDIF config the clock delay This function is used to config the cclk_in delay to sample and drvive the data ,should meet the min setup time and hold time, and user need to config this paramter according to your board setting. More...
 

Driver version

#define FSL_SDIF_DRIVER_VERSION   (MAKE_VERSION(2U, 0U, 5U))
 Driver version 2.0.5. More...
 

Data Structure Documentation

struct sdif_dma_descriptor_t

Data Fields

uint32_t dmaDesAttribute
 internal DMA attribute control and status
 
uint32_t dmaDataBufferSize
 internal DMA transfer buffer size control
 
const uint32_t * dmaDataBufferAddr0
 internal DMA buffer 0 addr ,the buffer size must be 32bit aligned
 
const uint32_t * dmaDataBufferAddr1
 internal DMA buffer 1 addr ,the buffer size must be 32bit aligned
 
struct sdif_dma_config_t

Data Fields

bool enableFixBurstLen
 
fix burst len enable/disable flag,When set, the AHB will

use only SINGLE, INCR4, INCR8 or INCR16 during start of normal burst transfers. More...

 
sdif_dma_mode_t mode
 define the DMA mode
 
uint8_t dmaDesSkipLen
 define the descriptor skip length ,the length between two descriptor this field is special for dual DMA mode
 
uint32_t * dmaDesBufferStartAddr
 internal DMA descriptor start address
 
uint32_t dmaDesBufferLen
 internal DMA buffer descriptor buffer len ,user need to pay attention to the dma descriptor buffer length if it is bigger enough for your transfer
 

Field Documentation

bool sdif_dma_config_t::enableFixBurstLen

When reset, the AHB will use SINGLE and INCR burst transfer operations

struct sdif_data_t

Data Fields

bool streamTransfer
 indicate this is a stream data transfer command
 
bool enableAutoCommand12
 indicate if auto stop will send when data transfer over
 
bool enableIgnoreError
 indicate if enable ignore error when transfer data
 
size_t blockSize
 Block size, take care when config this parameter.
 
uint32_t blockCount
 Block count.
 
uint32_t * rxData
 data buffer to recieve
 
const uint32_t * txData
 data buffer to transfer
 
struct sdif_command_t

Define card command-related attribute.

Data Fields

uint32_t index
 Command index.
 
uint32_t argument
 Command argument.
 
uint32_t response [4U]
 Response for this command.
 
uint32_t type
 define the command type
 
uint32_t responseType
 Command response type.
 
uint32_t flags
 Cmd flags.
 
uint32_t responseErrorFlags
 response error flags, need to check the flags when recieve the cmd response
 
struct sdif_transfer_t

Data Fields

sdif_data_tdata
 Data to transfer.
 
sdif_command_tcommand
 Command to send.
 
struct sdif_config_t

Data Fields

uint8_t responseTimeout
 command reponse timeout value
 
uint32_t cardDetDebounce_Clock
 define the debounce clock count which will used in card detect logic,typical value is 5-25ms
 
uint32_t endianMode
 
 define endian mode ,this field is not used in this

module actually, keep for compatible with middleware

 
uint32_t dataTimeout
 data timeout value
 
struct sdif_capability_t

Defines a structure to get the capability information of SDIF.

Data Fields

uint32_t sdVersion
 support SD card/sdio version
 
uint32_t mmcVersion
 support emmc card version
 
uint32_t maxBlockLength
 Maximum block length united as byte.
 
uint32_t maxBlockCount
 Maximum byte count can be transfered.
 
uint32_t flags
 Capability flags to indicate the support information.
 
struct sdif_transfer_callback_t

Data Fields

void(* cardInserted )(SDIF_Type *base, void *userData)
 card insert call back
 
void(* cardRemoved )(SDIF_Type *base, void *userData)
 card remove call back
 
void(* SDIOInterrupt )(SDIF_Type *base, void *userData)
 SDIO card interrupt occurs.
 
void(* DMADesUnavailable )(SDIF_Type *base, void *userData)
 DMA descriptor unavailable.
 
void(* CommandReload )(SDIF_Type *base, void *userData)
 command buffer full,need re-load
 
void(* TransferComplete )(SDIF_Type *base, void *handle, status_t status, void *userData)
 Transfer complete callback.
 
struct sdif_handle_t

Defines the structure to save the sdif state information and callback function. The detail interrupt status when send command or transfer data can be obtained from interruptFlags field by using mask defined in sdif_interrupt_flag_t;

Note
All the fields except interruptFlags and transferredWords must be allocated by the user.

Data Fields

sdif_data_t *volatile data
 Data to transfer.
 
sdif_command_t *volatile command
 Command to send.
 
volatile uint32_t interruptFlags
 Interrupt flags of last transaction.
 
volatile uint32_t dmaInterruptFlags
 DMA interrupt flags of last transaction.
 
volatile uint32_t transferredWords
 Words transferred by polling way.
 
sdif_transfer_callback_t callback
 Callback function.
 
void * userData
 Parameter for transfer complete callback.
 
struct sdif_host_t

Data Fields

SDIF_Type * base
 sdif peripheral base address
 
uint32_t sourceClock_Hz
 sdif source clock frequency united in Hz
 
sdif_config_t config
 sdif configuration
 
sdif_transfer_function_t transfer
 sdif transfer function
 
sdif_capability_t capability
 sdif capability information
 

Macro Definition Documentation

#define FSL_SDIF_DRIVER_VERSION   (MAKE_VERSION(2U, 0U, 5U))
#define SDIF_CLOCK_RANGE_NEED_DELAY   (50000000U)

Such as: response error/CRC error and so on

clock range value which need to add delay to avoid timing issue

Typedef Documentation

typedef status_t(* sdif_transfer_function_t)(SDIF_Type *base, sdif_transfer_t *content)

Enumeration Type Documentation

Enumerator
kStatus_SDIF_DescriptorBufferLenError 

Set DMA descriptor failed.

kStatue_SDIF_InvalidArgument 

invalid argument status

kStatus_SDIF_SyncCmdTimeout 

sync command to CIU timeout status

kStatus_SDIF_SendCmdFail 

send command to card fail

kStatus_SDIF_SendCmdErrorBufferFull 

send command to card fail, due to command buffer full user need to resend this command

kStatus_SDIF_DMATransferFailWithFBE 

DMA transfer data fail with fatal bus error , to do with this error :issue a hard reset/controller reset.

kStatus_SDIF_DMATransferDescriptorUnavaliable 

DMA descriptor unavalible.

kStatus_SDIF_DataTransferFail 

transfer data fail

kStatus_SDIF_ResponseError 

response error

kStatus_SDIF_DMAAddrNotAlign 

DMA address not align.

Enumerator
kSDIF_SupportHighSpeedFlag 

Support high-speed.

kSDIF_SupportDmaFlag 

Support DMA.

kSDIF_SupportSuspendResumeFlag 

Support suspend/resume.

kSDIF_SupportV330Flag 

Support voltage 3.3V.

kSDIF_Support4BitFlag 

Support 4 bit mode.

kSDIF_Support8BitFlag 

Support 8 bit mode.

Enumerator
kSDIF_ResetController 

reset controller,will reset: BIU/CIU interface CIU and state machine,ABORT_READ_DATA,SEND_IRQ_RESPONSE and READ_WAIT bits of control register,START_CMD bit of the command register

kSDIF_ResetFIFO 

reset data FIFO

kSDIF_ResetDMAInterface 

reset DMA interface

kSDIF_ResetAll 

reset all

Enumerator
kSDIF_Bus1BitWidth 

1bit bus width, 1bit mode and 4bit mode share one register bit

kSDIF_Bus4BitWidth 

4bit mode mask

kSDIF_Bus8BitWidth 

support 8 bit mode

Enumerator
kSDIF_CmdResponseExpect 

command request response

kSDIF_CmdResponseLengthLong 

command response length long

kSDIF_CmdCheckResponseCRC 

request check command response CRC

kSDIF_DataExpect 

request data transfer,ethier read/write

kSDIF_DataWriteToCard 

data transfer direction

kSDIF_DataStreamTransfer 

data transfer mode :stream/block transfer command

kSDIF_DataTransferAutoStop 

data transfer with auto stop at the end of

kSDIF_WaitPreTransferComplete 

wait pre transfer complete before sending this cmd

kSDIF_TransferStopAbort 

when host issue stop or abort cmd to stop data transfer ,this bit should set so that cmd/data state-machines of CIU can return to idle correctly

kSDIF_SendInitialization 

send initaliztion 80 clocks for SD card after power on

kSDIF_CmdUpdateClockRegisterOnly 

send cmd update the CIU clock register only

kSDIF_CmdtoReadCEATADevice 

host is perform read access to CE-ATA device

kSDIF_CmdExpectCCS 

command expect command completion signal signal

kSDIF_BootModeEnable 

this bit should only be set for mandatory boot mode

kSDIF_BootModeExpectAck 

boot mode expect ack

kSDIF_BootModeDisable 

when software set this bit along with START_CMD, CIU terminates the boot operation

kSDIF_BootModeAlternate 

select boot mode ,alternate or mandatory

kSDIF_CmdVoltageSwitch 

this bit set for CMD11 only

kSDIF_CmdDataUseHoldReg 

cmd and data send to card through the HOLD register

Enumerator
kCARD_CommandTypeNormal 

Normal command.

kCARD_CommandTypeSuspend 

Suspend command.

kCARD_CommandTypeResume 

Resume command.

kCARD_CommandTypeAbort 

Abort command.

Define the command response type from card to host controller.

Enumerator
kCARD_ResponseTypeNone 

Response type: none.

kCARD_ResponseTypeR1 

Response type: R1.

kCARD_ResponseTypeR1b 

Response type: R1b.

kCARD_ResponseTypeR2 

Response type: R2.

kCARD_ResponseTypeR3 

Response type: R3.

kCARD_ResponseTypeR4 

Response type: R4.

kCARD_ResponseTypeR5 

Response type: R5.

kCARD_ResponseTypeR5b 

Response type: R5b.

kCARD_ResponseTypeR6 

Response type: R6.

kCARD_ResponseTypeR7 

Response type: R7.

Enumerator
kSDIF_CardDetect 

mask for card detect

kSDIF_ResponseError 

command response error

kSDIF_CommandDone 

command transfer over

kSDIF_DataTransferOver 

data transfer over flag

kSDIF_WriteFIFORequest 

write FIFO request

kSDIF_ReadFIFORequest 

read FIFO request

kSDIF_ResponseCRCError 

reponse CRC error

kSDIF_DataCRCError 

data CRC error

kSDIF_ResponseTimeout 

response timeout

kSDIF_DataReadTimeout 

read data timeout

kSDIF_DataStarvationByHostTimeout 

data starvation by host time out

kSDIF_FIFOError 

indicate the FIFO underrun or overrun error

kSDIF_HardwareLockError 

hardware lock write error

kSDIF_DataStartBitError 

start bit error

kSDIF_AutoCmdDone 

indicate the auto command done

kSDIF_DataEndBitError 

end bit error

kSDIF_SDIOInterrupt 

interrupt from the SDIO card

kSDIF_CommandTransferStatus 

command transfer status collection

kSDIF_DataTransferStatus 

data transfer status collection

kSDIF_AllInterruptStatus 

all interrupt mask

Enumerator
kSDIF_DMATransFinishOneDescriptor 

DMA transfer finished for one DMA descriptor.

kSDIF_DMARecvFinishOneDescriptor 

DMA revieve finished for one DMA descriptor.

kSDIF_DMAFatalBusError 

DMA fatal bus error.

kSDIF_DMADescriptorUnavailable 

DMA descriptor unavailable.

kSDIF_DMACardErrorSummary 

card error summary

kSDIF_NormalInterruptSummary 

normal interrupt summary

kSDIF_AbnormalInterruptSummary 

abnormal interrupt summary

Enumerator
kSDIF_DisableCompleteInterrupt 

disable the complete interrupt flag for the ends in the buffer pointed to by this descriptor

kSDIF_DMADescriptorDataBufferEnd 

indicate this descriptor contain the last data buffer of data

kSDIF_DMADescriptorDataBufferStart 

indicate this descriptor contain the first data buffer of data,if first buffer size is 0,next descriptor contain the begaining of the data

kSDIF_DMASecondAddrChained 

indicate that the second addr in the descriptor is the next descriptor addr not the data buffer

kSDIF_DMADescriptorEnd 

indicate that the descriptor list reached its final descriptor

kSDIF_DMADescriptorOwnByDMA 

indicate the descriptor is own by SD/MMC DMA

Function Documentation

void SDIF_Init ( SDIF_Type *  base,
sdif_config_t config 
)

Configures the SDIF according to the user configuration.

Parameters
baseSDIF peripheral base address.
configSDIF configuration information.
void SDIF_Deinit ( SDIF_Type *  base)

user should call this function follow with IP reset

Parameters
baseSDIF peripheral base address.
bool SDIF_SendCardActive ( SDIF_Type *  base,
uint32_t  timeout 
)
Parameters
baseSDIF peripheral base address.
timeoutvalue
static uint32_t SDIF_DetectCardInsert ( SDIF_Type *  base,
bool  data3 
)
inlinestatic
Parameters
baseSDIF peripheral base address.
data3indicate use data3 as card insert detect pin
Return values
1card is inserted 0 card is removed
static void SDIF_EnableCardClock ( SDIF_Type *  base,
bool  enable 
)
inlinestatic
Parameters
baseSDIF peripheral base address.
enable/disableflag
static void SDIF_EnableLowPowerMode ( SDIF_Type *  base,
bool  enable 
)
inlinestatic
Parameters
baseSDIF peripheral base address.
enable/disableflag
uint32_t SDIF_SetCardClock ( SDIF_Type *  base,
uint32_t  srcClock_Hz,
uint32_t  target_HZ 
)
Parameters
baseSDIF peripheral base address.
srcClock_HzSDIF source clock frequency united in Hz.
target_HZcard bus clock frequency united in Hz.
Returns
The nearest frequency of busClock_Hz configured to SD bus.
bool SDIF_Reset ( SDIF_Type *  base,
uint32_t  mask,
uint32_t  timeout 
)
Parameters
baseSDIF peripheral base address.
maskindicate which block to reset.
timeoutvalue,set to wait the bit self clear
Returns
reset result.
static void SDIF_EnableCardPower ( SDIF_Type *  base,
bool  enable 
)
inlinestatic

once turn power on, software should wait for regulator/switch ramp-up time before trying to initialize card.

Parameters
baseSDIF peripheral base address.
enable/disableflag.
static uint32_t SDIF_GetCardWriteProtect ( SDIF_Type *  base)
inlinestatic
Parameters
baseSDIF peripheral base address.
static void SDIF_SetCardBusWidth ( SDIF_Type *  base,
sdif_bus_width_t  type 
)
inlinestatic
Parameters
baseSDIF peripheral base address.
databus width type
static void SDIF_AssertHardwareReset ( SDIF_Type *  base)
inlinestatic
Parameters
baseSDIF peripheral base address.
status_t SDIF_SendCommand ( SDIF_Type *  base,
sdif_command_t cmd,
uint32_t  timeout 
)
Parameters
baseSDIF peripheral base address.
commandconfiguration collection
timeoutvalue
Returns
command excute status
static void SDIF_EnableGlobalInterrupt ( SDIF_Type *  base,
bool  enable 
)
inlinestatic
Parameters
baseSDIF peripheral base address.
enable/disableflag
static void SDIF_EnableInterrupt ( SDIF_Type *  base,
uint32_t  mask 
)
inlinestatic
Parameters
baseSDIF peripheral base address.
interruptmask
static void SDIF_DisableInterrupt ( SDIF_Type *  base,
uint32_t  mask 
)
inlinestatic
Parameters
baseSDIF peripheral base address.
interruptmask
static uint32_t SDIF_GetInterruptStatus ( SDIF_Type *  base)
inlinestatic
Parameters
baseSDIF peripheral base address.
static void SDIF_ClearInterruptStatus ( SDIF_Type *  base,
uint32_t  mask 
)
inlinestatic
Parameters
baseSDIF peripheral base address.
statusmask to clear
void SDIF_TransferCreateHandle ( SDIF_Type *  base,
sdif_handle_t handle,
sdif_transfer_callback_t callback,
void *  userData 
)

register call back function for interrupt and enable the interrupt

Parameters
baseSDIF peripheral base address.
handleSDIF handle pointer.
callbackStructure pointer to contain all callback functions.
userDataCallback function parameter.
static void SDIF_EnableDmaInterrupt ( SDIF_Type *  base,
uint32_t  mask 
)
inlinestatic
Parameters
baseSDIF peripheral base address.
interruptmask to set
static void SDIF_DisableDmaInterrupt ( SDIF_Type *  base,
uint32_t  mask 
)
inlinestatic
Parameters
baseSDIF peripheral base address.
interruptmask to clear
static uint32_t SDIF_GetInternalDMAStatus ( SDIF_Type *  base)
inlinestatic
Parameters
baseSDIF peripheral base address.
Returns
the internal DMA status register
static void SDIF_ClearInternalDMAStatus ( SDIF_Type *  base,
uint32_t  mask 
)
inlinestatic
Parameters
baseSDIF peripheral base address.
statusmask to clear
status_t SDIF_InternalDMAConfig ( SDIF_Type *  base,
sdif_dma_config_t config,
const uint32_t *  data,
uint32_t  dataSize 
)
Parameters
baseSDIF peripheral base address.
internalDMA configuration collection
databuffer pointer
databuffer size
static void SDIF_EnableInternalDMA ( SDIF_Type *  base,
bool  enable 
)
inlinestatic
Parameters
baseSDIF peripheral base address.
enableinternal DMA enable or disable flag.
static void SDIF_SendReadWait ( SDIF_Type *  base)
inlinestatic
Parameters
baseSDIF peripheral base address.
bool SDIF_AbortReadData ( SDIF_Type *  base,
uint32_t  timeout 
)
Parameters
baseSDIF peripheral base address.
timeoutvalue to wait this bit self clear which indicate the data machine reset to idle
static void SDIF_EnableCEATAInterrupt ( SDIF_Type *  base,
bool  enable 
)
inlinestatic
Parameters
baseSDIF peripheral base address.
enable/disableflag
status_t SDIF_TransferNonBlocking ( SDIF_Type *  base,
sdif_handle_t handle,
sdif_dma_config_t dmaConfig,
sdif_transfer_t transfer 
)
Parameters
baseSDIF peripheral base address.
sdifhandle
DMAconfig structure This parameter can be config as:
  1. NULL In this condition, polling transfer mode is selected
  2. avaliable DMA config In this condition, DMA transfer mode is selected
sdiftransfer configuration collection
status_t SDIF_TransferBlocking ( SDIF_Type *  base,
sdif_dma_config_t dmaConfig,
sdif_transfer_t transfer 
)
Parameters
baseSDIF peripheral base address.
DMAconfig structure
  1. NULL In this condition, polling transfer mode is selected
  2. avaliable DMA config In this condition, DMA transfer mode is selected
sdiftransfer configuration collection
status_t SDIF_ReleaseDMADescriptor ( SDIF_Type *  base,
sdif_dma_config_t dmaConfig 
)
Parameters
baseSDIF peripheral base address.
sdifDMA config pointer
void SDIF_GetCapability ( SDIF_Type *  base,
sdif_capability_t capability 
)
Parameters
baseSDIF peripheral base address.
sdifcapability pointer
static uint32_t SDIF_GetControllerStatus ( SDIF_Type *  base)
inlinestatic
Parameters
baseSDIF peripheral base address.
static void SDIF_SendCCSD ( SDIF_Type *  base,
bool  withAutoStop 
)
inlinestatic
Parameters
baseSDIF peripheral base address.
sendauto stop flag
void SDIF_ConfigClockDelay ( uint32_t  target_HZ,
uint32_t  divider 
)
Parameters
targetfreq work mode
clockdivider which is used to decide if use pharse shift for delay