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:
mmi
2017-11-02 12:58:27 +00:00
parent 76783a6061
commit 4901cb1a09
27 changed files with 894 additions and 144 deletions

View File

@@ -67,7 +67,12 @@ ErrorStatus InternalFlash_construct(struct InternalFlash* self)
{
if (returnValue == SUCCESS)
{
returnValue = MemoryDevice_construct(&self->memoryDevice, INTERNAL_FLASH_BASE_ADDRESS, (INTERNAL_FLASH_BASE_ADDRESS + (INTERNAL_FLASH_NUMBER_OF_PAGES * INTERNAL_FLASH_PAGE_SIZE)), read, write, erasePage);
returnValue = MemoryDevice_construct(&self->memoryDevice,
INTERNAL_FLASH_BASE_ADDRESS,
INTERNAL_FLASH_BASE_ADDRESS + (INTERNAL_FLASH_NUMBER_OF_PAGES * INTERNAL_FLASH_PAGE_SIZE),
INTERNAL_FLASH_PAGE_SIZE,
MEMORY_DEVICE_NEEDS_ERASE_BEFORE_WRITE,
read, write, erasePage);
}
if (returnValue == SUCCESS)
{
@@ -100,7 +105,7 @@ ErrorStatus InternalFlash_write(const struct InternalFlash* self, uint32_t* buff
ErrorStatus returnValue = SUCCESS;
FLASH_Status FLASHStatus = FLASH_COMPLETE;
uint32_t _address = address;
uint32_t _endAddress = address + (length * 4);
uint32_t _endAddress = address + (length * 4) - 1;
if (self->initialized)
{
if (returnValue == SUCCESS)
@@ -110,21 +115,26 @@ ErrorStatus InternalFlash_write(const struct InternalFlash* self, uint32_t* buff
{
// Start address is NOT OK
returnValue = ERROR;
LOGGER_DEBUG(mainLog, "StartAddress error %X (%X %X)", _address, self->startAddress, self->endAddress);
}
}
if (returnValue == SUCCESS)
{
// Verify end address boundaries
if ((_endAddress >= self->endAddress))
if ((_endAddress > self->endAddress))
{
// End address is NOT OK
returnValue = ERROR;
LOGGER_DEBUG(mainLog, "EndAddress error %X (%X)", _endAddress, self->endAddress);
}
}
// Boundaries OK - Write to FLASH
if (returnValue == SUCCESS)
{
LOGGER_DEBUG(mainLog, "Writing on address %X with length %d until address %X", _address, length *4, _endAddress);
// Unlock the FLASH bank
FLASH_Unlock();
@@ -132,11 +142,14 @@ ErrorStatus InternalFlash_write(const struct InternalFlash* self, uint32_t* buff
int bufferIndex = 0;
while((_address < _endAddress) && (FLASHStatus == FLASH_COMPLETE))
{
LOGGER_DEBUG(mainLog, "address %X --- Data %d", _address, buffer[bufferIndex]);
FLASHStatus = FLASH_ProgramWord(_address, buffer[bufferIndex++]);
// 32bit data register requires increment by 4 for next word address
_address = _address + 4;
vTaskDelay(100);
}
LOGGER_DEBUG(mainLog, "Writing done = flash status is %d", FLASHStatus);
// After programming, lock the FLASH
FLASH_Lock();
}
@@ -156,6 +169,7 @@ ErrorStatus InternalFlash_read(const struct InternalFlash* self, uint32_t* buffe
uint32_t _address = address;
uint32_t _endAddress = address + (length * 4);
if (self->initialized)
{
if (returnValue == SUCCESS)
@@ -185,7 +199,7 @@ ErrorStatus InternalFlash_read(const struct InternalFlash* self, uint32_t* buffe
while(_address < _endAddress)
{
buffer[bufferIndex++] = *(uint32_t*) _address;
// 32bit data register requires increment by 4 for next word address
// // 32bit data register requires increment by 4 for next word address
_address = _address + 4;
}
}