From 40ba2ea4dce1d635ea706adc39d07c80d5cfb1bb Mon Sep 17 00:00:00 2001 From: Markus Koch Date: Sun, 22 Sep 2024 10:52:05 +0200 Subject: [PATCH] fw: Add watchdog Will reset after 1 second spent in app mainloop. --- firmware/app.c | 28 +++++++++++++++++++++++++++- firmware/lib/system.c | 28 +++++++++++++++++----------- 2 files changed, 44 insertions(+), 12 deletions(-) diff --git a/firmware/app.c b/firmware/app.c index 5a9db04..9262690 100644 --- a/firmware/app.c +++ b/firmware/app.c @@ -1,6 +1,7 @@ #include "lib/system.h" #include "lib/hal.h" #include +#include #define TIMER_INMENU TIMER_APP0 #define TIMER_AUX TIMER_APP1 @@ -98,12 +99,34 @@ void system_test() display_update(); } +// Note: This is only for watchdog testing. +// Never use _delay_ms(...) in your programs. Use timer_* functions instead. +void wdt_test() +{ + int i = 50; + display_clear(0); + while (i--) { + led[0].b = !led[0].b; + display_update(); + _delay_ms(100); + } + led[0].b = 0; + led[0].r = 1; + display_update(); + _delay_ms(2000); +} + void app_init() { return; } -#define APP_COUNT 3 +void app_suspend() +{ + return; +} + +#define APP_COUNT 4 enum app_return app_mainloop() { static int app_sel = 0; @@ -136,6 +159,9 @@ enum app_return app_mainloop() case 2: system_test(); break; + case 3: + wdt_test(); + break; default: app_sel = 0; break; diff --git a/firmware/lib/system.c b/firmware/lib/system.c index bda2719..94330df 100644 --- a/firmware/lib/system.c +++ b/firmware/lib/system.c @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -7,6 +8,7 @@ #include "pm.h" extern void app_init(); +extern void app_suspend(); extern enum app_return app_mainloop(); struct cRGB led[STRIPLEN]; @@ -39,6 +41,7 @@ void boot_animation(enum BOOT_COLOR color_offset) _delay_ms(10); display_clear(); for(int i = 0; i