MityDSP Documentation Index
Classes | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes
MityDSP::tcDspMmc Class Reference

Instances of this class handle access to a MultiMedia Card via the MityDSP SPI interface. More...

#include <core/DspMmc.h>

Inheritance diagram for MityDSP::tcDspMmc:
MityDSP::tcDspStorageBase

List of all members.

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 tsSectorMapgetMap (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.
tcDspSpimpSpi
 Access to the SPI bus.
tcDspOutputLatchmpLatch
 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.
tcDspGpiompGpio
 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)
tsSectorMapmpSectorInfo
 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)

Detailed Description

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

See also:
tcDspMmc Page

Constructor & Destructor Documentation

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.

Parameters:
[in]apSpiPointer to the SPI interface for the MMC.
[in]apLatchPointer to an output latch controlling Chip Select.
[in]anLatchIDID of the latch to use for this device.
[in]ahLockOptional parameter specifying a lock to use to protect MMC (and SPI) writes.
Note:
Specifying a shared lock to all devices sharing a SPI bus allows them to operate simultaneously. Not necessary if the SPI is used exclusively for the MMC device.
Returns:
None.
See also:
DspMmc.h
tcDspMmc::~tcDspMmc ( )

Default destructor.

Returns:
None.
See also:
DspMmc.h

Member Function Documentation

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.

Parameters:
[in]aGpioThe GPIO pointer
[in]aMaskThe GPIO bit that triggered the interrupt
[in]aMmcThe tcDspMmc pointer
Returns:
0
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.

Parameters:
[in]mmcCardThe "this->" pointer for the instance of tcDspMmc associated with this thread.
Returns:
0
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.

Returns:
True if reinitialization was successful.
See also:
DspMmc.h
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.

Parameters:
[in]apAddrPointer to the offset position on the MMC device.
[in]apDataA buffer containing the data to be written.
[in]anBytesSize of the data to be written in bytes.
Returns:
The number of bytes successfully written.
See also:
DspMmc.h

Implements MityDSP::tcDspStorageBase.

int tcDspMmc::write ( unsigned int  anSector,
unsigned int  anOffset,
void *  apData,
int  anBytes 
)
virtual

Sector-based version of the write method.

Parameters:
[in]anSectorThe sector to write to.
[in]anOffsetThe offset from the start of the sector.
[in]apDataA buffer containing the data to be written.
[in]anBytesSize of the data to be written in bytes.
Returns:
The number of bytes successfully written.
See also:
DspMmc.h

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.

Parameters:
[in]apStartAddrPointer to the data offset on the MMC device.
[out]apBufferA buffer to hold the data that is read.
[in]anBytesSize of the data to be read in bytes.
Returns:
The number of bytes successfully read.
See also:
DspMmc.h

Implements MityDSP::tcDspStorageBase.

int tcDspMmc::read ( unsigned int  anSector,
unsigned int  anOffset,
void *  apBuffer,
int  anBytes 
)
virtual

Sector-based version of the read method.

Parameters:
[in]anSectorThe sector to copy from.
[in]anOffsetThe offset from the start of the sector.
[out]apBufferA buffer to hold the data that is read.
[in]anBytesSize of the data to be read in bytes.
Returns:
The number of bytes successfully read.
See also:
DspMmc.h

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.

Parameters:
[in]aGpioThe GPIO with GPIO_2 as card detect line(NULL for none).
[in]anThreadPriThread priority of the debouncer
Returns:
None.
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.

Note:
The returned structure contains an mbZERO field. This field is non-zero if the status request fails.
Returns:
MMC status register contents.
See also:
DspMmc.h
const char * tcDspMmc::get_info ( void  )
virtual

This method reads the MMC card CID register, decodes the information, and returns a summary information string.

Note:
The returned string is valid until the next time the info() method is called.
Returns:
Pointer to the information string (which contains "No Response" if there was a failure).
See also:
DspMmc.h
void tcDspMmc::cardDetectThread ( )
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.

Returns:
0
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.

Returns:
True if initialization was successful.
See also:
DspMmc.h
bool tcDspMmc::read_sector ( unsigned int  anSector)
protected

This method reads the specified sector of the MMC device into the page buffer.

Parameters:
[in]anSectorThe sector to read into the page buffer.
Returns:
True if the sector was successfully read.
See also:
DspMmc.h
bool tcDspMmc::write_sector ( unsigned int  anSector)
protected

This method writes the page buffer out to the specified sector of the MMC device.

Parameters:
[in]anSectorThe sector to write the page buffer to.
Returns:
True if the page buffer was successfully written.
See also:
DspMmc.h
bool tcDspMmc::check_write ( void  )
protected

This method checks to see if a previous write operation was successful.

Returns:
True if successful.
See also:
DspMmc.h
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).

Returns:
None.
See also:
DspMmc.h
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.

Parameters:
[in]anExpectedThe 8-bit response to wait for.
[in]anAttemptsNumber of attempts to read the expected response (default: 256).
[out]apRequiredif passed in (default is NULL), will be set to the number of cycles required to complete the response.
Returns:
True if expected response is received, false otherwise.
See also:
DspMmc.h

Member Data Documentation

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


  
Generated on Mon Apr 22 2013 11:33:04 for MityDSP Core by  Doxygen Version 1.8.1.1
Copyright © 2009, Critical Link LLC, All rights reserved.