git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2914 35acf78f-673a-0410-8e92-d51de3d6d3f4

This commit is contained in:
gdisirio 2011-05-02 15:23:50 +00:00
parent 9dd9aca2d4
commit 31456cb4fe
4 changed files with 99 additions and 23 deletions

View File

@ -35,19 +35,24 @@
/* Driver constants. */
/*===========================================================================*/
#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_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. */

View File

@ -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 */
/** @} */

View File

@ -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

View File

@ -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 */