From 6a8a643ab00e5964a3fb77e5b2394561bb797e55 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Wed, 9 May 2012 18:44:47 +0000 Subject: [PATCH] git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@4179 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- boards/OLIMEX_STM32_P103/board.c | 15 +++++++++++++++ demos/ARMCM3-STM32F103-FATFS/main.c | 10 +--------- os/hal/include/mmc_spi.h | 22 ++++------------------ os/hal/src/mmc_spi.c | 25 +++++-------------------- readme.txt | 6 ++++-- 5 files changed, 29 insertions(+), 49 deletions(-) diff --git a/boards/OLIMEX_STM32_P103/board.c b/boards/OLIMEX_STM32_P103/board.c index 92f1fe364..cdd45553c 100644 --- a/boards/OLIMEX_STM32_P103/board.c +++ b/boards/OLIMEX_STM32_P103/board.c @@ -47,6 +47,21 @@ void __early_init(void) { stm32_clock_init(); } +#if HAL_USE_MMC_SPI +/* Board-related functions related to the MMC_SPI driver.*/ +bool_t mmc_lld_is_card_inserted(MMCDriver *mmcp) { + + (void)mmcp; + return palReadPad(GPIOC, GPIOC_MMCCP); +} + +bool_t mmc_lld_is_write_protected(MMCDriver *mmcp) { + + (void)mmcp; + return !palReadPad(GPIOC, GPIOC_MMCWP); +} +#endif + /* * Board-specific initialization code. */ diff --git a/demos/ARMCM3-STM32F103-FATFS/main.c b/demos/ARMCM3-STM32F103-FATFS/main.c index c45b119b0..8df04aef7 100644 --- a/demos/ARMCM3-STM32F103-FATFS/main.c +++ b/demos/ARMCM3-STM32F103-FATFS/main.c @@ -53,12 +53,6 @@ static SPIConfig hs_spicfg = {NULL, IOPORT2, GPIOB_SPI2NSS, 0}; static SPIConfig ls_spicfg = {NULL, IOPORT2, GPIOB_SPI2NSS, SPI_CR1_BR_2 | SPI_CR1_BR_1}; -/* Card insertion verification.*/ -static bool_t mmc_is_inserted(void) {return palReadPad(IOPORT3, GPIOC_MMCCP);} - -/* Card protection verification.*/ -static bool_t mmc_is_protected(void) {return !palReadPad(IOPORT3, GPIOC_MMCWP);} - /* Generic large buffer.*/ uint8_t fbuff[1024]; @@ -277,9 +271,7 @@ int main(void) { */ palSetPadMode(IOPORT2, GPIOB_SPI2NSS, PAL_MODE_OUTPUT_PUSHPULL); palSetPad(IOPORT2, GPIOB_SPI2NSS); - mmcObjectInit(&MMCD1, &SPID2, - &ls_spicfg, &hs_spicfg, - mmc_is_protected, mmc_is_inserted); + mmcObjectInit(&MMCD1, &SPID2, &ls_spicfg, &hs_spicfg); mmcStart(&MMCD1, NULL); /* diff --git a/os/hal/include/mmc_spi.h b/os/hal/include/mmc_spi.h index fd2850576..760ab3ad1 100644 --- a/os/hal/include/mmc_spi.h +++ b/os/hal/include/mmc_spi.h @@ -101,13 +101,6 @@ typedef enum { MMC_WRITING = 6 /**< Writing. */ } mmcstate_t; -/** - * @brief Function used to query some hardware status bits. - * - * @return The status. - */ -typedef bool_t (*mmcquery_t)(void); - /** * @brief Driver configuration structure. * @note Not required in the current implementation. @@ -146,14 +139,6 @@ typedef struct { * @brief SPI high speed configuration used during transfers. */ const SPIConfig *hscfg; - /** - * @brief Write protect status query function. - */ - mmcquery_t is_protected; - /** - * @brief Insertion status query function. - */ - mmcquery_t is_inserted; /** * @brief Card insertion event source. */ @@ -204,7 +189,7 @@ typedef struct { * * @api */ -#define mmcIsWriteProtected(mmcp) ((mmcp)->is_protected()) +#define mmcIsWriteProtected(mmcp) mmc_lld_is_write_protected(mmcp) /** @} */ /*===========================================================================*/ @@ -216,8 +201,7 @@ extern "C" { #endif void mmcInit(void); void mmcObjectInit(MMCDriver *mmcp, SPIDriver *spip, - const SPIConfig *lscfg, const SPIConfig *hscfg, - mmcquery_t is_protected, mmcquery_t is_inserted); + const SPIConfig *lscfg, const SPIConfig *hscfg); void mmcStart(MMCDriver *mmcp, const MMCConfig *config); void mmcStop(MMCDriver *mmcp); bool_t mmcConnect(MMCDriver *mmcp); @@ -230,6 +214,8 @@ extern "C" { bool_t mmcStopSequentialWrite(MMCDriver *mmcp); bool_t mmcSync(MMCDriver *mmcp); bool_t mmcGetInfo(MMCDriver *mmcp, BlockDeviceInfo *bdip); + bool_t mmc_lld_is_card_inserted(MMCDriver *mmcp); + bool_t mmc_lld_is_write_protected(MMCDriver *mmcp); #ifdef __cplusplus } #endif diff --git a/os/hal/src/mmc_spi.c b/os/hal/src/mmc_spi.c index 4fdec3f12..97f4f271d 100644 --- a/os/hal/src/mmc_spi.c +++ b/os/hal/src/mmc_spi.c @@ -49,8 +49,6 @@ /*===========================================================================*/ /* Forward declarations required by mmc_vmt.*/ -bool_t mmc_is_inserted(void *instance); -bool_t mmc_is_protected(void *instance); bool_t mmc_read(void *instance, uint32_t startblk, uint8_t *buffer, uint32_t n); bool_t mmc_write(void *instance, uint32_t startblk, @@ -60,8 +58,8 @@ bool_t mmc_write(void *instance, uint32_t startblk, * @brief Virtual methods table. */ static const struct MMCSDBlockDeviceVMT mmc_vmt = { - mmc_is_inserted, - mmc_is_protected, + (bool_t (*)(void *))mmc_lld_is_card_inserted, + (bool_t (*)(void *))mmc_lld_is_write_protected, (bool_t (*)(void *))mmcConnect, (bool_t (*)(void *))mmcDisconnect, mmc_read, @@ -102,16 +100,6 @@ static const uint8_t crc7_lookup_table[256] = { /* Driver local functions. */ /*===========================================================================*/ -bool_t mmc_is_inserted(void *instance) { - - return ((MMCDriver *)instance)->is_inserted(); -} - -bool_t mmc_is_protected(void *instance) { - - return ((MMCDriver *)instance)->is_protected(); -} - bool_t mmc_read(void *instance, uint32_t startblk, uint8_t *buffer, uint32_t n) { @@ -171,7 +159,7 @@ static void tmrfunc(void *p) { chSysLockFromIsr(); if (mmcp->cnt > 0) { - if (mmcp->is_inserted()) { + if (mmc_lld_is_card_inserted(mmcp)) { if (--mmcp->cnt == 0) { mmcp->state = MMC_INSERTED; chEvtBroadcastI(&mmcp->inserted_event); @@ -181,7 +169,7 @@ static void tmrfunc(void *p) { mmcp->cnt = MMC_POLLING_INTERVAL; } else { - if (!mmcp->is_inserted()) { + if (!mmc_lld_is_card_inserted(mmcp)) { mmcp->state = MMC_WAIT; mmcp->cnt = MMC_POLLING_INTERVAL; chEvtBroadcastI(&mmcp->removed_event); @@ -382,8 +370,7 @@ void mmcInit(void) { * @init */ void mmcObjectInit(MMCDriver *mmcp, SPIDriver *spip, - const SPIConfig *lscfg, const SPIConfig *hscfg, - mmcquery_t is_protected, mmcquery_t is_inserted) { + const SPIConfig *lscfg, const SPIConfig *hscfg) { mmcp->vmt = &mmc_vmt; mmcp->state = MMC_STOP; @@ -391,8 +378,6 @@ void mmcObjectInit(MMCDriver *mmcp, SPIDriver *spip, mmcp->spip = spip; mmcp->lscfg = lscfg; mmcp->hscfg = hscfg; - mmcp->is_protected = is_protected; - mmcp->is_inserted = is_inserted; mmcp->block_addresses = FALSE; chEvtInit(&mmcp->inserted_event); chEvtInit(&mmcp->removed_event); diff --git a/readme.txt b/readme.txt index 372a34c74..4ad7cb722 100644 --- a/readme.txt +++ b/readme.txt @@ -123,9 +123,11 @@ 3484947)(backported to 2.4.1). - FIX: Fixed various minor documentation errors (bug 3484942)(backported to 2.4.1). +- NEW: Modified the SDC driver to implement the new block devices abstract + interface. - NEW: Added two new functions to the MMC_SPI driver: mmcSync() and - mmc_Get_Info(). Also added the capability to operate through the new - block devices abstract interface. + mmc_Get_Info(). Also implemented the new block devices abstract + interface. - NEW: Added an abstract interface for block devices in the HAL. This abstraction layer is meant to unify the access protocol to the SDC and MMC_SPI (and potentially others) device drivers.