SAMV71 Xplained Ultra Software Package 1.5

SD/MMC APIs
[Libsdmmc_module]

Collaboration diagram for SD/MMC APIs:

Modules

 SD/MMC Spec. definitions
 SDIO APIs
 SD/MMC Lib Commands Definitions
 SD/MMC Status register constants
 SDIO Status definitions

Defines

#define CARD_ADDR(pSd)   (pSd->wAddress)
#define BLOCK_SIZE(pSd)   (pSd->wCurrBlockLen)
#define SD_ADDRESS(pSd, address)
#define MMC_ADDRESS(pSd, address)
#define SD_IsVer1_10(pSd)   (SD_SCR_SD_SPEC(pSd->SCR) >= SD_SCR_SD_SPEC_1_10)
#define SD_IsHsModeSupported(pSd)   (/*SD_IsVer1_10(pSd)||*/(SD_CSD_STRUCTURE(pSd->CSD)>=1))
#define SD_IsBusModeSupported(pSd)   (1)
#define MMC_IsVer4(pSd)   (MMC_CSD_SPEC_VERS(pSd->CSD) >= 4)
#define MMC_IsCSDVer1_2(pSd)
#define MMC_IsBootModeSupported(pSd)   ((MMC_IsVer4(pSd)&&(eMMC_CID_CBX(pSd->CID)==0x01))
#define MMC_IsBusModeSupported(pSd)   (MMC_IsVer4(pSd))
#define MMC_IsHsModeSupported(pSd)   (MMC_IsCSDVer1_2(pSd)&&(MMC_EXT_CARD_TYPE(pSd->EXT)&0x2))

Functions

uint8_t SD_Init (sSdCard *pSd)
void SD_DeInit (sSdCard *pSd)
uint8_t SD_SetupBusMode (sSdCard *pSd, uint8_t bMode)
uint8_t SD_SetupHSMode (sSdCard *pSd, uint8_t bMode)
uint8_t SD_GetCardType (sSdCard *pSd)
uint32_t SD_GetNumberBlocks (sSdCard *pSd)
uint32_t SD_GetBlockSize (sSdCard *pSd)
uint32_t SD_GetTotalSizeKB (sSdCard *pSd)
uint8_t SD_ReadBlocks (sSdCard *pSd, uint32_t dwAddr, void *pData, uint32_t dwNbBlocks)
uint8_t SD_WriteBlocks (sSdCard *pSd, uint32_t dwAddr, const void *pData, uint32_t dwNbBlocks)
uint8_t SD_Read (sSdCard *pSd, uint32_t dwAddr, void *pData, uint32_t dwNbBlocks, fSdmmcCallback fCallback, void *pArg)
uint8_t SD_Write (sSdCard *pSd, uint32_t dwAddr, const void *pData, uint32_t dwNbBlocks, fSdmmcCallback fCallback, void *pArg)
uint8_t SDIO_ReadDirect (sSdCard *pSd, uint8_t bFunctionNum, uint32_t dwAddress, uint8_t *pData, uint32_t dwSize)
uint8_t SDIO_WriteDirect (sSdCard *pSd, uint8_t bFunctionNum, uint32_t dwAddress, uint8_t bDataByte)
uint8_t SDIO_ReadBytes (sSdCard *pSd, uint8_t bFunctionNum, uint32_t dwAddress, uint8_t bIsFixedAddress, uint8_t *pData, uint16_t wSize, fSdmmcCallback fCallback, void *pArg)
uint8_t SDIO_WriteBytes (sSdCard *pSd, uint8_t bFunctionNum, uint32_t dwAddress, uint8_t bIsFixedAddress, uint8_t *pData, uint16_t wSize, fSdmmcCallback fCallback, void *pArg)
void _DumpREG (void *pREG, uint32_t dwSize)
 Dump register.
void SDIO_DumpCardInformation (sSdCard *pSd)
void SD_DumpCID (void *pCID)
void SD_DumpCSD (void *pCSD)
void SD_DumpExtCSD (void *pExtCSD)
void SD_DumpSCR (void *pSCR)
void SD_DumpSdStatus (void *pSdST)
 COMPILER_ALIGNED (32) const
void SDD_Initialize (sSdCard *pSd, const void *pDrv, uint8_t bSlot, const sSdHalFunctions *pHalf)
 COMPILER_ALIGNED (32)
 xDMA interrupt handler.

