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:
mmi
2017-11-07 15:50:25 +00:00
parent 27755498e6
commit 17207a3a4b
32 changed files with 1833 additions and 280 deletions

View File

@@ -53,11 +53,11 @@ struct CachedStorage
{
bool initialized;
unsigned int pageNumber;
unsigned int cacheSize;
size_t cacheSize;
bool dirty;
struct MemoryDevice* memoryDevice;
uint8_t storage[CACHED_STORAGE_PAGESIZE * 4]; // Times 4 to get 32bit width
uint8_t tempBuffer[CACHED_STORAGE_PAGESIZE * 4]; // Times 4 to get 32bit width
uint32_t* storage;
uint32_t* tempBuffer;
};
// -----------------------------------------------------------------------------
@@ -68,23 +68,13 @@ struct CachedStorage
/**
* Initializes the EEPROM hardware and reads the flash page
*/
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);
/**
* Terminates the EEPROM hardware. SPI port is available again
*/
void CachedStorage_destruct(struct CachedStorage* self);
/**
* Writes one byte to the storage buffer
*/
void CachedStorage_writeByte(struct CachedStorage* self, int offset, uint8_t value);
/**
* Writes two bytes to the storage buffer
*/
void CachedStorage_writeHalfWord(struct CachedStorage* self, int offset, uint16_t value);
/**
* Writes four bytes to the storage buffer
*/
@@ -95,15 +85,6 @@ void CachedStorage_writeWord(struct CachedStorage* self, int offset, uint32_t va
*/
void CachedStorage_writeBlob(struct CachedStorage* self, int offset, const void* blob, size_t blobSize);
/**
* Reads one byte from the storage buffer
*/
uint8_t CachedStorage_readByte(struct CachedStorage* self, int offset);
/**
* Reads two bytes from the storage buffer
*/
uint16_t CachedStorage_readHalfWord(struct CachedStorage* self, int offset);
/**
* Reads four bytes from the storage buffer

View File

@@ -56,12 +56,15 @@ struct DisplayDevice;
typedef ErrorStatus (*DisplayResetFunction)(const struct DisplayDevice* self);
typedef ErrorStatus (*DisplaySetStateFunction)(const struct DisplayDevice* self, DisplayDevice_functionalState state);
typedef ErrorStatus (*DisplayBackspaceFunction)(const struct DisplayDevice* self);
typedef ErrorStatus (*DisplayCursorPositionFunction)(const struct DisplayDevice* self, unsigned int row, unsigned int column);
typedef ErrorStatus (*DisplayWriteFunction)(const struct DisplayDevice* self, const char* buffer, size_t length, size_t row, size_t column);
typedef ErrorStatus (*DisplayClearFunction)(const struct DisplayDevice* self);
typedef ErrorStatus (*DisplayClearLineFunction)(const struct DisplayDevice* self, size_t row);
typedef ErrorStatus (*DisplaySetBrightnessFunction)(const struct DisplayDevice* self, size_t brightness);
typedef ErrorStatus (*DisplaySetContrastFunction)(const struct DisplayDevice* self, size_t contrast);
typedef ErrorStatus (*DisplayInvertFunction)(const struct DisplayDevice* self);
typedef ErrorStatus (*DisplaySetBlinkingCursor)(const struct DisplayDevice* self, DisplayDevice_functionalState state);
struct DisplayDeviceParameters
{
@@ -77,12 +80,15 @@ struct DisplayDevice
{
DisplayResetFunction _reset;
DisplaySetStateFunction _setState;
DisplayBackspaceFunction _backspace;
DisplayCursorPositionFunction _setCursorToPosition;
DisplayWriteFunction _write;
DisplayClearFunction _clear;
DisplayClearLineFunction _clearLine;
DisplaySetBrightnessFunction _setBrightness;
DisplaySetContrastFunction _setContrast;
DisplayInvertFunction _invert;
DisplaySetBlinkingCursor _setBlinkingCursor;
struct DisplayDeviceParameters parameters;
bool initialized;
};
@@ -94,20 +100,26 @@ struct DisplayDevice
extern 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);
extern ErrorStatus DisplayDevice_reset(const struct DisplayDevice* self);
extern ErrorStatus DisplayDevice_setState(const struct DisplayDevice* self, DisplayDevice_functionalState state);
extern ErrorStatus DisplayDevice_backspace(const struct DisplayDevice* self);
extern ErrorStatus DisplayDevice_setCursorToPosition(const struct DisplayDevice* self, unsigned int row, unsigned int column);
extern ErrorStatus DisplayDevice_write(const struct DisplayDevice* self, const char* buffer, size_t length, size_t row, size_t column);
extern ErrorStatus DisplayDevice_clear(const struct DisplayDevice* self);
extern ErrorStatus DisplayDevice_clearLine(const struct DisplayDevice* self, size_t row);
extern ErrorStatus DisplayDevice_setBrightness(const struct DisplayDevice* self, size_t brightness);
extern ErrorStatus DisplayDevice_setContrast(const struct DisplayDevice* self, size_t contrast);
extern ErrorStatus DisplayDevice_invert(const struct DisplayDevice* self);
extern ErrorStatus DisplayDevice_setBlinkingCursorState(const struct DisplayDevice* self, DisplayDevice_functionalState state);
#endif /* INC_DISPLAYDEVICE_H_ */

View File

@@ -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
{

View File

@@ -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;
}

View File

@@ -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.

View File

@@ -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;
}