implemented memory device, flashStorage and cached storage

git-svn-id: https://svn.vbchaos.nl/svn/hsb/trunk@268 05563f52-14a8-4384-a975-3d1654cca0fa
This commit is contained in:
mmi
2017-10-31 07:35:17 +00:00
parent a50a10995f
commit 76783a6061
17 changed files with 1103 additions and 13 deletions

View File

@@ -24,6 +24,7 @@ ARFLAGS = rs
OBJECTS = \ OBJECTS = \
ADCDevice.o \ ADCDevice.o \
CachedStorage.o \
CoverSolenoid.o \ CoverSolenoid.o \
DACDevice.o \ DACDevice.o \
DisplayDevice.o \ DisplayDevice.o \
@@ -33,6 +34,7 @@ IODevice.o \
KeyboardDevice.o \ KeyboardDevice.o \
Logger.o \ Logger.o \
MAX5715.o \ MAX5715.o \
MemoryDevice.o \
nhd0420.o \ nhd0420.o \
Observable.o \ Observable.o \
PID.o \ PID.o \

View File

@@ -0,0 +1,123 @@
// -----------------------------------------------------------------------------
/// @file CachedStorage.h
/// @brief EEPROM driver including local caching (for one page)
// -----------------------------------------------------------------------------
// 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
// -----------------------------------------------------------------------------
/// @defgroup {group_name} {group_description}
/// Description
/// @file adc.h
/// @ingroup {group_name}
#ifndef _CACHEDEEPROM_H_
#define _CACHEDEEPROM_H_
// -----------------------------------------------------------------------------
// Include files
// -----------------------------------------------------------------------------
#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
#include "stm32f10x.h"
#include "platform.h"
// -----------------------------------------------------------------------------
// Constant and macro definitions
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// Type definitions.
// -----------------------------------------------------------------------------
struct CachedStorage
{
bool initialized;
unsigned int pageSize;
bool dirty;
unsigned int page;
struct MemoryDevice* memoryDevice;
uint8_t storage[CACHED_STORAGE_PAGESIZE];
uint8_t tempBuffer[CACHED_STORAGE_PAGESIZE];
};
// -----------------------------------------------------------------------------
// Function declarations
// -----------------------------------------------------------------------------
/**
* Initializes the EEPROM hardware and reads the flash page
*/
ErrorStatus CachedStorage_construct(struct CachedStorage* self, struct MemoryDevice* memoryDevice, unsigned int page, unsigned int pageSize);
/**
* 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
*/
void CachedStorage_writeWord(struct CachedStorage* self, int offset, uint32_t value);
/**
* Writes binary data to the storage buffer
*/
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
*/
uint32_t CachedStorage_readWord(struct CachedStorage* self, int offset);
/**
* Reads binary data from the storage buffer
*/
const void* CachedStorage_readBlob(struct CachedStorage* self, int offset);
/**
* Writes the storage buffer to EEPROM (only if the contents differ)
*/
void CachedStorage_commit(struct CachedStorage* self);
#endif

View File

