Sending a Command

24 Mar

Sending a Command
For each supported MultiMediaCard command, device firmware needs to know the command index, the response type, the CRC value to send in the command, and whether the command’s six bytes are followed by more data. The code below stores this information about commands using an enumeration, a series of defines, and a table in ROM.

Storing Command Information
The sdmmc_cmd enumeration assigns a value to each command:

typedef enum
{
GO_IDLE_STATE,
SEND_OP_COND,
SEND_CSD,
SEND_CID,
STOP_TRANSMISSION,
SEND_STATUS,
SET_BLOCKLEN,
READ_SINGLE_BLOCK,
READ_MULTI_BLOCK,
WRITE_SINGLE_BLOCK,
WRITE_MULTI_BLOCK,
TAG_SECTOR_START,
TAG_SECTOR_END,
UNTAG_SECTOR,
TAG_ERASE_GRP_START,
TAG_ERASE_GRP_END,
UNTAG_ERASE_GRP,
ERASE,
LOCK_UNLOCK,
SD_APP_OP_COND,
APP_CMD,
READ_OCR,
CRC_ON_OFF
}sdmmc_cmd;

A table in ROM holds additional information about the commands. For each command, the table below stores a command name, CRC value, response type, and whether or not the command is followed by more data. Firmware can identify an entry in the table by specifying a command from the enumeration above. For example, SEND_CSD is the third enumeration constant in the enumeration, and cmdSEND_CSD is the third entry in the table.

#define MOREDATA !0
#define NODATA 0
const rom typSDC_CMD sdmmc_cmdtable[] =
{
// command name CRC response type more data?
{cmdGO_IDLE_STATE, 0×95, R1, NODATA},
{cmdSEND_OP_COND, 0xF9, R1, NODATA},
{cmdSEND_CSD, 0xAF, R1, MOREDATA},
{cmdSEND_CID, 0×1B, R1, MOREDATA},
{cmdSTOP_TRANSMISSION, 0xC3, R1, NODATA},
{cmdSEND_STATUS, 0xAF, R2, NODATA},
{cmdSET_BLOCKLEN, 0xFF, R1, NODATA},
{cmdREAD_SINGLE_BLOCK, 0xFF, R1, MOREDATA},
{cmdREAD_MULTI_BLOCK, 0xFF, R1, MOREDATA},
{cmdWRITE_SINGLE_BLOCK, 0xFF, R1, MOREDATA},
{cmdWRITE_MULTI_BLOCK, 0xFF, R1, MOREDATA},
{cmdTAG_SECTOR_START, 0xFF, R1, NODATA},
{cmdTAG_SECTOR_END, 0xFF, R1, NODATA},
{cmdUNTAG_SECTOR, 0xFF, R1, NODATA},
{cmdTAG_ERASE_GRP_START, 0xFF, R1, NODATA},
{cmdTAG_ERASE_GRP_END, 0xFF, R1, NODATA},
{cmdUNTAG_ERASE_GRP, 0xFF, R1, NODATA},
{cmdERASE, 0xDF, R1b, NODATA},
{cmdLOCK_UNLOCK, 0×89, R1b, NODATA},
{cmdSD_APP_OP_COND, 0xE5, R1, NODATA},
{cmdAPP_CMD, 0×73, R1, NODATA},
{cmdREAD_OCR, 0×25, R3, NODATA},
{cmdCRC_ON_OFF, 0×25, R1, NODATA}
};

In a command’s first byte, bit 7 = 0, bit 6 = 1, and bits 5..0 are the command index. In other words, the first byte in the command equals the command index + 40h.

The code below provides values for the first bytes in MultiMediaCard commands:

Random Posts

No comments yet

Leave a Reply

You must be logged in to post a comment.