MityDSP Documentation Index
Classes | Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes
MityDSP::tcDspStorageCache Class Reference

Instances of this class provide a simple cache between an application or filesystem (or other) driver. More...

#include <core/DspStorageCache.h>

Inheritance diagram for MityDSP::tcDspStorageCache:
MityDSP::tcDspStorageBase

List of all members.

Classes

struct  buf_list
 cache-list header structure More...

Public Member Functions

 tcDspStorageCache (tcDspStorageBase *apDevice, unsigned int anNumSectors)
 This constructor is used to create a read/write cache of the specified number of sectors for a tcDspStorageBase-derived class instance.
 ~tcDspStorageCache ()
 Default destructor.
virtual void reset (void)
 This routine resets all cache entries, without flushing any dirty entries.
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.
- 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 ()

Protected Types

typedef struct
MityDSP::tcDspStorageCache::buf_list 
tsBufferList
 cache-list header structure

Protected Member Functions

void resetDeviceInfo (void)
 This routine reads sector map information from the underlying device and creates copies of the map and the required cache buffers to match.
tsBufferListgetCacheSector (unsigned int anSector, unsigned int anExpectedSize, bool abLoad)
 This method checks the current cache for the sector in question.
tsBufferListflushCacheSector (tsBufferList *anEntry)
 This method checks the specified cache entry to see if it's "dirty".

Protected Attributes

LCK_Handle mhMutex
 Lock to serialize access.
BUF_Handle mhSectorPool
 Pool of sector buffers.
BUF_Handle mhSectorListPool
 Pool of cache list entries.
tcDspStorageBasempDevice
 Access to the storage device to cache.
unsigned int mnCacheSectors
 Maximum sectors in cache.
unsigned int mnMaxSectorSize
 Largest sector size (bytes)
tsBufferListmpCacheHead
 Head of cache linked list.
bool mbAnyDirty
 Set whenever any cache entries need to be flushed.
- 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
- 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.
- 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 provide a simple cache between an application or filesystem (or other) driver.

See also:
tcDspStorageCache Page

Member Typedef Documentation

cache-list header structure


Constructor & Destructor Documentation

tcDspStorageCache::tcDspStorageCache ( tcDspStorageBase apDevice,
unsigned int  anNumSectors 
)

This constructor is used to create a read/write cache of the specified number of sectors for a tcDspStorageBase-derived class instance.

Parameters:
[in]apDevicePointer to the underlying tcDspStorageBase device.
[in]anNumSectorsMaximum number of sectors to cache.
Returns:
None.
See also:
DspStorageCache.h
tcDspStorageCache::~tcDspStorageCache ( )

Default destructor.

Returns:
None.
See also:
DspStorageCache.h

Member Function Documentation

void tcDspStorageCache::reset ( void  )
virtual

This routine resets all cache entries, without flushing any dirty entries.

This is necessary when a removable device is removed, and subsequently reinserted (with unknown changes made in the mean time).

Writing out dirty cache entries in this case would be bad... a flush should have been done prior to removal by the application.

Returns:
None.
See also:
DspStorageCache.h
int tcDspStorageCache::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:
DspStorageCache.h

Implements MityDSP::tcDspStorageBase.

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

Sector-based version of the write method.

Note:
A request to write sector 0xFFFFFFFF is taken to be a request to flush all dirty cache entries.
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:
DspStorageCache.h

Implements MityDSP::tcDspStorageBase.

int tcDspStorageCache::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:
DspStorageCache.h

Implements MityDSP::tcDspStorageBase.

int tcDspStorageCache::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:
DspStorageCache.h

Implements MityDSP::tcDspStorageBase.

void tcDspStorageCache::resetDeviceInfo ( void  )
protected

This routine reads sector map information from the underlying device and creates copies of the map and the required cache buffers to match.

Any outstanding cache buffer should be freed prior to this call.

Returns:
None
See also:
DspStorageCache.h
tcDspStorageCache::tsBufferList * tcDspStorageCache::getCacheSector ( unsigned int  anSector,
unsigned int  anExpectedSize,
bool  abLoad 
)
protected

This method checks the current cache for the sector in question.

If not found, the sector is loaded (flushing the oldest entry, if necessary). A pointer to the cache entry is returned.

In either case, the sector is moved to the front of the cache list.

Parameters:
[in]anSectorThe sector to load or retrieve from cache
[in]anExpectedSizeThe expected sector size
[in]abLoadIf false, the entire sector is about to be written, so don't load it from the underlying device.
Returns:
Pointer to the cache entry.
See also:
DspStorageCache.h
tcDspStorageCache::tsBufferList * tcDspStorageCache::flushCacheSector ( tsBufferList anEntry)
protected

This method checks the specified cache entry to see if it's "dirty".

If so, it is written out to the underlying device and marked clean.

Parameters:
[in]anEntryThe cache entry to write back to the underlying device.
Returns:
The next cache entry in the list.
See also:
DspStorageCache.h

Member Data Documentation

LCK_Handle MityDSP::tcDspStorageCache::mhMutex
protected

Lock to serialize access.

BUF_Handle MityDSP::tcDspStorageCache::mhSectorPool
protected

Pool of sector buffers.

BUF_Handle MityDSP::tcDspStorageCache::mhSectorListPool
protected

Pool of cache list entries.

tcDspStorageBase* MityDSP::tcDspStorageCache::mpDevice
protected

Access to the storage device to cache.

unsigned int MityDSP::tcDspStorageCache::mnCacheSectors
protected

Maximum sectors in cache.

unsigned int MityDSP::tcDspStorageCache::mnMaxSectorSize
protected

Largest sector size (bytes)

tsBufferList* MityDSP::tcDspStorageCache::mpCacheHead
protected

Head of cache linked list.

bool MityDSP::tcDspStorageCache::mbAnyDirty
protected

Set whenever any cache entries need to be flushed.


  
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.