From 174b6a1ba2483ab226bb8e7279f9a3b6535be308 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 14 Nov 2009 11:51:24 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1290 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/io/mmc_spi.c | 24 +++++++++++++++++++----- os/io/mmc_spi.h | 8 ++++++++ 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/os/io/mmc_spi.c b/os/io/mmc_spi.c index 4e9d6e3f5..517291814 100644 --- a/os/io/mmc_spi.c +++ b/os/io/mmc_spi.c @@ -240,6 +240,7 @@ void mmcStop(MMCDriver *mmcp) { */ bool_t mmcConnect(MMCDriver *mmcp) { unsigned i; + bool_t result; chDbgCheck(mmcp != NULL, "mmcConnect"); @@ -278,8 +279,21 @@ bool_t mmcConnect(MMCDriver *mmcp) { /* Initialization complete, full speed. */ spiStart(mmcp->mmc_spip, mmcp->mmc_hscfg); - mmcp->mmc_state = MMC_READY; - return FALSE; + + /* Setting block size.*/ + if (send_command(mmcp, MMC_CMDSETBLOCKLEN, MMC_BLOCK_SIZE) != 0x00) + return TRUE; + + /* Transition to MMC_READY state (if not extracted).*/ + chSysLock(); + if (mmcp->mmc_state == MMC_INSERTED) { + mmcp->mmc_state = MMC_READY; + result = FALSE; + } + else + result = TRUE; + chSysUnlock(); + return result; } if (mmcp->mmc_state == MMC_READY) return FALSE; @@ -310,7 +324,7 @@ bool_t mmcStartSequentialRead(MMCDriver *mmcp, uint32_t startblk) { chSysUnlock(); spiSelect(mmcp->mmc_spip); - send_hdr(mmcp, MMC_CMDREADMULTIPLE, startblk << 9); + send_hdr(mmcp, MMC_CMDREADMULTIPLE, startblk * MMC_BLOCK_SIZE); if (recvr1(mmcp) != 0x00) { spiUnselect(mmcp->mmc_spip); chSysLock(); @@ -347,7 +361,7 @@ bool_t mmcSequentialRead(MMCDriver *mmcp, uint8_t *buffer) { for (i = 0; i < MMC_WAIT_DATA; i++) { spiReceive(mmcp->mmc_spip, 1, buffer); if (buffer[0] == 0xFE) { - spiReceive(mmcp->mmc_spip, 512, buffer); + spiReceive(mmcp->mmc_spip, MMC_BLOCK_SIZE, buffer); /* CRC ignored. */ spiIgnore(mmcp->mmc_spip, 2); return FALSE; @@ -418,7 +432,7 @@ bool_t mmcStartSequentialWrite(MMCDriver *mmcp, uint32_t startblk) { chSysUnlock(); spiSelect(mmcp->mmc_spip); - send_hdr(mmcp, MMC_CMDWRITEMULTIPLE, startblk << 9); + send_hdr(mmcp, MMC_CMDWRITEMULTIPLE, startblk * MMC_BLOCK_SIZE); if (recvr1(mmcp) != 0x00) { spiUnselect(mmcp->mmc_spip); chSysLock(); diff --git a/os/io/mmc_spi.h b/os/io/mmc_spi.h index 1a2a29469..e89f17117 100644 --- a/os/io/mmc_spi.h +++ b/os/io/mmc_spi.h @@ -31,6 +31,13 @@ /* Driver pre-compile time settings. */ /*===========================================================================*/ +/** + * @brief Block size for MMC transfers. + */ +#if !defined(MMC_BLOCK_SIZE) || defined(__DOXYGEN__) +#define MMC_BLOCK_SIZE 512 +#endif + /** * @brief Delays insertions. * @details If enabled this options inserts delays into the MMC waiting @@ -70,6 +77,7 @@ #define MMC_CMDINIT 1 #define MMC_CMDREADCSD 9 #define MMC_CMDSTOP 12 +#define MMC_CMDSETBLOCKLEN 16 #define MMC_CMDREAD 17 #define MMC_CMDREADMULTIPLE 18 #define MMC_CMDWRITE 24 -- cgit v1.2.3