Instances of this class provide a simple cache between an application or filesystem (or other) driver. More...
#include <core/DspStorageCache.h>
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 tsSectorMap * | getMap (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. | |
tsBufferList * | getCacheSector (unsigned int anSector, unsigned int anExpectedSize, bool abLoad) |
This method checks the current cache for the sector in question. | |
tsBufferList * | flushCacheSector (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. | |
tcDspStorageBase * | mpDevice |
Access to the storage device to cache. | |
unsigned int | mnCacheSectors |
Maximum sectors in cache. | |
unsigned int | mnMaxSectorSize |
Largest sector size (bytes) | |
tsBufferList * | mpCacheHead |
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) | |
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 | |
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) |
Instances of this class provide a simple cache between an application or filesystem (or other) driver.
|
protected |
cache-list header structure
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.
[in] | apDevice | Pointer to the underlying tcDspStorageBase device. |
[in] | anNumSectors | Maximum number of sectors to cache. |
tcDspStorageCache::~tcDspStorageCache | ( | ) |
|
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.
|
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.
|
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.
|
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.
[in] | anSector | The sector to load or retrieve from cache |
[in] | anExpectedSize | The expected sector size |
[in] | abLoad | If false, the entire sector is about to be written, so don't load it from the underlying device. |
|
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.
[in] | anEntry | The cache entry to write back to the underlying device. |
|
protected |
Lock to serialize access.
|
protected |
Pool of sector buffers.
|
protected |
Pool of cache list entries.
|
protected |
Access to the storage device to cache.
|
protected |
Maximum sectors in cache.
|
protected |
Largest sector size (bytes)
|
protected |
Head of cache linked list.
|
protected |
Set whenever any cache entries need to be flushed.