状态寄存器总是显示超时uint32 MCI_Send_ACMD( void )
{
uint8 i, retryCount;
uint32 CmdArgument;
uint32 respStatus;
uint32 respValue[4];
if ( MCI_CardType == SD_CARD )
{
CmdArgument = CardRCA; /* Use the address from SET_RELATIVE_ADDR cmd */
}
else /* if MMC or unknown card type, use 0x0. */
{
CmdArgument = 0x00000000;
}
retryCount = 20;
while ( retryCount > 0 )
{
MCI_SendCmd( APP_CMD, CmdArgument, EXPECT_SHORT_RESP, 0 );
respStatus = MCI_GetCmdResp( APP_CMD, EXPECT_SHORT_RESP, (uint32 *)&respValue[0] );
if ( !respStatus && (respValue[0] & CARD_STATUS_ACMD_ENABLE) ) {
return( TRUE );
}
for ( i = 0; i < 0x20; i++ );
retryCount--;
}
return( FALSE );
}
回来的状态respStatus总是超时是为什么啊uint32 MCI_GetCmdResp( uint8 ExpectCmdData, uint32 ExpectResp, uint32 *CmdResp )
{
uint32 CmdRespStatus = 0;
uint32 LastCmdIndex;
if ( ExpectResp == EXPECT_NO_RESP )
{
return ( 0 );
}
while ( 1 )
{
CmdRespStatus = MCI_STATUS; //MCI_STATUS MCI 状态寄存器
if ( CmdRespStatus & (MCI_CMD_TIMEOUT) ) //MCI_CMD_TIMEOUT (1 << 2)
{
MCI_CLEAR = CmdRespStatus | MCI_CMD_TIMEOUT;
MCI_COMMAND = 0;
MCI_ARGUMENT = 0xFFFFFFFF;
return ( CmdRespStatus );
}
if ( CmdRespStatus & MCI_CMD_CRC_FAIL ) // MCI_CMD_CRC_FAIL (1 << 0)
{
MCI_CLEAR = CmdRespStatus | MCI_CMD_CRC_FAIL;
LastCmdIndex = MCI_COMMAND & 0x003F;
if ( (LastCmdIndex == SEND_OP_COND) || (LastCmdIndex == SEND_APP_OP_COND) //SEND_OP_COND 1 SEND_APP_OP_COND 41
|| (LastCmdIndex == STOP_TRANSMISSION) ) {
MCI_COMMAND = 0;
MCI_ARGUMENT = 0xFFFFFFFF;
break; }
else
{
return ( CmdRespStatus );
}
}
else if ( CmdRespStatus & MCI_CMD_RESP_END ) //MCI_CMD_RESP_END (1 << 6)
{
MCI_CLEAR = CmdRespStatus | MCI_CMD_RESP_END;
break; }
}
if ( (MCI_RESP_CMD & 0x3F) != ExpectCmdData ) //MCI_RESP_CMD 命令响应寄存器
{
if ( (ExpectCmdData != SEND_OP_COND) && (ExpectCmdData != SEND_APP_OP_COND)
&& (ExpectCmdData != ALL_SEND_CID) && (ExpectCmdData != SEND_CSD) )
{
CmdRespStatus = INVALID_RESPONSE;
return ( INVALID_RESPONSE );
}
}
if ( ExpectResp == EXPECT_SHORT_RESP )
{
*CmdResp = MCI_RESP0;
}
else if ( ExpectResp == EXPECT_LONG_RESP )
{
*CmdResp = MCI_RESP0;
*(CmdResp+1) = MCI_RESP1;
*(CmdResp+2) = MCI_RESP2;
*(CmdResp+3) = MCI_RESP3;
}
return ( 0 ); }
|