diff --git a/SD_CARD/BaS_gcc/sources/mmcbb.c b/SD_CARD/BaS_gcc/sources/mmcbb.c index 8525325..e40787c 100644 --- a/SD_CARD/BaS_gcc/sources/mmcbb.c +++ b/SD_CARD/BaS_gcc/sources/mmcbb.c @@ -102,12 +102,7 @@ static volatile DSTATUS Stat = STA_NOINIT; /* Physical drive status */ - -static volatile -uint32_t Timer1, Timer2; /* 1kHz decrement timer stopped at zero (disk_timerproc()) */ - -static -uint8_t CardType; /* Card type flags */ +static uint8_t CardType; /* Card type flags */ @@ -243,11 +238,9 @@ void power_off (void) /* Disable SPI function */ } - /*-----------------------------------------------------------------------*/ /* Receive a data packet from the MMC */ /*-----------------------------------------------------------------------*/ - static int rcvr_datablock ( /* 1:OK, 0:Error */ uint8_t *buff, /* Data buffer */ @@ -255,13 +248,12 @@ int rcvr_datablock ( /* 1:OK, 0:Error */ ) { uint8_t token; + uint32_t target = MCF_SLT_SCNT(0) - (200 * 1000L * 132); - - Timer1 = 200; do { /* Wait for DataStart token in timeout of 200ms */ token = xchg_spi(0xFF); /* This loop will take a time. Insert rot_rdq() here for multitask envilonment. */ - } while ((token == 0xFF) && Timer1); + } while ((token == 0xFF) && MCF_SLT_SCNT(0) > target); if(token != 0xFE) return 0; /* Function fails if invalid DataStart token or timeout */ rcvr_spi_multi(buff, btr); /* Store trailing data to the buffer */ @@ -374,12 +366,13 @@ DSTATUS disk_initialize(uint8_t drv) ty = 0; if (send_cmd(CMD0, 0) == 1) { /* Put the card SPI/Idle state */ - Timer1 = 1000; /* Initialization timeout = 1 sec */ + uint32_t target = MCF_SLT_SCNT(0) - (1000L * 1000L * 132); /* 1 sec */ + if (send_cmd(CMD8, 0x1AA) == 1) { /* SDv2? */ for (n = 0; n < 4; n++) ocr[n] = xchg_spi(0xFF); /* Get 32 bit return value of R7 resp */ if (ocr[2] == 0x01 && ocr[3] == 0xAA) { /* Is the card supports vcc of 2.7-3.6V? */ - while (Timer1 && send_cmd(ACMD41, 1UL << 30)) ; /* Wait for end of initialization with ACMD41(HCS) */ - if (Timer1 && send_cmd(CMD58, 0) == 0) { /* Check CCS bit in the OCR */ + while (MCF_SLT_SCNT(0) > target && send_cmd(ACMD41, 1UL << 30)) ; /* Wait for end of initialization with ACMD41(HCS) */ + if (MCF_SLT_SCNT(0) > target && send_cmd(CMD58, 0) == 0) { /* Check CCS bit in the OCR */ for (n = 0; n < 4; n++) ocr[n] = xchg_spi(0xFF); ty = (ocr[0] & 0x40) ? CT_SD2 | CT_BLOCK : CT_SD2; /* Card id SDv2 */ } @@ -390,8 +383,8 @@ DSTATUS disk_initialize(uint8_t drv) } else { ty = CT_MMC; cmd = CMD1; /* MMCv3 (CMD1(0)) */ } - while (Timer1 && send_cmd(cmd, 0)) ; /* Wait for end of initialization */ - if (!Timer1 || send_cmd(CMD16, 512) != 0) /* Set block length: 512 */ + while (MCF_SLT_SCNT(0) > target && send_cmd(cmd, 0)) ; /* Wait for end of initialization */ + if (!MCF_SLT_SCNT(0) > target || send_cmd(CMD16, 512) != 0) /* Set block length: 512 */ ty = 0; } } @@ -641,15 +634,8 @@ DRESULT disk_ioctl ( void disk_timerproc (void) { - uint16_t n; uint8_t s; - - n = Timer1; /* 1kHz decrement timer stopped at 0 */ - if (n) Timer1 = --n; - n = Timer2; - if (n) Timer2 = --n; - s = Stat; if (WP) /* Write protected */ s |= STA_PROTECT;