From d1b846fc36566ca9ff5deb939f12397084b5bd06 Mon Sep 17 00:00:00 2001 From: Peter Wittich Date: Tue, 19 Nov 2019 17:46:44 +0100 Subject: [PATCH] Mark stale monitoring data in CLI (#29) keep track of last update tick time for I2C based readouts and indicate when the last update was more than 60 seconds ago --- projects/cm_mcu/CommandLineTask.c | 26 +++++++++++++++++++++++++- projects/cm_mcu/FireFlyTask.c | 8 +++++++- projects/cm_mcu/FreeRTOSConfig.h | 1 + projects/cm_mcu/MonitorTask.c | 2 ++ projects/cm_mcu/MonitorTask.h | 1 + projects/cm_mcu/Tasks.h | 2 ++ 6 files changed, 38 insertions(+), 2 deletions(-) diff --git a/projects/cm_mcu/CommandLineTask.c b/projects/cm_mcu/CommandLineTask.c index e3ba793f..b80bd3c0 100644 --- a/projects/cm_mcu/CommandLineTask.c +++ b/projects/cm_mcu/CommandLineTask.c @@ -511,8 +511,14 @@ static BaseType_t mon_ctl(char *m, size_t s, const char *mm) dcdc_args.n_commands-1); return pdFALSE; } - + // update times, in seconds + TickType_t now = pdTICKS_TO_MS( xTaskGetTickCount())/1000; + TickType_t last = pdTICKS_TO_MS(dcdc_args.updateTick)/1000; int copied = 0; + if ( (now-last) > 60 ) { + int mins = (now-last)/60; + copied += snprintf(m+copied, s-copied, "%s: stale data, last update %d minutes ago\r\n", __func__, mins); + } copied += snprintf(m+copied, s-copied, "%s\r\n", dcdc_args.commands[i1].name); for (int ps = 0; ps < dcdc_args.n_devices; ++ps) { copied += snprintf(m+copied, s-copied, "SUPPLY %s\r\n", @@ -621,6 +627,17 @@ static BaseType_t ff_ctl(char *m, size_t s, const char *mm) int copied = 0; static int whichff = 0; + if ( whichff == 0 ) { + // check for stale data + TickType_t now = pdTICKS_TO_MS( xTaskGetTickCount())/1000; + TickType_t last = pdTICKS_TO_MS(getFFupdateTick())/1000; + if ( (now-last) > 60 ) { + int mins = (now-last)/60; + copied += snprintf(m+copied, s-copied, "%s: stale data, last update %d minutes ago\r\n", __func__, mins); + } + + } + if ( argc == 0 ) { // default command: temps if ( whichff == 0 ) { @@ -696,6 +713,13 @@ static BaseType_t fpga_ctl(char *m, size_t s, const char *mm) static int whichfpga = 0; int howmany = fpga_args.n_devices*fpga_args.n_pages; if ( whichfpga == 0 ) { + TickType_t now = pdTICKS_TO_MS( xTaskGetTickCount())/1000; + TickType_t last = pdTICKS_TO_MS(getFFupdateTick())/1000; + if ( (now-last) > 60 ) { + int mins = (now-last)/60; + copied += snprintf(m+copied, s-copied, "%s: stale data, last update %d minutes ago\r\n", __func__, mins); + } + copied += snprintf(m+copied, s-copied, "FPGA monitors\r\n"); copied += snprintf(m+copied, s-copied, "%s\r\n", fpga_args.commands[0].name); } diff --git a/projects/cm_mcu/FireFlyTask.c b/projects/cm_mcu/FireFlyTask.c index 01a1d3fc..03ae373a 100644 --- a/projects/cm_mcu/FireFlyTask.c +++ b/projects/cm_mcu/FireFlyTask.c @@ -125,6 +125,12 @@ int8_t getFFvalue(const uint8_t i) return ff_temp[i]; } +static TickType_t ff_updateTick = 0; +TickType_t getFFupdateTick() +{ + return ff_updateTick; +} + static int write_ff_register(const char *name, uint8_t reg, uint16_t value, int size) { @@ -300,7 +306,7 @@ void FireFlyTask(void *parameters) break; } } - + ff_updateTick = xTaskGetTickCount(); // select the appropriate output for the mux data[0] = 0x1U << ff_i2c_addrs[ff].mux_bit; char tmp[64]; diff --git a/projects/cm_mcu/FreeRTOSConfig.h b/projects/cm_mcu/FreeRTOSConfig.h index fd7ae7ee..64026764 100644 --- a/projects/cm_mcu/FreeRTOSConfig.h +++ b/projects/cm_mcu/FreeRTOSConfig.h @@ -137,6 +137,7 @@ header file. */ #define CLI_UART UART4_BASE // Front panel //#define CLI_UART UART1_BASE // Zynq +#define pdTICKS_TO_MS( xTicks ) ( ( ( TickType_t ) ( xTicks ) * 1000u ) / configTICK_RATE_HZ ) #ifdef __cplusplus } diff --git a/projects/cm_mcu/MonitorTask.c b/projects/cm_mcu/MonitorTask.c index 4eae6add..5b6c0d38 100644 --- a/projects/cm_mcu/MonitorTask.c +++ b/projects/cm_mcu/MonitorTask.c @@ -85,6 +85,7 @@ void MonitorTask(void *parameters) bool log = true; int current_error_cnt = 0; + args->updateTick = xLastWakeTime; // initial value for (;;) { // check if the 3.3V is there or not. If it disappears then nothing works @@ -105,6 +106,7 @@ void MonitorTask(void *parameters) else { good = true; } + args->updateTick = xTaskGetTickCount(); // current time in ticks // loop over devices for ( uint8_t ps = 0; ps < args->n_devices; ++ ps ) { if ( getPSStatus(5) != PWR_ON) diff --git a/projects/cm_mcu/MonitorTask.h b/projects/cm_mcu/MonitorTask.h index 74ff6869..31cba583 100644 --- a/projects/cm_mcu/MonitorTask.h +++ b/projects/cm_mcu/MonitorTask.h @@ -44,6 +44,7 @@ struct MonitorTaskArgs_t { const int n_pages; tSMBus *smbus; volatile tSMBusStatus *smbus_status; + volatile TickType_t updateTick; }; // DC-DC converter #define NSUPPLIES_PS (5) // 5 devices, 2 pages each diff --git a/projects/cm_mcu/Tasks.h b/projects/cm_mcu/Tasks.h index 0c189650..d1573952 100644 --- a/projects/cm_mcu/Tasks.h +++ b/projects/cm_mcu/Tasks.h @@ -58,6 +58,8 @@ extern QueueHandle_t xFFlyQueue; const char* getFFname(const uint8_t i); int8_t getFFvalue(const uint8_t i); +TickType_t getFFupdateTick(); + int disable_xcvr_cdr(const char *name);