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

master
gdisirio 2012-05-09 18:44:47 +00:00
parent 7f87eee586
commit 6a8a643ab0
5 changed files with 29 additions and 49 deletions

View File

@ -47,6 +47,21 @@ void __early_init(void) {
stm32_clock_init(); 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. * Board-specific initialization code.
*/ */

View File

@ -53,12 +53,6 @@ static SPIConfig hs_spicfg = {NULL, IOPORT2, GPIOB_SPI2NSS, 0};
static SPIConfig ls_spicfg = {NULL, IOPORT2, GPIOB_SPI2NSS, static SPIConfig ls_spicfg = {NULL, IOPORT2, GPIOB_SPI2NSS,
SPI_CR1_BR_2 | SPI_CR1_BR_1}; 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.*/ /* Generic large buffer.*/
uint8_t fbuff[1024]; uint8_t fbuff[1024];
@ -277,9 +271,7 @@ int main(void) {
*/ */
palSetPadMode(IOPORT2, GPIOB_SPI2NSS, PAL_MODE_OUTPUT_PUSHPULL); palSetPadMode(IOPORT2, GPIOB_SPI2NSS, PAL_MODE_OUTPUT_PUSHPULL);
palSetPad(IOPORT2, GPIOB_SPI2NSS); palSetPad(IOPORT2, GPIOB_SPI2NSS);
mmcObjectInit(&MMCD1, &SPID2, mmcObjectInit(&MMCD1, &SPID2, &ls_spicfg, &hs_spicfg);
&ls_spicfg, &hs_spicfg,
mmc_is_protected, mmc_is_inserted);
mmcStart(&MMCD1, NULL); mmcStart(&MMCD1, NULL);
/* /*

View File

@ -101,13 +101,6 @@ typedef enum {
MMC_WRITING = 6 /**< Writing. */ MMC_WRITING = 6 /**< Writing. */
} mmcstate_t; } mmcstate_t;
/**
* @brief Function used to query some hardware status bits.
*
* @return The status.
*/
typedef bool_t (*mmcquery_t)(void);
/** /**
* @brief Driver configuration structure. * @brief Driver configuration structure.
* @note Not required in the current implementation. * @note Not required in the current implementation.
@ -146,14 +139,6 @@ typedef struct {
* @brief SPI high speed configuration used during transfers. * @brief SPI high speed configuration used during transfers.
*/ */
const SPIConfig *hscfg; 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. * @brief Card insertion event source.
*/ */
@ -204,7 +189,7 @@ typedef struct {
* *
* @api * @api
*/ */
#define mmcIsWriteProtected(mmcp) ((mmcp)->is_protected()) #define mmcIsWriteProtected(mmcp) mmc_lld_is_write_protected(mmcp)
/** @} */ /** @} */
/*===========================================================================*/ /*===========================================================================*/
@ -216,8 +201,7 @@ extern "C" {
#endif #endif
void mmcInit(void); void mmcInit(void);
void mmcObjectInit(MMCDriver *mmcp, SPIDriver *spip, void mmcObjectInit(MMCDriver *mmcp, SPIDriver *spip,
const SPIConfig *lscfg, const SPIConfig *hscfg, const SPIConfig *lscfg, const SPIConfig *hscfg);
mmcquery_t is_protected, mmcquery_t is_inserted);
void mmcStart(MMCDriver *mmcp, const MMCConfig *config); void mmcStart(MMCDriver *mmcp, const MMCConfig *config);
void mmcStop(MMCDriver *mmcp); void mmcStop(MMCDriver *mmcp);
bool_t mmcConnect(MMCDriver *mmcp); bool_t mmcConnect(MMCDriver *mmcp);
@ -230,6 +214,8 @@ extern "C" {
bool_t mmcStopSequentialWrite(MMCDriver *mmcp); bool_t mmcStopSequentialWrite(MMCDriver *mmcp);
bool_t mmcSync(MMCDriver *mmcp); bool_t mmcSync(MMCDriver *mmcp);
bool_t mmcGetInfo(MMCDriver *mmcp, BlockDeviceInfo *bdip); 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 #ifdef __cplusplus
} }
#endif #endif

View File

@ -49,8 +49,6 @@
/*===========================================================================*/ /*===========================================================================*/
/* Forward declarations required by mmc_vmt.*/ /* 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, bool_t mmc_read(void *instance, uint32_t startblk,
uint8_t *buffer, uint32_t n); uint8_t *buffer, uint32_t n);
bool_t mmc_write(void *instance, uint32_t startblk, 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. * @brief Virtual methods table.
*/ */
static const struct MMCSDBlockDeviceVMT mmc_vmt = { static const struct MMCSDBlockDeviceVMT mmc_vmt = {
mmc_is_inserted, (bool_t (*)(void *))mmc_lld_is_card_inserted,
mmc_is_protected, (bool_t (*)(void *))mmc_lld_is_write_protected,
(bool_t (*)(void *))mmcConnect, (bool_t (*)(void *))mmcConnect,
(bool_t (*)(void *))mmcDisconnect, (bool_t (*)(void *))mmcDisconnect,
mmc_read, mmc_read,
@ -102,16 +100,6 @@ static const uint8_t crc7_lookup_table[256] = {
/* Driver local functions. */ /* 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, bool_t mmc_read(void *instance, uint32_t startblk,
uint8_t *buffer, uint32_t n) { uint8_t *buffer, uint32_t n) {
@ -171,7 +159,7 @@ static void tmrfunc(void *p) {
chSysLockFromIsr(); chSysLockFromIsr();
if (mmcp->cnt > 0) { if (mmcp->cnt > 0) {
if (mmcp->is_inserted()) { if (mmc_lld_is_card_inserted(mmcp)) {
if (--mmcp->cnt == 0) { if (--mmcp->cnt == 0) {
mmcp->state = MMC_INSERTED; mmcp->state = MMC_INSERTED;
chEvtBroadcastI(&mmcp->inserted_event); chEvtBroadcastI(&mmcp->inserted_event);
@ -181,7 +169,7 @@ static void tmrfunc(void *p) {
mmcp->cnt = MMC_POLLING_INTERVAL; mmcp->cnt = MMC_POLLING_INTERVAL;
} }
else { else {
if (!mmcp->is_inserted()) { if (!mmc_lld_is_card_inserted(mmcp)) {
mmcp->state = MMC_WAIT; mmcp->state = MMC_WAIT;
mmcp->cnt = MMC_POLLING_INTERVAL; mmcp->cnt = MMC_POLLING_INTERVAL;
chEvtBroadcastI(&mmcp->removed_event); chEvtBroadcastI(&mmcp->removed_event);
@ -382,8 +370,7 @@ void mmcInit(void) {
* @init * @init
*/ */
void mmcObjectInit(MMCDriver *mmcp, SPIDriver *spip, void mmcObjectInit(MMCDriver *mmcp, SPIDriver *spip,
const SPIConfig *lscfg, const SPIConfig *hscfg, const SPIConfig *lscfg, const SPIConfig *hscfg) {
mmcquery_t is_protected, mmcquery_t is_inserted) {
mmcp->vmt = &mmc_vmt; mmcp->vmt = &mmc_vmt;
mmcp->state = MMC_STOP; mmcp->state = MMC_STOP;
@ -391,8 +378,6 @@ void mmcObjectInit(MMCDriver *mmcp, SPIDriver *spip,
mmcp->spip = spip; mmcp->spip = spip;
mmcp->lscfg = lscfg; mmcp->lscfg = lscfg;
mmcp->hscfg = hscfg; mmcp->hscfg = hscfg;
mmcp->is_protected = is_protected;
mmcp->is_inserted = is_inserted;
mmcp->block_addresses = FALSE; mmcp->block_addresses = FALSE;
chEvtInit(&mmcp->inserted_event); chEvtInit(&mmcp->inserted_event);
chEvtInit(&mmcp->removed_event); chEvtInit(&mmcp->removed_event);

View File

@ -123,9 +123,11 @@
3484947)(backported to 2.4.1). 3484947)(backported to 2.4.1).
- FIX: Fixed various minor documentation errors (bug 3484942)(backported - FIX: Fixed various minor documentation errors (bug 3484942)(backported
to 2.4.1). 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 - NEW: Added two new functions to the MMC_SPI driver: mmcSync() and
mmc_Get_Info(). Also added the capability to operate through the new mmc_Get_Info(). Also implemented the new block devices abstract
block devices abstract interface. interface.
- NEW: Added an abstract interface for block devices in the HAL. This - 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 abstraction layer is meant to unify the access protocol to the SDC and
MMC_SPI (and potentially others) device drivers. MMC_SPI (and potentially others) device drivers.