use shorter sd_send_bytes() routines

This commit is contained in:
Markus Fröschle
2012-11-19 15:02:06 +00:00
parent 5ee9f19b2c
commit c3f7e0e76e
2 changed files with 29 additions and 28 deletions

View File

@@ -28,5 +28,7 @@ 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 uint32_t sd_card_get_status(void);
extern uint8_t sd_send_byte(uint8_t byte);
extern uint16_t sd_send_word(uint16_t word);
#endif /* _SD_CARD_H_ */ #endif /* _SD_CARD_H_ */

View File

@@ -65,7 +65,7 @@ uint32_t sd_com(uint32_t data)
* initialized previously (either by sd_com or a direct register write). * initialized previously (either by sd_com or a direct register write).
* Returns a byte received from SPI (contents of the RX FIFO). * Returns a byte received from SPI (contents of the RX FIFO).
*/ */
inline uint8_t sd_byte(uint8_t byte) inline uint8_t sd_send_byte(uint8_t byte)
{ {
* (volatile uint8_t *) (&MCF_DSPI_DTFR + 3) = byte; * (volatile uint8_t *) (&MCF_DSPI_DTFR + 3) = byte;
@@ -75,7 +75,7 @@ inline uint8_t sd_byte(uint8_t byte)
/* /*
* as above, but word sized * as above, but word sized
*/ */
inline uint16_t sd_word(uint16_t word) inline uint16_t sd_send_word(uint16_t word)
{ {
* (volatile uint16_t *) (&MCF_DSPI_DTFR + 2) = word; * (volatile uint16_t *) (&MCF_DSPI_DTFR + 2) = word;
@@ -116,9 +116,11 @@ int sd_card_init(void)
wait(10000); wait(10000);
MCF_DSPI_DMCR = DSPI_DMCR_CONF; MCF_DSPI_DMCR = DSPI_DMCR_CONF;
for (i = 0; i < 10; i++)
{
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++)
{
ret = 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 */
@@ -130,10 +132,8 @@ int sd_card_init(void)
} }
MCF_DSPI_DMCR = DSPI_DMCR_CONF; MCF_DSPI_DMCR = DSPI_DMCR_CONF;
for (i = 0; i < 2; i++)
{
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);
MCF_DSPI_DMCR = DSPI_DMCR_CONF; MCF_DSPI_DMCR = DSPI_DMCR_CONF;
@@ -154,23 +154,22 @@ void sd_card_idle(void)
for (i = 0; i < 100; i++) for (i = 0; i < 100; i++)
{ {
ret = sd_com(MCF_DSPI_DTFR_EOQ | MCF_DSPI_DTFR_CS5 | 0x00FF); ret = sd_send_byte(0xff);
ret = sd_com(MCF_DSPI_DTFR_EOQ | MCF_DSPI_DTFR_CS5 | 0x0040); ret = sd_send_byte(0x40);
ret = sd_com(MCF_DSPI_DTFR_EOQ | MCF_DSPI_DTFR_CS5 | 0x0000); ret = sd_send_byte(0x00);
ret = sd_com(MCF_DSPI_DTFR_EOQ | MCF_DSPI_DTFR_CS5 | 0x0000); ret = sd_send_byte(0x00);
ret = sd_com(MCF_DSPI_DTFR_EOQ | MCF_DSPI_DTFR_CS5 | 0x0000); ret = sd_send_byte(0x00);
ret = sd_com(MCF_DSPI_DTFR_EOQ | MCF_DSPI_DTFR_CS5 | 0x0000); ret = sd_send_byte(0x00);
ret = sd_com(MCF_DSPI_DTFR_EOQ | MCF_DSPI_DTFR_CS5 | 0x0095); ret = sd_send_byte(0x95);
for (j = 0; j < 6; j++) for (j = 0; j < 6; j++)
{ {
ret = sd_com(MCF_DSPI_DTFR_EOQ | MCF_DSPI_DTFR_CS5 | 0x00FF); ret = sd_send_byte(0xff);
if (ret & 0x01) if (ret & 0x01)
{
break; break;
} }
} if (ret & 0x01)
break;
} }
} }
@@ -180,13 +179,13 @@ void sd_card_read_ic(void)
while (/* no suitable data received */ 1) while (/* no suitable data received */ 1)
{ {
ret = sd_com(MCF_DSPI_DTFR_EOQ | MCF_DSPI_DTFR_CS5 | 0x00FF); ret = sd_send_byte(0xFF);
ret = sd_com(MCF_DSPI_DTFR_EOQ | MCF_DSPI_DTFR_CS5 | 0x0048); ret = sd_send_byte(0x48);
ret = sd_com(MCF_DSPI_DTFR_EOQ | MCF_DSPI_DTFR_CS5 | 0x0000); ret = sd_send_byte(0x00);
ret = sd_com(MCF_DSPI_DTFR_EOQ | MCF_DSPI_DTFR_CS5 | 0x0000); ret = sd_send_byte(0x00);
ret = sd_com(MCF_DSPI_DTFR_EOQ | MCF_DSPI_DTFR_CS5 | 0x0001); ret = sd_send_byte(0x01);
ret = sd_com(MCF_DSPI_DTFR_EOQ | MCF_DSPI_DTFR_CS5 | 0x00aa); ret = sd_send_byte(0xaa);
ret = sd_com(MCF_DSPI_DTFR_EOQ | MCF_DSPI_DTFR_CS5 | 0x0087); ret = sd_send_byte(0x87);
ret = sd_card_get_status(); ret = sd_card_get_status();
@@ -198,7 +197,7 @@ void sd_card_read_ic(void)
{ {
continue; continue;
} }
ret = sd_com(MCF_DSPI_DTFR_EOQ | MCF_DSPI_DTFR_CS5 | 0x00ff); ret = sd_send_byte(0xff);
/* move.b d5,d0 ? */ /* move.b d5,d0 ? */
} }
} }
@@ -209,7 +208,7 @@ uint32_t sd_card_get_status(void)
do do
{ {
ret = sd_com(MCF_DSPI_DTFR_EOQ | MCF_DSPI_DTFR_CS5 | 0x00FF); ret = sd_send_byte(0xFF);
} while ((ret & 0xff) == 0xff); } while ((ret & 0xff) == 0xff);
return ret; return ret;