Files
hsb/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/HAL/src/MemoryDevice.c
mmi 4901cb1a09 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
2017-11-02 12:58:27 +00:00

126 lines
3.7 KiB
C

// -----------------------------------------------------------------------------
/// @file MemoryDevice.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 MemoryDevice.c
/// @ingroup {group_name}
// -----------------------------------------------------------------------------
// Include files
// -----------------------------------------------------------------------------
#include "stdio.h"
#include "MemoryDevice.h"
// -----------------------------------------------------------------------------
// Constant and macro definitions
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// Type definitions
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// File-scope variables
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// Function declarations
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// Function definitions
// -----------------------------------------------------------------------------
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;
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;
}
void MemoryDevice_destruct(struct MemoryDevice* self)
{
self->_read = NULL;
self->_write = NULL;
}
ErrorStatus MemoryDevice_write(const struct MemoryDevice* self, uint32_t* buffer, uint32_t address, unsigned int length)
{
ErrorStatus returnValue = SUCCESS;
if (self->_write != NULL)
{
returnValue = self->_write(self, buffer, address, length);
}
return returnValue;
}
ErrorStatus MemoryDevice_read(const struct MemoryDevice* self, uint32_t* buffer, uint32_t address, unsigned int length)
{
ErrorStatus returnValue = SUCCESS;
if (self->_read != NULL)
{
returnValue = self->_read(self, buffer, address, length);
}
return returnValue;
}
ErrorStatus MemoryDevice_erasePage(struct MemoryDevice* self, unsigned int page)
{
{
ErrorStatus returnValue = SUCCESS;
if (self->_erasePage != NULL)
{
returnValue = self->_erasePage(self, page);
}
return returnValue;
}
}