Variables

uint32_t switchStatus [512/32]

Detailed Description

Definitions and functions for SD/MMC card access.


Define Documentation

#define BLOCK_SIZE (   pSd  )     (pSd->wCurrBlockLen)

Return SD/MMC card block size (Default size now, 512B)

Definition at line 170 of file sdmmc.c.

#define CARD_ADDR (   pSd  )     (pSd->wAddress)

Return SD/MMC card address

Definition at line 167 of file sdmmc.c.

#define MMC_ADDRESS (   pSd,
  address 
)
Value:
(((pSd)->dwTotalSize >= 0x7FFFFFFF) ? \
      (address):((address) << 9))

Definition at line 177 of file sdmmc.c.

#define MMC_IsBootModeSupported (   pSd  )     ((MMC_IsVer4(pSd)&&(eMMC_CID_CBX(pSd->CID)==0x01))

Check if MMC card support boot mode (4.3 or later)

Definition at line 201 of file sdmmc.c.

#define MMC_IsBusModeSupported (   pSd  )     (MMC_IsVer4(pSd))

Check if MMC card support 8-bit mode (4.0 or later)

Definition at line 205 of file sdmmc.c.

#define MMC_IsCSDVer1_2 (   pSd  ) 
Value:
((SD_CSD_STRUCTURE(pSd->CSD)==2) \
       ||(SD_CSD_STRUCTURE(pSd->CSD)>2&&MMC_EXT_CSD_STRUCTURE(pSd->EXT)>=2))

Check if MMC CSD structure is 1.2 (3.1 or later)

Definition at line 196 of file sdmmc.c.

#define MMC_IsHsModeSupported (   pSd  )     (MMC_IsCSDVer1_2(pSd)&&(MMC_EXT_CARD_TYPE(pSd->EXT)&0x2))

Check if MMC card support HS mode (4.0 or later)

Definition at line 208 of file sdmmc.c.

#define MMC_IsVer4 (   pSd  )     (MMC_CSD_SPEC_VERS(pSd->CSD) >= 4)

Check if MMC Spec version 4

Definition at line 193 of file sdmmc.c.

#define SD_ADDRESS (   pSd,
  address 
)
Value:
(((pSd)->dwTotalSize >= 0xFFFFFFFF) ? \
      (address):((address) << 9))

Convert block address to SD/MMC command parameter

Definition at line 173 of file sdmmc.c.

#define SD_IsBusModeSupported (   pSd  )     (1)

Check if SD card support 4-bit mode (All SD card)

Definition at line 190 of file sdmmc.c.

#define SD_IsHsModeSupported (   pSd  )     (/*SD_IsVer1_10(pSd)||*/(SD_CSD_STRUCTURE(pSd->CSD)>=1))

Check if SD card support HS mode (1.10 or later)

Definition at line 186 of file sdmmc.c.

#define SD_IsVer1_10 (   pSd  )     (SD_SCR_SD_SPEC(pSd->SCR) >= SD_SCR_SD_SPEC_1_10)

Check if SD Spec version 1.10 or later

Definition at line 182 of file sdmmc.c.


Function Documentation

COMPILER_ALIGNED ( 32   ) 

xDMA interrupt handler.

Start ILI9488 DMA Rx transfer .

Start ILI9488 DMA Rx transfer in SMC mode.

ILI9488 configure window. dwX X start position. dwX Y start position. dwWidth Width of window. dwHeight Height of window.

TWI interrupt handler. Forwards the interrupt to the TWI driver handler.

Handler for UART4.

AFE output value

Process UART4 interrupts

Pins to configure for the application.

Date buffer MCI interrupt handler. Forwards the event to the MCI driver handlers.

Double-buffer for storing incoming USART data. Invoked when the configuration of the device changes. Parse used endpoints.

Parameters:
cfgnum New configuration number.

Buffer for USB requests data

Parameters:
pRxBuffer point to Rx buffer address
wRxSize Rx buffer size in byte
Returns:
0 if the xDMA transfer successfully; otherwise returns ILI9488_DMA_ERROR_XXX.
Parameters:
Instr Instruct
pTxData point to Tx buffer address
pRxData point to Rx buffer address
ReadWrite Command/Write/Read access
Size buffer size in byte
Returns:
0

Definition at line 115 of file main.c.

Here is the call graph for this function:

void SD_DeInit ( sSdCard pSd  ) 

De-initialize the driver. Invoked when SD card disconnected.

Parameters:
pSd Pointer to a SD card driver instance.

Definition at line 2824 of file sdmmc.c.

void SD_DumpCID ( void *  pCID  ) 

Display the content of the CID register

Parameters:
pCID Pointer to CID data.

Definition at line 3162 of file sdmmc.c.

void SD_DumpCSD ( void *  pCSD  ) 

Display the content of the CSD register

Parameters:
pSd Pointer to sSdCard instance.

Definition at line 3224 of file sdmmc.c.

void SD_DumpExtCSD ( void *  pExtCSD  ) 

Display the content of the EXT_CSD register

Parameters:
pExtCSD Pointer to extended CSD data.

Definition at line 3311 of file sdmmc.c.

void SD_DumpSCR ( void *  pSCR  ) 

Display the content of the SCR register

Parameters:
pSCR Pointer to SCR data.

Definition at line 3389 of file sdmmc.c.

void SD_DumpSdStatus ( void *  pSdST  ) 

Display the content of the SD Status

Parameters:
pSdST Pointer to SD card status data.

Definition at line 3410 of file sdmmc.c.

uint32_t SD_GetBlockSize ( sSdCard pSd  ) 

Return reported block size of the SD/MMC card. (SD/MMC access block size is always 512B for R/W).

Parameters:
pSd Pointer to sSdCard instance.

Definition at line 2863 of file sdmmc.c.

uint8_t SD_GetCardType ( sSdCard pSd  ) 

Return type of the card.

Parameters:
pSd Pointer to sSdCard instance.
See also:
SD/MMC Card Types

Definition at line 2837 of file sdmmc.c.

uint32_t SD_GetNumberBlocks ( sSdCard pSd  ) 

Return reported number of blocks for the SD/MMC card.

Parameters:
pSd Pointer to sSdCard instance.

Definition at line 2874 of file sdmmc.c.

uint32_t SD_GetTotalSizeKB ( sSdCard pSd  ) 

Return size of the SD/MMC card, in KB.

Parameters:
pSd Pointer to sSdCard instance.

Definition at line 2848 of file sdmmc.c.

uint8_t SD_Init ( sSdCard pSd  ) 

Run the SDcard initialization sequence. This function runs the initialisation procedure and the identification process, then it sets the SD card in transfer state to set the block length and the bus width.

Returns:
0 if successful; otherwise returns an error code.
Parameters:
pSd Pointer to a SD card driver instance.

Definition at line 2716 of file sdmmc.c.

uint8_t SD_Read ( sSdCard pSd,
uint32_t  address,
void *  pData,
uint32_t  length,
fSdmmcCallback  pCallback,
void *  pArgs 
)

Read Blocks of data in a buffer pointed by pData. The buffer size must be at least 512 byte long. This function checks the SD card status register and address the card if required before sending the read command.

Returns:
0 if successful; otherwise returns an error code.
Parameters:
pSd Pointer to a SD card driver instance.
address Address of the block to read.
pData Data buffer whose size is at least the block size, it can be 1,2 or 4-bytes aligned when used with DMA.
length Number of blocks to be read.
pCallback Pointer to callback function that invoked when read done. 0 to start a blocked read.
pArgs Pointer to callback function arguments.

Definition at line 2528 of file sdmmc.c.

uint8_t SD_ReadBlocks ( sSdCard pSd,
uint32_t  address,
void *  pData,
uint32_t  nbBlocks 
)

Read Blocks of data in a buffer pointed by pData. The buffer size must be at least 512 byte long. This function checks the SD card status register and address the card if required before sending the read command.

Returns:
0 if successful; otherwise returns an error code.
Parameters:
pSd Pointer to a SD card driver instance.
address Address of the block to read.
nbBlocks Number of blocks to be read.
pData Data buffer whose size is at least the block size, it can be 1,2 or 4-bytes aligned when used with DMA.

Definition at line 2593 of file sdmmc.c.

uint8_t SD_Write ( sSdCard pSd,
uint32_t  address,
const void *  pData,
uint32_t  length,
fSdmmcCallback  pCallback,
void *  pArgs 
)

Write Blocks of data in a buffer pointed by pData. The buffer size must be at least 512 byte long. This function checks the SD card status register and address the card if required before sending the read command.

