|
ChibiOS/RT
2.5.1 |
|
Generic MMC driver.
This module implements a portable MMC/SD driver that uses a SPI driver as physical layer. Hot plugging and removal are supported through kernel events.
HAL_USE_MMC_SPI and HAL_USE_SPI options must be enabled in halconf.h.The driver implements a state machine internally, not all the driver functionalities can be used in any moment, any transition not explicitly shown in the following diagram has to be considered an error and shall be captured by an assertion (if enabled).
Data Structures | |
| struct | MMCConfig |
| MMC/SD over SPI driver configuration structure. More... | |
| struct | MMCDriverVMT |
MMCDriver virtual methods table. More... | |
| struct | MMCDriver |
| Structure representing a MMC/SD over SPI driver. More... | |
Functions | |
| void | mmcInit (void) |
| MMC over SPI driver initialization. | |
| void | mmcObjectInit (MMCDriver *mmcp) |
| Initializes an instance. | |
| void | mmcStart (MMCDriver *mmcp, const MMCConfig *config) |
| Configures and activates the MMC peripheral. | |
| void | mmcStop (MMCDriver *mmcp) |
| Disables the MMC peripheral. | |
| bool_t | mmcConnect (MMCDriver *mmcp) |
| Performs the initialization procedure on the inserted card. | |
| bool_t | mmcDisconnect (MMCDriver *mmcp) |
| Brings the driver in a state safe for card removal. | |
| bool_t | mmcStartSequentialRead (MMCDriver *mmcp, uint32_t startblk) |
| Starts a sequential read. | |
| bool_t | mmcSequentialRead (MMCDriver *mmcp, uint8_t *buffer) |
| Reads a block within a sequential read operation. | |
| bool_t | mmcStopSequentialRead (MMCDriver *mmcp) |
| Stops a sequential read gracefully. | |
| bool_t | mmcStartSequentialWrite (MMCDriver *mmcp, uint32_t startblk) |
| Starts a sequential write. | |
| bool_t | mmcSequentialWrite (MMCDriver *mmcp, const uint8_t *buffer) |
| Writes a block within a sequential write operation. | |
| bool_t | mmcStopSequentialWrite (MMCDriver *mmcp) |
| Stops a sequential write gracefully. | |
| bool_t | mmcSync (MMCDriver *mmcp) |
| Waits for card idle condition. | |
| bool_t | mmcGetInfo (MMCDriver *mmcp, BlockDeviceInfo *bdip) |
| Returns the media info. | |
| bool_t | mmcErase (MMCDriver *mmcp, uint32_t startblk, uint32_t endblk) |
| Erases blocks. | |
MMC_SPI configuration options | |
| #define | MMC_NICE_WAITING TRUE |
| Delays insertions. | |
Macro Functions | |
| #define | mmcIsCardInserted(mmcp) mmc_lld_is_card_inserted(mmcp) |
| Returns the card insertion status. | |
| #define | mmcIsWriteProtected(mmcp) mmc_lld_is_write_protected(mmcp) |
| Returns the write protect status. | |
Defines | |
| #define | _mmc_driver_methods _mmcsd_block_device_methods |
MMCDriver specific methods. | |
| void mmcInit | ( | void | ) |
MMC over SPI driver initialization.
halInit(), there is no need to explicitly initialize the driver.Definition at line 369 of file mmc_spi.c.
Referenced by halInit().
| void mmcObjectInit | ( | MMCDriver * | mmcp | ) |
Initializes an instance.
| [out] | mmcp | pointer to the MMCDriver object |
Definition at line 380 of file mmc_spi.c.
References BLK_STOP, MMCDriver::config, FALSE, and MMCDriver::vmt.
Configures and activates the MMC peripheral.
Definition at line 396 of file mmc_spi.c.
References BLK_ACTIVE, BLK_STOP, chDbgAssert, chDbgCheck, and MMCDriver::config.
| void mmcStop | ( | MMCDriver * | mmcp | ) |
Disables the MMC peripheral.
| [in] | mmcp | pointer to the MMCDriver object |
Definition at line 413 of file mmc_spi.c.
References BLK_ACTIVE, BLK_STOP, chDbgAssert, chDbgCheck, MMCDriver::config, MMCConfig::spip, and spiStop().

Performs the initialization procedure on the inserted card.
This function should be invoked when a card is inserted and brings the driver in the MMC_READY state where it is possible to perform read and write operations.
| [in] | mmcp | pointer to the MMCDriver object |
| CH_SUCCESS | the operation succeeded and the driver is now in the MMC_READY state. |
| CH_FAILED | the operation failed. |
Definition at line 440 of file mmc_spi.c.
References BLK_ACTIVE, BLK_CONNECTING, BLK_READY, CH_FAILED, CH_SUCCESS, chDbgAssert, chDbgCheck, chThdSleepMilliseconds, MMCDriver::config, MMCConfig::hscfg, MMCConfig::lscfg, MMCSD_BLOCK_SIZE, MMCSD_CMD8_PATTERN, mmcsdGetCapacity(), spiIgnore(), MMCConfig::spip, spiStart(), spiStop(), and TRUE.

Brings the driver in a state safe for card removal.
| [in] | mmcp | pointer to the MMCDriver object |
| CH_SUCCESS | the operation succeeded and the driver is now in the MMC_INSERTED state. |
| CH_FAILED | the operation failed. |
Definition at line 547 of file mmc_spi.c.
References BLK_ACTIVE, BLK_DISCONNECTING, BLK_READY, CH_SUCCESS, chDbgAssert, chDbgCheck, chSysLock, chSysUnlock, MMCDriver::config, MMCConfig::spip, and spiStop().

