diff --git a/SD_CARD/BaS_gcc/.project b/SD_CARD/BaS_gcc/.project index 18fee7e..499285f 100644 --- a/SD_CARD/BaS_gcc/.project +++ b/SD_CARD/BaS_gcc/.project @@ -7,7 +7,6 @@ org.eclipse.cdt.managedbuilder.core.genmakebuilder - clean,full,incremental, ?name? diff --git a/SD_CARD/BaS_gcc/sources/BaS.c b/SD_CARD/BaS_gcc/sources/BaS.c index 821bb6d..273cce2 100644 --- a/SD_CARD/BaS_gcc/sources/BaS.c +++ b/SD_CARD/BaS_gcc/sources/BaS.c @@ -31,7 +31,9 @@ #include "bas_types.h" #include "sd_card.h" #include - + +#include +#include /* imported routines */ extern int mmu_init(); extern int vec_init(); @@ -175,12 +177,25 @@ void BaS(void) uint8_t *src; uint8_t *dst = (uint8_t *)TOS; uint32_t *adr; + DRESULT res; + FATFS fs; + FRESULT fres; - - disk_initialize(0); pic_init(); nvram_init(); + disk_initialize(0); + res = disk_status(0); + xprintf("disk status of SD card is %d\r\n", res); + if (res == RES_OK) + { + fres = f_mount(0, &fs); + xprintf("mount status of SD card fs is %d\r\n", fres); + if (fres == FR_OK) + { + ; + } + } xprintf("copy EmuTOS: "); /* copy EMUTOS */ diff --git a/SD_CARD/BaS_gcc/sources/mmcbb.c b/SD_CARD/BaS_gcc/sources/mmcbb.c index ac98b31..2b08b43 100644 --- a/SD_CARD/BaS_gcc/sources/mmcbb.c +++ b/SD_CARD/BaS_gcc/sources/mmcbb.c @@ -101,7 +101,7 @@ #define CMD58 (58) /* READ_OCR */ -static volatile DSTATUS Stat = STA_NOINIT; /* Physical drive status */ +static volatile DSTATUS Stat = 0 /* STA_NOINIT */; /* Physical drive status */ static uint8_t CardType; /* Card type flags */ diff --git a/SD_CARD/BaS_gcc/sources/sd_card.c b/SD_CARD/BaS_gcc/sources/sd_card.c index 6ff3fe5..86d4429 100644 --- a/SD_CARD/BaS_gcc/sources/sd_card.c +++ b/SD_CARD/BaS_gcc/sources/sd_card.c @@ -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; -} diff --git a/SD_CARD/BaS_gcc/sources/sysinit.c b/SD_CARD/BaS_gcc/sources/sysinit.c index ed369c2..2329edd 100644 --- a/SD_CARD/BaS_gcc/sources/sysinit.c +++ b/SD_CARD/BaS_gcc/sources/sysinit.c @@ -751,9 +751,6 @@ livo: /* Symbols from the linker script */ -extern uint8_t _STRAM_END[]; -#define STRAM_END ((uint32_t)_STRAM_END) - extern uint8_t _FIRETOS[]; #define FIRETOS ((uint32_t)_FIRETOS) /* where FireTOS is stored in flash */