@@ -0,0 +1,141 @@
// -----------------------------------------------------------------------------
/// @file MemoryDevice.h
/// @brief File 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) 2015 Micro-Key bv
// -----------------------------------------------------------------------------
/// @defgroup {group_name} {group_description}
/// Description
/// @file MemoryDevice.h
/// @ingroup {group_name}
#ifndef INC_MEMORYDEVICE_H_
#define INC_MEMORYDEVICE_H_
// -----------------------------------------------------------------------------
// Include files
// -----------------------------------------------------------------------------
#include <stdbool.h>
#include "stm32f10x.h"
// -----------------------------------------------------------------------------
// Constant and macro definitions
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// Type definitions.
// -----------------------------------------------------------------------------
struct MemoryDevice;
typedef ErrorStatus (*MemoryReadFunction)(const struct MemoryDevice* self, uint32_t* buffer, uint32_t address, unsigned int length);
typedef ErrorStatus (*MemoryWriteFunction)(const struct MemoryDevice* self, uint32_t* buffer, uint32_t address, unsigned int length);
typedef ErrorStatus (*MemoryErasePageFunction)(const struct MemoryDevice* self, unsigned int page);
struct MemoryDevice
{
MemoryReadFunction _read;
MemoryWriteFunction _write;
MemoryErasePageFunction _erasePage;
uint32_t startAddress;
uint32_t endAddress;
};
// -----------------------------------------------------------------------------
// Function declarations
// -----------------------------------------------------------------------------
/** ----------------------------------------------------------------------------
* MemoryDevice_construct
* Description of function
*
* @param self
* @param startAddress
* @return ErrorStatus
*
* @todo
* -----------------------------------------------------------------------------
*/
extern ErrorStatus MemoryDevice_construct(struct MemoryDevice* self, uint32_t startAddress, uint32_t endAddress, MemoryReadFunction read, MemoryWriteFunction write, MemoryErasePageFunction erasePage);
/** ----------------------------------------------------------------------------
* MemoryDevice_destruct
* Description of function
*
* @param self
* @param
* @return void
*
* @todo
* -----------------------------------------------------------------------------
*/
extern void MemoryDevice_destruct(struct MemoryDevice* self);
/** ----------------------------------------------------------------------------
* MemoryDevice_read
* Description of function
*
* @param self
* @param buffer
* @param address
* @param length
*
* @return ErrorStatus
*
* @todo
* -----------------------------------------------------------------------------
*/
extern ErrorStatus MemoryDevice_write(const struct MemoryDevice* self, uint32_t* buffer, uint32_t address, unsigned int length);
/** ----------------------------------------------------------------------------
* MemoryDevice_read
* Description of function
*
* @param self
* @param buffer
* @param address
* @param length
*
* @return ErrorStatus
*
* @todo
* -----------------------------------------------------------------------------
*/
extern ErrorStatus MemoryDevice_read(const struct MemoryDevice* self, uint32_t* buffer, uint32_t address, unsigned int length);
/** ----------------------------------------------------------------------------
* MemoryDevice_erasePage
* Description of function
*
* @param self
* @param page
* @return ErrorStatus
*
* @todo
* -----------------------------------------------------------------------------
*/
extern ErrorStatus MemoryDevice_erasePage(struct MemoryDevice* self, unsigned int page);
#endif /* INC_MEMORYDEVICE_H_ */

View File

@@ -0,0 +1,271 @@
// -----------------------------------------------------------------------------
/// @file CachedStorage.c
/// @brief EEPROM driver including local caching (for one page)
// -----------------------------------------------------------------------------
// 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 CachedStorage.c
/// @ingroup {group_name}
// -----------------------------------------------------------------------------
// Include files
// -----------------------------------------------------------------------------
#include "Logger.h"
#include <string.h>
#include "CachedStorage.h"
#include "InternalFlash.h"
#include "stm32f10x_flash.h"
// -----------------------------------------------------------------------------
// Constant and macro definitions
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// Type definitions
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// File-scope variables
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// Function declarations
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// Function definitions
// -----------------------------------------------------------------------------
ErrorStatus CachedStorage_construct(struct CachedStorage* self, struct MemoryDevice* memoryDevice, unsigned int page, unsigned int pageSize)
{
ErrorStatus returnValue = SUCCESS;
if (!self->initialized)
{
self->page = page;
self->dirty = false;
if (returnValue == SUCCESS)
{
self->memoryDevice = memoryDevice;
}
if (returnValue == SUCCESS)
{
MemoryDevice_read(self->memoryDevice, (uint32_t*)self->storage, (self->memoryDevice->startAddress + (self->page * self->pageSize)), self->pageSize);
self->initialized = true;
}
}
return returnValue;
}
void CachedStorage_destruct(struct CachedStorage* self)
{
if (self->initialized)
{
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)
{
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;
}
}
}
}
void CachedStorage_writeBlob(struct CachedStorage* self, int offset, const void* blob, size_t blobSize)
{
if (self->initialized)
{
if(offset + blobSize <= CACHED_STORAGE_PAGESIZE)
{
memcpy(&self->storage[offset], blob, blobSize);
self->dirty = true;
}
}
}
uint8_t CachedStorage_readByte(struct CachedStorage* self, int offset)
{
if (self->initialized)
{
if(offset < CACHED_STORAGE_PAGESIZE)
{
return self->storage[offset];
}
else
{
return 0;
}
}
}
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;
}
}
}
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;
}
}
}
const void* CachedStorage_readBlob(struct CachedStorage* self, int offset)
{
if (self->initialized)
{
if(offset < CACHED_STORAGE_PAGESIZE)
{
return &self->storage[offset];
}
else
{
return NULL;
}
}
}
void CachedStorage_commit(struct CachedStorage* self)
{
if (self->initialized)
{
if(self->dirty)
{
MemoryDevice_read(self->memoryDevice, (uint32_t*)self->tempBuffer, (self->memoryDevice->startAddress + (self->page * self->pageSize)), self->pageSize);
if(memcmp(self->tempBuffer, self->storage, CACHED_STORAGE_PAGESIZE) != 0)
{
MemoryDevice_write(self->memoryDevice, (uint32_t*)self->storage, (self->memoryDevice->startAddress + (self->page * 0x800)), 20);
}
else
{
LOGGER_DEBUG(mainLog, "CachedStorage content on page %d unchanged, did not write", self->page);
}
self->dirty = false;
}
else
{
LOGGER_DEBUG(mainLog, "CachedStorage content on page %d unchanged, did not write", self->page);
}
}
}

