| Summary |
#include <file_config.h>
BOOL Command (
U8 cmd, /* Command code for SD Card */
U32 arg, /* Command Argument */
U32 resp_type, /* Command Response type */
U32* rp); /* Buffer to recive a response */
|
| Description | The function Command sends a command to the Flash memory card. The parameter cmd is one of the available SD/MMC Commands. The parameter arg is a 32-bit SD Command argument. The parameter resp_type specifies the expected response type: | Type | Description |
|---|
| RESP_NONE | No response expected. | | RESP_SHORT | 4-byte short response expected. | | RESP_LONG | 16-byte long response expected. |
The parameter rp is a pointer to a buffer to store the response. The function is part of the MCI Driver. The prototype is defined in the file File_Config.h. Developers must customize the function. |
| Example |
/* MCI Device Driver Control Block */
MCI_DRV mci0_drv = {
Init,
UnInit,
Delay,
BusMode,
BusWidth,
BusSpeed,
Command,
ReadBlock,
WriteBlock,
NULL,
CheckMedia
};
/* Send a Command to Flash card and get a response. */
static BOOL Command (U8 cmd, U32 arg, U32 resp_type, U32 *rp) {
U32 cmdval,stat;
cmd &= 0x3F;
cmdval = 0x400 | cmd;
switch (resp_type) {
case RESP_SHORT:
cmdval |= 0x40;
break;
case RESP_LONG:
cmdval |= 0xC0;
break;
}
MCI_ARGUMENT = arg;
MCI_COMMAND = cmdval; /* Send the command. */
if (resp_type == RESP_NONE) {
while (MCI_STATUS & MCI_CMD_ACTIVE); /* Wait until command finished. */
MCI_CLEAR = 0x7FF;
return (__TRUE);
}
for (;;) {
stat = MCI_STATUS;
if (stat & MCI_CMD_TIMEOUT) {
MCI_CLEAR = stat & MCI_CLEAR_MASK;
return (__FALSE);
}
if (stat & MCI_CMD_CRC_FAIL) {
MCI_CLEAR = stat & MCI_CLEAR_MASK;
if ((cmd == SEND_OP_COND) ||
(cmd == SEND_APP_OP_COND) ||
(cmd == STOP_TRANS)) {
MCI_COMMAND = 0;
break;
}
return (__FALSE);
}
if (stat & MCI_CMD_RESP_END) {
MCI_CLEAR = stat & MCI_CLEAR_MASK;
break;
}
}
if ((MCI_RESP_CMD & 0x3F) != cmd) {
if ((cmd != SEND_OP_COND) &&
(cmd != SEND_APP_OP_COND) &&
(cmd != ALL_SEND_CID) &&
(cmd != SEND_CSD)) {
return (__FALSE);
}
}
rp[0] = MCI_RESP0; /* Read MCI response registers */
if (resp_type == RESP_LONG) {
rp[1] = MCI_RESP1;
rp[2] = MCI_RESP2;
rp[3] = MCI_RESP3;
}
return (__TRUE);
}
|