Starts a sequential read.
| [in] | mmcp | pointer to the MMCDriver object |
| [in] | startblk | first block to read |
| CH_SUCCESS | the operation succeeded. |
| CH_FAILED | the operation failed. |
Definition at line 581 of file mmc_spi.c.
References BLK_READING, BLK_READY, CH_FAILED, CH_SUCCESS, chDbgAssert, chDbgCheck, MMCDriver::config, MMCConfig::hscfg, MMCSD_BLOCK_SIZE, MMCConfig::spip, spiSelect(), spiStart(), and spiStop().

Reads a block within a sequential read operation.
| [in] | mmcp | pointer to the MMCDriver object |
| [out] | buffer | pointer to the read buffer |
| CH_SUCCESS | the operation succeeded. |
| CH_FAILED | the operation failed. |
Definition at line 619 of file mmc_spi.c.
References BLK_READING, CH_FAILED, CH_SUCCESS, chDbgCheck, MMCDriver::config, MMCSD_BLOCK_SIZE, spiIgnore(), MMCConfig::spip, spiReceive(), spiStop(), and spiUnselect().

Stops a sequential read gracefully.
| [in] | mmcp | pointer to the MMCDriver object |
| CH_SUCCESS | the operation succeeded. |
| CH_FAILED | the operation failed. |
Definition at line 653 of file mmc_spi.c.
References BLK_READING, BLK_READY, CH_FAILED, CH_SUCCESS, chDbgCheck, MMCDriver::config, MMCConfig::spip, spiSend(), and spiUnselect().

Starts a sequential write.
| [in] | mmcp | pointer to the MMCDriver object |
| [in] | startblk | first block to write |
| CH_SUCCESS | the operation succeeded. |
| CH_FAILED | the operation failed. |
Definition at line 685 of file mmc_spi.c.
References BLK_READY, BLK_WRITING, CH_FAILED, CH_SUCCESS, chDbgAssert, chDbgCheck, MMCDriver::config, MMCConfig::hscfg, MMCSD_BLOCK_SIZE, MMCConfig::spip, spiSelect(), spiStart(), and spiStop().

Writes a block within a sequential write operation.
| [in] | mmcp | pointer to the MMCDriver object |
| [out] | buffer | pointer to the write buffer |
| CH_SUCCESS | the operation succeeded. |
| CH_FAILED | the operation failed. |
Definition at line 721 of file mmc_spi.c.
References BLK_WRITING, CH_FAILED, CH_SUCCESS, chDbgCheck, MMCDriver::config, MMCSD_BLOCK_SIZE, spiIgnore(), MMCConfig::spip, spiReceive(), spiSend(), spiStop(), and spiUnselect().

Stops a sequential write gracefully.
| [in] | mmcp | pointer to the MMCDriver object |
| CH_SUCCESS | the operation succeeded. |
| CH_FAILED | the operation failed. |
Definition at line 756 of file mmc_spi.c.
References BLK_READY, BLK_WRITING, CH_FAILED, CH_SUCCESS, chDbgCheck, MMCDriver::config, MMCConfig::spip, spiSend(), and spiUnselect().

Waits for card idle condition.
| [in] | mmcp | pointer to the MMCDriver object |
| CH_SUCCESS | the operation succeeded. |
| CH_FAILED | the operation failed. |
Definition at line 783 of file mmc_spi.c.
References BLK_READY, CH_FAILED, CH_SUCCESS, and chDbgCheck.
| bool_t mmcGetInfo | ( | MMCDriver * | mmcp, |
| BlockDeviceInfo * | bdip | ||
| ) |
Returns the media info.
| [in] | mmcp | pointer to the MMCDriver object |
| [out] | bdip | pointer to a BlockDeviceInfo structure |
| CH_SUCCESS | the operation succeeded. |
| CH_FAILED | the operation failed. |
Definition at line 806 of file mmc_spi.c.
References BlockDeviceInfo::blk_num, BLK_READY, BlockDeviceInfo::blk_size, CH_FAILED, CH_SUCCESS, chDbgCheck, and MMCSD_BLOCK_SIZE.
Erases blocks.
| [in] | mmcp | pointer to the MMCDriver object |
| [in] | startblk | starting block number |
| [in] | endblk | ending block number |
| CH_SUCCESS | the operation succeeded. |
| CH_FAILED | the operation failed. |
Definition at line 832 of file mmc_spi.c.
References CH_FAILED, CH_SUCCESS, chDbgCheck, MMCDriver::config, MMCSD_BLOCK_SIZE, MMCConfig::spip, and spiStop().

| #define MMC_NICE_WAITING TRUE |
Delays insertions.
If enabled this options inserts delays into the MMC waiting routines releasing some extra CPU time for the threads with lower priority, this may slow down the driver a bit however. This option is recommended also if the SPI driver does not use a DMA channel and heavily loads the CPU.
| #define _mmc_driver_methods _mmcsd_block_device_methods |
| #define mmcIsCardInserted | ( | mmcp | ) | mmc_lld_is_card_inserted(mmcp) |
Returns the card insertion status.
sdc_lld_is_card_inserted(), this function must be provided by the application because it is not part of the SDC driver.| [in] | mmcp | pointer to the MMCDriver object |
| FALSE | card not inserted. |
| TRUE | card inserted. |
| #define mmcIsWriteProtected | ( | mmcp | ) | mmc_lld_is_write_protected(mmcp) |
Returns the write protect status.
| [in] | mmcp | pointer to the MMCDriver object |
| FALSE | card not inserted. |
| TRUE | card inserted. |