From aa57b9adc3426e306d11cd1a25f624b52c5440e5 Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Thu, 1 Feb 2024 08:29:17 +0100 Subject: [PATCH] Make watchdog code conditional --- main.c | 5 ++++- nanovna.h | 9 +++++++++ sa_core.c | 2 ++ ui.c | 11 ++++++++++- 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/main.c b/main.c index 32d2a87..23cbb67 100644 --- a/main.c +++ b/main.c @@ -285,7 +285,9 @@ static THD_FUNCTION(Thread1, arg) // plot trace and other indications as raster draw_all(completed); // flush markmap only if scan completed to prevent // remaining traces +#ifdef __WATCHDOG__ wdgReset(&WDGD1); +#endif // STOP_PROFILE } @@ -3103,6 +3105,7 @@ int main(void) set_sweep_frequency(ST_STOP, (freq_t) 4000000); sweep(false); #endif +#ifdef __WATCHDOG__ static const WDGConfig scan_wdgcfg = { STM32_IWDG_PR_256, STM32_IWDG_RL(1 * (40000 / 256)), /* 1 second */ @@ -3110,7 +3113,7 @@ int main(void) }; wdgInit(); wdgStart(&WDGD1, &scan_wdgcfg); - +#endif if (reset_state|| (caldata_recall(0) == -1)) { load_LCD_properties(); } diff --git a/nanovna.h b/nanovna.h index e11701e..98d69c9 100644 --- a/nanovna.h +++ b/nanovna.h @@ -65,6 +65,15 @@ #define __LINEARITY__ // Not available #define __SELFTEST__ // Add selftest option (not fully disable it) #define __CALIBRATE__ // Add calibration menu and functions +#define __WATCHDOG__ +#ifdef __WATCHDOG__ +//#if (HAL_USE_WDG != TRUE) +//#error "HAL_USE_WDG must be set to true" +//#endif +//#if (STM32_WDG_USE_IWDG != TRUE) +//#error "STM32_WDG_USE_IWDG must be set to true" +//#endif +#endif #define __FAST_SWEEP__ // Pre-fill SI4432 RSSI buffer to get fastest sweep in zero span mode // #define __AUDIO__ #define __SPUR__ // Does spur reduction by shifting IF diff --git a/sa_core.c b/sa_core.c index 478fb22..532492c 100644 --- a/sa_core.c +++ b/sa_core.c @@ -4932,7 +4932,9 @@ again: // Spur redu t++; // one subscan done if (break_on_operation && operation_requested) // break subscanning if requested break; // abort +#ifdef __WATCHDOG__ wdgReset(&WDGD1); +#endif } while (t < local_vbw_steps); // till all sub steps done TRACE(7); #ifdef TINYSA4 diff --git a/ui.c b/ui.c index 3cfb211..54b19a8 100644 --- a/ui.c +++ b/ui.c @@ -186,7 +186,9 @@ int btn_side(void) static int btn_check(void) { systime_t ticks; +#ifdef __WATCHDOG__ wdgReset(&WDGD1); +#endif // Debounce input while(TRUE){ ticks = chVTGetSystemTimeX(); @@ -213,7 +215,9 @@ static int btn_check(void) static int btn_wait_release(void) { while (TRUE) { +#ifdef __WATCHDOG__ wdgReset(&WDGD1); +#endif systime_t ticks = chVTGetSystemTimeX(); systime_t dt = ticks - last_button_down_ticks; // Debounce input @@ -301,7 +305,9 @@ touch_measure_x(void) static inline int touch_status(void) { +#ifdef __WATCHDOG__ wdgReset(&WDGD1); +#endif return adc_single_read(ADC_TOUCH_Y) > TOUCH_THRESHOLD; } @@ -657,8 +663,9 @@ extern const char *states[]; break; chThdSleepMilliseconds(40); if ((cnt++)&0x07) continue; // Not update time so fast - +#ifdef __WATCHDOG__ wdgReset(&WDGD1); +#endif #ifdef TINYSA4 #ifdef __USE_RTC__ @@ -7803,7 +7810,9 @@ static void sa_save_file(uint8_t format) { #else plot_printf(fs_filename, FF_LFN_BUF, "%08x.%s", rtc_get_FAT(), file_ext[format]); #endif +#ifdef __WATCHDOG__ wdgReset(&WDGD1); +#endif } else { ui_mode_keypad(KM_FILENAME);