edited sdio driver, todo: check crc response handling
This commit is contained in:
parent
b5fbdb4bb6
commit
6e5d32350c
@ -30,8 +30,8 @@ typedef uint8_t CID_t;
|
|||||||
|
|
||||||
void initModuleHw();
|
void initModuleHw();
|
||||||
|
|
||||||
int SDIO_sendCmd(uint8_t CMD, uint32_t arg, uint8_t expectedAns);
|
int SDIO_send_cmd(uint8_t CMD, uint32_t arg, uint8_t expectedAns);
|
||||||
int SDIO_getResp(uint8_t expectedCMD, uint8_t typeOfAns, uint32_t* responseBuffer);
|
int SDIO_get_response(uint8_t expectedCMD, uint8_t typeOfAns, uint32_t* responseBuffer);
|
||||||
|
|
||||||
|
|
||||||
void SDIO_wait_cmd_sent();
|
void SDIO_wait_cmd_sent();
|
||||||
@ -225,7 +225,7 @@ void switchPrescaler(uint8_t clkdiv) {
|
|||||||
//Send Command
|
//Send Command
|
||||||
//Clear respone Flags
|
//Clear respone Flags
|
||||||
//->CRC Fail, complete response, Timeout
|
//->CRC Fail, complete response, Timeout
|
||||||
int SDIO_sendCmd(uint8_t CMD, uint32_t arg, uint8_t expectedAns){
|
int SDIO_send_cmd(uint8_t CMD, uint32_t arg, uint8_t expectedAns){
|
||||||
//Clear Flags
|
//Clear Flags
|
||||||
SDIO->ICR = SDIO_ICR_CCRCFAILC | SDIO_ICR_CMDRENDC | SDIO_ICR_CTIMEOUTC | SDIO_ICR_CMDSENTC;
|
SDIO->ICR = SDIO_ICR_CCRCFAILC | SDIO_ICR_CMDRENDC | SDIO_ICR_CTIMEOUTC | SDIO_ICR_CMDSENTC;
|
||||||
//Send command
|
//Send command
|
||||||
@ -239,7 +239,7 @@ void SDIO_wait_cmd_sent() {
|
|||||||
SDIO->ICR |= SDIO_ICR_CMDSENTC;
|
SDIO->ICR |= SDIO_ICR_CMDSENTC;
|
||||||
}
|
}
|
||||||
|
|
||||||
int SDIO_getResp(uint8_t expectedCMD, uint8_t typeOfAns, uint32_t *responseBuffer) {
|
int SDIO_get_response(uint8_t expectedCMD, uint8_t typeOfAns, uint32_t *responseBuffer) {
|
||||||
//Return with success because no data is needed
|
//Return with success because no data is needed
|
||||||
if (typeOfAns == NO_ANS) return 0;
|
if (typeOfAns == NO_ANS) return 0;
|
||||||
|
|
||||||
@ -249,9 +249,8 @@ int SDIO_getResp(uint8_t expectedCMD, uint8_t typeOfAns, uint32_t *responseBuffe
|
|||||||
|
|
||||||
//Exclude ACMD41 and CMD2 from valid CRC check
|
//Exclude ACMD41 and CMD2 from valid CRC check
|
||||||
if ((SDIO->STA & SDIO_STA_CCRCFAIL)) {
|
if ((SDIO->STA & SDIO_STA_CCRCFAIL)) {
|
||||||
if(expectedCMD == 0x3f) {
|
if(expectedCMD == 0x3f) { // TODO: This seems odd..
|
||||||
//This command does not have a CRC...Doushite....
|
break;
|
||||||
break;//Hopefully the response is correct. Even without CRC....
|
|
||||||
} else
|
} else
|
||||||
return CCRCFAIL;
|
return CCRCFAIL;
|
||||||
}
|
}
|
||||||
@ -281,9 +280,9 @@ int SDIO_send_CMD55(){
|
|||||||
uint32_t response;
|
uint32_t response;
|
||||||
do {
|
do {
|
||||||
//Execute Command and check for valid response
|
//Execute Command and check for valid response
|
||||||
SDIO_sendCmd(55, cardInfo.rca, SHORT_ANS);
|
SDIO_send_cmd(55, cardInfo.rca, SHORT_ANS);
|
||||||
|
|
||||||
if (!SDIO_getResp(55, SHORT_ANS, &response))
|
if (!SDIO_get_response(55, SHORT_ANS, &response))
|
||||||
{
|
{
|
||||||
//Response valid. Check if Card has accepted switch to application command mode
|
//Response valid. Check if Card has accepted switch to application command mode
|
||||||
converter.value = response;
|
converter.value = response;
|
||||||
@ -302,8 +301,8 @@ ACMD41_RESP_t SDIO_send_ACMD41(uint8_t HCS){
|
|||||||
|
|
||||||
do {
|
do {
|
||||||
|
|
||||||
SDIO_sendCmd(41, (HCS ? (1<<30) : 0) | (1<<28), SHORT_ANS);
|
SDIO_send_cmd(41, (HCS ? (1<<30) : 0) | (1<<28), SHORT_ANS);
|
||||||
if (!SDIO_getResp(0x3F, SHORT_ANS, &response)) {
|
if (!SDIO_get_response(0x3F, SHORT_ANS, &response)) {
|
||||||
if (response & OCS_BUSY) { // Card is ready... Who knows why this bit is called busy...
|
if (response & OCS_BUSY) { // Card is ready... Who knows why this bit is called busy...
|
||||||
if (response & OCS_CCS) {
|
if (response & OCS_CCS) {
|
||||||
return ACMD41_RESP_SDXC;
|
return ACMD41_RESP_SDXC;
|
||||||
@ -326,8 +325,8 @@ int SDIO_send_CMD2() {
|
|||||||
uint32_t response[4];
|
uint32_t response[4];
|
||||||
int retry = 0x20;
|
int retry = 0x20;
|
||||||
do {
|
do {
|
||||||
SDIO_sendCmd(2, 0, LONG_ANS);
|
SDIO_send_cmd(2, 0, LONG_ANS);
|
||||||
if (!SDIO_getResp(0x3F, LONG_ANS, response)) return 0;
|
if (!SDIO_get_response(0x3F, LONG_ANS, response)) return 0;
|
||||||
}while(retry-- > 0);
|
}while(retry-- > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -335,8 +334,8 @@ int SDIO_send_CMD3(uint16_t* rca) {
|
|||||||
uint32_t response;
|
uint32_t response;
|
||||||
int retry = 0x20;
|
int retry = 0x20;
|
||||||
do {
|
do {
|
||||||
SDIO_sendCmd(3, 0, SHORT_ANS);
|
SDIO_send_cmd(3, 0, SHORT_ANS);
|
||||||
if (!SDIO_getResp(3, SHORT_ANS, &response)) {
|
if (!SDIO_get_response(3, SHORT_ANS, &response)) {
|
||||||
// TODO: Do some *optional* checking
|
// TODO: Do some *optional* checking
|
||||||
*rca = ((response & 0xFFFF0000) >> 16);
|
*rca = ((response & 0xFFFF0000) >> 16);
|
||||||
return 0;
|
return 0;
|
||||||
@ -346,7 +345,7 @@ int SDIO_send_CMD3(uint16_t* rca) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int SDIO_send_CMD0() {
|
int SDIO_send_CMD0() {
|
||||||
SDIO_sendCmd(0, 0, NO_ANS);
|
SDIO_send_cmd(0, 0, NO_ANS);
|
||||||
SDIO_wait_cmd_sent();
|
SDIO_wait_cmd_sent();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -356,8 +355,8 @@ CMD8_RESP_t SDIO_send_CMD8() {
|
|||||||
int res = 0;
|
int res = 0;
|
||||||
int retry = 0x20;
|
int retry = 0x20;
|
||||||
do {
|
do {
|
||||||
SDIO_sendCmd(8, 0x1CC, SHORT_ANS);
|
SDIO_send_cmd(8, 0x1CC, SHORT_ANS);
|
||||||
res = SDIO_getResp(8, SHORT_ANS, &response);
|
res = SDIO_get_response(8, SHORT_ANS, &response);
|
||||||
if (res == 0) {
|
if (res == 0) {
|
||||||
if (response & 0x100)
|
if (response & 0x100)
|
||||||
return CMD8_RESP_ACK;
|
return CMD8_RESP_ACK;
|
||||||
@ -368,6 +367,9 @@ CMD8_RESP_t SDIO_send_CMD8() {
|
|||||||
return CMD8_RESP_TIMEOUT;
|
return CMD8_RESP_TIMEOUT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief initDetectandProtectionPins
|
||||||
|
*/
|
||||||
void initDetectandProtectionPins() {
|
void initDetectandProtectionPins() {
|
||||||
#if SDIO_ENABLE_WRITEPROT==1
|
#if SDIO_ENABLE_WRITEPROT==1
|
||||||
WRITEPROT_PORT->PUPDR |= ((WRITEPROT_PULLUP ? 1 : 0)<<WRITEPROT_PIN*2);
|
WRITEPROT_PORT->PUPDR |= ((WRITEPROT_PULLUP ? 1 : 0)<<WRITEPROT_PIN*2);
|
||||||
@ -378,6 +380,10 @@ void initDetectandProtectionPins() {
|
|||||||
__DSB();
|
__DSB();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief checkNotInserted
|
||||||
|
* @return return 0 if card is inserted, else 1
|
||||||
|
*/
|
||||||
int checkNotInserted() {
|
int checkNotInserted() {
|
||||||
#if SDIO_ENABLE_INS
|
#if SDIO_ENABLE_INS
|
||||||
return ((INS_PORT->IDR & INS_PIN) == INS_ACTIVE_LEVEL ? 0 : 1);
|
return ((INS_PORT->IDR & INS_PIN) == INS_ACTIVE_LEVEL ? 0 : 1);
|
||||||
@ -385,7 +391,10 @@ int checkNotInserted() {
|
|||||||
return 0; // Assume Card is inserted
|
return 0; // Assume Card is inserted
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* @brief checkWriteProtection
|
||||||
|
* @return 0 if card is writable.
|
||||||
|
*/
|
||||||
int checkWriteProtection() {
|
int checkWriteProtection() {
|
||||||
#if SDIO_ENABLE_WRITEPROT
|
#if SDIO_ENABLE_WRITEPROT
|
||||||
return ((WRITEPROT_PORT->IDR & WRITEPROT_PIN) == WRITEPROT_ACTIVE_LEVEL ? 1 : 0);
|
return ((WRITEPROT_PORT->IDR & WRITEPROT_PIN) == WRITEPROT_ACTIVE_LEVEL ? 1 : 0);
|
||||||
|
Loading…
Reference in New Issue
Block a user