From 31456cb4fea72d79b9c1af9a5b0cc7e3fed1ed6e Mon Sep 17 00:00:00 2001 From: gdisirio Date: Mon, 2 May 2011 15:23:50 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2914 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/include/sdc.h | 43 ++++++++++++++++++++---------------- os/hal/platforms/STM32/sdc_lld.c | 36 ++++++++++++++++++++++++++++++ os/hal/platforms/STM32/sdc_lld.h | 2 ++ os/hal/src/sdc.c | 47 ++++++++++++++++++++++++++++++++++------ 4 files changed, 102 insertions(+), 26 deletions(-) diff --git a/os/hal/include/sdc.h b/os/hal/include/sdc.h index 802145525..38b907000 100644 --- a/os/hal/include/sdc.h +++ b/os/hal/include/sdc.h @@ -35,25 +35,30 @@ /* Driver constants. */ /*===========================================================================*/ -#define SDC_CMD_GO_IDLE_STATE 0 -#define SDC_CMD_ALL_SEND_CID 2 -#define SDC_CMD_SEND_RELATIVE_ADDR 3 -#define SDC_CMD_SEL_DESEL_CARD 7 -#define SDC_CMD_SEND_IF_COND 8 -#define SDC_CMD_SEND_CSD 9 -#define SDC_CMD_SET_BLOCKLEN 16 -#define SDC_CMD_APP_OP_COND 41 -#define SDC_CMD_APP_CMD 55 - -#define SDC_MODE_CARDTYPE_MASK 0xF -#define SDC_MODE_CARDTYPE_SDV11 0 /**< Card is V1.1 compliant. */ -#define SDC_MODE_CARDTYPE_SDV20 1 /**< Card is V2.0 compliant. */ -#define SDC_MODE_CARDTYPE_MMC 2 /**< Card is MMC compliant. */ -#define SDC_MODE_HIGH_CAPACITY 0x10 /**< High capacity card. */ - -#define SDC_CMD8_PATTERN 0x000001AA - -#define SDC_ACMD41_RETRY 100 +#define SDC_BLOCK_SIZE 512 /**< Fixed block size. */ + +#define SDC_CMD_GO_IDLE_STATE 0 +#define SDC_CMD_ALL_SEND_CID 2 +#define SDC_CMD_SEND_RELATIVE_ADDR 3 +#define SDC_CMD_SEL_DESEL_CARD 7 +#define SDC_CMD_SEND_IF_COND 8 +#define SDC_CMD_SEND_CSD 9 +#define SDC_CMD_STOP_TRANSMISSION 12 +#define SDC_CMD_SET_BLOCKLEN 16 +#define SDC_CMD_READ_MULTIPLE_BLOCK 18 +#define SDC_CMD_WRITE_MULTIPLE_BLOCK 25 +#define SDC_CMD_APP_OP_COND 41 +#define SDC_CMD_APP_CMD 55 + +#define SDC_MODE_CARDTYPE_MASK 0xF +#define SDC_MODE_CARDTYPE_SDV11 0 /**< Card is V1.1 compliant.*/ +#define SDC_MODE_CARDTYPE_SDV20 1 /**< Card is V2.0 compliant.*/ +#define SDC_MODE_CARDTYPE_MMC 2 /**< Card is MMC compliant. */ +#define SDC_MODE_HIGH_CAPACITY 0x10 /**< High capacity card. */ + +#define SDC_CMD8_PATTERN 0x000001AA + +#define SDC_ACMD41_RETRY 100 /*===========================================================================*/ /* Driver pre-compile time settings. */ diff --git a/os/hal/platforms/STM32/sdc_lld.c b/os/hal/platforms/STM32/sdc_lld.c index bc6855fed..b289da8ba 100644 --- a/os/hal/platforms/STM32/sdc_lld.c +++ b/os/hal/platforms/STM32/sdc_lld.c @@ -301,6 +301,42 @@ bool_t sdc_lld_send_cmd_long_crc(SDCDriver *sdcp, uint8_t cmd, uint32_t arg, return FALSE; } +/** + * @brief Data read through the SDIO bus. + * + * @param[in] sdcp pointer to the @p SDCDriver object + * @param[out] buf pointer to the read buffer + * @param[in] n number of blocks to read + * @return The operation status. + * @retval FALSE operation succeeded, the requested blocks have been + * read. + * @retval TRUE operation failed, the state of the buffer is uncertain. + * + * @notapi + */ +bool_t sdc_lld_read_blocks(SDCDriver *sdcp, uint8_t *buf, uint32_t n) { + + return TRUE; +} + +/** + * @brief Data write through the SDIO bus. + * + * @param[in] sdcp pointer to the @p SDCDriver object + * @param[out] buf pointer to the write buffer + * @param[in] n number of blocks to write + * @return The operation status. + * @retval FALSE operation succeeded, the requested blocks have been + * written. + * @retval TRUE operation failed. + * + * @notapi + */ +bool_t sdc_lld_write_blocks(SDCDriver *sdcp, const uint8_t *buf, uint32_t n) { + + return TRUE; +} + #endif /* HAL_USE_SDC */ /** @} */ diff --git a/os/hal/platforms/STM32/sdc_lld.h b/os/hal/platforms/STM32/sdc_lld.h index e55205b53..349c1df95 100644 --- a/os/hal/platforms/STM32/sdc_lld.h +++ b/os/hal/platforms/STM32/sdc_lld.h @@ -172,6 +172,8 @@ extern "C" { uint32_t *resp); bool_t sdc_lld_send_cmd_long_crc(SDCDriver *sdcp, uint8_t cmd, uint32_t arg, uint32_t *resp); + bool_t sdc_lld_read_blocks(SDCDriver *sdcp, uint8_t *buffer, uint32_t n); + bool_t sdc_lld_write_blocks(SDCDriver *sdcp, const uint8_t *buf, uint32_t n); #ifdef __cplusplus } #endif diff --git a/os/hal/src/sdc.c b/os/hal/src/sdc.c index a4b80e60b..847647de4 100644 --- a/os/hal/src/sdc.c +++ b/os/hal/src/sdc.c @@ -205,8 +205,9 @@ bool_t sdcConnect(SDCDriver *sdcp) { if (sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_SEL_DESEL_CARD, resp[0], resp)) goto failed; - /* Block lenght fixed at 512 bytes.*/ - if (sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_SET_BLOCKLEN, 512, resp)) + /* Block length fixed at 512 bytes.*/ + if (sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_SET_BLOCKLEN, + SDC_BLOCK_SIZE, resp)) goto failed; /* Switches to wide bus mode.*/ @@ -237,7 +238,7 @@ failed: */ bool_t sdcDisconnect(SDCDriver *sdcp) { - chDbgCheck(sdcp != NULL, "sdcConnect"); + chDbgCheck(sdcp != NULL, "sdcDisconnect"); chSysLock(); chDbgAssert(sdcp->state == SDC_ACTIVE, @@ -255,7 +256,8 @@ bool_t sdcDisconnect(SDCDriver *sdcp) { * * @param[in] sdcp pointer to the @p SDCDriver object * @param[in] startblk first block to read - * @param[out] buffer pointer to the read buffer + * @param[out] buf pointer to the read buffer + * @param[in] n number of blocks to read * @return The operation status. * @retval FALSE operation succeeded, the requested blocks have been * read. @@ -264,8 +266,23 @@ bool_t sdcDisconnect(SDCDriver *sdcp) { * @api */ bool_t sdcRead(SDCDriver *sdcp, uint32_t startblk, - uint8_t *buffer, uint32_t n) { + uint8_t *buf, uint32_t n) { + bool_t sts; + uint32_t resp[1]; + + chDbgCheck((sdcp != NULL) && (buffer != NULL) && (n > 0), "sdcRead"); + + if ((sdcp->cardmode & SDC_MODE_HIGH_CAPACITY) == 0) + startblk *= SDC_BLOCK_SIZE; + + if (sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_READ_MULTIPLE_BLOCK, + startblk, resp)) + return TRUE; + sts = sdc_lld_read_blocks(sdcp, buffer, n); + sts = sts || sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_STOP_TRANSMISSION, + 0, resp); + return sts; } /** @@ -275,7 +292,8 @@ bool_t sdcRead(SDCDriver *sdcp, uint32_t startblk, * * @param[in] sdcp pointer to the @p SDCDriver object * @param[in] startblk first block to write - * @param[out] buffer pointer to the write buffer + * @param[out] buf pointer to the write buffer + * @param[in] n number of blocks to write * @return The operation status. * @retval FALSE operation succeeded, the requested blocks have been * written. @@ -284,8 +302,23 @@ bool_t sdcRead(SDCDriver *sdcp, uint32_t startblk, * @api */ bool_t sdcWrite(SDCDriver *sdcp, uint32_t startblk, - const uint8_t *buffer, uint32_t n) { + const uint8_t *buf, uint32_t n) { + bool_t sts; + uint32_t resp[1]; + + chDbgCheck((sdcp != NULL) && (buffer != NULL) && (n > 0), "sdcWrite"); + + if ((sdcp->cardmode & SDC_MODE_HIGH_CAPACITY) == 0) + startblk *= SDC_BLOCK_SIZE; + + if (sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_READ_MULTIPLE_BLOCK, + startblk, resp)) + return TRUE; + sts = sdc_lld_write_blocks(sdcp, buffer, n); + sts = sts || sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_STOP_TRANSMISSION, + 0, resp); + return sts; } #endif /* HAL_USE_SDC */ -- cgit v1.2.3