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

master
gdisirio 2011-05-01 10:33:44 +00:00
parent 40c7b22bf4
commit d5fb75afc4
3 changed files with 44 additions and 10 deletions

View File

@ -206,6 +206,7 @@ void sdc_lld_send_cmd_none(SDCDriver *sdcp, uint8_t cmd, uint32_t arg) {
/**
* @brief Sends an SDIO command with a short response expected.
* @note The CRC is not verified.
*
* @param[in] sdcp pointer to the @p SDCDriver object
* @param[in[ cmd card command
@ -222,6 +223,37 @@ bool_t sdc_lld_send_cmd_short(SDCDriver *sdcp, uint8_t cmd, uint32_t arg,
uint32_t *resp) {
uint32_t sta;
(void)sdcp;
SDIO->ARG = arg;
SDIO->CMD = (uint32_t)cmd | SDIO_CMD_WAITRESP_0 | SDIO_CMD_CPSMEN;
while (((sta = SDIO->STA) & (SDIO_STA_CMDREND | SDIO_STA_CTIMEOUT |
SDIO_STA_CCRCFAIL)) == 0)
;
SDIO->ICR = 0xFFFFFFFF;
if ((sta & (SDIO_STA_CTIMEOUT)) != 0)
return TRUE;
*resp = SDIO->RESP1;
return FALSE;
}
/**
* @brief Sends an SDIO command with a short response expected and CRC.
*
* @param[in] sdcp pointer to the @p SDCDriver object
* @param[in[ cmd card command
* @param[in] arg command argument
* @param[out] resp pointer to the response buffer (one word)
* @return The operation status.
* @retval FALSE the operation succeeded.
* @retval TRUE the operation failed because timeout, CRC check or
* other errors.
*
* @notapi
*/
bool_t sdc_lld_send_cmd_short_crc(SDCDriver *sdcp, uint8_t cmd, uint32_t arg,
uint32_t *resp) {
uint32_t sta;
(void)sdcp;
SDIO->ARG = arg;
SDIO->CMD = (uint32_t)cmd | SDIO_CMD_WAITRESP_0 | SDIO_CMD_CPSMEN;
@ -236,7 +268,7 @@ bool_t sdc_lld_send_cmd_short(SDCDriver *sdcp, uint8_t cmd, uint32_t arg,
}
/**
* @brief Sends an SDIO command with a long response expected.
* @brief Sends an SDIO command with a long response expected and CRC.
*
* @param[in] sdcp pointer to the @p SDCDriver object
* @param[in[ cmd card command
@ -249,8 +281,8 @@ bool_t sdc_lld_send_cmd_short(SDCDriver *sdcp, uint8_t cmd, uint32_t arg,
*
* @notapi
*/
bool_t sdc_lld_send_cmd_long(SDCDriver *sdcp, uint8_t cmd, uint32_t arg,
uint32_t *resp) {
bool_t sdc_lld_send_cmd_long_crc(SDCDriver *sdcp, uint8_t cmd, uint32_t arg,
uint32_t *resp) {
uint32_t sta;

View File

@ -160,8 +160,10 @@ extern "C" {
void sdc_lld_send_cmd_none(SDCDriver *sdcp, uint8_t cmd, uint32_t arg);
bool_t sdc_lld_send_cmd_short(SDCDriver *sdcp, uint8_t cmd, uint32_t arg,
uint32_t *resp);
bool_t sdc_lld_send_cmd_long(SDCDriver *sdcp, uint8_t cmd, uint32_t arg,
uint32_t *resp);
bool_t sdc_lld_send_cmd_short_crc(SDCDriver *sdcp, uint8_t cmd, uint32_t arg,
uint32_t *resp);
bool_t sdc_lld_send_cmd_long_crc(SDCDriver *sdcp, uint8_t cmd, uint32_t arg,
uint32_t *resp);
#ifdef __cplusplus
}
#endif

View File

@ -146,17 +146,17 @@ bool_t sdcConnect(SDCDriver *sdcp) {
sdc_lld_send_cmd_none(sdcp, SDC_CMD_GO_IDLE_STATE, 0);
/* V2.0 cards detection.*/
if (!sdc_lld_send_cmd_short(sdcp, SDC_CMD_SEND_IF_COND,
SDC_CMD8_PATTERN, &resp))
if (!sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_SEND_IF_COND,
SDC_CMD8_PATTERN, &resp))
sdcp->cardmode |= SDC_MODE_CARDTYPE_SDV20;
/* Voltage verification.*/
if (((resp >> 8) & 0xF) != 1)
goto failed;
if (sdc_lld_send_cmd_short(sdcp, SDC_CMD_APP_CMD, 0, &resp))
if (sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_APP_CMD, 0, &resp))
goto failed;
else {
/* MMC or SD detection.*/
if (sdc_lld_send_cmd_short(sdcp, SDC_CMD_APP_CMD, 0, &resp))
if (sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_APP_CMD, 0, &resp))
sdcp->cardmode |= SDC_MODE_CARDTYPE_MMC;
}
@ -173,7 +173,7 @@ bool_t sdcConnect(SDCDriver *sdcp) {
i = 0;
while (TRUE) {
chThdSleepMilliseconds(10);
if (sdc_lld_send_cmd_short(sdcp, SDC_CMD_APP_CMD, 0, &resp))
if (sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_APP_CMD, 0, &resp))
goto failed;
if (sdc_lld_send_cmd_short(sdcp, SDC_CMD_APP_OP_COND, ocr, &resp))
goto failed;