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

This commit is contained in:
gdisirio 2009-11-14 11:51:24 +00:00
parent dc283fd4e6
commit 174b6a1ba2
2 changed files with 27 additions and 5 deletions

View File

@ -240,6 +240,7 @@ void mmcStop(MMCDriver *mmcp) {
*/ */
bool_t mmcConnect(MMCDriver *mmcp) { bool_t mmcConnect(MMCDriver *mmcp) {
unsigned i; unsigned i;
bool_t result;
chDbgCheck(mmcp != NULL, "mmcConnect"); chDbgCheck(mmcp != NULL, "mmcConnect");
@ -278,8 +279,21 @@ bool_t mmcConnect(MMCDriver *mmcp) {
/* Initialization complete, full speed. */ /* Initialization complete, full speed. */
spiStart(mmcp->mmc_spip, mmcp->mmc_hscfg); spiStart(mmcp->mmc_spip, mmcp->mmc_hscfg);
/* 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; mmcp->mmc_state = MMC_READY;
return FALSE; result = FALSE;
}
else
result = TRUE;
chSysUnlock();
return result;
} }
if (mmcp->mmc_state == MMC_READY) if (mmcp->mmc_state == MMC_READY)
return FALSE; return FALSE;
@ -310,7 +324,7 @@ bool_t mmcStartSequentialRead(MMCDriver *mmcp, uint32_t startblk) {
chSysUnlock(); chSysUnlock();
spiSelect(mmcp->mmc_spip); spiSelect(mmcp->mmc_spip);
send_hdr(mmcp, MMC_CMDREADMULTIPLE, startblk << 9); send_hdr(mmcp, MMC_CMDREADMULTIPLE, startblk * MMC_BLOCK_SIZE);
if (recvr1(mmcp) != 0x00) { if (recvr1(mmcp) != 0x00) {
spiUnselect(mmcp->mmc_spip); spiUnselect(mmcp->mmc_spip);
chSysLock(); chSysLock();
@ -347,7 +361,7 @@ bool_t mmcSequentialRead(MMCDriver *mmcp, uint8_t *buffer) {
for (i = 0; i < MMC_WAIT_DATA; i++) { for (i = 0; i < MMC_WAIT_DATA; i++) {
spiReceive(mmcp->mmc_spip, 1, buffer); spiReceive(mmcp->mmc_spip, 1, buffer);
if (buffer[0] == 0xFE) { if (buffer[0] == 0xFE) {
spiReceive(mmcp->mmc_spip, 512, buffer); spiReceive(mmcp->mmc_spip, MMC_BLOCK_SIZE, buffer);
/* CRC ignored. */ /* CRC ignored. */
spiIgnore(mmcp->mmc_spip, 2); spiIgnore(mmcp->mmc_spip, 2);
return FALSE; return FALSE;
@ -418,7 +432,7 @@ bool_t mmcStartSequentialWrite(MMCDriver *mmcp, uint32_t startblk) {
chSysUnlock(); chSysUnlock();
spiSelect(mmcp->mmc_spip); spiSelect(mmcp->mmc_spip);
send_hdr(mmcp, MMC_CMDWRITEMULTIPLE, startblk << 9); send_hdr(mmcp, MMC_CMDWRITEMULTIPLE, startblk * MMC_BLOCK_SIZE);
if (recvr1(mmcp) != 0x00) { if (recvr1(mmcp) != 0x00) {
spiUnselect(mmcp->mmc_spip); spiUnselect(mmcp->mmc_spip);
chSysLock(); chSysLock();

View File

@ -31,6 +31,13 @@
/* Driver pre-compile time settings. */ /* 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. * @brief Delays insertions.
* @details If enabled this options inserts delays into the MMC waiting * @details If enabled this options inserts delays into the MMC waiting
@ -70,6 +77,7 @@
#define MMC_CMDINIT 1 #define MMC_CMDINIT 1
#define MMC_CMDREADCSD 9 #define MMC_CMDREADCSD 9
#define MMC_CMDSTOP 12 #define MMC_CMDSTOP 12
#define MMC_CMDSETBLOCKLEN 16
#define MMC_CMDREAD 17 #define MMC_CMDREAD 17
#define MMC_CMDREADMULTIPLE 18 #define MMC_CMDREADMULTIPLE 18
#define MMC_CMDWRITE 24 #define MMC_CMDWRITE 24