ChibiOS/RT
2.5.1
MMC over SPI Driver
Collaboration diagram for MMC over SPI Driver:

Detailed Description

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.

Precondition:
In order to use the MMC_SPI driver the HAL_USE_MMC_SPI and HAL_USE_SPI options must be enabled in halconf.h.

Driver State Machine

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).

dot_inline_dotgraph_12.png

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.

Function Documentation

void mmcInit ( void  )

MMC over SPI driver initialization.

Note:
This function is implicitly invoked by halInit(), there is no need to explicitly initialize the driver.
Function Class:
Initializer, this function just initializes an object and can be invoked before the kernel is initialized.

Definition at line 369 of file mmc_spi.c.

Referenced by halInit().

void mmcObjectInit ( MMCDriver mmcp)

Initializes an instance.

Parameters:
[out]mmcppointer to the MMCDriver object
Function Class:
Initializer, this function just initializes an object and can be invoked before the kernel is initialized.

Definition at line 380 of file mmc_spi.c.

References BLK_STOP, MMCDriver::config, FALSE, and MMCDriver::vmt.

void mmcStart ( MMCDriver mmcp,
const MMCConfig config 
)

Configures and activates the MMC peripheral.

Parameters:
[in]mmcppointer to the MMCDriver object
[in]configpointer to the MMCConfig object.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

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.

Parameters:
[in]mmcppointer to the MMCDriver object
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 413 of file mmc_spi.c.

References BLK_ACTIVE, BLK_STOP, chDbgAssert, chDbgCheck, MMCDriver::config, MMCConfig::spip, and spiStop().

Here is the call graph for this function:

bool_t mmcConnect ( MMCDriver mmcp)

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.

Note:
It is possible to invoke this function from the insertion event handler.
Parameters:
[in]mmcppointer to the MMCDriver object
Returns:
The operation status.
Return values:
CH_SUCCESSthe operation succeeded and the driver is now in the MMC_READY state.
CH_FAILEDthe operation failed.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

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.

Here is the call graph for this function:

bool_t mmcDisconnect ( MMCDriver mmcp)

Brings the driver in a state safe for card removal.

Parameters:
[in]mmcppointer to the MMCDriver object
Returns:
The operation status.
Return values:
CH_SUCCESSthe operation succeeded and the driver is now in the MMC_INSERTED state.
CH_FAILEDthe operation failed.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

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().

Here is the call graph for this function:

bool_t mmcStartSequentialRead ( MMCDriver mmcp,
uint32_t  startblk 
)

Starts a sequential read.

Parameters:
[in]mmcppointer to the MMCDriver object
[in]startblkfirst block to read
Returns:
The operation status.
Return values:
CH_SUCCESSthe operation succeeded.
CH_FAILEDthe operation failed.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

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().

Here is the call graph for this function:

bool_t mmcSequentialRead ( MMCDriver mmcp,
uint8_t buffer 
)

Reads a block within a sequential read operation.

Parameters:
[in]mmcppointer to the MMCDriver object
[out]bufferpointer to the read buffer
Returns:
The operation status.
Return values:
CH_SUCCESSthe operation succeeded.
CH_FAILEDthe operation failed.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

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().

Here is the call graph for this function:

bool_t mmcStopSequentialRead ( MMCDriver mmcp)

Stops a sequential read gracefully.

Parameters:
[in]mmcppointer to the MMCDriver object
Returns:
The operation status.
Return values:
CH_SUCCESSthe operation succeeded.
CH_FAILEDthe operation failed.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

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().

Here is the call graph for this function:

bool_t mmcStartSequentialWrite ( MMCDriver mmcp,
uint32_t  startblk 
)

Starts a sequential write.

Parameters:
[in]mmcppointer to the MMCDriver object
[in]startblkfirst block to write
Returns:
The operation status.
Return values:
CH_SUCCESSthe operation succeeded.
CH_FAILEDthe operation failed.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

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().

Here is the call graph for this function:

bool_t mmcSequentialWrite ( MMCDriver mmcp,
const uint8_t buffer 
)

Writes a block within a sequential write operation.

Parameters:
[in]mmcppointer to the MMCDriver object
[out]bufferpointer to the write buffer
Returns:
The operation status.
Return values:
CH_SUCCESSthe operation succeeded.
CH_FAILEDthe operation failed.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

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().

Here is the call graph for this function:

bool_t mmcStopSequentialWrite ( MMCDriver mmcp)

Stops a sequential write gracefully.

Parameters:
[in]mmcppointer to the MMCDriver object
Returns:
The operation status.
Return values:
CH_SUCCESSthe operation succeeded.
CH_FAILEDthe operation failed.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

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().

Here is the call graph for this function:

bool_t mmcSync ( MMCDriver mmcp)

Waits for card idle condition.

Parameters:
[in]mmcppointer to the MMCDriver object
Returns:
The operation status.
Return values:
CH_SUCCESSthe operation succeeded.
CH_FAILEDthe operation failed.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

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.

Parameters:
[in]mmcppointer to the MMCDriver object
[out]bdippointer to a BlockDeviceInfo structure
Returns:
The operation status.
Return values:
CH_SUCCESSthe operation succeeded.
CH_FAILEDthe operation failed.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

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.

bool_t mmcErase ( MMCDriver mmcp,
uint32_t  startblk,
uint32_t  endblk 
)

Erases blocks.

Parameters:
[in]mmcppointer to the MMCDriver object
[in]startblkstarting block number
[in]endblkending block number
Returns:
The operation status.
Return values:
CH_SUCCESSthe operation succeeded.
CH_FAILEDthe operation failed.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 832 of file mmc_spi.c.

References CH_FAILED, CH_SUCCESS, chDbgCheck, MMCDriver::config, MMCSD_BLOCK_SIZE, MMCConfig::spip, and spiStop().

Here is the call graph for this function:


Define Documentation

#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.

Definition at line 60 of file mmc_spi.h.

#define _mmc_driver_methods   _mmcsd_block_device_methods

MMCDriver specific methods.

Definition at line 97 of file mmc_spi.h.

#define mmcIsCardInserted (   mmcp)    mmc_lld_is_card_inserted(mmcp)

Returns the card insertion status.

Note:
This macro wraps a low level function named sdc_lld_is_card_inserted(), this function must be provided by the application because it is not part of the SDC driver.
Parameters:
[in]mmcppointer to the MMCDriver object
Returns:
The card state.
Return values:
FALSEcard not inserted.
TRUEcard inserted.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 152 of file mmc_spi.h.

#define mmcIsWriteProtected (   mmcp)    mmc_lld_is_write_protected(mmcp)

Returns the write protect status.

Parameters:
[in]mmcppointer to the MMCDriver object
Returns:
The card state.
Return values:
FALSEcard not inserted.
TRUEcard inserted.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 164 of file mmc_spi.h.