View File

@@ -0,0 +1,115 @@
// -----------------------------------------------------------------------------
/// @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, MemoryReadFunction read, MemoryWriteFunction write, MemoryErasePageFunction erasePage)
{
ErrorStatus returnValue = SUCCESS;
self->_read = read;
self->_write = write;
self->_erasePage = erasePage;
self->startAddress = startAddress;
self->endAddress = endAddress;
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;
}
}

View File

@@ -27,6 +27,7 @@ stm32f10x_it.o \
CathodeMCP.o \ CathodeMCP.o \
gpio.o \ gpio.o \
internalADC.o \ internalADC.o \
InternalFlash.o \
keypadMatrix.o \ keypadMatrix.o \
oli_stm32_h107.o \ oli_stm32_h107.o \
PCBA.o \ PCBA.o \

View File

@@ -0,0 +1,144 @@
// -----------------------------------------------------------------------------
/// @file InternalFlash.h
/// @brief File 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) 2015 Micro-Key bv
// -----------------------------------------------------------------------------
/// @defgroup {group_name} {group_description}
/// Description
/// @file InternalFlash.h
/// @ingroup {group_name}
#ifndef INC_INTERNALFLASH_H_
#define INC_INTERNALFLASH_H_
// -----------------------------------------------------------------------------
// Include files
// -----------------------------------------------------------------------------
#include <stdbool.h>
#include "stm32f10x.h"
#include "stm32f10x_flash.h"
#include "MemoryDevice.h"
// -----------------------------------------------------------------------------
// Constant and macro definitions
// -----------------------------------------------------------------------------
#define INTERNAL_FLASH_BASE_ADDRESS ((uint32_t)0x08000000)
#define INTERNAL_FLASH_PAGE_SIZE ((uint32_t)0x800)
#define INTERNAL_FLASH_NUMBER_OF_PAGES ((uint32_t)0x80)
// -----------------------------------------------------------------------------
// Type definitions.
// -----------------------------------------------------------------------------
struct InternalFlash
{
struct MemoryDevice memoryDevice;
bool initialized;
uint32_t startAddress;
uint32_t endAddress;
uint32_t pageSize;
};
// -----------------------------------------------------------------------------
// Function declarations
// -----------------------------------------------------------------------------
/** ----------------------------------------------------------------------------
* InternalFlash_construct
* Description of function
*
* @param self
*
* @return ErrorStatus
*
* @todo
* -----------------------------------------------------------------------------
*/
extern ErrorStatus InternalFlash_construct(struct InternalFlash* self);
/** ----------------------------------------------------------------------------
* InternalFlash_destruct
* Description of function
*
* @param self
* @param
* @return void
*
* @todo
* -----------------------------------------------------------------------------
*/
extern void InternalFlash_destruct(struct InternalFlash* self);
/** ----------------------------------------------------------------------------
* InternalFlash_write
* Description of function
*
* @param self
* @param buffer
* @param address
* @param length
*
* @return ErrorStatus
*
* @todo
* -----------------------------------------------------------------------------
*/
extern ErrorStatus InternalFlash_write(const struct InternalFlash* self, uint32_t* buffer, uint32_t address, unsigned int length);
/** ----------------------------------------------------------------------------
* InternalFlash_read
* Description of function
*
* @param self
* @param buffer
* @param address
* @param length
*
* @return ErrorStatus
*
* @todo
* -----------------------------------------------------------------------------
*/
extern ErrorStatus InternalFlash_read(const struct InternalFlash* self, uint32_t* buffer, uint32_t address, unsigned int length);
/** ----------------------------------------------------------------------------
* InternalFlash_erasePage
* Description of function
*
* @param self
* @param page
*
* @param length
*
* @return ErrorStatus
*
* @todo
* -----------------------------------------------------------------------------
*/
extern ErrorStatus InternalFlash_erasePage(const struct InternalFlash* self, unsigned int page);
#endif /* INC_INTERNALFLASH_H_ */