Returns:
0 if successful; otherwise returns an error code.
Parameters:
pSd Pointer to a SD card driver instance.
address Address of the block to write.
pData Data buffer whose size is at least the block size, it can be 1,2 or 4-bytes aligned when used with DMA.
length Number of blocks to be write.
pCallback Pointer to callback function that invoked when write done. 0 to start a blocked write.
pArgs Pointer to callback function arguments.

Definition at line 2563 of file sdmmc.c.

uint8_t SD_WriteBlocks ( sSdCard pSd,
uint32_t  address,
const void *  pData,
uint32_t  nbBlocks 
)

Write Block of data pointed by pData. The buffer size must be at least 512 byte long. This function checks the SD card status register and address the card if required before sending the read command.

Returns:
0 if successful; otherwise returns an error code.
Parameters:
pSd Pointer to a SD card driver instance.
address Address of block to write.
nbBlocks Number of blocks to be read
pData Data buffer whose size is at least the block size, it can be 1,2 or 4-bytes aligned when used with DMA.

Definition at line 2631 of file sdmmc.c.

void SDD_Initialize ( sSdCard pSd,
const void *  pDrv,
uint8_t  bSlot,
const sSdHalFunctions pHalf 
)

Initialize SD/MMC driver structure.

Parameters:
pSd Pointer to a SD card driver instance.
pDrv Pointer to low level driver instance.
bSlot Slot number.
pHalf Pointer to hardware access functions.

Definition at line 2697 of file sdmmc.c.

void SDIO_DumpCardInformation ( sSdCard pSd  ) 

Display SDIO card informations (CIS, tuple ...)

Parameters:
pSd Pointer to sSdCard instance.

Definition at line 3064 of file sdmmc.c.

Here is the call graph for this function:

uint8_t SDIO_ReadBytes ( sSdCard pSd,
uint8_t  functionNum,
uint32_t  address,
uint8_t  isFixedAddress,
uint8_t *  pData,
uint16_t  size,
fSdmmcCallback  fCallback,
void *  pArg 
)

Read byte by byte from SDIO card, using RW_EXTENDED command.

Parameters:
pSd Pointer to SdCard instance.
functionNum Function number.
address First byte address of data in SDIO card.
isFixedAddress During transfer the data address is never increased.
pData Pointer to data buffer.
size Size of data to read (1 ~ 512).
fCallback Callback function invoked when transfer finished.
pArg Pointer to callback argument.
Returns:
0 if successful; otherwise returns an error code.

Definition at line 2973 of file sdmmc.c.

uint8_t SDIO_ReadDirect ( sSdCard pSd,
uint8_t  functionNum,
uint32_t  address,
uint8_t *  pData,
uint32_t  size 
)

Read one or more bytes from SDIO card, using RW_DIRECT command.

Parameters:
pSd Pointer to SdCard instance.
functionNum Function number.
address First register address to read from.
pData Pointer to data buffer.
size Buffer size, number of bytes to read.
Returns:
0 if successful; otherwise returns an error code.

Definition at line 2890 of file sdmmc.c.

uint8_t SDIO_WriteBytes ( sSdCard pSd,
uint8_t  functionNum,
uint32_t  address,
uint8_t  isFixedAddress,
uint8_t *  pData,
uint16_t  size,
fSdmmcCallback  fCallback,
void *  pArg 
)

Write byte by byte to SDIO card, using RW_EXTENDED command.

Parameters:
pSd Pointer to SdCard instance.
functionNum Function number.
address First byte address of data in SDIO card.
isFixedAddress During transfer the data address is never increased.
pData Pointer to data buffer.
size Size of data to write (1 ~ 512).
fCallback Callback function invoked when transfer finished.
pArg Pointer to callback argument.
Returns:
0 if successful; otherwise returns an error code.

Definition at line 3021 of file sdmmc.c.

uint8_t SDIO_WriteDirect ( sSdCard pSd,
uint8_t  functionNum,
uint32_t  address,
uint8_t  dataByte 
)

Write one byte to SDIO card, using RW_DIRECT command.

Parameters:
pSd Pointer to SdCard instance.
functionNum Function number.
address Register address to write to.
dataByte Data to write.
Returns:
0 if successful; otherwise returns an error code.

Definition at line 2933 of file sdmmc.c.

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines