LPCOpen Platform for LPC18XX/43XX microcontrollers  18XX43XX
LPCOpen Platform for the NXP LPC18XX/43XX family of Microcontrollers
Data Structures | Macros | Functions
CHIP: LPC18xx/43xx SD/MMC driver

Detailed Description

Data Structures

struct  mci_card_struct
 

Macros

#define CMD_MASK_RESP   (0x3UL << 28)
 
#define CMD_RESP(r)   (((r) & 0x3) << 28)
 
#define CMD_RESP_R0   (0 << 28)
 
#define CMD_RESP_R1   (1 << 28)
 
#define CMD_RESP_R2   (2 << 28)
 
#define CMD_RESP_R3   (3 << 28)
 
#define CMD_BIT_AUTO_STOP   (1 << 24)
 
#define CMD_BIT_APP   (1 << 23)
 
#define CMD_BIT_INIT   (1 << 22)
 
#define CMD_BIT_BUSY   (1 << 21)
 
#define CMD_BIT_LS   (1 << 20) /* Low speed, used during acquire */
 
#define CMD_BIT_DATA   (1 << 19)
 
#define CMD_BIT_WRITE   (1 << 18)
 
#define CMD_BIT_STREAM   (1 << 17)
 
#define CMD_MASK_CMD   (0xff)
 
#define CMD_SHIFT_CMD   (0)
 
#define CMD(c, r)   ( ((c) & CMD_MASK_CMD) | CMD_RESP((r)) )
 
#define CMD_IDLE   CMD(MMC_GO_IDLE_STATE, 0) | CMD_BIT_LS | CMD_BIT_INIT
 
#define CMD_SD_OP_COND   CMD(SD_APP_OP_COND, 1) | CMD_BIT_LS | CMD_BIT_APP
 
#define CMD_SD_SEND_IF_COND   CMD(SD_CMD8, 1) | CMD_BIT_LS
 
#define CMD_MMC_OP_COND   CMD(MMC_SEND_OP_COND, 3) | CMD_BIT_LS | CMD_BIT_INIT
 
#define CMD_ALL_SEND_CID   CMD(MMC_ALL_SEND_CID, 2) | CMD_BIT_LS
 
#define CMD_MMC_SET_RCA   CMD(MMC_SET_RELATIVE_ADDR, 1) | CMD_BIT_LS
 
#define CMD_SD_SEND_RCA   CMD(SD_SEND_RELATIVE_ADDR, 1) | CMD_BIT_LS
 
#define CMD_SEND_CSD   CMD(MMC_SEND_CSD, 2) | CMD_BIT_LS
 
#define CMD_SEND_EXT_CSD   CMD(MMC_SEND_EXT_CSD, 1) | CMD_BIT_LS | CMD_BIT_DATA
 
#define CMD_DESELECT_CARD   CMD(MMC_SELECT_CARD, 0)
 
#define CMD_SELECT_CARD   CMD(MMC_SELECT_CARD, 1)
 
#define CMD_SET_BLOCKLEN   CMD(MMC_SET_BLOCKLEN, 1)
 
#define CMD_SEND_STATUS   CMD(MMC_SEND_STATUS, 1)
 
#define CMD_READ_SINGLE   CMD(MMC_READ_SINGLE_BLOCK, 1) | CMD_BIT_DATA
 
#define CMD_READ_MULTIPLE   CMD(MMC_READ_MULTIPLE_BLOCK, 1) | CMD_BIT_DATA | CMD_BIT_AUTO_STOP
 
#define CMD_SD_SET_WIDTH   CMD(SD_APP_SET_BUS_WIDTH, 1) | CMD_BIT_APP
 
#define CMD_STOP   CMD(MMC_STOP_TRANSMISSION, 1) | CMD_BIT_BUSY
 
#define CMD_WRITE_SINGLE   CMD(MMC_WRITE_BLOCK, 1) | CMD_BIT_DATA | CMD_BIT_WRITE
 
#define CMD_WRITE_MULTIPLE   CMD(MMC_WRITE_MULTIPLE_BLOCK, 1) | CMD_BIT_DATA | CMD_BIT_WRITE | CMD_BIT_AUTO_STOP
 

Functions

int32_t Chip_SDMMC_GetState (LPC_SDMMC_T *pSDMMC)
 Get card's current state (idle, transfer, program, etc.) More...
 
uint32_t Chip_SDMMC_Acquire (LPC_SDMMC_T *pSDMMC, mci_card_struct *pcardinfo)
 Function to enumerate the SD/MMC/SDHC/MMC+ cards. More...
 
uint64_t Chip_SDMMC_GetDeviceSize (LPC_SDMMC_T *pSDMMC)
 Get the device size of SD/MMC card (after enumeration) More...
 
