|
|
|
@ -21,8 +21,6 @@
|
|
|
|
|
#define ENABLE_DEBUG (0) |
|
|
|
|
#include "debug.h" |
|
|
|
|
|
|
|
|
|
extern unsigned long xtimer_now(void); |
|
|
|
|
|
|
|
|
|
/* --- MCI configurations --- */ |
|
|
|
|
#define N_BUF 4 /* Block transfer FIFO depth (>= 2) */ |
|
|
|
|
#define USE_4BIT 1 /* Use wide bus mode if SDC is detected */ |
|
|
|
@ -415,12 +413,12 @@ static int send_cmd(unsigned int idx, unsigned long arg, unsigned int rt, unsign
|
|
|
|
|
MCI_COMMAND = mc; /* Initiate command transaction */ |
|
|
|
|
|
|
|
|
|
//Timer[1] = 100;
|
|
|
|
|
uint32_t timerstart = xtimer_now(); |
|
|
|
|
uint32_t timerstart = xtimer_now_usec(); |
|
|
|
|
|
|
|
|
|
while (1) { /* Wait for end of the cmd/resp transaction */ |
|
|
|
|
|
|
|
|
|
//if (!Timer[1]) return 0;
|
|
|
|
|
if (xtimer_now() - timerstart > 10000) { |
|
|
|
|
if ((xtimer_now_usec() - timerstart) > 10000) { |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -477,10 +475,10 @@ static int wait_ready(unsigned short tmr)
|
|
|
|
|
{ |
|
|
|
|
unsigned long rc; |
|
|
|
|
|
|
|
|
|
uint32_t stoppoll = xtimer_now() + tmr * MS_IN_USEC; |
|
|
|
|
uint32_t stoppoll = xtimer_now_usec() + tmr * MS_IN_USEC; |
|
|
|
|
bool bBreak = false; |
|
|
|
|
|
|
|
|
|
while (xtimer_now() < stoppoll/*Timer[0]*/) { |
|
|
|
|
while (xtimer_now_usec() < stoppoll/*Timer[0]*/) { |
|
|
|
|
if (send_cmd(CMD13, (unsigned long) CardRCA << 16, 1, &rc) && ((rc & 0x01E00) == 0x00800)) { |
|
|
|
|
bBreak = true; |
|
|
|
|
break; |
|
|
|
@ -492,9 +490,6 @@ static int wait_ready(unsigned short tmr)
|
|
|
|
|
return bBreak;//Timer[0] ? 1 : 0;
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*-----------------------------------------------------------------------*/ |
|
|
|
|
/* Swap byte order */ |
|
|
|
|
/*-----------------------------------------------------------------------*/ |
|
|
|
@ -510,16 +505,12 @@ static void bswap_cp(unsigned char *dst, const unsigned long *src)
|
|
|
|
|
*dst++ = (unsigned char)(d >> 0); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*--------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
Public Functions |
|
|
|
|
|
|
|
|
|
---------------------------------------------------------------------------*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*-----------------------------------------------------------------------*/ |
|
|
|
|
/* Initialize Disk Drive */ |
|
|
|
|
/*-----------------------------------------------------------------------*/ |
|
|
|
@ -548,7 +539,7 @@ diskio_sta_t mci_initialize(void)
|
|
|
|
|
/*---- Card is 'idle' state ----*/ |
|
|
|
|
|
|
|
|
|
/* Initialization timeout of 1000 msec */ |
|
|
|
|
uint32_t start = xtimer_now(); |
|
|
|
|
uint32_t start = xtimer_now_usec(); |
|
|
|
|
|
|
|
|
|
/* SDC Ver2 */ |
|
|
|
|
if (send_cmd(CMD8, 0x1AA, 1, resp) && (resp[0] & 0xFFF) == 0x1AA) { |
|
|
|
@ -558,7 +549,7 @@ diskio_sta_t mci_initialize(void)
|
|
|
|
|
do { |
|
|
|
|
/* Wait while card is busy state (use ACMD41 with HCS bit) */ |
|
|
|
|
/* This loop will take a time. Insert wai_tsk(1) here for multitask envilonment. */ |
|
|
|
|
if (xtimer_now() > start + 1000000/* !Timer[0] */) { |
|
|
|
|
if (xtimer_now_usec() > (start + 1000000/* !Timer[0] */)) { |
|
|
|
|
DEBUG("%s, %d: Timeout #1\n", RIOT_FILE_RELATIVE, __LINE__); |
|
|
|
|
goto di_fail; |
|
|
|
|
} |
|
|
|
@ -584,8 +575,8 @@ diskio_sta_t mci_initialize(void)
|
|
|
|
|
DEBUG("%s, %d: %lX\n", RIOT_FILE_RELATIVE, __LINE__, resp[0]); |
|
|
|
|
|
|
|
|
|
/* This loop will take a time. Insert wai_tsk(1) here for multitask envilonment. */ |
|
|
|
|
if (xtimer_now() > start + 1000000/* !Timer[0] */) { |
|
|
|
|
DEBUG("now: %lu, started at: %lu\n", xtimer_now(), start); |
|
|
|
|
if (xtimer_now_usec() > (start + 1000000/* !Timer[0] */)) { |
|
|
|
|
DEBUG("now: %lu, started at: %lu\n", xtimer_now_usec(), start); |
|
|
|
|
DEBUG("%s, %d: Timeout #2\n", RIOT_FILE_RELATIVE, __LINE__); |
|
|
|
|
goto di_fail; |
|
|
|
|
} |
|
|
|
|