diff options
| author | Keith Packard <keithp@keithp.com> | 2013-04-01 02:08:18 -0700 | 
|---|---|---|
| committer | Keith Packard <keithp@keithp.com> | 2013-04-01 02:08:18 -0700 | 
| commit | b34370cea662eb245e43aca20a6650b84b55ef6f (patch) | |
| tree | 7066f6a98b4e9a81549c04605c31cc52cd4854a1 /src/drivers/ao_sdcard.h | |
| parent | b3a41bed39ec1abfc3ab74e9be7dd393e975542b (diff) | |
altos: Retry SD card I/O. Use time for timeouts instead of counts
Sometimes I/O operations may fail; give the card a chance and retry
the operation in case it works the next time.
Replace the loop counts with loops that check the clock so that
they'll have consistent timeouts even if the CPU or SPI speed changes.
Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'src/drivers/ao_sdcard.h')
| -rw-r--r-- | src/drivers/ao_sdcard.h | 19 | 
1 files changed, 12 insertions, 7 deletions
diff --git a/src/drivers/ao_sdcard.h b/src/drivers/ao_sdcard.h index 512439b4..e55a3dec 100644 --- a/src/drivers/ao_sdcard.h +++ b/src/drivers/ao_sdcard.h @@ -49,9 +49,14 @@ ao_sdcard_init(void);  #define SDCARD_APP_SEND_OP_COMD			41  /* Status */ -#define SDCARD_STATUS_READY_STATE	0 -#define SDCARD_STATUS_IDLE_STATE	1 -#define SDCARD_STATUS_ILLEGAL_COMMAND	4 +#define SDCARD_STATUS_READY_STATE	0x00 +#define SDCARD_STATUS_IDLE_STATE	0x01 +#define SDCARD_STATUS_ERASE_RESET	0x02 +#define SDCARD_STATUS_ILLEGAL_COMMAND	0x04 +#define SDCARD_STATUS_COM_CRC_ERROR	0x08 +#define SDCARD_STATUS_ERASE_SEQ_ERROR	0x10 +#define SDCARD_STATUS_ADDRESS_ERROR	0x20 +#define SDCARD_STATUS_PARAMETER_ERROR	0x40  #define SDCARD_STATUS_TIMEOUT		0xff  #define SDCARD_DATA_START_BLOCK		0xfe @@ -60,10 +65,10 @@ ao_sdcard_init(void);  #define SDCARD_DATA_RES_MASK		0x1f  #define SDCARD_DATA_RES_ACCEPTED	0x05 -#define SDCARD_CMD_TIMEOUT		100 -#define SDCARD_IDLE_WAIT		1000 -#define SDCARD_BLOCK_TIMEOUT		100 -#define SDCARD_IDLE_TIMEOUT		1000 +#define SDCARD_CMD_TIMEOUT		AO_MS_TO_TICKS(100) +#define SDCARD_BUSY_TIMEOUT		AO_MS_TO_TICKS(100) +#define SDCARD_IDLE_WAIT		10000 +#define SDCARD_BLOCK_TIMEOUT		AO_MS_TO_TICKS(1000)  enum ao_sdtype {  	ao_sdtype_unknown,  | 
