MityDSP Documentation Index

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.

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

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] 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.
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] aGpio The GPIO pointer
[in] aMask The GPIO bit that triggered the interrupt
[in] aMmc The 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] mmcCard The "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] 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.
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] 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.
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] 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.
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] 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.
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] aGpio The GPIO with GPIO_2 as card detect line(NULL for none).
[in] anThreadPri Thread 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 (  )  [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.

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] anSector The 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] anSector The 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] 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.
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.

Access to the SPI bus.

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

if true, a high capacity SD card

True if mutex created locally.

unsigned char* MityDSP::tcDspMmc::mpPageBuffer [protected]

Buffer for a sector of data.

GPIO for card detect interrupt.

unsigned short MityDSP::tcDspMmc::mnMyIntMask [protected]

core interrupt mask.

core interrupt level.

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 Fri Sep 23 16:33:52 2011 for MityDSP Core by  Doxygen Version 1.6.1
Copyright © 2009, Critical Link LLC, All rights reserved.