From 1ffb12ac9b28bbb3ebb07d2e27a5913d3147be44 Mon Sep 17 00:00:00 2001 From: Wolfgang Hottgenroth Date: Fri, 12 Feb 2021 19:10:11 +0100 Subject: [PATCH] stat watchdog --- cube/User/Inc/eeprom.h | 3 +-- cube/User/Src/eeprom.c | 18 ++++++++---------- cube/User/Src/regularCmds.c | 9 ++++----- 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/cube/User/Inc/eeprom.h b/cube/User/Inc/eeprom.h index c47c4da..5b95a36 100644 --- a/cube/User/Inc/eeprom.h +++ b/cube/User/Inc/eeprom.h @@ -21,8 +21,7 @@ static_assert((sizeof(t_eepromHeader) <= EEPROM_WRITE_BLOCK_SIZE), "t_eepromHead typedef struct __attribute__((__packed__)) s_deviceStats { uint32_t totalRunningHours; uint32_t totalPowercycles; - uint32_t totalRequests; - uint32_t totalFailures; + uint32_t totalWatchdogResets; } t_deviceStats; static_assert((sizeof(t_deviceStats) <= EEPROM_WRITE_BLOCK_SIZE), "t_deviceStats has illegal size, must be less than or equal 32"); diff --git a/cube/User/Src/eeprom.c b/cube/User/Src/eeprom.c index bbbe3ad..0855b8b 100644 --- a/cube/User/Src/eeprom.c +++ b/cube/User/Src/eeprom.c @@ -21,7 +21,7 @@ static const uint8_t EEPROM_WREN = 0x06; // static const uint8_t EEPROM_WRSR = 0x01; -static const uint32_t EEPROM_MAGIC = 0xaffe000a; +static const uint32_t EEPROM_MAGIC = 0xaffe000b; static const uint16_t EEPROM_HEADER_ADDR = EEPROM_BASE_ADDR; @@ -114,14 +114,10 @@ void eepromSpiTxCpltCallback(SPI_HandleTypeDef *hspi) { static void eepromHourlyUpdateDeviceStats(void *handle) { deviceStats.s.totalRunningHours += 1; - deviceStats.s.totalRequests += 0; - deviceStats.s.totalFailures += 0; - logMsg("eeHUDS, about to write updated device stats"); logMsg("eeHUDS, total powercycles so far: %d", deviceStats.s.totalPowercycles); logMsg("eeHUDS, total running hours so far: %d", deviceStats.s.totalRunningHours); - logMsg("eeHUDS, total requests so far: %d", deviceStats.s.totalRequests); - logMsg("eeHUDS, total failures so far: %d", deviceStats.s.totalFailures); + logMsg("eeHUDS, total watchdog resets: %d", deviceStats.s.totalWatchdogResets); eepromWrite(DEVICE_STATS_ADDR, deviceStats.b, sizeof(deviceStats)); } @@ -154,8 +150,7 @@ void eepromInit() { deviceStats.s.totalPowercycles = 0; deviceStats.s.totalRunningHours = 0; - deviceStats.s.totalRequests = 0; - deviceStats.s.totalFailures = 0; + deviceStats.s.totalWatchdogResets = 0; logMsg("eeI, about to write device stats for the first time"); eepromWrite(DEVICE_STATS_ADDR, deviceStats.b, sizeof(deviceStats)); eepromActiveDelay(EEPROM_AFTER_WRITE_DELAY); @@ -180,10 +175,13 @@ void eepromInit() { eepromRead(DEVICE_STATS_ADDR, deviceStats.b, sizeof(deviceStats)); logMsg("eeI, total powercycles so far: %d", deviceStats.s.totalPowercycles); logMsg("eeI, total running hours so far: %d", deviceStats.s.totalRunningHours); - logMsg("eeI, total requests so far: %d", deviceStats.s.totalRequests); - logMsg("eeI, total failures so far: %d", deviceStats.s.totalFailures); + logMsg("eeI, total watchdog resets: %d", deviceStats.s.totalWatchdogResets); deviceStats.s.totalPowercycles += 1; + if (__HAL_RCC_GET_FLAG(RCC_FLAG_IWDGRST)) { + logMsg("eeI, this was a watchdog reset"); + deviceStats.s.totalWatchdogResets += 1; + } logMsg("eeI, about to write device stats with updated power cycles counter"); eepromWrite(DEVICE_STATS_ADDR, deviceStats.b, sizeof(deviceStats)); eepromActiveDelay(EEPROM_AFTER_WRITE_DELAY); diff --git a/cube/User/Src/regularCmds.c b/cube/User/Src/regularCmds.c index 2d1ab12..2af979c 100644 --- a/cube/User/Src/regularCmds.c +++ b/cube/User/Src/regularCmds.c @@ -15,13 +15,12 @@ static bool globalStatsCmd(uint8_t argc, char **args) { t_deviceStats *deviceStats = getGlobalDeviceStats(); sendFormatString(\ "Global Device statistics\n\r" \ - " Total running hours: %ld\n\r" \ - " Total power cycles: %ld\n\r" \ - " Total requests: %ld\n\r" \ - " Total failures: %ld\n\r" \ + " Total running hours: %ld\n\r" \ + " Total power cycles: %ld\n\r" \ + " Total watchdog resets: %ld\n\r" \ "\n\r", deviceStats->totalRunningHours, deviceStats->totalPowercycles, - deviceStats->totalRequests, deviceStats->totalFailures + deviceStats->totalWatchdogResets ); return true;