device configuration prepared

This commit is contained in:
2020-11-30 18:29:53 +01:00
parent 76ff0d8e24
commit f22c821ca3
4 changed files with 117 additions and 46 deletions

View File

@ -3,9 +3,10 @@
#include <stdint.h>
#include <spi.h>
#include <assert.h>
#define CONFIG_MAGIC 0xdead0003
#define CONFIG_MAGIC 0xdead0004
#define DEVICE_MAGIC 0xaffe0000
typedef struct __attribute__((__packed__)) s_configBlock {
uint32_t configMagic;
@ -27,11 +28,12 @@ typedef struct __attribute__((__packed__)) s_configBlock {
#define MBUSDEVICE_NUM_OF_CONSIDEREDFIELDS 4
typedef struct __attribute__((__packed__)) s_deviceBlock {
char deviceName[MBUSDEVICE_NAMELENGTH];
uint8_t address;
int8_t consideredField[MBUSDEVICE_NUM_OF_CONSIDEREDFIELDS];
int32_t period;
uint8_t filler[7];
uint32_t deviceMagic;
char deviceName[MBUSDEVICE_NAMELENGTH];
uint8_t address;
int8_t consideredField[MBUSDEVICE_NUM_OF_CONSIDEREDFIELDS];
int32_t period;
uint8_t filler[3];
} t_deviceBlock;
void configInit();

View File

@ -4,21 +4,47 @@
#include <stdint.h>
#include <spi.h>
#include <config.h>
#include <assert.h>
#define EEPROM_WRITE_BLOCK_SIZE 32
#define EEPROM_AFTER_WRITE_DELAY 7
typedef struct __attribute__((__packed__)) s_eepromHeader {
uint32_t magic;
uint32_t writeCounter;
} t_eepromHeader;
static_assert((sizeof(t_eepromHeader) <= EEPROM_WRITE_BLOCK_SIZE), "t_eepromHeader has illegal size, must be less than or equal 32");
typedef struct __attribute__((__packed__)) s_deviceStats {
uint32_t totalRunningHours;
uint32_t totalPowercycles;
uint32_t totalRequests;
uint32_t totalFailures;
} t_deviceStats;
static_assert((sizeof(t_deviceStats) <= EEPROM_WRITE_BLOCK_SIZE), "t_deviceStats has illegal size, must be less than or equal 32");
static_assert((sizeof(t_configBlock) % 32 == 0), "t_configBlock has illegal size, must be dividable by 32");
static_assert((sizeof(t_deviceBlock) % 32 == 0), "t_deviceBlock has illegal size, must be dividable by 32");
#define EEPROM_BASE_ADDR 0
#define EEPROM_DEVICE_STATS_ADDR 32
#define EEPROM_CONFIG_BLOCK_ADDR 64
#define EEPROM_DEVICE_BLOCK_BASE_ADDR (EEPROM_CONFIG_BLOCK_ADDR + sizeof(t_configBlock))
void eepromInit();
void eepromWrite(uint16_t addr, uint8_t *buf, uint8_t len);
void eepromRead(uint16_t addr, uint8_t *buf, uint8_t len);
void eepromSpiTxCpltCallback(SPI_HandleTypeDef *hspi);
t_deviceStats* getGlobalDeviceStats();
void eepromReadConfigBlock(uint8_t blockNum, t_configBlock *destConfigBlock);
void eepromWriteConfigBlock(uint8_t blockNum, t_configBlock *srcConfigBlock);
void eepromReadConfigBlock(t_configBlock *destConfigBlock);
void eepromWriteConfigBlock(t_configBlock *srcConfigBlock);
void eepromReadDeviceBlock(uint8_t blockNum, t_deviceBlock *destDeviceBlock);
void eepromWriteDeviceBlock(uint8_t blockNum, t_deviceBlock *srcDeviceBlock);
#endif /* EEPROM_H_ */