Instances of this class handle access to a MultiMedia Card via the MityDSP SPI interface. More...
#include <core/DspMmc.h>
Classes | |
union | tuMmcStatus |
status information returned by MMC card More... | |
Public Member Functions | |
tcDspMmc (tcDspSpi *apSpi, tcDspOutputLatch *apLatch, unsigned int anLatchID, LCK_Handle ahLock=NULL) | |
This constructor is used to open an interface to a MMC device via the provided SPI interface. | |
~tcDspMmc () | |
Default destructor. | |
virtual bool | reinit (void) |
This method reinitializes the MMC device, places it in on-line mode, and queries the device for its Chip-Specific Data. | |
virtual int | write (void *apAddr, void *apData, int anBytes) |
This routine writes an arbitrary amount of data to an MMC device at a specified offset from the start of the device. | |
virtual int | write (unsigned int anSector, unsigned int anOffset, void *apData, int anBytes) |
Sector-based version of the write method. | |
virtual int | read (void *apStartAddr, void *apBuffer, int anBytes) |
This routine reads an arbitrary amount of data from an MMC device from the specified offset position. | |
virtual int | read (unsigned int anSector, unsigned int anOffset, void *apBuffer, int anBytes) |
Sector-based version of the read method. | |
virtual void | setCardDetectGPIO (tcDspGpio *aGpio, int anThreadPri) |
Sets the GPIO used for card detect. | |
virtual void | cardDetectInterrupt (void) |
Interrupt service routine for the MMC class. | |
virtual tuMmcStatus | get_status (void) |
This method reads the MMC card Status register and returns its contents. | |
virtual const char * | get_info (void) |
This method reads the MMC card CID register, decodes the information, and returns a summary information string. | |
Static Public Member Functions | |
static void | interrupt_dispatch (tcDspGpio *aGpio, unsigned int mask, void *aMmc) |
Static interrupt dispatch routine. | |
static void | cardDetectDispatch (Arg mmcCard) |
Static thread dispatch routine. | |
Static Public Attributes | |
static const int | gnSTAT_LENGTH = 2 |
length (in bytes) of status info | |
static const int | gnBLOCK_SIZE = 512 |
fixed block size for high capacity SD cards; | |
Protected Member Functions | |
virtual void | cardDetectThread () |
Thread to pend on the card detect semaphore. | |
bool | initialize (void) |
This method resets the MMC device, places it in on-line mode, and queries the device for its Chip-Specific Data. | |
bool | read_sector (unsigned int anSector) |
This method reads the specified sector of the MMC device into the page buffer. | |
bool | write_sector (unsigned int anSector) |
This method writes the page buffer out to the specified sector of the MMC device. | |
bool | check_write (void) |
This method checks to see if a previous write operation was successful. | |
void | setup_spi (void) |
This method is used to set the SPI in the required mode for the MMC interface. | |
bool | wait_for_response (unsigned char anExpected, int anAttempts=256, int *apRequired=NULL) |
This method reads the SPI interface repeatedly, waiting for a specified response. | |
Protected Attributes | |
LCK_Handle | mhMutex |
Lock to serialize access. | |
tcDspSpi * | mpSpi |
Access to the SPI bus. | |
tcDspOutputLatch * | mpLatch |
Access to latch selector. | |
unsigned int | mnLatchID |
ID of latch to use (if any). | |
unsigned int | mnSectorSize |
Sector size (bytes). | |
bool | mbIsHighCapacity |
if true, a high capacity SD card | |
bool | mbMutexCreated |
True if mutex created locally. | |
unsigned char * | mpPageBuffer |
Buffer for a sector of data. | |
tcDspGpio * | mpGpio |
GPIO for card detect interrupt. | |
unsigned short | mnMyIntMask |
core interrupt mask. | |
int | mnMyIntLevel |
core interrupt level. | |
int | mnMyIntVector |
core interrupt vector. | |
SEM_Handle | mhCardDetectSem |
Semaphore for card detect. | |
TSK_Handle | mhCardDetectThrd |
Thread used for card detect "debounce". |
Instances of this class handle access to a MultiMedia Card via the MityDSP SPI interface.
It is derived from tcDspStorageBase to provide a consistent interface for higher-level drivers (such as filesystems).
tcDspMmc::tcDspMmc | ( | tcDspSpi * | apSpi, | |
tcDspOutputLatch * | apLatch, | |||
unsigned int | anLatchID, | |||
LCK_Handle | ahLock = NULL | |||
) |
This constructor is used to open an interface to a MMC device via the provided SPI interface.
[in] | apSpi | Pointer to the SPI interface for the MMC. |
[in] | apLatch | Pointer to an output latch controlling Chip Select. |
[in] | anLatchID | ID of the latch to use for this device. |
[in] | ahLock | Optional parameter specifying a lock to use to protect MMC (and SPI) writes. |
tcDspMmc::~tcDspMmc | ( | ) |
void tcDspMmc::interrupt_dispatch | ( | tcDspGpio * | aGpio, | |
unsigned int | aMask, | |||
void * | aMmc | |||
) | [static] |
Static interrupt dispatch routine.
Required because of the hidden this pointer associated with a member function, which cannot be passed directly to the interrupt dispatcher.
[in] | aGpio | The GPIO pointer |
[in] | aMask | The GPIO bit that triggered the interrupt |
[in] | aMmc | The tcDspMmc pointer |
void tcDspMmc::cardDetectDispatch | ( | Arg | mmcCard | ) | [static] |
Static thread dispatch routine.
Required because of the hidden this pointer associated with a member function, which cannot be passed directly to the thread.
[in] | mmcCard | The "this->" pointer for the instance of tcDspMmc associated with this thread. |
bool tcDspMmc::reinit | ( | void | ) | [virtual] |
This method reinitializes the MMC device, places it in on-line mode, and queries the device for its Chip-Specific Data.
If the sector size, the number of sectors available, or the overall device size changes, the sector map and page buffer are recreated.
int tcDspMmc::write | ( | void * | apAddr, | |
void * | apData, | |||
int | anBytes | |||
) | [virtual] |
This routine writes an arbitrary amount of data to an MMC device at a specified offset from the start of the device.
The routine handles preservation of data when only a partial sector is written. The data does not have to be sector aligned, although writing aligned, full sectors is most efficient.
[in] | apAddr | Pointer to the offset position on the MMC device. |
[in] | apData | A buffer containing the data to be written. |
[in] | anBytes | Size of the data to be written in bytes. |
Implements MityDSP::tcDspStorageBase.
int tcDspMmc::write | ( | unsigned int | anSector, | |
unsigned int | anOffset, | |||
void * | apData, | |||
int | anBytes | |||
) | [virtual] |
Sector-based version of the write method.
[in] | anSector | The sector to write to. |
[in] | anOffset | The offset from the start of the sector. |
[in] | apData | A buffer containing the data to be written. |
[in] | anBytes | Size of the data to be written in bytes. |
Implements MityDSP::tcDspStorageBase.
int tcDspMmc::read | ( | void * | apStartAddr, | |
void * | apBuffer, | |||
int | anBytes | |||
) | [virtual] |
This routine reads an arbitrary amount of data from an MMC device from the specified offset position.
Results of the read are stored in apBuffer.
[in] | apStartAddr | Pointer to the data offset on the MMC device. |
[out] | apBuffer | A buffer to hold the data that is read. |
[in] | anBytes | Size of the data to be read in bytes. |
Implements MityDSP::tcDspStorageBase.
int tcDspMmc::read | ( | unsigned int | anSector, | |
unsigned int | anOffset, | |||
void * | apBuffer, | |||
int | anBytes | |||
) | [virtual] |
Sector-based version of the read method.
[in] | anSector | The sector to copy from. |
[in] | anOffset | The offset from the start of the sector. |
[out] | apBuffer | A buffer to hold the data that is read. |
[in] | anBytes | Size of the data to be read in bytes. |
Implements MityDSP::tcDspStorageBase.
void tcDspMmc::setCardDetectGPIO | ( | tcDspGpio * | aGpio, | |
int | anThreadPri | |||
) | [virtual] |
Sets the GPIO used for card detect.
This function enablesd interrupts on GPIO_2 for use as a card detect.
[in] | aGpio | The GPIO with GPIO_2 as card detect line(NULL for none). |
[in] | anThreadPri | Thread priority of the debouncer |
void tcDspMmc::cardDetectInterrupt | ( | void | ) | [virtual] |
Interrupt service routine for the MMC class.
The ISR reads and clears the pending interrupt. If the pending interrupt has a callback registered for it, the routine is called.
"Interrupt-ness" is taken care of by the 'dispatcher' in DSP/BIOS. Installed by the constructor.
tcDspMmc::tuMmcStatus tcDspMmc::get_status | ( | void | ) | [virtual] |
This method reads the MMC card Status register and returns its contents.
const char * tcDspMmc::get_info | ( | void | ) | [virtual] |
This method reads the MMC card CID register, decodes the information, and returns a summary information string.
void tcDspMmc::cardDetectThread | ( | ) | [protected, virtual] |
Thread to pend on the card detect semaphore.
When the semaphore is posted the thread will sleep for a tenth of a second then wake and re-enable interrupts, then call the callback if it's set.
bool tcDspMmc::initialize | ( | void | ) | [protected] |
This method resets the MMC device, places it in on-line mode, and queries the device for its Chip-Specific Data.
This data is used to determine the sector size, the number of sectors available, and the overall device size.
bool tcDspMmc::read_sector | ( | unsigned int | anSector | ) | [protected] |
This method reads the specified sector of the MMC device into the page buffer.
[in] | anSector | The sector to read into the page buffer. |
bool tcDspMmc::write_sector | ( | unsigned int | anSector | ) | [protected] |
This method writes the page buffer out to the specified sector of the MMC device.
[in] | anSector | The sector to write the page buffer to. |
bool tcDspMmc::check_write | ( | void | ) | [protected] |
This method checks to see if a previous write operation was successful.
void tcDspMmc::setup_spi | ( | void | ) | [protected] |
This method is used to set the SPI in the required mode for the MMC interface.
It is called before every read and write, so that the SPI may be used with multiple devices simultaneously (in conjunction with a shared lock).
bool tcDspMmc::wait_for_response | ( | unsigned char | anExpected, | |
int | anAttempts = 256 , |
|||
int * | apRequired = NULL | |||
) | [protected] |
This method reads the SPI interface repeatedly, waiting for a specified response.
The routine returns "true" if the response is received within the specified number of attempts.
[in] | anExpected | The 8-bit response to wait for. |
[in] | anAttempts | Number of attempts to read the expected response (default: 256). |
[out] | apRequired | if passed in (default is NULL), will be set to the number of cycles required to complete the response. |
const int MityDSP::tcDspMmc::gnSTAT_LENGTH = 2 [static] |
length (in bytes) of status info
const int MityDSP::tcDspMmc::gnBLOCK_SIZE = 512 [static] |
fixed block size for high capacity SD cards;
LCK_Handle MityDSP::tcDspMmc::mhMutex [protected] |
Lock to serialize access.
tcDspSpi* MityDSP::tcDspMmc::mpSpi [protected] |
Access to the SPI bus.
tcDspOutputLatch* MityDSP::tcDspMmc::mpLatch [protected] |
Access to latch selector.
unsigned int MityDSP::tcDspMmc::mnLatchID [protected] |
ID of latch to use (if any).
unsigned int MityDSP::tcDspMmc::mnSectorSize [protected] |
Sector size (bytes).
bool MityDSP::tcDspMmc::mbIsHighCapacity [protected] |
if true, a high capacity SD card
bool MityDSP::tcDspMmc::mbMutexCreated [protected] |
True if mutex created locally.
unsigned char* MityDSP::tcDspMmc::mpPageBuffer [protected] |
Buffer for a sector of data.
tcDspGpio* MityDSP::tcDspMmc::mpGpio [protected] |
GPIO for card detect interrupt.
unsigned short MityDSP::tcDspMmc::mnMyIntMask [protected] |
core interrupt mask.
int MityDSP::tcDspMmc::mnMyIntLevel [protected] |
core interrupt level.
int MityDSP::tcDspMmc::mnMyIntVector [protected] |
core interrupt vector.
SEM_Handle MityDSP::tcDspMmc::mhCardDetectSem [protected] |
Semaphore for card detect.
TSK_Handle MityDSP::tcDspMmc::mhCardDetectThrd [protected] |
Thread used for card detect "debounce".