made SD card working on plain EmuTOS

This commit is contained in:
Markus Fröschle
2013-10-12 16:22:51 +00:00
parent 4d216bf2f0
commit 5a55faa169
4 changed files with 47 additions and 21 deletions

View File

@@ -33,6 +33,7 @@ typedef enum {
DSTATUS disk_initialize (uint8_t); DSTATUS disk_initialize (uint8_t);
DSTATUS disk_reset(uint8_t);
DSTATUS disk_status (uint8_t); DSTATUS disk_status (uint8_t);
DRESULT disk_read (uint8_t, uint8_t*, uint32_t, uint8_t); DRESULT disk_read (uint8_t, uint8_t*, uint32_t, uint8_t);
#if _READONLY == 0 #if _READONLY == 0

View File

@@ -108,7 +108,7 @@ void *dma_memcpy(void *dst, void *src, size_t n)
end = MCF_SLT0_SCNT; end = MCF_SLT0_SCNT;
time = (start - end) / 132 / 1000; time = (start - end) / 132 / 1000;
xprintf("start = %d, end = %d, time = %d\r\n", start, end, time); xprintf("start = %d, end = %d, time = %d\r\n", start, end, time);
xprintf("took %d ms (%d.%d Mbytes/second)\r\n", time, n / time / 1000, n / time % 1000); //xprintf("took %d ms (%d.%d Mbytes/second)\r\n", time, n / time / 1000, n / time % 1000);
/* /*
* verify if copy succeeded * verify if copy succeeded

View File

@@ -45,7 +45,8 @@
MCF_DSPI_DCTAR_DT(0b0010) | /* 2 */ \ MCF_DSPI_DCTAR_DT(0b0010) | /* 2 */ \
MCF_DSPI_DCTAR_BR(0b0000); } /* clock / 2 */ MCF_DSPI_DCTAR_BR(0b0000); } /* clock / 2 */
#define SPICLK_SLOW() { MCF_DSPI_DCTAR0 = MCF_DSPI_DCTAR_TRSZ(0b111) | /* transfer size = 8 bit */ \ #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 */ \ 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_PASC_3CLK | /* 3 clock DSPISCK to DSPICS negation prescaler */ \
MCF_DSPI_DCTAR_PDT_3CLK | /* 3 clock delay between DSPICS assertions prescaler */ \ MCF_DSPI_DCTAR_PDT_3CLK | /* 3 clock delay between DSPICS assertions prescaler */ \
@@ -53,7 +54,8 @@
MCF_DSPI_DCTAR_CSSCK(8) | /* delay scaler * 512 */\ MCF_DSPI_DCTAR_CSSCK(8) | /* delay scaler * 512 */\
MCF_DSPI_DCTAR_ASC(8) | /* 2 */ \ MCF_DSPI_DCTAR_ASC(8) | /* 2 */ \
MCF_DSPI_DCTAR_DT(9) | /* 2 */ \ MCF_DSPI_DCTAR_DT(9) | /* 2 */ \
MCF_DSPI_DCTAR_BR(7); } MCF_DSPI_DCTAR_BR(7); \
}
@@ -93,10 +95,7 @@ static volatile DSTATUS Stat = 0 /* STA_NOINIT */; /* Physical drive status */
static uint8_t CardType; /* Card type flags */ static uint8_t CardType; /* Card type flags */
static uint32_t dspi_fifo_val = // MCF_DSPI_DTFR_CONT | /* enable continous chip select */ static uint32_t dspi_fifo_val = MCF_DSPI_DTFR_CTCNT;
/* CTAS use DCTAR0 for clock and attributes */
MCF_DSPI_DTFR_CTCNT;
/*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/
/* Send/Receive data to the MMC (Platform dependent) */ /* Send/Receive data to the MMC (Platform dependent) */
@@ -211,6 +210,8 @@ static int select(void) /* 1:OK, 0:Timeout */
*/ */
static void power_on(void) /* Enable SSP module */ static void power_on(void) /* Enable SSP module */
{ {
MCF_PAD_PAR_DSPI = 0x1fff; /* configure all DSPI GPIO pins for DSPI usage */
dspi_fifo_val = MCF_DSPI_DTFR_CTCNT;
/* /*
* initialize DSPI module configuration register * initialize DSPI module configuration register
*/ */
@@ -466,7 +467,13 @@ DSTATUS disk_status(uint8_t drv)
return Stat; /* Return disk status */ return Stat; /* Return disk status */
} }
DSTATUS disk_reset(uint8_t drv)
{
if (drv) return STA_NOINIT;
deselect();
disk_initialize(0);
}
/*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/
/* Read sector(s) */ /* Read sector(s) */
@@ -474,8 +481,23 @@ DSTATUS disk_status(uint8_t drv)
DRESULT disk_read(uint8_t drv, uint8_t *buff, uint32_t sector, uint8_t count) DRESULT disk_read(uint8_t drv, uint8_t *buff, uint32_t sector, uint8_t count)
{ {
if (drv || !count) return RES_PARERR; /* Check parameter */ if (drv)
if (Stat & STA_NOINIT) return RES_NOTRDY; /* Check if drive is ready */ {
xprintf("wrong drive in disk_read()\r\n");
return RES_PARERR; /* Check parameter */
}
if (! count)
{
xprintf("wrong coung in disk_read()\r\n");
return RES_PARERR;
}
if (Stat & STA_NOINIT)
{
xprintf("drive not ready in disk_read()\r\n");
return RES_NOTRDY; /* Check if drive is ready */
}
if (!(CardType & CT_BLOCK)) sector *= 512; /* LBA or BA conversion (byte addressing cards) */ if (!(CardType & CT_BLOCK)) sector *= 512; /* LBA or BA conversion (byte addressing cards) */
@@ -555,8 +577,10 @@ DRESULT disk_write(uint8_t drv, const uint8_t *buff, uint32_t sector, uint8_t co
} }
deselect(); deselect();
if (count) if (count) /* we had an error, try a reinit */
{
xprintf("disk_write() failed (count=%d)\r\n", count); xprintf("disk_write() failed (count=%d)\r\n", count);
}
return count ? RES_ERROR : RES_OK; /* Return result */ return count ? RES_ERROR : RES_OK; /* Return result */
} }
@@ -603,7 +627,7 @@ DRESULT disk_ioctl(uint8_t drv, uint8_t ctrl, void *buff)
break; break;
case GET_SECTOR_SIZE : /* Get sector size in unit of byte (WORD) */ case GET_SECTOR_SIZE : /* Get sector size in unit of byte (WORD) */
*(uint16_t*)buff = 512; * (uint32_t*) buff = 512;
res = RES_OK; res = RES_OK;
break; break;

View File

@@ -30,7 +30,7 @@
#define DRIVER_VERSION 0x130 #define DRIVER_VERSION 0x130
#define MY_MAJOR 65 #define MY_MAJOR 7
#define MY_MINOR 0 #define MY_MINOR 0
uint16_t xhdi_version(void) uint16_t xhdi_version(void)
@@ -133,6 +133,7 @@ uint32_t xhdi_read_write(uint16_t major, uint16_t minor, uint16_t rwflag,
ret = ((rwflag & 1) ? disk_write(0, buf, recno, num_sectors) : disk_read(0, buf, recno, num_sectors)); ret = ((rwflag & 1) ? disk_write(0, buf, recno, num_sectors) : disk_read(0, buf, recno, num_sectors));
if (ret != RES_OK) if (ret != RES_OK)
{ {
disk_reset(0);
retries++; retries++;
if (retries < max_retries) continue; if (retries < max_retries) continue;