From 2b33a868adcc4277f2316626fbdeb099840a1d82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Fr=C3=B6schle?= Date: Thu, 20 Dec 2012 22:08:24 +0000 Subject: [PATCH] improved SD-card speed --- BaS_gcc/Makefile | 3 ++- BaS_gcc/sources/flash.c | 1 + BaS_gcc/sources/mmc.c | 14 +++++++------- BaS_gcc/sources/sd_card.c | 36 ++++++++++++++++++++++++++++++++++-- 4 files changed, 44 insertions(+), 10 deletions(-) diff --git a/BaS_gcc/Makefile b/BaS_gcc/Makefile index 0d1e5cf..f8b751a 100644 --- a/BaS_gcc/Makefile +++ b/BaS_gcc/Makefile @@ -70,7 +70,8 @@ CSRCS= \ $(SRCDIR)/wait.c \ $(SRCDIR)/s19reader.c \ $(SRCDIR)/flash.c \ - $(SRCDIR)/basflash.c + $(SRCDIR)/basflash.c \ + $(SRCDIR)/flash.c ASRCS= \ $(SRCDIR)/startcf.S \ diff --git a/BaS_gcc/sources/flash.c b/BaS_gcc/sources/flash.c index e160f2f..3f7a0b3 100644 --- a/BaS_gcc/sources/flash.c +++ b/BaS_gcc/sources/flash.c @@ -51,6 +51,7 @@ void sector_erase(uint8_t *address, uint16_t sector) } while (* (volatile uint32_t *) (address + sector) != 0xffffffff); } + #ifdef _NOT_USED_ * MX28LV640DB.alg bra lab0x5a diff --git a/BaS_gcc/sources/mmc.c b/BaS_gcc/sources/mmc.c index d4490b6..0b50a37 100644 --- a/BaS_gcc/sources/mmc.c +++ b/BaS_gcc/sources/mmc.c @@ -26,13 +26,13 @@ #define CS_LOW() { dspi_fifo_val |= MCF_DSPI_DTFR_CS5; } #define SPICLK_FAST() { MCF_DSPI_DCTAR0 = MCF_DSPI_DCTAR_TRSZ(0b111) | /* transfer size = 8 bit */ \ - MCF_DSPI_DCTAR_PCSSCK(0b01) | /* 3 clock DSPICS to DSPISCK delay prescaler */ \ - MCF_DSPI_DCTAR_PASC_3CLK | /* 3 clock DSPISCK to DSPICS negation prescaler */ \ - MCF_DSPI_DCTAR_PDT_3CLK | /* 3 clock delay between DSPICS assertions prescaler */ \ - MCF_DSPI_DCTAR_PBR_1CLK | /* 1 clock prescaler */ \ - MCF_DSPI_DCTAR_ASC(0b1001) | /* 1024 */ \ - MCF_DSPI_DCTAR_DT(0b1001) | /* 1024 */ \ - MCF_DSPI_DCTAR_BR(0b0001); } + MCF_DSPI_DCTAR_PCSSCK(0b01) | /* 1 clock DSPICS to DSPISCK delay prescaler */ \ + MCF_DSPI_DCTAR_PASC_1CLK | /* 1 clock DSPISCK to DSPICS negation prescaler */ \ + MCF_DSPI_DCTAR_PDT_1CLK | /* 1 clock delay between DSPICS assertions prescaler */ \ + MCF_DSPI_DCTAR_PBR_3CLK | /* 3 clock Baudrate prescaler */ \ + MCF_DSPI_DCTAR_ASC(0b0000) | /* 2 */ \ + MCF_DSPI_DCTAR_DT(0b0000) | /* 2 */ \ + MCF_DSPI_DCTAR_BR(0b0000); } /* clock / 2 */ #define SPICLK_SLOW() { MCF_DSPI_DCTAR0 = MCF_DSPI_DCTAR_TRSZ(0b111) | /* transfer size = 8 bit */ \ MCF_DSPI_DCTAR_PCSSCK(0b01) | /* 3 clock DSPICS to DSPISCK delay prescaler */ \ diff --git a/BaS_gcc/sources/sd_card.c b/BaS_gcc/sources/sd_card.c index 82bb53f..d0f600b 100644 --- a/BaS_gcc/sources/sd_card.c +++ b/BaS_gcc/sources/sd_card.c @@ -28,9 +28,9 @@ #include #define WELCOME_NAME "WELCOME.MSG" -#define FLASHCODE_NAME "BASFLASH.BIN" +#define FLASHCODE_NAME "BENCH.BIN" -#define FLASHCODE_ADDRESS 0x01000000L +#define FLASHCODE_ADDRESS 0x03000000L /* * initialize SD-card and FF FAT filesystem routines. Harness to load a file during boot. @@ -72,6 +72,38 @@ void sd_card_init(void) xprintf("could not open directory \"\\\" on SD-card! Error code: %d\r\n", fres); } + /* + * let's see if we find our boot flashing executable on disk + */ + fres = f_open(&file, FLASHCODE_NAME, FA_READ); + if (fres == FR_OK) + { + /* + * yes, load and execute it + * + * FIXME: we will need some kind of user confirmation here + * to avoid unwanted flashing or "bootsector viruses" before going productive + */ + uint32_t size; /* length of code piece read */ + uint32_t total_size = 0L; + uint32_t start_time = MCF_SLT_SCNT(0); + uint32_t end_time; + uint32_t time = 0; + + while ((fres = f_read(&file, (void *) FLASHCODE_ADDRESS, 1024 * 1000, &size)) == FR_OK && size > 0) + { + total_size += size / 1024; + xprintf("read hunk of %d bytes, total_size = %d kBytes\r\n", size, total_size); + } + end_time = MCF_SLT_SCNT(0); + time = (end_time - start_time) / 132L; + xprintf("result of f_read: %ld, %ld kbytes read\r\n", fres, total_size); + xprintf("time to load %s: %ld s\r\n", FLASHCODE_NAME, time / 1000 / 100); + xprintf("equals to about %ld kBytes/second\r\n", total_size / (time / 1000 / 100)); + + } + f_close(&file); + fres = f_open(&file, WELCOME_NAME, FA_READ); if (fres == FR_OK) {