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. | |
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. |
Instances of this class provide a simple cache between an application or filesystem (or other) driver.
typedef struct MityDSP::tcDspStorageCache::buf_list MityDSP::tcDspStorageCache::tsBufferList [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 | ( | ) |
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.
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.
[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.
int tcDspStorageCache::write | ( | unsigned int | anSector, | |
unsigned int | anOffset, | |||
void * | apData, | |||
int | anBytes | |||
) | [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.
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.
[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.
int tcDspStorageCache::read | ( | unsigned int | anSector, | |
unsigned int | anOffset, | |||
void * | apBuffer, | |||
int | anBytes | |||
) | [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.
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.
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.
[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. |
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.
[in] | anEntry | The cache entry to write back to the underlying device. |
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.