stat watchdog

This commit is contained in:
Wolfgang Hottgenroth 2021-02-12 19:10:11 +01:00
parent c43c332fdf
commit 1ffb12ac9b
Signed by: wn
GPG Key ID: E49AF3B9EF6DD469
3 changed files with 13 additions and 17 deletions

View File

@ -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");

View File

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

View File

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