View File

@@ -49,7 +49,7 @@
// Constant and macro definitions // Constant and macro definitions
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
#define CACHED_STORAGE_PAGESIZE ((uint16_t)0x200)
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// Type definitions. // Type definitions.
@@ -79,6 +79,8 @@ extern struct SpiDevice* const spiEEPROM;
// Export of Keypad // Export of Keypad
extern struct Keypad* const keypad; extern struct Keypad* const keypad;
extern struct Storm700* const storm700; extern struct Storm700* const storm700;
// internal FLASH
extern struct InternalFlash* const iFlash;
// Export of GPIOs // Export of GPIOs
extern struct Gpio* const ledGreen; extern struct Gpio* const ledGreen;
extern struct Gpio* const ledOrange; extern struct Gpio* const ledOrange;

View File

@@ -0,0 +1,241 @@
// -----------------------------------------------------------------------------
/// @file InternalFlash.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 InternalFlash.c
/// @ingroup {group_name}
// -----------------------------------------------------------------------------
// Include files
// -----------------------------------------------------------------------------
#include "Logger.h"
#include "MemoryDevice.h"
#include "InternalFlash.h"
// -----------------------------------------------------------------------------
// Constant and macro definitions
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// Type definitions
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// File-scope variables
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// Function declarations
// -----------------------------------------------------------------------------
static ErrorStatus read(const struct MemoryDevice* self, uint32_t* buffer, uint32_t address, unsigned int length);
static ErrorStatus write(const struct MemoryDevice* self, uint32_t* buffer, uint32_t address, unsigned int length);
static ErrorStatus erasePage(const struct MemoryDevice* self, unsigned int page);
// -----------------------------------------------------------------------------
// Function definitions
// -----------------------------------------------------------------------------
ErrorStatus InternalFlash_construct(struct InternalFlash* self)
{
ErrorStatus returnValue = SUCCESS;
if (!self->initialized)
{
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);
}
if (returnValue == SUCCESS)
{
self->startAddress = INTERNAL_FLASH_BASE_ADDRESS;
self->endAddress = (INTERNAL_FLASH_BASE_ADDRESS + (INTERNAL_FLASH_NUMBER_OF_PAGES * INTERNAL_FLASH_PAGE_SIZE));
self->pageSize = INTERNAL_FLASH_PAGE_SIZE;
self->initialized = true;
}
}
else
{
returnValue = ERROR;
}
return returnValue;
}
void InternalFlash_destruct(struct InternalFlash* self)
{
if (self->initialized)
{
MemoryDevice_destruct(&self->memoryDevice);
self->initialized = false;
}
}
ErrorStatus InternalFlash_write(const struct InternalFlash* self, uint32_t* buffer, uint32_t address, unsigned int length)
{
ErrorStatus returnValue = SUCCESS;
FLASH_Status FLASHStatus = FLASH_COMPLETE;
uint32_t _address = address;
uint32_t _endAddress = address + (length * 4);
if (self->initialized)
{
if (returnValue == SUCCESS)
{
// Verify start address boundaries
if ((_address < self->startAddress) && (_address >= self->endAddress))
{
// Start address is NOT OK
returnValue = ERROR;
}
}
if (returnValue == SUCCESS)
{
// Verify end address boundaries
if ((_endAddress >= self->endAddress))
{
// End address is NOT OK
returnValue = ERROR;
}
}
// Boundaries OK - Write to FLASH
if (returnValue == SUCCESS)
{
// Unlock the FLASH bank
FLASH_Unlock();
// Loop writing until end address is reached
int bufferIndex = 0;
while((_address < _endAddress) && (FLASHStatus == FLASH_COMPLETE))
{
FLASHStatus = FLASH_ProgramWord(_address, buffer[bufferIndex++]);
// 32bit data register requires increment by 4 for next word address
_address = _address + 4;
}
// After programming, lock the FLASH
FLASH_Lock();
}
}
else
{
returnValue = ERROR;
LOGGER_ERROR(mainLog, "BOEH");
}
return returnValue;
}
ErrorStatus InternalFlash_read(const struct InternalFlash* self, uint32_t* buffer, uint32_t address, unsigned int length)
{
ErrorStatus returnValue = SUCCESS;
uint32_t _address = address;
uint32_t _endAddress = address + (length * 4);
if (self->initialized)
{
if (returnValue == SUCCESS)
{
// Verify start address boundaries
if ((_address < self->startAddress) && (_address >= self->endAddress))
{
// Start address is NOT OK
returnValue = ERROR;
}
}
if (returnValue == SUCCESS)
{
// Verify end address boundaries
if ((_endAddress >= self->endAddress))
{
// End address is NOT OK
returnValue = ERROR;
}
}
// Boundaries OK - Read from FLASH
if (returnValue == SUCCESS)
{
// Loop reading until end address is reached
int bufferIndex = 0;
while(_address < _endAddress)
{
buffer[bufferIndex++] = *(uint32_t*) _address;
// 32bit data register requires increment by 4 for next word address
_address = _address + 4;
}
}
}
else
{
returnValue = ERROR;
}
return returnValue;
}
ErrorStatus InternalFlash_erasePage(const struct InternalFlash* self, unsigned int page)
{
ErrorStatus returnValue = SUCCESS;
FLASH_Status FLASHStatus;
if (self->initialized)
{
// Unlock the FLASH bank
FLASH_Unlock();
FLASHStatus = FLASH_ErasePage(self->startAddress + (self->pageSize * page));
// After programming, lock the FLASH
FLASH_Lock();
if (FLASHStatus != FLASH_COMPLETE)
{
returnValue = ERROR;
}
}
else
{
returnValue = ERROR;
}
return returnValue;
}
static ErrorStatus read(const struct MemoryDevice* self, uint32_t* buffer, uint32_t address, unsigned int length)
{
return InternalFlash_read((const struct InternalFlash*)self, buffer, address, length);
}
static ErrorStatus write(const struct MemoryDevice* self, uint32_t* buffer, uint32_t address, unsigned int length)
{
return InternalFlash_write((const struct InternalFlash*)self, buffer, address, length);
}
static ErrorStatus erasePage(const struct MemoryDevice* self, unsigned int page)
{
return InternalFlash_erasePage((const struct InternalFlash*)self, page);
}

