fixed typo in spi initialization
This commit is contained in:
@@ -79,7 +79,7 @@ int spi_init(void)
|
||||
* First 16 bits are the SPI command field (basically say only HOW to transfer the second
|
||||
* half), second are the data to transfer
|
||||
*/
|
||||
uint32_t sd_com(uint32_t data)
|
||||
uint32_t spi_command(uint32_t data)
|
||||
{
|
||||
uint32_t ret;
|
||||
|
||||
@@ -94,24 +94,27 @@ uint32_t sd_com(uint32_t data)
|
||||
|
||||
/*
|
||||
* transfer a byte to SPI. This only works if the rest of the DSPI TX FIFO has been
|
||||
* initialized previously (either by sd_com or a direct register write).
|
||||
* initialized previously (either by spi_com or a direct register write).
|
||||
* Returns a byte received from SPI (contents of the RX FIFO).
|
||||
*/
|
||||
|
||||
#define MCF_DSPI_DTFR_BYTE _MBAR[0x8a37]
|
||||
inline uint8_t spi_send_byte(uint8_t byte)
|
||||
{
|
||||
* (volatile uint8_t *) (&MCF_DSPI_DTFR + 3) = byte;
|
||||
MCF_DSPI_DTFR_BYTE = byte;
|
||||
|
||||
return * (volatile uint8_t *) (&MCF_DSPI_DRFR + 3);
|
||||
return MCF_DSPI_DTFR_BYTE;
|
||||
}
|
||||
|
||||
/*
|
||||
* as above, but word sized
|
||||
*/
|
||||
#define MCF_DSPI_DTFR_WORD _MBAR[0x8ad6]
|
||||
inline uint16_t spi_send_word(uint16_t word)
|
||||
{
|
||||
* (volatile uint16_t *) (&MCF_DSPI_DTFR + 2) = word;
|
||||
MCF_DSPI_DTFR_WORD = word;
|
||||
|
||||
return * (volatile uint16_t *) (&MCF_DSPI_DRFR + 2);
|
||||
return MCF_DSPI_DTFR_WORD;
|
||||
}
|
||||
|
||||
int spi_init(void)
|
||||
@@ -150,7 +153,7 @@ int spi_init(void)
|
||||
|
||||
MCF_DSPI_DMCR = DSPI_DMCR_CONF;
|
||||
|
||||
ret = sd_com(MCF_DSPI_DTFR_EOQ | MCF_DSPI_DTFR_CS5 | 0x00FF);
|
||||
ret = spi_command(MCF_DSPI_DTFR_EOQ | MCF_DSPI_DTFR_CS5 | 0x00FF);
|
||||
for (i = 1; i < 10; i++)
|
||||
{
|
||||
rb = spi_send_byte(0xff);
|
||||
@@ -161,101 +164,22 @@ int spi_init(void)
|
||||
|
||||
for (i = 0; i < 2; i++)
|
||||
{
|
||||
ret = sd_com(MCF_DSPI_DTFR_EOQ | MCF_DSPI_DTFR_CS5);
|
||||
ret = spi_command(MCF_DSPI_DTFR_EOQ | MCF_DSPI_DTFR_CS5);
|
||||
}
|
||||
|
||||
MCF_DSPI_DMCR = DSPI_DMCR_CONF;
|
||||
ret = sd_com(MCF_DSPI_DTFR_EOQ | MCF_DSPI_DTFR_CS5 | 0x00FF);
|
||||
ret = spi_command(MCF_DSPI_DTFR_EOQ | MCF_DSPI_DTFR_CS5 | 0x00FF);
|
||||
rb = spi_send_byte(0xff);
|
||||
|
||||
MCF_DSPI_DMCR = DSPI_DMCR_CONF;
|
||||
|
||||
wait(10000);
|
||||
|
||||
//sd_card_idle();
|
||||
xprintf("finished\r\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void sd_card_idle(void)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
uint32_t ret;
|
||||
|
||||
for (i = 0; i < 100; i++)
|
||||
{
|
||||
ret = spi_send_byte(0xff);
|
||||
ret = spi_send_byte(0x40);
|
||||
ret = spi_send_byte(0x00);
|
||||
ret = spi_send_byte(0x00);
|
||||
ret = spi_send_byte(0x00);
|
||||
ret = spi_send_byte(0x00);
|
||||
ret = spi_send_byte(0x95);
|
||||
|
||||
for (j = 0; j < 6; j++)
|
||||
{
|
||||
ret = spi_send_byte(0xff);
|
||||
if (ret & 0x01)
|
||||
break;
|
||||
}
|
||||
if (ret & 0x01)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void sd_card_read_ic(void)
|
||||
{
|
||||
uint8_t rb;
|
||||
|
||||
while (/* no suitable data received */ 1)
|
||||
{
|
||||
rb = spi_send_byte(0xFF);
|
||||
rb = spi_send_byte(0x48);
|
||||
rb = spi_send_byte(0x00);
|
||||
rb = spi_send_byte(0x00);
|
||||
rb = spi_send_byte(0x01);
|
||||
rb = spi_send_byte(0xaa);
|
||||
rb = spi_send_byte(0x87);
|
||||
|
||||
rb = sd_card_get_status();
|
||||
|
||||
if (rb == 5)
|
||||
{
|
||||
while (rb == 5)
|
||||
{
|
||||
rb = spi_send_byte(0xff);
|
||||
rb = spi_send_byte(0x7a);
|
||||
rb = spi_send_byte(0x00);
|
||||
rb = spi_send_byte(0x00);
|
||||
rb = spi_send_byte(0x00);
|
||||
rb = spi_send_byte(0x00);
|
||||
rb = spi_send_byte(0x01);
|
||||
rb = sd_card_get_status();
|
||||
}
|
||||
}
|
||||
else if (rb == 1)
|
||||
{
|
||||
//sd_card_read_ic();
|
||||
}
|
||||
else
|
||||
{
|
||||
continue;
|
||||
}
|
||||
rb = spi_send_byte(0xff);
|
||||
/* move.b d5,d0 ? */
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t sd_card_get_status(void)
|
||||
{
|
||||
uint8_t ret;
|
||||
|
||||
do
|
||||
{
|
||||
ret = spi_send_byte(0xFF);
|
||||
} while (ret == 0xff);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user