int32_t Chip_SDMMC_GetDeviceBlocks (LPC_SDMMC_T *pSDMMC)
 Get the number of device blocks of SD/MMC card (after enumeration) Since Chip_SDMMC_GetDeviceSize is limited to 32 bits cards with greater than 2 GBytes of data will not be correct, in such cases users can use this function to get the size of the card in blocks. More...
 
int32_t Chip_SDMMC_ReadBlocks (LPC_SDMMC_T *pSDMMC, void *buffer, int32_t start_block, int32_t num_blocks)
 Performs the read of data from the SD/MMC card. More...
 
int32_t Chip_SDMMC_WriteBlocks (LPC_SDMMC_T *pSDMMC, void *buffer, int32_t start_block, int32_t num_blocks)
 Performs write of data to the SD/MMC card. More...
 

Macro Definition Documentation

#define CMD (   c,
 
)    ( ((c) & CMD_MASK_CMD) | CMD_RESP((r)) )

Definition at line 63 of file sdmmc_18xx_43xx.h.

#define CMD_ALL_SEND_CID   CMD(MMC_ALL_SEND_CID, 2) | CMD_BIT_LS

Definition at line 69 of file sdmmc_18xx_43xx.h.

#define CMD_BIT_APP   (1 << 23)

Definition at line 53 of file sdmmc_18xx_43xx.h.

#define CMD_BIT_AUTO_STOP   (1 << 24)

Definition at line 52 of file sdmmc_18xx_43xx.h.

#define CMD_BIT_BUSY   (1 << 21)

Definition at line 55 of file sdmmc_18xx_43xx.h.

#define CMD_BIT_DATA   (1 << 19)

Definition at line 57 of file sdmmc_18xx_43xx.h.

#define CMD_BIT_INIT   (1 << 22)

Definition at line 54 of file sdmmc_18xx_43xx.h.

#define CMD_BIT_LS   (1 << 20) /* Low speed, used during acquire */

Definition at line 56 of file sdmmc_18xx_43xx.h.

#define CMD_BIT_STREAM   (1 << 17)

Definition at line 59 of file sdmmc_18xx_43xx.h.

#define CMD_BIT_WRITE   (1 << 18)

Definition at line 58 of file sdmmc_18xx_43xx.h.

#define CMD_DESELECT_CARD   CMD(MMC_SELECT_CARD, 0)

Definition at line 74 of file sdmmc_18xx_43xx.h.

#define CMD_IDLE   CMD(MMC_GO_IDLE_STATE, 0) | CMD_BIT_LS | CMD_BIT_INIT

Definition at line 65 of file sdmmc_18xx_43xx.h.

#define CMD_MASK_CMD   (0xff)

Definition at line 60 of file sdmmc_18xx_43xx.h.

#define CMD_MASK_RESP   (0x3UL << 28)

Definition at line 46 of file sdmmc_18xx_43xx.h.

#define CMD_MMC_OP_COND   CMD(MMC_SEND_OP_COND, 3) | CMD_BIT_LS | CMD_BIT_INIT

Definition at line 68 of file sdmmc_18xx_43xx.h.

#define CMD_MMC_SET_RCA   CMD(MMC_SET_RELATIVE_ADDR, 1) | CMD_BIT_LS

Definition at line 70 of file sdmmc_18xx_43xx.h.

#define CMD_READ_MULTIPLE   CMD(MMC_READ_MULTIPLE_BLOCK, 1) | CMD_BIT_DATA | CMD_BIT_AUTO_STOP

Definition at line 79 of file sdmmc_18xx_43xx.h.

#define CMD_READ_SINGLE   CMD(MMC_READ_SINGLE_BLOCK, 1) | CMD_BIT_DATA

Definition at line 78 of file sdmmc_18xx_43xx.h.

#define CMD_RESP (   r)    (((r) & 0x3) << 28)

Definition at line 47 of file sdmmc_18xx_43xx.h.

#define CMD_RESP_R0   (0 << 28)

Definition at line 48 of file sdmmc_18xx_43xx.h.

#define CMD_RESP_R1   (1 << 28)

Definition at line 49 of file sdmmc_18xx_43xx.h.

#define CMD_RESP_R2   (2 << 28)

Definition at line 50 of file sdmmc_18xx_43xx.h.

#define CMD_RESP_R3   (3 << 28)

Definition at line 51 of file sdmmc_18xx_43xx.h.

#define CMD_SD_OP_COND   CMD(SD_APP_OP_COND, 1) | CMD_BIT_LS | CMD_BIT_APP

Definition at line 66 of file sdmmc_18xx_43xx.h.

#define CMD_SD_SEND_IF_COND   CMD(SD_CMD8, 1) | CMD_BIT_LS

Definition at line 67 of file sdmmc_18xx_43xx.h.