View File

@@ -43,6 +43,7 @@
#include "gpio.h" #include "gpio.h"
#include "Interlock.h" #include "Interlock.h"
#include "internalADC.h" #include "internalADC.h"
#include "InternalFlash.h"
#include "keypadMatrix.h" #include "keypadMatrix.h"
#include "MAX5715.h" #include "MAX5715.h"
#include "nhd0420.h" #include "nhd0420.h"
@@ -131,6 +132,9 @@ static struct SpiDevice _spiEEPROM = {.initialized = false};
static struct Keypad _keypad = {.initialized = false}; static struct Keypad _keypad = {.initialized = false};
static struct Storm700 _storm700 = {.initialized = false}; static struct Storm700 _storm700 = {.initialized = false};
// Interal FLASH
static struct InternalFlash _iFlash = {.initialized = false};
// GPIOs // GPIOs
static struct Gpio _ledGreen = {.initialized = false}; static struct Gpio _ledGreen = {.initialized = false};
static struct Gpio _ledOrange = {.initialized = false}; static struct Gpio _ledOrange = {.initialized = false};
@@ -182,6 +186,8 @@ struct SpiParameters* const spiEEPROMParam = &_spi3EEPROMParameters;
struct Keypad* const keypad = &_keypad; struct Keypad* const keypad = &_keypad;
struct Storm700* const storm700 = &_storm700; struct Storm700* const storm700 = &_storm700;
struct InternalFlash* const iFlash = &_iFlash;
struct Gpio* const ledGreen = &_ledGreen; struct Gpio* const ledGreen = &_ledGreen;
struct Gpio* const ledOrange = &_ledOrange; struct Gpio* const ledOrange = &_ledOrange;
@@ -602,6 +608,7 @@ static ErrorStatus initPeriphery(void)
IRQ_setInterruptProperties(RTC_IRQn, 13, 0, ENABLE); IRQ_setInterruptProperties(RTC_IRQn, 13, 0, ENABLE);
RTC_construct(rtc); RTC_construct(rtc);
/* --------------------------------------------------------------------*/ /* --------------------------------------------------------------------*/
/* USART1 */ /* USART1 */
/* --------------------------------------------------------------------*/ /* --------------------------------------------------------------------*/
@@ -690,6 +697,13 @@ static ErrorStatus initPeriphery(void)
IRQ_setInterruptProperties(EXTI9_5_IRQn, 12, 12, ENABLE); IRQ_setInterruptProperties(EXTI9_5_IRQn, 12, 12, ENABLE);
/* --------------------------------------------------------------------*/
/* INTERNAL FLASH MEMORY */
/* --------------------------------------------------------------------*/
InternalFlash_construct(iFlash);
/* --------------------------------------------------------------------*/ /* --------------------------------------------------------------------*/
/* GPIOs */ /* GPIOs */
/* --------------------------------------------------------------------*/ /* --------------------------------------------------------------------*/

