Updated memory storage functionality
- cachedStorage is functional - Presets can be loaded from FLASH - CRC32 added and applied - Presets with corrputed data will be replaced by default preset Next: Preset update functionality from menu git-svn-id: https://svn.vbchaos.nl/svn/hsb/trunk@269 05563f52-14a8-4384-a975-3d1654cca0fa
This commit is contained in:
@@ -60,13 +60,22 @@
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
|
||||
ErrorStatus CachedStorage_construct(struct CachedStorage* self, struct MemoryDevice* memoryDevice, unsigned int page, unsigned int pageSize)
|
||||
ErrorStatus CachedStorage_construct(struct CachedStorage* self, struct MemoryDevice* memoryDevice, unsigned int pageNumber)
|
||||
{
|
||||
ErrorStatus returnValue = SUCCESS;
|
||||
if (!self->initialized)
|
||||
{
|
||||
self->page = page;
|
||||
self->dirty = false;
|
||||
if (returnValue == SUCCESS)
|
||||
{
|
||||
if (pageNumber > 0)
|
||||
{
|
||||
self->pageNumber = pageNumber;
|
||||
}
|
||||
else
|
||||
{
|
||||
returnValue = ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
if (returnValue == SUCCESS)
|
||||
{
|
||||
@@ -75,8 +84,12 @@ ErrorStatus CachedStorage_construct(struct CachedStorage* self, struct MemoryDev
|
||||
}
|
||||
if (returnValue == SUCCESS)
|
||||
{
|
||||
MemoryDevice_read(self->memoryDevice, (uint32_t*)self->storage, (self->memoryDevice->startAddress + (self->page * self->pageSize)), self->pageSize);
|
||||
self->initialized = true;
|
||||
self->cacheSize = CACHED_STORAGE_PAGESIZE / 4;
|
||||
MemoryDevice_read(self->memoryDevice, (uint32_t*)self->storage, self->memoryDevice->startAddress + self->memoryDevice->pageSize * self->pageNumber, self->cacheSize);
|
||||
self->initialized = true;
|
||||
self->dirty = false;
|
||||
|
||||
LOGGER_DEBUG(mainLog, "Created Cached Storage at page: %d", self->pageNumber);
|
||||
}
|
||||
}
|
||||
return returnValue;
|
||||
@@ -196,6 +209,10 @@ uint8_t CachedStorage_readByte(struct CachedStorage* self, int offset)
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t CachedStorage_readHalfWord(struct CachedStorage* self, int offset)
|
||||
@@ -211,6 +228,10 @@ uint16_t CachedStorage_readHalfWord(struct CachedStorage* self, int offset)
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t CachedStorage_readWord(struct CachedStorage* self, int offset)
|
||||
@@ -226,6 +247,10 @@ uint32_t CachedStorage_readWord(struct CachedStorage* self, int offset)
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
const void* CachedStorage_readBlob(struct CachedStorage* self, int offset)
|
||||
@@ -241,6 +266,10 @@ const void* CachedStorage_readBlob(struct CachedStorage* self, int offset)
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void CachedStorage_commit(struct CachedStorage* self)
|
||||
@@ -249,23 +278,27 @@ void CachedStorage_commit(struct CachedStorage* self)
|
||||
{
|
||||
if(self->dirty)
|
||||
{
|
||||
MemoryDevice_read(self->memoryDevice, (uint32_t*)self->tempBuffer, (self->memoryDevice->startAddress + (self->page * self->pageSize)), self->pageSize);
|
||||
MemoryDevice_read(self->memoryDevice, (uint32_t*)self->tempBuffer, self->memoryDevice->startAddress + self->memoryDevice->pageSize * self->pageNumber, self->cacheSize);
|
||||
|
||||
|
||||
if(memcmp(self->tempBuffer, self->storage, CACHED_STORAGE_PAGESIZE) != 0)
|
||||
if(memcmp(self->tempBuffer, self->storage, (sizeof(self->storage) / sizeof(self->storage[0]))) != 0)
|
||||
{
|
||||
MemoryDevice_write(self->memoryDevice, (uint32_t*)self->storage, (self->memoryDevice->startAddress + (self->page * 0x800)), 20);
|
||||
if (self->memoryDevice->needsEraseBeforeWrite)
|
||||
{
|
||||
MemoryDevice_erasePage(self->memoryDevice, self->pageNumber);
|
||||
}
|
||||
MemoryDevice_write(self->memoryDevice, (uint32_t*)self->storage, self->memoryDevice->startAddress + self->memoryDevice->pageSize * self->pageNumber, self->cacheSize);
|
||||
}
|
||||
else
|
||||
{
|
||||
LOGGER_DEBUG(mainLog, "CachedStorage content on page %d unchanged, did not write", self->page);
|
||||
LOGGER_DEBUG(mainLog, "CachedStorage content unchanged, did not write");
|
||||
}
|
||||
|
||||
self->dirty = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
LOGGER_DEBUG(mainLog, "CachedStorage content on page %d unchanged, did not write", self->page);
|
||||
LOGGER_DEBUG(mainLog, "CachedStorage content unchanged, did not write");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,15 +56,25 @@
|
||||
// Function definitions
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
ErrorStatus MemoryDevice_construct(struct MemoryDevice* self, uint32_t startAddress, uint32_t endAddress, MemoryReadFunction read, MemoryWriteFunction write, MemoryErasePageFunction erasePage)
|
||||
ErrorStatus MemoryDevice_construct(struct MemoryDevice* self, uint32_t startAddress, uint32_t endAddress, uint32_t pageSize, bool needsEraseBeforeWrite, MemoryReadFunction read, MemoryWriteFunction write, MemoryErasePageFunction erasePage)
|
||||
{
|
||||
ErrorStatus returnValue = SUCCESS;
|
||||
|
||||
self->_read = read;
|
||||
self->_write = write;
|
||||
self->_erasePage = erasePage;
|
||||
self->startAddress = startAddress;
|
||||
self->endAddress = endAddress;
|
||||
if (!self->initialized)
|
||||
{
|
||||
self->_read = read;
|
||||
self->_write = write;
|
||||
self->_erasePage = erasePage;
|
||||
self->startAddress = startAddress;
|
||||
self->endAddress = endAddress;
|
||||
self->pageSize = pageSize;
|
||||
self->initialized = true;
|
||||
self->needsEraseBeforeWrite = needsEraseBeforeWrite;
|
||||
}
|
||||
else
|
||||
{
|
||||
returnValue = ERROR;
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
// -----------------------------------------------------------------------------
|
||||
/// @file crc32.c
|
||||
/// @brief Description
|
||||
// -----------------------------------------------------------------------------
|
||||
// Micro-Key bv
|
||||
// Industrieweg 28, 9804 TG Noordhorn
|
||||
// Postbus 92, 9800 AB Zuidhorn
|
||||
// The Netherlands
|
||||
// Tel: +31 594 503020
|
||||
// Fax: +31 594 505825
|
||||
// Email: support@microkey.nl
|
||||
// Web: www.microkey.nl
|
||||
// -----------------------------------------------------------------------------
|
||||
/// $Revision$
|
||||
/// $Author$
|
||||
/// $Date$
|
||||
// (c) 2017 Micro-Key bv
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
/// @file crc32.c
|
||||
/// @ingroup {group_name}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Include files
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
#include "crc32.h"
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Constant and macro definitions
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Type definitions
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// File-scope variables
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Function declarations
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Function definitions
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
uint32_t crc32_calculate(uint32_t crc, const void* buffer, size_t size)
|
||||
{
|
||||
const uint8_t *p;
|
||||
|
||||
p = buffer;
|
||||
crc = crc ^ ~0U;
|
||||
|
||||
while (size--)
|
||||
crc = crc32_tab[(crc ^ *p++) & 0xFF] ^ (crc >> 8);
|
||||
|
||||
return crc ^ ~0U;
|
||||
}
|
||||
Reference in New Issue
Block a user