Fixed some major issues with RAM shortage. Also moved the cached storage to a MALLOC design instead of fixed memory usage. Using freertos porteds malloc and free required to move to HEAP4 to make sure memory does not get fragmented.
Resized nearly all task stacks Also: - Menu fixes for insertion. Almost done, just need to fix the negative voltage insertion for mcp and cathode - Added Device parameters, must be filled in git-svn-id: https://svn.vbchaos.nl/svn/hsb/trunk@271 05563f52-14a8-4384-a975-3d1654cca0fa
This commit is contained in:
@@ -60,7 +60,7 @@
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
|
||||
ErrorStatus CachedStorage_construct(struct CachedStorage* self, struct MemoryDevice* memoryDevice, unsigned int pageNumber)
|
||||
ErrorStatus CachedStorage_construct(struct CachedStorage* self, struct MemoryDevice* memoryDevice, unsigned int pageNumber, size_t cacheSize)
|
||||
{
|
||||
ErrorStatus returnValue = SUCCESS;
|
||||
if (!self->initialized)
|
||||
@@ -82,10 +82,39 @@ ErrorStatus CachedStorage_construct(struct CachedStorage* self, struct MemoryDev
|
||||
self->memoryDevice = memoryDevice;
|
||||
|
||||
}
|
||||
|
||||
if (returnValue == SUCCESS)
|
||||
{
|
||||
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->cacheSize = cacheSize;
|
||||
self->tempBuffer = pvPortMalloc(cacheSize * 4);
|
||||
if (self->tempBuffer == NULL)
|
||||
{
|
||||
returnValue = ERROR;
|
||||
LOGGER_ERROR(mainLog, "Failed to malloc to tempbuffer");
|
||||
}
|
||||
else
|
||||
{
|
||||
LOGGER_INFO(mainLog, "Created tempBuffer memory with size %x at address %p", self->cacheSize, self->tempBuffer);
|
||||
}
|
||||
}
|
||||
|
||||
if (returnValue == SUCCESS)
|
||||
{
|
||||
self->storage = pvPortMalloc(cacheSize * 4);
|
||||
if (self->storage == NULL)
|
||||
{
|
||||
returnValue = ERROR;
|
||||
LOGGER_ERROR(mainLog, "Failed to malloc to storage");
|
||||
}
|
||||
else
|
||||
{
|
||||
LOGGER_INFO(mainLog, "Created storage memory with size %x at address %p", self->cacheSize, self->storage);
|
||||
}
|
||||
}
|
||||
|
||||
if (returnValue == SUCCESS)
|
||||
{
|
||||
MemoryDevice_read(self->memoryDevice, self->storage, self->memoryDevice->startAddress + self->memoryDevice->pageSize * self->pageNumber, self->cacheSize);
|
||||
self->initialized = true;
|
||||
self->dirty = false;
|
||||
|
||||
@@ -99,87 +128,22 @@ void CachedStorage_destruct(struct CachedStorage* self)
|
||||
{
|
||||
if (self->initialized)
|
||||
{
|
||||
vPortFree(self->storage);
|
||||
vPortFree(self->tempBuffer);
|
||||
LOGGER_INFO(mainLog, "Free'd buffers");
|
||||
self->initialized = false;
|
||||
}
|
||||
}
|
||||
|
||||
void CachedStorage_writeByte(struct CachedStorage* self, int offset, uint8_t value)
|
||||
{
|
||||
if (self->initialized)
|
||||
{
|
||||
if(offset < CACHED_STORAGE_PAGESIZE)
|
||||
{
|
||||
if(value != self->storage[offset])
|
||||
{
|
||||
self->storage[offset] = value;
|
||||
self->dirty = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CachedStorage_writeHalfWord(struct CachedStorage* self, int offset, uint16_t _value)
|
||||
{
|
||||
if (self->initialized)
|
||||
{
|
||||
if(offset < CACHED_STORAGE_PAGESIZE - 1)
|
||||
{
|
||||
uint16_t value = _value;
|
||||
|
||||
if((value & 0xFF) != self->storage[offset + 1])
|
||||
{
|
||||
self->storage[offset + 1] = value & 0xFF;
|
||||
self->dirty = true;
|
||||
}
|
||||
|
||||
value >>= 8;
|
||||
|
||||
if((value & 0xFF) != self->storage[offset])
|
||||
{
|
||||
self->storage[offset] = value & 0xFF;
|
||||
self->dirty = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CachedStorage_writeWord(struct CachedStorage* self, int offset, uint32_t _value)
|
||||
{
|
||||
if (self->initialized)
|
||||
{
|
||||
if(offset < CACHED_STORAGE_PAGESIZE - 3)
|
||||
if(offset < self->cacheSize)
|
||||
{
|
||||
uint32_t value = _value;
|
||||
|
||||
if((value & 0xFF) != self->storage[offset + 3])
|
||||
{
|
||||
self->storage[offset + 3] = value & 0xFF;
|
||||
self->dirty = true;
|
||||
}
|
||||
|
||||
value >>= 8;
|
||||
|
||||
if((value & 0xFF) != self->storage[offset + 2])
|
||||
{
|
||||
self->storage[offset + 2] = value & 0xFF;
|
||||
self->dirty = true;
|
||||
}
|
||||
|
||||
value >>= 8;
|
||||
|
||||
if((value & 0xFF) != self->storage[offset + 1])
|
||||
{
|
||||
self->storage[offset + 1] = value & 0xFF;
|
||||
self->dirty = true;
|
||||
}
|
||||
|
||||
value >>= 8;
|
||||
|
||||
if((value & 0xFF) != self->storage[offset])
|
||||
{
|
||||
self->storage[offset] = value & 0xFF;
|
||||
self->dirty = true;
|
||||
}
|
||||
self->storage[offset] = _value;
|
||||
self->dirty = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -188,19 +152,23 @@ void CachedStorage_writeBlob(struct CachedStorage* self, int offset, const void*
|
||||
{
|
||||
if (self->initialized)
|
||||
{
|
||||
if(offset + blobSize <= CACHED_STORAGE_PAGESIZE)
|
||||
if(offset + blobSize <= self->cacheSize)
|
||||
{
|
||||
memcpy(&self->storage[offset], blob, blobSize);
|
||||
memcpy(&self->storage[offset], blob, blobSize * 4);
|
||||
self->dirty = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
LOGGER_ERROR(mainLog, "WriteBlob failed at offset %d, blobsize %d --- %p", offset, blobSize, self->storage[offset]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t CachedStorage_readByte(struct CachedStorage* self, int offset)
|
||||
uint32_t CachedStorage_readWord(struct CachedStorage* self, int offset)
|
||||
{
|
||||
if (self->initialized)
|
||||
{
|
||||
if(offset < CACHED_STORAGE_PAGESIZE)
|
||||
if(offset < self->cacheSize)
|
||||
{
|
||||
return self->storage[offset];
|
||||
}
|
||||
@@ -215,54 +183,19 @@ uint8_t CachedStorage_readByte(struct CachedStorage* self, int offset)
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t CachedStorage_readHalfWord(struct CachedStorage* self, int offset)
|
||||
{
|
||||
if (self->initialized)
|
||||
{
|
||||
if(offset < CACHED_STORAGE_PAGESIZE - 1)
|
||||
{
|
||||
return self->storage[offset + 1] | (self->storage[offset] << 8);
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t CachedStorage_readWord(struct CachedStorage* self, int offset)
|
||||
{
|
||||
if (self->initialized)
|
||||
{
|
||||
if(offset < CACHED_STORAGE_PAGESIZE - 3)
|
||||
{
|
||||
return self->storage[offset + 3] | (self->storage[offset + 2] << 8) | (self->storage[offset + 1] << 16) | (self->storage[offset] << 24);
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
const void* CachedStorage_readBlob(struct CachedStorage* self, int offset)
|
||||
{
|
||||
if (self->initialized)
|
||||
{
|
||||
if(offset < CACHED_STORAGE_PAGESIZE)
|
||||
if(offset < self->cacheSize)
|
||||
{
|
||||
return &self->storage[offset];
|
||||
}
|
||||
else
|
||||
{
|
||||
LOGGER_ERROR(mainLog, "ReadBlob failed at offset %d --- %p", offset, self->storage[offset]);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
@@ -278,16 +211,16 @@ void CachedStorage_commit(struct CachedStorage* self)
|
||||
{
|
||||
if(self->dirty)
|
||||
{
|
||||
MemoryDevice_read(self->memoryDevice, (uint32_t*)self->tempBuffer, self->memoryDevice->startAddress + self->memoryDevice->pageSize * self->pageNumber, self->cacheSize);
|
||||
MemoryDevice_read(self->memoryDevice, self->tempBuffer, self->memoryDevice->startAddress + self->memoryDevice->pageSize * self->pageNumber, self->cacheSize);
|
||||
|
||||
|
||||
if(memcmp(self->tempBuffer, self->storage, (sizeof(self->storage) / sizeof(self->storage[0]))) != 0)
|
||||
if(memcmp(self->tempBuffer, self->storage, (self->cacheSize * 4)) != 0)
|
||||
{
|
||||
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);
|
||||
MemoryDevice_write(self->memoryDevice, self->storage, self->memoryDevice->startAddress + self->memoryDevice->pageSize * self->pageNumber, self->cacheSize);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -60,25 +60,31 @@
|
||||
ErrorStatus DisplayDevice_construct (struct DisplayDevice* self, struct DisplayDeviceParameters* parameters,
|
||||
DisplayResetFunction reset,
|
||||
DisplaySetStateFunction setState,
|
||||
DisplayBackspaceFunction backspace,
|
||||
DisplayCursorPositionFunction setCursorToPosition,
|
||||
DisplayWriteFunction write,
|
||||
DisplayClearFunction clear,
|
||||
DisplayClearLineFunction clearLine,
|
||||
DisplaySetBrightnessFunction setBrightness,
|
||||
DisplaySetContrastFunction setContrast,
|
||||
DisplayInvertFunction invert)
|
||||
DisplayInvertFunction invert,
|
||||
DisplaySetBlinkingCursor setBlinkingCursor)
|
||||
{
|
||||
ErrorStatus returnValue = SUCCESS;
|
||||
|
||||
if (!self->initialized)
|
||||
{
|
||||
self->_reset = reset;
|
||||
self->_setState = setState;
|
||||
self->_write = write;
|
||||
self->_clear = clear;
|
||||
self->_clearLine = clearLine,
|
||||
self->_setBrightness = setBrightness;
|
||||
self->_setContrast = setContrast;
|
||||
self->_invert = invert;
|
||||
self->_reset = reset;
|
||||
self->_setState = setState;
|
||||
self->_backspace = backspace;
|
||||
self->_setCursorToPosition = setCursorToPosition;
|
||||
self->_write = write;
|
||||
self->_clear = clear;
|
||||
self->_clearLine = clearLine,
|
||||
self->_setBrightness = setBrightness;
|
||||
self->_setContrast = setContrast;
|
||||
self->_invert = invert;
|
||||
self->_setBlinkingCursor = setBlinkingCursor;
|
||||
|
||||
self->initialized = true;
|
||||
|
||||
@@ -128,6 +134,42 @@ ErrorStatus DisplayDevice_setState(const struct DisplayDevice* self, DisplayDevi
|
||||
}
|
||||
|
||||
|
||||
ErrorStatus DisplayDevice_backspace(const struct DisplayDevice* self)
|
||||
{
|
||||
ErrorStatus returnValue = SUCCESS;
|
||||
if (self->initialized)
|
||||
{
|
||||
if (self->_backspace != NULL)
|
||||
{
|
||||
returnValue = self->_backspace(self);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
returnValue = ERROR;
|
||||
}
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
|
||||
ErrorStatus DisplayDevice_setCursorToPosition(const struct DisplayDevice* self, unsigned int row, unsigned int column)
|
||||
{
|
||||
ErrorStatus returnValue = SUCCESS;
|
||||
if (self->initialized)
|
||||
{
|
||||
if (self->_setCursorToPosition != NULL)
|
||||
{
|
||||
returnValue = self->_setCursorToPosition(self, row, column);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
returnValue = ERROR;
|
||||
}
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
|
||||
ErrorStatus DisplayDevice_write(const struct DisplayDevice* self, const char* buffer, size_t length, size_t row, size_t column)
|
||||
{
|
||||
ErrorStatus returnValue = SUCCESS;
|
||||
@@ -234,3 +276,21 @@ ErrorStatus DisplayDevice_invert(const struct DisplayDevice* self)
|
||||
}
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
|
||||
ErrorStatus DisplayDevice_setBlinkingCursorState(const struct DisplayDevice* self, DisplayDevice_functionalState state)
|
||||
{
|
||||
ErrorStatus returnValue = SUCCESS;
|
||||
if (self->initialized)
|
||||
{
|
||||
if (self->_setBlinkingCursor != NULL)
|
||||
{
|
||||
returnValue = self->_setBlinkingCursor(self, state);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
returnValue = ERROR;
|
||||
}
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@
|
||||
// Constant and macro definitions
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
#define LOGQUEUE_SIZE (24)
|
||||
#define LOGQUEUE_SIZE (20)
|
||||
|
||||
// Makefile compile options:
|
||||
// ENABLE_SERIAL_LOGGING: Use the serial port for logging.
|
||||
|
||||
@@ -67,10 +67,13 @@ static int nhd0420_cursorRowOffset[NHD0420_NUMBER_OF_ROWS] =
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
static ErrorStatus setState(const struct DisplayDevice* self, DisplayDevice_functionalState state);
|
||||
static ErrorStatus backspace(const struct DisplayDevice* self);
|
||||
static ErrorStatus setCursorToPosition(const struct DisplayDevice* self, unsigned int row, unsigned int column);
|
||||
static ErrorStatus write(const struct DisplayDevice* self, const char* buffer, size_t length, size_t row, size_t column);
|
||||
static ErrorStatus clear(const struct DisplayDevice* self);
|
||||
static ErrorStatus setBrightness(const struct DisplayDevice* self, size_t brightness);
|
||||
static ErrorStatus setContrast(const struct DisplayDevice* self, size_t contrast);
|
||||
static ErrorStatus setBlinkingCursorState(const struct DisplayDevice* self, DisplayDevice_functionalState state);
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Function definitions
|
||||
@@ -95,7 +98,7 @@ ErrorStatus NHD0420_construct(struct NHD0420* self, const struct IODevice* devic
|
||||
ddParameters.contrastMin = NHD0420_CONTRAST_MIN;
|
||||
ddParameters.contrastMax = NHD0420_CONTRAST_MAX;
|
||||
|
||||
returnValue = DisplayDevice_construct(&self->displayDevice, &ddParameters, NULL, setState, write, clear, NULL, setBrightness, setContrast, NULL);
|
||||
returnValue = DisplayDevice_construct(&self->displayDevice, &ddParameters, NULL, setState, backspace, setCursorToPosition, write, clear, NULL, setBrightness, setContrast, NULL, setBlinkingCursorState);
|
||||
|
||||
if (returnValue == SUCCESS)
|
||||
{
|
||||
@@ -390,6 +393,17 @@ static ErrorStatus setState(const struct DisplayDevice* self, DisplayDevice_func
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
static ErrorStatus backspace(const struct DisplayDevice* self)
|
||||
{
|
||||
return NHD0420_useBackspace((const struct NHD0420*)self);
|
||||
}
|
||||
|
||||
|
||||
ErrorStatus setCursorToPosition(const struct DisplayDevice* self, unsigned int row, unsigned int column)
|
||||
{
|
||||
return NHD0420_setCursorToPosition((const struct NHD0420*)self, row, column);
|
||||
}
|
||||
|
||||
|
||||
static ErrorStatus write(const struct DisplayDevice* self, const char* buffer, size_t length, size_t row, size_t column)
|
||||
{
|
||||
@@ -462,3 +476,24 @@ static ErrorStatus setContrast(const struct DisplayDevice* self, size_t contrast
|
||||
}
|
||||
|
||||
|
||||
static ErrorStatus setBlinkingCursorState(const struct DisplayDevice* self, DisplayDevice_functionalState state)
|
||||
{
|
||||
ErrorStatus returnValue = SUCCESS;
|
||||
if (self->initialized)
|
||||
{
|
||||
if (state == ON)
|
||||
{
|
||||
returnValue = NHD0420_turnOnBlinkingCursor((const struct NHD0420*)self);
|
||||
}
|
||||
else
|
||||
{
|
||||
returnValue = NHD0420_turnOffBlinkingCursor((const struct NHD0420*)self);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
returnValue = ERROR;
|
||||
}
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user