View File

@@ -6,7 +6,7 @@
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/> <provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/> <provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
<provider copy-of="extension" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser"/> <provider copy-of="extension" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser"/>
<provider class="fr.ac6.mcu.ide.build.CrossBuiltinSpecsDetector" console="false" env-hash="-24990244560702828" id="fr.ac6.mcu.ide.build.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="Ac6 SW4 STM32 MCU Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true"> <provider class="fr.ac6.mcu.ide.build.CrossBuiltinSpecsDetector" console="false" env-hash="510461499985258339" id="fr.ac6.mcu.ide.build.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="Ac6 SW4 STM32 MCU Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<language-scope id="org.eclipse.cdt.core.gcc"/> <language-scope id="org.eclipse.cdt.core.gcc"/>
<language-scope id="org.eclipse.cdt.core.g++"/> <language-scope id="org.eclipse.cdt.core.g++"/>
</provider> </provider>
@@ -18,7 +18,7 @@
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/> <provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/> <provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
<provider copy-of="extension" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser"/> <provider copy-of="extension" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser"/>
<provider class="fr.ac6.mcu.ide.build.CrossBuiltinSpecsDetector" console="false" env-hash="-24990244560702828" id="fr.ac6.mcu.ide.build.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="Ac6 SW4 STM32 MCU Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true"> <provider class="fr.ac6.mcu.ide.build.CrossBuiltinSpecsDetector" console="false" env-hash="510461499985258339" id="fr.ac6.mcu.ide.build.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="Ac6 SW4 STM32 MCU Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<language-scope id="org.eclipse.cdt.core.gcc"/> <language-scope id="org.eclipse.cdt.core.gcc"/>
<language-scope id="org.eclipse.cdt.core.g++"/> <language-scope id="org.eclipse.cdt.core.g++"/>
</provider> </provider>

View File

@@ -62,7 +62,7 @@ _Min_Stack_Size = 0x400; /* required amount of stack */
MEMORY MEMORY
{ {
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 64K RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 64K
ROM (rx) : ORIGIN = 0x8000000, LENGTH = 256K ROM (rx) : ORIGIN = 0x8000000, LENGTH = 254K
} }
/* Sections */ /* Sections */

View File

@@ -25,6 +25,8 @@
// Include files // Include files
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
#include <stdlib.h>
#include "DAConverter.h" #include "DAConverter.h"
#include "Logger.h" #include "Logger.h"
@@ -91,7 +93,7 @@ extern ErrorStatus DAConverter_setOutputVoltage(const struct DAConverter* self,
uint32_t dacValue; uint32_t dacValue;
dacValue = calculateDACValue(self, voltage); dacValue = calculateDACValue(self, voltage);
DACDevice_write(self->dacDevice, dacValue); DACDevice_write(self->dacDevice, dacValue);
LOGGER_DEBUG(mainLog, "Voltage %d --- value %X", voltage, dacValue); LOGGER_DEBUG(mainLog, "Voltage %d --- value %X", voltage, (unsigned int)dacValue);
} }
} }
else else

View File

@@ -25,6 +25,7 @@
// Include files // Include files
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
#include <stdlib.h>
#include <string.h> #include <string.h>
#include "hsb-mrts.h" #include "hsb-mrts.h"

View File

@@ -47,6 +47,7 @@
#include "misc.h" #include "misc.h"
#include "stm32f10x_rcc.h" #include "stm32f10x_rcc.h"
#include "CachedStorage.h"
#include "DisplayDevice.h" #include "DisplayDevice.h"
#include "KeyboardDevice.h" #include "KeyboardDevice.h"
#include "MAX5715.h" #include "MAX5715.h"
@@ -56,10 +57,12 @@
#include "CathodeMCP.h" #include "CathodeMCP.h"
#include "Interlock.h" #include "Interlock.h"
#include "internalADC.h" #include "internalADC.h"
#include "InternalFlash.h"
#include "gpio.h" #include "gpio.h"
#include "IODevice.h" #include "IODevice.h"
#include "keypadMatrix.h" #include "keypadMatrix.h"
#include "Logger.h" #include "Logger.h"
#include "MemoryDevice.h"
#include "PCBA.h" #include "PCBA.h"
#include "uart.h" #include "uart.h"
#include "spi.h" #include "spi.h"
@@ -102,6 +105,7 @@ static struct HwValidationMenuItems hwTestItems;
struct HwValidationMenu* hwValidation = &_hwValidation; struct HwValidationMenu* hwValidation = &_hwValidation;
static struct CachedStorage cs = {.initialized = false};
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// Function declarations // Function declarations
@@ -125,7 +129,7 @@ int main (void)
ledTaskArguments.led = ledOrange; ledTaskArguments.led = ledOrange;
ledTaskArguments.frequency = 1; ledTaskArguments.frequency = 1;
xTaskCreate(initTask, (const char* const)"initTask", 1024, NULL, 5, &initTaskHandle); xTaskCreate(initTask, (const char* const)"initTask", 2048, NULL, 5, &initTaskHandle);
/* Start the scheduler. */ /* Start the scheduler. */
vTaskStartScheduler(); vTaskStartScheduler();
@@ -199,17 +203,17 @@ static void initTask(void* parameters)
xTaskCreate(ledBlinkTask, (const char* const)"ledTask", 100, &ledTaskArguments, 0, &ledTaskHandle); xTaskCreate(ledBlinkTask, (const char* const)"ledTask", 100, &ledTaskArguments, 0, &ledTaskHandle);
// Construct the displays // Construct the displays
Displays_construct(); // Displays_construct();
// Construct the AD Converters // Construct the AD Converters
ADConverters_construct(); // ADConverters_construct();
// Construct the DA Converters // Construct the DA Converters
DAConverters_construct(); // DAConverters_construct();
hsb_generateStartScreen(mainDisplay); // hsb_generateStartScreen(mainDisplay);
// Let start screen stay for 5 seconds // Let start screen stay for 5 seconds
vTaskDelay(INIT_START_SCREEN_DELAY); // vTaskDelay(INIT_START_SCREEN_DELAY);
///TODO MUST BE UPDATED ///TODO MUST BE UPDATED
@@ -232,7 +236,35 @@ static void initTask(void* parameters)
// HwValidationMenu_construct(hwValidation, &uart1->device, &hwTestItems, 1, 1024); // HwValidationMenu_construct(hwValidation, &uart1->device, &hwTestItems, 1, 1024);
// Construct the repair menu // Construct the repair menu
repairMenus_construct(); // repairMenus_construct();
uint32_t buffer[128];
int i;
for (i = 0; i < 128; i++)
{
buffer[i] = i + 4;
vTaskDelay(20);
}
//
// vTaskDelay(5000);
//
CachedStorage_construct(&cs, &iFlash->memoryDevice, 127, CACHED_STORAGE_PAGESIZE);
MemoryDevice_erasePage(&iFlash->memoryDevice, 127);
CachedStorage_writeBlob(&cs, 0, buffer, sizeof(buffer));
CachedStorage_commit(&cs);
////
// vTaskDelay(1000);
//
const uint32_t* buffer2;
buffer2 = CachedStorage_readBlob(&cs, 0);
for (i = 0; i < 128; i++)
{
LOGGER_DEBUG(mainLog, "Value %d ---> %d", i, (unsigned int)buffer2[i]);
vTaskDelay(20);
}
// Create task that repeats to print out TASK information on the logger // Create task that repeats to print out TASK information on the logger
xTaskCreate(printSystemInfoTask, (const char* const)"SysInfoTask", 512, NULL, 0, &sysTaskHandle); xTaskCreate(printSystemInfoTask, (const char* const)"SysInfoTask", 512, NULL, 0, &sysTaskHandle);

