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. | |
Public Member Functions inherited from MityDSP::tcDspStorageBase | |
tcDspStorageBase () | |
This constructor is used to initialize storage base class. | |
virtual | ~tcDspStorageBase () |
Default Destructor. | |
virtual bool | erase (unsigned int anSector) |
This routine provides a default erase method. | |
virtual void | registerISRCallback (tfIsrCallback afCallback, void *apUserArg) |
This method is used to register a callback that is activated whenever the device changes state. | |
virtual void * | getAddress (unsigned int anSector, unsigned int anOffset) |
This routine uses the device's sector map to compute an offset address from a supplied sector and offset. | |
virtual unsigned int | getSize (unsigned int anSector) |
This routine uses the device's sector map to determine the size of the specified sector. | |
virtual unsigned int | getSector (void *apAddr) |
This routine uses the device's sector map to compute a sector from a from a supplied offset address. | |
virtual double | getDeviceSizeKB (void) |
This routine returns the size of the device in kilobytes. | |
const tsSectorMap * | getMap (int &anNumSectors) |
This routine returns a pointer to access the device's sector map. | |
virtual bool | getMediaPresent () |
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 Member Functions inherited from MityDSP::tcDspStorageBase | |
static int | readDispatch (unsigned int anSector, unsigned int anOffset, char *apBuffer, unsigned int anLength, void *apInstance) |
Static dispatch routine to allow the read method to be registered as a callback. | |
static int | writeDispatch (unsigned int anSector, unsigned int anOffset, char *apData, unsigned int anBytes, void *apInstance) |
Static dispatch routine to allow the write method to be registered as a callback. |
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". | |
Protected Attributes inherited from MityDSP::tcDspStorageBase | |
unsigned int | mnNumSectors |
Number of sectors in this device. | |
double | mnDeviceSize |
Overall device size (in bytes) | |
tsSectorMap * | mpSectorInfo |
Map of sectors and sizes. | |
bool | mbMediaPresent |
True if device is loaded. | |
tfIsrCallback | mfIsrCallback |
void * | mpUserArg |
User-supplied argument for ISR callback. |
Additional Inherited Members | |
Public Types inherited from MityDSP::tcDspStorageBase | |
typedef void(* | tfIsrCallback )(bool, void *) |
prototype for the ISR callback | |
Public Attributes inherited from MityDSP::tcDspStorageBase | |
unsigned int | mnTxBytes |
Count of bytes written (debug) | |
unsigned int | mnRxBytes |
Count of bytes read (debug) |
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 | ( | ) |
|
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 |
|
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. |
|
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.
|
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.
|
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.
|
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.
|
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.
|
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 |
|
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.
|
virtual |
This method reads the MMC card Status register and returns its contents.
|
virtual |
This method reads the MMC card CID register, decodes the information, and returns a summary information string.
|
protectedvirtual |
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.
|
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.
|
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. |
|
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. |
|
protected |
This method checks to see if a previous write operation was successful.
|
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).
|
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. |
|
static |
length (in bytes) of status info
|
static |
fixed block size for high capacity SD cards;
|
protected |
Lock to serialize access.
|
protected |
Access to the SPI bus.
|
protected |
Access to latch selector.
|
protected |
ID of latch to use (if any)
|
protected |
Sector size (bytes)
|
protected |
if true, a high capacity SD card
|
protected |
True if mutex created locally.
|
protected |
Buffer for a sector of data.
|
protected |
GPIO for card detect interrupt.
|
protected |
core interrupt mask.
|
protected |
core interrupt level.
|
protected |
core interrupt vector.
|
protected |
Semaphore for card detect.
|
protected |
Thread used for card detect "debounce".