use shorter sd_send_bytes() routines

This commit is contained in:
Markus Fröschle
2012-11-19 16:42:46 +00:00
parent c3f7e0e76e
commit 31b6e02a23
2 changed files with 18 additions and 17 deletions

View File

@@ -27,7 +27,7 @@ const uint32_t DSPI_DMCR_CONF = MCF_DSPI_DMCR_MSTR | /* FireBee is DSPI master*/
extern int sd_card_init(void); extern int sd_card_init(void);
extern uint32_t sd_com(uint32_t data); extern uint32_t sd_com(uint32_t data);
extern void sd_card_idle(void); extern void sd_card_idle(void);
extern uint32_t sd_card_get_status(void); extern uint8_t sd_card_get_status(void);
extern uint8_t sd_send_byte(uint8_t byte); extern uint8_t sd_send_byte(uint8_t byte);
extern uint16_t sd_send_word(uint16_t word); extern uint16_t sd_send_word(uint16_t word);

View File

@@ -85,6 +85,7 @@ inline uint16_t sd_send_word(uint16_t word)
int sd_card_init(void) int sd_card_init(void)
{ {
uint32_t ret; uint32_t ret;
uint8_t rb;
int i; int i;
xprintf("SD-Card initialization: "); xprintf("SD-Card initialization: ");
@@ -120,7 +121,7 @@ int sd_card_init(void)
ret = sd_com(MCF_DSPI_DTFR_EOQ | MCF_DSPI_DTFR_CS5 | 0x00FF); ret = sd_com(MCF_DSPI_DTFR_EOQ | MCF_DSPI_DTFR_CS5 | 0x00FF);
for (i = 1; i < 10; i++) for (i = 1; i < 10; i++)
{ {
ret = sd_send_byte(0xff); rb = sd_send_byte(0xff);
} }
MCF_DSPI_DMCR = DSPI_DMCR_CONF | MCF_DSPI_DMCR_CSIS5; /* CS5 inactive */ MCF_DSPI_DMCR = DSPI_DMCR_CONF | MCF_DSPI_DMCR_CSIS5; /* CS5 inactive */
@@ -133,7 +134,7 @@ int sd_card_init(void)
MCF_DSPI_DMCR = DSPI_DMCR_CONF; MCF_DSPI_DMCR = DSPI_DMCR_CONF;
ret = sd_com(MCF_DSPI_DTFR_EOQ | MCF_DSPI_DTFR_CS5 | 0x00FF); ret = sd_com(MCF_DSPI_DTFR_EOQ | MCF_DSPI_DTFR_CS5 | 0x00FF);
ret = sd_send_byte(0xff); rb = sd_send_byte(0xff);
MCF_DSPI_DMCR = DSPI_DMCR_CONF; MCF_DSPI_DMCR = DSPI_DMCR_CONF;
@@ -175,21 +176,21 @@ void sd_card_idle(void)
void sd_card_read_ic(void) void sd_card_read_ic(void)
{ {
uint32_t ret; uint8_t rb;
while (/* no suitable data received */ 1) while (/* no suitable data received */ 1)
{ {
ret = sd_send_byte(0xFF); rb = sd_send_byte(0xFF);
ret = sd_send_byte(0x48); rb = sd_send_byte(0x48);
ret = sd_send_byte(0x00); rb = sd_send_byte(0x00);
ret = sd_send_byte(0x00); rb = sd_send_byte(0x00);
ret = sd_send_byte(0x01); rb = sd_send_byte(0x01);
ret = sd_send_byte(0xaa); rb = sd_send_byte(0xaa);
ret = sd_send_byte(0x87); rb = sd_send_byte(0x87);
ret = sd_card_get_status(); rb = sd_card_get_status();
if ((ret & 0xff) == 5) if (rb == 5)
{ {
; /* sd v1 */ ; /* sd v1 */
} }
@@ -197,19 +198,19 @@ void sd_card_read_ic(void)
{ {
continue; continue;
} }
ret = sd_send_byte(0xff); rb = sd_send_byte(0xff);
/* move.b d5,d0 ? */ /* move.b d5,d0 ? */
} }
} }
uint32_t sd_card_get_status(void) uint8_t sd_card_get_status(void)
{ {
uint32_t ret; uint8_t ret;
do do
{ {
ret = sd_send_byte(0xFF); ret = sd_send_byte(0xFF);
} while ((ret & 0xff) == 0xff); } while (ret == 0xff);
return ret; return ret;
} }