?? sdmmc_mci.c
字號:
if( (R1 & R1_SPI_IDLE)==R1_SPI_IDLE) {
TRACE_DEBUG("R1_SPI_IDLE\n\r");
}
if( (R1 & R1_SPI_ERASE_RESET)==R1_SPI_ERASE_RESET) {
TRACE_DEBUG("R1_SPI_ERASE_RESET\n\r");
}
if( (R1 & R1_SPI_ILLEGAL_COMMAND)==R1_SPI_ILLEGAL_COMMAND) {
TRACE_DEBUG("R1_SPI_ILLEGAL_COMMAND\n\r");
}
if( (R1 & R1_SPI_COM_CRC)==R1_SPI_COM_CRC) {
TRACE_DEBUG("R1_SPI_COM_CRC\n\r");
}
if( (R1 & R1_SPI_ERASE_SEQ)==R1_SPI_ERASE_SEQ) {
TRACE_DEBUG("R1_SPI_ERASE_SEQ\n\r");
}
if( (R1 & R1_SPI_ADDRESS)==R1_SPI_ADDRESS) {
TRACE_DEBUG("R1_SPI_ADDRESS\n\r");
}
if( (R1 & R1_SPI_PARAMETER)==R1_SPI_PARAMETER) {
TRACE_DEBUG("R1_SPI_PARAMETER\n\r");
}
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void DecodeR2(unsigned char R2)
{
if( (R2 & R2_SPI_CARD_LOCKED)==R2_SPI_CARD_LOCKED) {
TRACE_DEBUG("R2_SPI_CARD_LOCKED\n\r");
}
if( (R2 & R2_SPI_WP_ERASE_SKIP)==R2_SPI_WP_ERASE_SKIP) {
TRACE_DEBUG("R2_SPI_WP_ERASE_SKIP/R2_SPI_LOCK_UNLOCK_FAIL\n\r");
}
if( (R2 & R2_SPI_ERROR)==R2_SPI_ERROR) {
TRACE_DEBUG("R2_SPI_ERROR\n\r");
}
if( (R2 & R2_SPI_CC_ERROR)==R2_SPI_CC_ERROR) {
TRACE_DEBUG("R2_SPI_CC_ERROR\n\r");
}
if( (R2 & R2_SPI_CARD_ECC_ERROR)==R2_SPI_CARD_ECC_ERROR) {
TRACE_DEBUG("R2_SPI_CARD_ECC_ERROR\n\r");
}
if( (R2 & R2_SPI_WP_VIOLATION)==R2_SPI_WP_VIOLATION) {
TRACE_DEBUG("R2_SPI_WP_VIOLATION\n\r");
}
if( (R2 & R2_SPI_ERASE_PARAM)==R2_SPI_ERASE_PARAM) {
TRACE_DEBUG("R2_SPI_ERASE_PARAM\n\r");
}
if( (R2 & R2_SPI_OUT_OF_RANGE)==R2_SPI_OUT_OF_RANGE) {
TRACE_DEBUG("R2_SPI_OUT_OF_RANGE/R2_SPI_CSD_OVERWRITE\n\r");
}
}
//------------------------------------------------------------------------------
/// Initialization delay: The maximum of 1 msec, 74 clock cycles and supply ramp
/// up time.
/// Returns the command transfer result (see SendCommand).
/// \param pSd Pointer to a SdCard driver instance.
//------------------------------------------------------------------------------
static unsigned char Pon(SdCard *pSd)
{
SdCmd *pCommand = &(pSd->command);
unsigned int response;
unsigned char error;
memset(pCommand, 0, sizeof(SdCmd));
// Fill command information
pCommand->cmd = AT91C_POWER_ON_INIT;
pCommand->pResp = &response;
// Set SD command state
pSd->state = SD_STATE_STBY;
// Send command
error = SendCommand(pSd);
return error;
}
//------------------------------------------------------------------------------
/// Resets all cards to idle state
/// Returns the command transfer result (see SendCommand).
/// \param pSd Pointer to a SdCard driver instance.
//------------------------------------------------------------------------------
static unsigned char Cmd0(SdCard *pSd)
{
SdCmd *pCommand = &(pSd->command);
unsigned int response;
unsigned char error;
TRACE_DEBUG("Cmd0()\n\r");
memset(pCommand, 0, sizeof(SdCmd));
// Fill command information
pCommand->cmd = AT91C_GO_IDLE_STATE_CMD;
pCommand->pResp = &response;
// Set SD command state
pSd->state = SD_STATE_STBY;
// send command
error = SendCommand(pSd);
return error;
}
//------------------------------------------------------------------------------
/// MMC send operation condition command.
/// Sends host capacity support information and activates the card's
/// initialization process.
/// Returns the command transfer result (see SendCommand).
/// \param pSd Pointer to a SdCard driver instance.
//------------------------------------------------------------------------------
static unsigned char Cmd1(SdCard *pSd)
{
SdCmd *pCommand = &(pSd->command);
unsigned char error;
unsigned int response;
TRACE_DEBUG("Cmd1()\n\r");
memset(pCommand, 0, sizeof(SdCmd));
// Fill command information
pCommand->cmd = AT91C_MMC_SEND_OP_COND_CMD;
pCommand->arg = AT91C_MMC_HOST_VOLTAGE_RANGE;
pCommand->resType = 3;
pCommand->pResp = &response;
// Set SD command state
pSd->state = SD_STATE_STBY;
// send command
error = SendCommand(pSd);
if (error) {
return error;
}
if ((response & AT91C_CARD_POWER_UP_BUSY) == AT91C_CARD_POWER_UP_BUSY) {
return 0;
}
else {
return SD_ERROR_DRIVER;
}
}
//------------------------------------------------------------------------------
/// Asks any card to send the CID numbers
/// on the CMD line (any card that is
/// connected to the host will respond)
/// Returns the command transfer result (see SendCommand).
/// \param pSd Pointer to a SD card driver instance.
/// \param pCid Buffer for storing the CID numbers.
//------------------------------------------------------------------------------
static unsigned char Cmd2(SdCard *pSd, unsigned int *pCid)
{
SdCmd *pCommand = &(pSd->command);
TRACE_DEBUG("Cmd2()\n\r");
memset(pCommand, 0, sizeof(SdCmd));
// Fill the command information
pCommand->cmd = AT91C_ALL_SEND_CID_CMD;
pCommand->resType = 2;
pCommand->pResp = pCid;
// Set SD command state
pSd->state = SD_STATE_STBY;
// Send the command
return SendCommand(pSd);
}
//------------------------------------------------------------------------------
/// Ask the card to publish a new relative address (RCA)
/// Returns the command transfer result (see SendCommand).
/// \param pSd Pointer to a SD card driver instance.
//------------------------------------------------------------------------------
static unsigned char Cmd3(SdCard *pSd)
{
SdCmd *pCommand = &(pSd->command);
unsigned int cardAddress;
unsigned char error;
TRACE_DEBUG("Cmd3()\n\r");
memset(pCommand, 0, sizeof(SdCmd));
// Fill command information
pCommand->cmd = AT91C_SET_RELATIVE_ADDR_CMD;
// Assign relative address to MMC card
if (pSd->cardType == CARD_MMC) {
pCommand->arg = (0x1 << 16);
}
pCommand->resType = 1;
pCommand->pResp = &cardAddress;
// Set SD command state
pSd->state = SD_STATE_STBY;
// Send command
error = SendCommand(pSd);
if (error) {
return error;
}
// Save card address in driver
if (pSd->cardType != CARD_MMC) {
pSd->cardAddress = (cardAddress >> 16) & 0xFFFF;
}
else {
// Default MMC RCA is 0x0001
pSd->cardAddress = 1;
}
return 0;
}
//------------------------------------------------------------------------------
/// Command toggles a card between the
/// stand-by and transfer states or between
/// the programming and disconnect states.
/// Returns the command transfer result (see SendCommand).
/// \param pSd Pointer to a SD card driver instance.
/// \param address Relative Card Address (0 deselects all).
//------------------------------------------------------------------------------
static unsigned char Cmd7(SdCard *pSd, unsigned int address)
{
SdCmd *pCommand = &(pSd->command);
TRACE_DEBUG("Cmd7()\n\r");
memset(pCommand, 0, sizeof(SdCmd));
// Fill command information
pCommand->cmd = AT91C_SEL_DESEL_CARD_CMD;
pCommand->arg = address << 16;
pCommand->resType = 1;
// Set SD command state
pSd->state = SD_STATE_STBY;
// Send command
return SendCommand(pSd);
}
//------------------------------------------------------------------------------
/// Sends SD Memory Card interface
/// condition, which includes host supply
/// voltage information and asks the card
/// whether card supports voltage.
/// Returns 0 if successful; otherwise returns SD_ERROR_NORESPONSE if the card did
/// not answer the command, or SD_ERROR_DRIVER.
/// \param pSd Pointer to a SD card driver instance.
/// \param supplyVoltage Expected supply voltage.
//------------------------------------------------------------------------------
static unsigned char Cmd8(SdCard *pSd, unsigned char supplyVoltage)
{
SdCmd *pCommand = &(pSd->command);
unsigned int response[2];
unsigned char error;
TRACE_DEBUG("Cmd8()\n\r");
memset(pCommand, 0, sizeof(SdCmd));
// Fill command information
pCommand->cmd = AT91C_SEND_IF_COND;
pCommand->arg = (supplyVoltage << 8) | (0xAA);
pCommand->resType = 7;
pCommand->pResp = &response[0];
// Set SD command state
pSd->state = SD_STATE_STBY;
TRACE_DEBUG("supplyVoltage: 0x%x\n\r", supplyVoltage);
// Send command
error = SendCommand(pSd);
// Check result
if (error == MCI_STATUS_NORESPONSE) {
return SD_ERROR_NORESPONSE;
}
// SD_R7
// Bit 0 - 7: check pattern
// Bit 8 -11: voltage accepted
else if (!error && ((response[0] & 0x00000FFF) == ((supplyVoltage << 8) | 0xAA))) {
return 0;
}
else {
return SD_ERROR_DRIVER;
}
}
//------------------------------------------------------------------------------
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -