Skip to content
Browse files

first functional test of go_idle_cmd code

  • Loading branch information...
1 parent e90f152 commit 2dc2254f6549ba895a6b70ab89554a0330cd0958 @betovar committed May 9, 2012
Showing with 22 additions and 28 deletions.
  1. +11 −14 libraries/Card/SecureDigital/SDMC.cpp
  2. +3 −1 libraries/Card/SecureDigital/SDMC.h
  3. +8 −13 main.cpp
View
25 libraries/Card/SecureDigital/SDMC.cpp
@@ -71,45 +71,41 @@ void SecureDigitalMemoryCard::end(void) {
}
/**
- * @brief Card Initialization and Identification Flow (SD mode)
+ * @brief Card detect and debug function
*/
-void SecureDigitalMemoryCard::test(void) {
+void SecureDigitalMemoryCard::cardDetect(void) {
if (sdio_card_detect()) {
SerialUSB.println("SDIO_DBG: Card detected");
} else {
SerialUSB.println("SDIO_DBG: Card not detected");
}
}
+
/**
* @brief Card Initialization and Identification Flow (SD mode)
*/
void SecureDigitalMemoryCard::init(void) {
- if (sdio_card_detect()) {
- SerialUSB.println("SDIO_DBG: Card detected");
- } else {
- SerialUSB.println("SDIO_DBG: Card not detected");
- }
+ this->cardDetect();
sdio_power_on(this->sdio_d);
- sdio_clock_enable(this->sdio_d);
SerialUSB.println("SDIO_DBG: Powered on");
delay(1);
this->cmd(GO_IDLE_STATE); //CMD0
- sdio_clear_interrupt(this->sdio_d, ~SDIO_ICR_RESERVED);
- SerialUSB.println("SDIO_DBG: Idle state reached");
+ //sdio_clear_interrupt(this->sdio_d, ~SDIO_ICR_RESERVED);
+ SerialUSB.println("SDIO_DBG: Card in idle state");
icr R7;
CSD.version = CSD_UNDEFINED;
this->cmd(SEND_IF_COND, //CMD8
SDIO_HOST_SUPPLY_VOLTAGE | SDIO_CHECK_PATTERN,
SDIO_WRSP_SHRT,
(uint32*)&R7);
- SerialUSB.println("SDIO_DBG: Interface condition checked");
uint32 arg;
if (sdio_get_status(this->sdio_d, SDIO_STA_CMDREND)) {
if ((R7.CHECK_PATTERN != SDIO_CHECK_PATTERN) |
(R7.VOLTAGE_ACCEPTED != SDIO_HOST_SUPPLY_VOLTAGE)) {
SerialUSB.println("SDIO_ERR: Unusuable Card");
return;
}
+ SerialUSB.println("SDIO_DBG: Interface condition check passed");
arg = SDIO_HOST_CAPACITY_SUPPORT;
} else {
/** the host should set HCS to 0 if the card returns no response to CMD8 */
@@ -222,23 +218,24 @@ void SecureDigitalMemoryCard::cmd(SDIOCommand cmd,
SDIO_MASK_CMDSENTIE | SDIO_MASK_CMDRENDIE |
SDIO_MASK_CTIMEOUTIE | SDIO_MASK_CCRCFAILIE, 2);
sdio_load_arg(this->sdio_d, arg);
+ sdio_clock_enable(this->sdio_d);
sdio_send_cmd(this->sdio_d, (wrsp << SDIO_CMD_WAITRESP_BIT) | cmd |
SDIO_CMD_CPSMEN | SDIO_CMD_IEN);
- if (sdio_get_status(this->sdio_d, SDIO_STA_CMDACT)) {
+ if (sdio_is_cmd_act(this->sdio_d)) {
SerialUSB.println("SDIO_DBG: Command active");
- } else {
- SerialUSB.println("SDIO_DBG: Command inactive");
}
switch (wrsp) {
case SDIO_WRSP_NONE:
//check cmdsent
+ SerialUSB.println("SDIO_DBG: Waiting for CMDSENT...");
this->wait(SDIO_FLAG_CMDSENT);
SerialUSB.println("SDIO_DBG: Command sent");
//sdio_clear_interrupt(this->sdio_d, SDIO_ICR_CMDSENTC);
break;
case SDIO_WRSP_SHRT:
case SDIO_WRSP_LONG:
//wait for resp
+ SerialUSB.println("SDIO_DBG: Waiting for CMDREND...");
this->wait(SDIO_FLAG_CMDREND);
SerialUSB.println("SDIO_DBG: Command response recieved");
//sdio_clear_interrupt(this->sdio_d, SDIO_ICR_CMDRENDC);
View
4 libraries/Card/SecureDigital/SDMC.h
@@ -73,7 +73,8 @@ typedef enum SDIOClockFrequency {
SDIO_500_KHZ = 142,
SDIO_400_KHZ = 178,
SDIO_300_KHZ = 238,
- SDIO_CLK_INIT = SDIO_400_KHZ
+ SDIO_CLK_INIT = SDIO_400_KHZ,
+ SDIO_CLK_DATA = SDIO_24_MHZ
} SDIOClockFrequency;
typedef enum SDIOBlockSize {
@@ -201,6 +202,7 @@ class SecureDigitalMemoryCard {
void test(void);
void end(void);
// convenience functions
+ void cardDetect(void);
void clockFreq(SDIOClockFrequency);
void busMode(SDIOBusMode);
void blockSize(SDIOBlockSize);
View
21 main.cpp
@@ -23,7 +23,13 @@ void setup() {
void loop() {
waitForButtonPress();
- SDMC.test();
+ SerialUSB.println("SDIO_DBG: Starting SDMC test");
+ SDMC.begin();
+ SerialUSB.println("SDIO_DBG: Initializing card");
+ SDMC.init();
+ SerialUSB.println("SDIO_DBG: Initialization complete");
+ SDMC.end();
+ SerialUSB.println("SDIO_DBG: Test complete");
}
// Force init to be called *first*, i.e. before static object allocation.
@@ -38,15 +44,4 @@ int main(void) {
loop();
}
return 0;
-}
-
-/**
- toggleLED();
- SerialUSB.println("SDIO_DBG: Running SDMC test");
- SDMC.begin();
- SerialUSB.println("SDIO_DBG: Initializing card");
- SDMC.init();
- SerialUSB.println("SDIO_DBG: Test complete");
- SDMC.end();
- toggleLED();
-*/
+}

0 comments on commit 2dc2254

Please sign in to comment.
Something went wrong with that request. Please try again.