#define CMD_SD_SEND_RCA   CMD(SD_SEND_RELATIVE_ADDR, 1) | CMD_BIT_LS

Definition at line 71 of file sdmmc_18xx_43xx.h.

#define CMD_SD_SET_WIDTH   CMD(SD_APP_SET_BUS_WIDTH, 1) | CMD_BIT_APP

Definition at line 80 of file sdmmc_18xx_43xx.h.

#define CMD_SELECT_CARD   CMD(MMC_SELECT_CARD, 1)

Definition at line 75 of file sdmmc_18xx_43xx.h.

#define CMD_SEND_CSD   CMD(MMC_SEND_CSD, 2) | CMD_BIT_LS

Definition at line 72 of file sdmmc_18xx_43xx.h.

#define CMD_SEND_EXT_CSD   CMD(MMC_SEND_EXT_CSD, 1) | CMD_BIT_LS | CMD_BIT_DATA

Definition at line 73 of file sdmmc_18xx_43xx.h.

#define CMD_SEND_STATUS   CMD(MMC_SEND_STATUS, 1)

Definition at line 77 of file sdmmc_18xx_43xx.h.

#define CMD_SET_BLOCKLEN   CMD(MMC_SET_BLOCKLEN, 1)

Definition at line 76 of file sdmmc_18xx_43xx.h.

#define CMD_SHIFT_CMD   (0)

Definition at line 61 of file sdmmc_18xx_43xx.h.

#define CMD_STOP   CMD(MMC_STOP_TRANSMISSION, 1) | CMD_BIT_BUSY

Definition at line 81 of file sdmmc_18xx_43xx.h.

#define CMD_WRITE_MULTIPLE   CMD(MMC_WRITE_MULTIPLE_BLOCK, 1) | CMD_BIT_DATA | CMD_BIT_WRITE | CMD_BIT_AUTO_STOP

Definition at line 83 of file sdmmc_18xx_43xx.h.

#define CMD_WRITE_SINGLE   CMD(MMC_WRITE_BLOCK, 1) | CMD_BIT_DATA | CMD_BIT_WRITE

Definition at line 82 of file sdmmc_18xx_43xx.h.

Function Documentation

uint32_t Chip_SDMMC_Acquire ( LPC_SDMMC_T pSDMMC,
mci_card_struct pcardinfo 
)

Function to enumerate the SD/MMC/SDHC/MMC+ cards.

Parameters
pSDMMC: SDMMC peripheral selected
pcardinfo: Pointer to pre-allocated card info structure
Returns
1 if a card is acquired, otherwise 0

Definition at line 322 of file sdmmc_18xx_43xx.c.

int32_t Chip_SDMMC_GetDeviceBlocks ( LPC_SDMMC_T pSDMMC)

Get the number of device blocks of SD/MMC card (after enumeration) Since Chip_SDMMC_GetDeviceSize is limited to 32 bits cards with greater than 2 GBytes of data will not be correct, in such cases users can use this function to get the size of the card in blocks.

Parameters
pSDMMC: SDMMC peripheral selected
Returns
Number of 512 bytes blocks in the card

Definition at line 490 of file sdmmc_18xx_43xx.c.

uint64_t Chip_SDMMC_GetDeviceSize ( LPC_SDMMC_T pSDMMC)

Get the device size of SD/MMC card (after enumeration)

Parameters
pSDMMC: SDMMC peripheral selected
Returns
Card size in number of bytes (capacity)

Definition at line 484 of file sdmmc_18xx_43xx.c.

int32_t Chip_SDMMC_GetState ( LPC_SDMMC_T pSDMMC)

Get card's current state (idle, transfer, program, etc.)

Parameters
pSDMMC: SDMMC peripheral selected
Returns
Current SD card transfer state

Definition at line 307 of file sdmmc_18xx_43xx.c.

int32_t Chip_SDMMC_ReadBlocks ( LPC_SDMMC_T pSDMMC,
void *  buffer,
int32_t  start_block,
int32_t  num_blocks 
)

Performs the read of data from the SD/MMC card.

Parameters
pSDMMC: SDMMC peripheral selected
buffer: Pointer to data buffer to copy to
start_block: Start block number
num_blocks: Number of block to read
Returns
Bytes read, or 0 on error

Definition at line 496 of file sdmmc_18xx_43xx.c.

int32_t Chip_SDMMC_WriteBlocks ( LPC_SDMMC_T pSDMMC,
void *  buffer,
int32_t  start_block,
int32_t  num_blocks 
)

Performs write of data to the SD/MMC card.

Parameters
pSDMMC: SDMMC peripheral selected
buffer: Pointer to data buffer to copy to
start_block: Start block number
num_blocks: Number of block to write
Returns
Number of bytes actually written, or 0 on error

Definition at line 543 of file sdmmc_18xx_43xx.c.