View File

@@ -922,6 +922,7 @@ static ErrorStatus repairMenu_createMenu(struct RepairMenu* self)
repairMenu_addKeyAction_SCROLLUP(&self->menuArray[RM_PRESET_PRINT], 'U', PRESSED); repairMenu_addKeyAction_SCROLLUP(&self->menuArray[RM_PRESET_PRINT], 'U', PRESSED);
repairMenu_addKeyAction_SCROLLDOWN(&self->menuArray[RM_PRESET_PRINT], 'D', PRESSED); repairMenu_addKeyAction_SCROLLDOWN(&self->menuArray[RM_PRESET_PRINT], 'D', PRESSED);
repairMenu_addKeyAction_GOTOSTATE(&self->menuArray[RM_PRESET_PRINT], 'X', PRESSED, PRESETMENU); repairMenu_addKeyAction_GOTOSTATE(&self->menuArray[RM_PRESET_PRINT], 'X', PRESSED, PRESETMENU);
repairMenu_addKeyAction_GOTOSTATE(&self->menuArray[PRESETMENU], 'L', PRESSED, PRESETMENU);
repairMenu_createMenuPage(&self->menuArray[REPAIR_RUNNING], MENU_HAS_NO_CURSOR, 4); repairMenu_createMenuPage(&self->menuArray[REPAIR_RUNNING], MENU_HAS_NO_CURSOR, 4);
repairMenu_addKeyAction_GOTOSTATE(&self->menuArray[REPAIR_RUNNING], 'X', PRESSED, REPAIR_ASK_PAUSE); repairMenu_addKeyAction_GOTOSTATE(&self->menuArray[REPAIR_RUNNING], 'X', PRESSED, REPAIR_ASK_PAUSE);

View File

@@ -229,7 +229,7 @@ static void repairProcess_task(void* parameters)
// The signal profile is identical for all rows in the regulation process // The signal profile is identical for all rows in the regulation process
SignalProfileGenerator_calculate(&self->signalProfileGenerator); SignalProfileGenerator_calculate(&self->signalProfileGenerator);
LOGGER_DEBUG(mainLog, "Signal: %d, TimeToRemain %d", self->signalProfileGenerator.signal, SignalProfileGenerator_getRemainingTime(&self->signalProfileGenerator)); LOGGER_DEBUG(mainLog, "Signal: %d, TimeToRemain %d", self->signalProfileGenerator.signal, (unsigned int)SignalProfileGenerator_getRemainingTime(&self->signalProfileGenerator));
// Check for correct signal // Check for correct signal
// if (self->signalProfileGenerator.signal >= 0) // if (self->signalProfileGenerator.signal >= 0)