MityDSP Documentation Index
tcDspStorageCache

Introduction

The tcDspStorageCache class is used to provide a simple read/write cache for other physical devices derived from the tcDspStorageBase class. The constructor takes a pointer to a tcDspStorageBase object for the underlying device, and the number of sectors worth of cache to provide.

As sectors are ready off the disk, the cached data is placed in a linked list. The most-recently accessed data is always moved to the head of the list. When the list is full, the oldest entry is purged to make room for the newest.

When a sector is written to, the cached copy is marked as dirty. Dirty sectors are written back to the device only when they are removed from the cache (i.e., they become the oldest entry and are purged to make room for new data), or when manually flushed via a zero byte write to sector 0xFFFFFFFF.

See also:
MityDSP::tcDspStorageBase Class Reference
MityDSP::tcDspStorageCache Class Reference

Example

This is a simple example of tcDspStorageCache creation and usage:

{
unsigned int gnSPI_BASE_ADDR = 0xB0000200;
int bytes, myLatchID = 1;
char lpBuffer[1024];
tcDspOutputLatch MyClass::mpOutputLatch;
tcDspSpi *MyClass::mpSpi;
tcDspMmc *MyClass::mpMmc;
tcDspStorageCache *MyClass::mpMmcCache;
// create access to the SPI
mpSpi = new tcDspSpi((void *)gnSPI_BASE_ADDR);
// create access to MMC on SPI with provided CS latch
mpMmc = new tcDspMmc(mpSpi, mpOutputLatch, myLatchID);
tcDspError::report(<strong>FILE</strong>, <strong>LINE</strong>, status,
"MMC Device Size is %.1f KB", mpMmc->getSizeKB());
// create 256-sector cache for MMC
mpMmcCache = new tcDspStorageCache(mpMmc, 256);
// use the cache just like the underlying device...
// read 1K of data from sector 7
bytes = mpMmcCache->read(7, 0, (void *)lpBuffer, sizeof(lpBuffer));
// do something application-specific
...
// write 512 bytes to disk, at an offset of 2K into the MMC
bytes = mpMmcCache->write((void *)0x800, (void *)lpBuffer, 512);
...
}

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