aboutsummaryrefslogtreecommitdiffstats
path: root/os/hal/src
diff options
context:
space:
mode:
authorgdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2012-05-10 12:26:24 +0000
committergdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2012-05-10 12:26:24 +0000
commit97dce7b94464b891a25170e6556daac5bb30f7ef (patch)
tree41c359d3c2297f48867eb614be59c9f91d51e65d /os/hal/src
parent6a8a643ab00e5964a3fb77e5b2394561bb797e55 (diff)
downloadChibiOS-97dce7b94464b891a25170e6556daac5bb30f7ef.tar.gz
ChibiOS-97dce7b94464b891a25170e6556daac5bb30f7ef.tar.bz2
ChibiOS-97dce7b94464b891a25170e6556daac5bb30f7ef.zip
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@4180 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'os/hal/src')
-rw-r--r--os/hal/src/mmc_spi.c114
-rw-r--r--os/hal/src/mmcsd.c120
-rw-r--r--os/hal/src/sdc.c113
3 files changed, 205 insertions, 142 deletions
diff --git a/os/hal/src/mmc_spi.c b/os/hal/src/mmc_spi.c
index 97f4f271d..dad837613 100644
--- a/os/hal/src/mmc_spi.c
+++ b/os/hal/src/mmc_spi.c
@@ -108,7 +108,7 @@ bool_t mmc_read(void *instance, uint32_t startblk,
while (n > 0) {
if (mmcSequentialRead((MMCDriver *)instance, buffer))
return TRUE;
- buffer += SDMMC_BLOCK_SIZE;
+ buffer += MMCSD_BLOCK_SIZE;
n--;
}
if (mmcStopSequentialRead((MMCDriver *)instance))
@@ -124,7 +124,7 @@ bool_t mmc_write(void *instance, uint32_t startblk,
while (n > 0) {
if (mmcSequentialWrite((MMCDriver *)instance, buffer))
return TRUE;
- buffer += SDMMC_BLOCK_SIZE;
+ buffer += MMCSD_BLOCK_SIZE;
n--;
}
if (mmcStopSequentialWrite((MMCDriver *)instance))
@@ -191,13 +191,13 @@ static void wait(MMCDriver *mmcp) {
uint8_t buf[4];
for (i = 0; i < 16; i++) {
- spiReceive(mmcp->spip, 1, buf);
+ spiReceive(mmcp->config->spip, 1, buf);
if (buf[0] == 0xFF)
return;
}
/* Looks like it is a long wait.*/
while (TRUE) {
- spiReceive(mmcp->spip, 1, buf);
+ spiReceive(mmcp->config->spip, 1, buf);
if (buf[0] == 0xFF)
break;
#ifdef MMC_NICE_WAITING
@@ -230,7 +230,7 @@ static void send_hdr(MMCDriver *mmcp, uint8_t cmd, uint32_t arg) {
/* Calculate CRC for command header, shift to right position, add stop bit.*/
buf[5] = ((crc7(0, buf, 5) & 0x7F) << 1) | 0x01;
- spiSend(mmcp->spip, 6, buf);
+ spiSend(mmcp->config->spip, 6, buf);
}
/**
@@ -247,7 +247,7 @@ static uint8_t recvr1(MMCDriver *mmcp) {
uint8_t r1[1];
for (i = 0; i < 9; i++) {
- spiReceive(mmcp->spip, 1, r1);
+ spiReceive(mmcp->config->spip, 1, r1);
if (r1[0] != 0xFF)
return r1[0];
}
@@ -268,7 +268,7 @@ static uint8_t recvr3(MMCDriver *mmcp, uint8_t* buffer) {
uint8_t r1;
r1 = recvr1(mmcp);
- spiReceive(mmcp->spip, 4, buffer);
+ spiReceive(mmcp->config->spip, 4, buffer);
return r1;
}
@@ -287,10 +287,10 @@ static uint8_t recvr3(MMCDriver *mmcp, uint8_t* buffer) {
static uint8_t send_command_R1(MMCDriver *mmcp, uint8_t cmd, uint32_t arg) {
uint8_t r1;
- spiSelect(mmcp->spip);
+ spiSelect(mmcp->config->spip);
send_hdr(mmcp, cmd, arg);
r1 = recvr1(mmcp);
- spiUnselect(mmcp->spip);
+ spiUnselect(mmcp->config->spip);
return r1;
}
@@ -311,10 +311,10 @@ static uint8_t send_command_R3(MMCDriver *mmcp, uint8_t cmd, uint32_t arg,
uint8_t *response) {
uint8_t r1;
- spiSelect(mmcp->spip);
+ spiSelect(mmcp->config->spip);
send_hdr(mmcp, cmd, arg);
r1 = recvr3(mmcp, response);
- spiUnselect(mmcp->spip);
+ spiUnselect(mmcp->config->spip);
return r1;
}
@@ -328,16 +328,16 @@ static uint8_t send_command_R3(MMCDriver *mmcp, uint8_t cmd, uint32_t arg,
static void sync(MMCDriver *mmcp) {
uint8_t buf[1];
- spiSelect(mmcp->spip);
+ spiSelect(mmcp->config->spip);
while (TRUE) {
- spiReceive(mmcp->spip, 1, buf);
+ spiReceive(mmcp->config->spip, 1, buf);
if (buf[0] == 0xFF)
break;
#ifdef MMC_NICE_WAITING
chThdSleep(1); /* Trying to be nice with the other threads.*/
#endif
}
- spiUnselect(mmcp->spip);
+ spiUnselect(mmcp->config->spip);
}
/*===========================================================================*/
@@ -369,15 +369,11 @@ void mmcInit(void) {
*
* @init
*/
-void mmcObjectInit(MMCDriver *mmcp, SPIDriver *spip,
- const SPIConfig *lscfg, const SPIConfig *hscfg) {
+void mmcObjectInit(MMCDriver *mmcp) {
mmcp->vmt = &mmc_vmt;
mmcp->state = MMC_STOP;
mmcp->config = NULL;
- mmcp->spip = spip;
- mmcp->lscfg = lscfg;
- mmcp->hscfg = hscfg;
mmcp->block_addresses = FALSE;
chEvtInit(&mmcp->inserted_event);
chEvtInit(&mmcp->removed_event);
@@ -425,7 +421,7 @@ void mmcStop(MMCDriver *mmcp) {
chVTResetI(&mmcp->vt);
}
chSysUnlock();
- spiStop(mmcp->spip);
+ spiStop(mmcp->config->spip);
}
/**
@@ -456,13 +452,13 @@ bool_t mmcConnect(MMCDriver *mmcp) {
if (mmcp->state == MMC_INSERTED) {
/* Slow clock mode and 128 clock pulses.*/
- spiStart(mmcp->spip, mmcp->lscfg);
- spiIgnore(mmcp->spip, 16);
+ spiStart(mmcp->config->spip, mmcp->config->lscfg);
+ spiIgnore(mmcp->config->spip, 16);
/* SPI mode selection.*/
i = 0;
while (TRUE) {
- if (send_command_R1(mmcp, SDMMC_CMD_GO_IDLE_STATE, 0) == 0x01)
+ if (send_command_R1(mmcp, MMCSD_CMD_GO_IDLE_STATE, 0) == 0x01)
break;
if (++i >= MMC_CMD0_RETRY)
return TRUE;
@@ -474,14 +470,14 @@ bool_t mmcConnect(MMCDriver *mmcp) {
This method is based on "How to support SDC Ver2 and high capacity cards"
by ElmChan.*/
uint8_t r3[4];
- if (send_command_R3(mmcp, SDMMC_CMD_SEND_IF_COND,
- SDMMC_CMD8_PATTERN, r3) != 0x05) {
+ if (send_command_R3(mmcp, MMCSD_CMD_SEND_IF_COND,
+ MMCSD_CMD8_PATTERN, r3) != 0x05) {
/* Switch to SDHC mode.*/
i = 0;
while (TRUE) {
- if ((send_command_R1(mmcp, SDMMC_CMD_APP_CMD, 0) == 0x01) &&
- (send_command_R3(mmcp, SDMMC_CMD_APP_OP_COND,
+ if ((send_command_R1(mmcp, MMCSD_CMD_APP_CMD, 0) == 0x01) &&
+ (send_command_R3(mmcp, MMCSD_CMD_APP_OP_COND,
0x400001aa, r3) == 0x00))
break;
@@ -491,7 +487,7 @@ bool_t mmcConnect(MMCDriver *mmcp) {
}
/* Execute dedicated read on OCR register */
- send_command_R3(mmcp, SDMMC_CMD_READ_OCR, 0, r3);
+ send_command_R3(mmcp, MMCSD_CMD_READ_OCR, 0, r3);
/* Check if CCS is set in response. Card operates in block mode if set.*/
if(r3[0] & 0x40)
@@ -501,7 +497,7 @@ bool_t mmcConnect(MMCDriver *mmcp) {
/* Initialization.*/
i = 0;
while (TRUE) {
- uint8_t b = send_command_R1(mmcp, SDMMC_CMD_INIT, 0);
+ uint8_t b = send_command_R1(mmcp, MMCSD_CMD_INIT, 0);
if (b == 0x00)
break;
if (b != 0x01)
@@ -512,11 +508,11 @@ bool_t mmcConnect(MMCDriver *mmcp) {
}
/* Initialization complete, full speed.*/
- spiStart(mmcp->spip, mmcp->hscfg);
+ spiStart(mmcp->config->spip, mmcp->config->hscfg);
/* Setting block size.*/
- if (send_command_R1(mmcp, SDMMC_CMD_SET_BLOCKLEN,
- SDMMC_BLOCK_SIZE) != 0x00)
+ if (send_command_R1(mmcp, MMCSD_CMD_SET_BLOCKLEN,
+ MMCSD_BLOCK_SIZE) != 0x00)
return TRUE;
/* Transition to MMC_READY state (if not extracted).*/
@@ -568,7 +564,7 @@ bool_t mmcDisconnect(MMCDriver *mmcp) {
default:
status = TRUE;
}
- spiStop(mmcp->spip);
+ spiStop(mmcp->config->spip);
return status;
}
@@ -596,16 +592,16 @@ bool_t mmcStartSequentialRead(MMCDriver *mmcp, uint32_t startblk) {
mmcp->state = MMC_READING;
chSysUnlock();
- spiStart(mmcp->spip, mmcp->hscfg);
- spiSelect(mmcp->spip);
+ spiStart(mmcp->config->spip, mmcp->config->hscfg);
+ spiSelect(mmcp->config->spip);
if(mmcp->block_addresses)
- send_hdr(mmcp, SDMMC_CMD_READ_MULTIPLE_BLOCK, startblk);
+ send_hdr(mmcp, MMCSD_CMD_READ_MULTIPLE_BLOCK, startblk);
else
- send_hdr(mmcp, SDMMC_CMD_READ_MULTIPLE_BLOCK, startblk * SDMMC_BLOCK_SIZE);
+ send_hdr(mmcp, MMCSD_CMD_READ_MULTIPLE_BLOCK, startblk * MMCSD_BLOCK_SIZE);
if (recvr1(mmcp) != 0x00) {
- spiUnselect(mmcp->spip);
+ spiUnselect(mmcp->config->spip);
chSysLock();
if (mmcp->state == MMC_READING)
mmcp->state = MMC_READY;
@@ -640,16 +636,16 @@ bool_t mmcSequentialRead(MMCDriver *mmcp, uint8_t *buffer) {
chSysUnlock();
for (i = 0; i < MMC_WAIT_DATA; i++) {
- spiReceive(mmcp->spip, 1, buffer);
+ spiReceive(mmcp->config->spip, 1, buffer);
if (buffer[0] == 0xFE) {
- spiReceive(mmcp->spip, SDMMC_BLOCK_SIZE, buffer);
+ spiReceive(mmcp->config->spip, MMCSD_BLOCK_SIZE, buffer);
/* CRC ignored. */
- spiIgnore(mmcp->spip, 2);
+ spiIgnore(mmcp->config->spip, 2);
return FALSE;
}
}
/* Timeout.*/
- spiUnselect(mmcp->spip);
+ spiUnselect(mmcp->config->spip);
chSysLock();
if (mmcp->state == MMC_READING)
mmcp->state = MMC_READY;
@@ -669,7 +665,7 @@ bool_t mmcSequentialRead(MMCDriver *mmcp, uint8_t *buffer) {
* @api
*/
bool_t mmcStopSequentialRead(MMCDriver *mmcp) {
- static const uint8_t stopcmd[] = {0x40 | SDMMC_CMD_STOP_TRANSMISSION,
+ static const uint8_t stopcmd[] = {0x40 | MMCSD_CMD_STOP_TRANSMISSION,
0, 0, 0, 0, 1, 0xFF};
bool_t result;
@@ -682,12 +678,12 @@ bool_t mmcStopSequentialRead(MMCDriver *mmcp) {
}
chSysUnlock();
- spiSend(mmcp->spip, sizeof(stopcmd), stopcmd);
+ spiSend(mmcp->config->spip, sizeof(stopcmd), stopcmd);
/* result = recvr1(mmcp) != 0x00;*/
/* Note, ignored r1 response, it can be not zero, unknown issue.*/
recvr1(mmcp);
result = FALSE;
- spiUnselect(mmcp->spip);
+ spiUnselect(mmcp->config->spip);
chSysLock();
if (mmcp->state == MMC_READING)
@@ -720,17 +716,17 @@ bool_t mmcStartSequentialWrite(MMCDriver *mmcp, uint32_t startblk) {
mmcp->state = MMC_WRITING;
chSysUnlock();
- spiStart(mmcp->spip, mmcp->hscfg);
- spiSelect(mmcp->spip);
+ spiStart(mmcp->config->spip, mmcp->config->hscfg);
+ spiSelect(mmcp->config->spip);
if(mmcp->block_addresses)
- send_hdr(mmcp, SDMMC_CMD_WRITE_MULTIPLE_BLOCK, startblk);
+ send_hdr(mmcp, MMCSD_CMD_WRITE_MULTIPLE_BLOCK, startblk);
else
- send_hdr(mmcp, SDMMC_CMD_WRITE_MULTIPLE_BLOCK,
- startblk * SDMMC_BLOCK_SIZE);
+ send_hdr(mmcp, MMCSD_CMD_WRITE_MULTIPLE_BLOCK,
+ startblk * MMCSD_BLOCK_SIZE);
if (recvr1(mmcp) != 0x00) {
- spiUnselect(mmcp->spip);
+ spiUnselect(mmcp->config->spip);
chSysLock();
if (mmcp->state == MMC_WRITING)
mmcp->state = MMC_READY;
@@ -765,17 +761,17 @@ bool_t mmcSequentialWrite(MMCDriver *mmcp, const uint8_t *buffer) {
}
chSysUnlock();
- spiSend(mmcp->spip, sizeof(start), start); /* Data prologue. */
- spiSend(mmcp->spip, SDMMC_BLOCK_SIZE, buffer); /* Data. */
- spiIgnore(mmcp->spip, 2); /* CRC ignored. */
- spiReceive(mmcp->spip, 1, b);
+ spiSend(mmcp->config->spip, sizeof(start), start); /* Data prologue. */
+ spiSend(mmcp->config->spip, MMCSD_BLOCK_SIZE, buffer);/* Data. */
+ spiIgnore(mmcp->config->spip, 2); /* CRC ignored. */
+ spiReceive(mmcp->config->spip, 1, b);
if ((b[0] & 0x1F) == 0x05) {
wait(mmcp);
return FALSE;
}
/* Error.*/
- spiUnselect(mmcp->spip);
+ spiUnselect(mmcp->config->spip);
chSysLock();
if (mmcp->state == MMC_WRITING)
mmcp->state = MMC_READY;
@@ -806,8 +802,8 @@ bool_t mmcStopSequentialWrite(MMCDriver *mmcp) {
}
chSysUnlock();
- spiSend(mmcp->spip, sizeof(stop), stop);
- spiUnselect(mmcp->spip);
+ spiSend(mmcp->config->spip, sizeof(stop), stop);
+ spiUnselect(mmcp->config->spip);
chSysLock();
if (mmcp->state == MMC_WRITING) {
@@ -871,7 +867,7 @@ bool_t mmcGetInfo(MMCDriver *mmcp, BlockDeviceInfo *bdip) {
chSysUnlock();
bdip->blk_num = 0; /* NOTE: To be implemented.*/
- bdip->blk_size = SDMMC_BLOCK_SIZE;
+ bdip->blk_size = MMCSD_BLOCK_SIZE;
return FALSE;
}
diff --git a/os/hal/src/mmcsd.c b/os/hal/src/mmcsd.c
new file mode 100644
index 000000000..88f8a5505
--- /dev/null
+++ b/os/hal/src/mmcsd.c
@@ -0,0 +1,120 @@
+/*
+ ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
+ 2011,2012 Giovanni Di Sirio.
+
+ This file is part of ChibiOS/RT.
+
+ ChibiOS/RT is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ ChibiOS/RT is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+/**
+ * @file mmcsd.c
+ * @brief MMC/SD cards common code.
+ *
+ * @addtogroup MMCSD
+ * @{
+ */
+
+#include "ch.h"
+#include "hal.h"
+
+#if HAL_USE_MMC_SPI || HAL_USE_SDC || defined(__DOXYGEN__)
+
+/*===========================================================================*/
+/* Driver local definitions. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver exported variables. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver local variables. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver local functions. */
+/*===========================================================================*/
+
+/**
+ * @brief Get slice with data from uint32_t[4] array.
+ *
+ * @notapi
+ */
+static uint32_t mmcsd_get_slice(uint32_t *data, uint32_t end, uint32_t start) {
+ uint32_t word = 0;
+ uint32_t mask = 0;
+
+ chDbgCheck(end >= start, "sdc_get_slice");
+
+ while ((start - 32 * word) > 31){
+ word++;
+ data++;
+ }
+
+ end -= 32 * word;
+ start -= 32 * word;
+
+ if (end < 31){
+ /* Value lays in one word.*/
+ mask = (1 << (end - start + 1)) - 1;
+ return (*data >> start) & mask;
+ }
+ else{
+ /* Value spread on separate words.*/
+ uint32_t lsb, msb;
+ lsb = *data >> start;
+ data++;
+ mask = (1 << (end - 32 + 1)) - 1;
+ msb = *data & mask;
+ msb = msb << (32 - start);
+ return msb | lsb;
+ }
+}
+
+/*===========================================================================*/
+/* Driver exported functions. */
+/*===========================================================================*/
+
+/**
+ * @brief Extract card capacity from a CSD.
+ * @details The capacity is returned as number of available blocks.
+ *
+ * @param[in] csd the CSD record
+ *
+ * @return The card capacity.
+ * @retval 0 CSD format error
+ */
+uint32_t mmcsdGetCapacity(uint32_t csd[4]) {
+
+ switch (csd[3] >> 30) {
+ uint32_t a, b, c;
+ case 0:
+ /* CSD version 1.0 */
+ a = mmcsd_get_slice(csd, MMCSD_CSD_10_C_SIZE_SLICE);
+ b = mmcsd_get_slice(csd, MMCSD_CSD_10_C_SIZE_MULT_SLICE);
+ c = mmcsd_get_slice(csd, MMCSD_CSD_10_READ_BL_LEN_SLICE);
+ return (a + 1) << (b + 2) << (c - 9); /* 2^9 == MMCSD_BLOCK_SIZE. */
+ case 1:
+ /* CSD version 2.0.*/
+ return 1024 * (mmcsd_get_slice(csd, MMCSD_CSD_20_C_SIZE_SLICE) + 1);
+ default:
+ /* Reserved value detected.*/
+ return 0;
+ }
+}
+
+#endif /* HAL_USE_MMC_SPI || HAL_USE_SDC */
+
+/** @} */
diff --git a/os/hal/src/sdc.c b/os/hal/src/sdc.c
index 483263776..3ff938f98 100644
--- a/os/hal/src/sdc.c
+++ b/os/hal/src/sdc.c
@@ -62,42 +62,6 @@ static const struct MMCSDBlockDeviceVMT sdc_vmt = {
/*===========================================================================*/
/**
- * @brief Get slice with data from uint32_t[4] array.
- *
- * @notapi
- */
-static uint32_t _sdc_get_slice(uint32_t *data, int32_t end, int32_t start) {
- uint32_t word = 0;
- uint32_t mask = 0;
-
- chDbgCheck(((start >=0) && (end >=0) && (end >= start)), "sdc_get_slice");
-
- while ((start - 32 * word) > 31){
- word++;
- data++;
- }
-
- end -= 32 * word;
- start -= 32 * word;
-
- if (end < 31){
- /* Value lays in one word.*/
- mask = (1 << (end - start + 1)) - 1;
- return (*data >> start) & mask;
- }
- else{
- /* Value spread on separate words.*/
- uint32_t lsb, msb;
- lsb = *data >> start;
- data++;
- mask = (1 << (end - 32 + 1)) - 1;
- msb = *data & mask;
- msb = msb << (32 - start);
- return (msb | lsb);
- }
-}
-
-/**
* @brief Wait for the card to complete pending operations.
*
* @param[in] sdcp pointer to the @p SDCDriver object
@@ -112,16 +76,16 @@ bool_t _sdc_wait_for_transfer_state(SDCDriver *sdcp) {
uint32_t resp[1];
while (TRUE) {
- if (sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_SEND_STATUS,
+ if (sdc_lld_send_cmd_short_crc(sdcp, MMCSD_CMD_SEND_STATUS,
sdcp->rca, resp) ||
- SDC_R1_ERROR(resp[0]))
+ MMCSD_R1_ERROR(resp[0]))
return CH_FAILED;
- switch (SDC_R1_STS(resp[0])) {
- case SDC_STS_TRAN:
+ switch (MMCSD_R1_STS(resp[0])) {
+ case MMCSD_STS_TRAN:
return CH_SUCCESS;
- case SDC_STS_DATA:
- case SDC_STS_RCV:
- case SDC_STS_PRG:
+ case MMCSD_STS_DATA:
+ case MMCSD_STS_RCV:
+ case MMCSD_STS_PRG:
#if SDC_NICE_WAITING
chThdSleepMilliseconds(1);
#endif
@@ -239,23 +203,23 @@ bool_t sdcConnect(SDCDriver *sdcp) {
sdc_lld_start_clk(sdcp);
/* Enforces the initial card state.*/
- sdc_lld_send_cmd_none(sdcp, SDC_CMD_GO_IDLE_STATE, 0);
+ sdc_lld_send_cmd_none(sdcp, MMCSD_CMD_GO_IDLE_STATE, 0);
/* V2.0 cards detection.*/
- if (!sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_SEND_IF_COND,
- SDC_CMD8_PATTERN, resp)) {
+ if (!sdc_lld_send_cmd_short_crc(sdcp, MMCSD_CMD_SEND_IF_COND,
+ MMCSD_CMD8_PATTERN, resp)) {
sdcp->cardmode = SDC_MODE_CARDTYPE_SDV20;
/* Voltage verification.*/
if (((resp[0] >> 8) & 0xF) != 1)
goto failed;
- if (sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_APP_CMD, 0, resp) ||
- SDC_R1_ERROR(resp[0]))
+ if (sdc_lld_send_cmd_short_crc(sdcp, MMCSD_CMD_APP_CMD, 0, resp) ||
+ MMCSD_R1_ERROR(resp[0]))
goto failed;
}
else {
#if SDC_MMC_SUPPORT
/* MMC or SD V1.1 detection.*/
- if (sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_APP_CMD, 0, resp) ||
+ if (sdc_lld_send_cmd_short_crc(sdcp, SDMMC_CMD_APP_CMD, 0, resp) ||
SDC_R1_ERROR(resp[0]))
sdcp->cardmode = SDC_MODE_CARDTYPE_MMC;
else
@@ -283,10 +247,10 @@ bool_t sdcConnect(SDCDriver *sdcp) {
/* SD-type initialization. */
i = 0;
while (TRUE) {
- if (sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_APP_CMD, 0, resp) ||
- SDC_R1_ERROR(resp[0]))
+ if (sdc_lld_send_cmd_short_crc(sdcp, MMCSD_CMD_APP_CMD, 0, resp) ||
+ MMCSD_R1_ERROR(resp[0]))
goto failed;
- if (sdc_lld_send_cmd_short(sdcp, SDC_CMD_APP_OP_COND, ocr, resp))
+ if (sdc_lld_send_cmd_short(sdcp, MMCSD_CMD_APP_OP_COND, ocr, resp))
goto failed;
if ((resp[0] & 0x80000000) != 0) {
if (resp[0] & 0x40000000)
@@ -300,30 +264,31 @@ bool_t sdcConnect(SDCDriver *sdcp) {
}
/* Reads CID.*/
- if (sdc_lld_send_cmd_long_crc(sdcp, SDC_CMD_ALL_SEND_CID, 0, sdcp->cid))
+ if (sdc_lld_send_cmd_long_crc(sdcp, MMCSD_CMD_ALL_SEND_CID, 0, sdcp->cid))
goto failed;
/* Asks for the RCA.*/
- if (sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_SEND_RELATIVE_ADDR,
+ if (sdc_lld_send_cmd_short_crc(sdcp, MMCSD_CMD_SEND_RELATIVE_ADDR,
0, &sdcp->rca))
goto failed;
/* Reads CSD.*/
- if (sdc_lld_send_cmd_long_crc(sdcp, SDC_CMD_SEND_CSD, sdcp->rca, sdcp->csd))
+ if (sdc_lld_send_cmd_long_crc(sdcp, MMCSD_CMD_SEND_CSD,
+ sdcp->rca, sdcp->csd))
goto failed;
/* Switches to high speed.*/
sdc_lld_set_data_clk(sdcp);
/* Selects the card for operations.*/
- if (sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_SEL_DESEL_CARD,
+ if (sdc_lld_send_cmd_short_crc(sdcp, MMCSD_CMD_SEL_DESEL_CARD,
sdcp->rca, resp))
goto failed;
/* Block length fixed at 512 bytes.*/
- if (sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_SET_BLOCKLEN,
- SDC_BLOCK_SIZE, resp) ||
- SDC_R1_ERROR(resp[0]))
+ if (sdc_lld_send_cmd_short_crc(sdcp, MMCSD_CMD_SET_BLOCKLEN,
+ MMCSD_BLOCK_SIZE, resp) ||
+ MMCSD_R1_ERROR(resp[0]))
goto failed;
/* Switches to wide bus mode.*/
@@ -331,35 +296,17 @@ bool_t sdcConnect(SDCDriver *sdcp) {
case SDC_MODE_CARDTYPE_SDV11:
case SDC_MODE_CARDTYPE_SDV20:
sdc_lld_set_bus_mode(sdcp, SDC_MODE_4BIT);
- if (sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_APP_CMD, sdcp->rca, resp) ||
- SDC_R1_ERROR(resp[0]))
+ if (sdc_lld_send_cmd_short_crc(sdcp, MMCSD_CMD_APP_CMD, sdcp->rca, resp) ||
+ MMCSD_R1_ERROR(resp[0]))
goto failed;
- if (sdc_lld_send_cmd_short_crc(sdcp, SDC_CMD_SET_BUS_WIDTH, 2, resp) ||
- SDC_R1_ERROR(resp[0]))
+ if (sdc_lld_send_cmd_short_crc(sdcp, MMCSD_CMD_SET_BUS_WIDTH, 2, resp) ||
+ MMCSD_R1_ERROR(resp[0]))
goto failed;
break;
}
/* Determine capacity.*/
- switch (sdcp->csd[3] >> 30) {
- uint32_t a, b, c;
- case 0:
- /* CSD version 1.0 */
- a = _sdc_get_slice(sdcp->csd, SDC_CSD_10_C_SIZE_SLICE);
- b = _sdc_get_slice(sdcp->csd, SDC_CSD_10_C_SIZE_MULT_SLICE);
- c = _sdc_get_slice(sdcp->csd, SDC_CSD_10_READ_BL_LEN_SLICE);
- sdcp->capacity = ((a + 1) << (b + 2) << c) / 512;
- break;
- case 1:
- /* CSD version 2.0 */
- a = _sdc_get_slice(sdcp->csd, SDC_CSD_20_C_SIZE_SLICE);
- sdcp->capacity = 1024 * (a + 1);
- break;
- default:
- /* Reserved value detected. */
- sdcp->capacity = 0;
- break;
- }
+ sdcp->capacity = mmcsdGetCapacity(sdcp->csd);
if (sdcp->capacity == 0)
goto failed;
@@ -553,7 +500,7 @@ bool_t sdcGetInfo(SDCDriver *sdcp, BlockDeviceInfo *bdip) {
chSysUnlock();
bdip->blk_num = 0; /* NOTE: To be implemented.*/
- bdip->blk_size = SDMMC_BLOCK_SIZE;
+ bdip->blk_size = MMCSD_BLOCK_SIZE;
return FALSE;
}