From 6d7119c0e204196cb0286a91dc05d79fae6665a1 Mon Sep 17 00:00:00 2001 From: Wolfgang Hottgenroth Date: Fri, 27 Nov 2020 15:25:19 +0100 Subject: [PATCH] configuration --- cube/User/Inc/config.h | 1 + cube/User/Inc/eeprom.h | 3 +++ cube/User/Src/config.c | 14 +++++++++++++- cube/User/Src/eeprom.c | 12 +++++++++++- cube/User/Src/main2.c | 2 ++ 5 files changed, 30 insertions(+), 2 deletions(-) diff --git a/cube/User/Inc/config.h b/cube/User/Inc/config.h index d5a228f..5d1e360 100644 --- a/cube/User/Inc/config.h +++ b/cube/User/Inc/config.h @@ -15,6 +15,7 @@ typedef struct __attribute__((__packed__)) s_configBlock { char statusTopic[64]; char mbusDataTopic[64]; char syslogServerName[64]; + uint8_t filler[3]; } t_configBlock; void configInit(); diff --git a/cube/User/Inc/eeprom.h b/cube/User/Inc/eeprom.h index 1e48c01..4cad744 100644 --- a/cube/User/Inc/eeprom.h +++ b/cube/User/Inc/eeprom.h @@ -3,6 +3,7 @@ #include #include +#include typedef struct __attribute__((__packed__)) s_deviceStats { @@ -17,5 +18,7 @@ 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); + #endif /* EEPROM_H_ */ diff --git a/cube/User/Src/config.c b/cube/User/Src/config.c index 6fa90dc..b7972c8 100644 --- a/cube/User/Src/config.c +++ b/cube/User/Src/config.c @@ -1,5 +1,7 @@ -#include +#include +#include +#include t_configBlock defaultConfigBlock = { @@ -12,9 +14,19 @@ t_configBlock defaultConfigBlock = { .statusTopic = "IoT/MBGW3/Status", .mbusDataTopic = "IoT/MBGW3/Measurement", .syslogServerName = "syslogserver", + .filler = { 0, 0, 0 } }; +t_configBlock mainConfigBlock; + + + t_configBlock* getConfig() { return &defaultConfigBlock; +} + + +void configInit() { + eepromReadConfigBlock(0, &mainConfigBlock); } \ No newline at end of file diff --git a/cube/User/Src/eeprom.c b/cube/User/Src/eeprom.c index a08c05f..471a3e4 100644 --- a/cube/User/Src/eeprom.c +++ b/cube/User/Src/eeprom.c @@ -48,6 +48,8 @@ static t_deviceStatsBlock deviceStats; static const uint8_t NUM_OF_BLOCKS = 2; static const uint16_t BLOCK_ADDR[] = { 64, 4128 }; +static const uint8_t EEPROM_WRITE_BLOCK_SIZE = 32; + typedef union { struct __attribute__((__packed__)) s_spiMsg { @@ -58,7 +60,6 @@ typedef union { uint8_t b[sizeof(struct s_spiMsg)]; } t_spiMsg; - t_deviceStats* getGlobalDeviceStats() { return &(deviceStats.s); } @@ -126,6 +127,15 @@ static void eepromHourlyUpdateDeviceStats(void *handle) { eepromWrite(DEVICE_STATS_ADDR, deviceStats.b, sizeof(deviceStats)); } +void eepromReadConfigBlock(uint8_t blockNum, t_configBlock *destConfigBlock) { + uint8_t configBlockSizeMod = sizeof(*destConfigBlock) % EEPROM_WRITE_BLOCK_SIZE; + if (configBlockSizeMod != 0) { + coloredMsg(LOG_RED, false, "eeRCB, config block size must be dividable by 32"); + coloredMsg(LOG_RED, false, "eeRCB, current size is %d", sizeof(*destConfigBlock)); + coloredMsg(LOG_RED, false, "eeRCB, append %d filler octets", configBlockSizeMod); + } +} + // active waiting, use only during initialization! static void eepromActiveDelay(uint8_t delay_ms) { activeDelay(delay_ms); diff --git a/cube/User/Src/main2.c b/cube/User/Src/main2.c index 60cdbce..528efd1 100644 --- a/cube/User/Src/main2.c +++ b/cube/User/Src/main2.c @@ -20,11 +20,13 @@ #include #include #include +#include void my_setup_1() { schInit(); logInit(); + configInit(); showInit(); }