From 9cf4f9dfc7f6bcd1c46c96d9e388bf677e7148f1 Mon Sep 17 00:00:00 2001 From: Stephane D'Alu Date: Sun, 10 Jul 2016 13:35:31 +0200 Subject: moved wdg to LLD --- demos/NRF52/Classic/halconf.h | 7 ++++++ demos/NRF52/Classic/main.c | 52 ++++++++++++++++++++++++++++++++++++++----- demos/NRF52/Classic/mcuconf.h | 3 +++ 3 files changed, 57 insertions(+), 5 deletions(-) (limited to 'demos/NRF52') diff --git a/demos/NRF52/Classic/halconf.h b/demos/NRF52/Classic/halconf.h index 976c634..e218263 100644 --- a/demos/NRF52/Classic/halconf.h +++ b/demos/NRF52/Classic/halconf.h @@ -156,6 +156,13 @@ #define HAL_USE_USB FALSE #endif +/** + * @brief Enables the WDG subsystem. + */ +#if !defined(HAL_USE_WDG) || defined(__DOXYGEN__) +#define HAL_USE_WDG TRUE +#endif + /*===========================================================================*/ /* ADC driver related settings. */ /*===========================================================================*/ diff --git a/demos/NRF52/Classic/main.c b/demos/NRF52/Classic/main.c index efa6591..fde485a 100644 --- a/demos/NRF52/Classic/main.c +++ b/demos/NRF52/Classic/main.c @@ -10,6 +10,21 @@ #define LED_EXT 14 +bool watchdog_started = false; + +void watchdog_callback(void) { + palTogglePad(IOPORT1, LED2); + palTogglePad(IOPORT1, LED3); + palTogglePad(IOPORT1, LED4); +} + +WDGConfig WDG_config = { + .pause_on_sleep = 0, + .pause_on_halt = 0, + .timeout_ms = 5000, + .callback = watchdog_callback, +}; + /* * Command Random @@ -49,10 +64,31 @@ static void cmd_random(BaseSequentialStream *chp, int argc, char *argv[]) { + +static void cmd_watchdog(BaseSequentialStream *chp, int argc, char *argv[]) { + if ((argc == 0) || (strcmp(argv[0], "start"))) { + chprintf(chp, "Usage: watchdog start\r\n"); + return; + } + chprintf(chp, + "Watchdog started\r\n" + "You need to push BTN1 every 5 seconds\r\n"); + + watchdog_started = true; + wdgStart(&WDGD1, &WDG_config); +} + + + + + + + static THD_WORKING_AREA(shell_wa, 1024); static const ShellCommand commands[] = { - {"random", cmd_random}, + {"random", cmd_random }, + {"watchdog", cmd_watchdog }, {NULL, NULL} }; @@ -73,6 +109,10 @@ static SerialConfig serial_config = { + + + + static THD_WORKING_AREA(waThread1, 64); static THD_FUNCTION(Thread1, arg) { @@ -135,11 +175,13 @@ int main(void) test_execute((BaseSequentialStream *)&SD1); while (true) { - chThdSleepMilliseconds(100); - + if (watchdog_started && + (palReadPad(IOPORT1, BTN1) == 0)) { + palTogglePad(IOPORT1, LED1); + wdgReset(&WDGD1); + } + chThdSleepMilliseconds(250); } - - } diff --git a/demos/NRF52/Classic/mcuconf.h b/demos/NRF52/Classic/mcuconf.h index 9961da0..c73c34e 100644 --- a/demos/NRF52/Classic/mcuconf.h +++ b/demos/NRF52/Classic/mcuconf.h @@ -46,4 +46,7 @@ #define NRF5_RNG_USE_RNG0 TRUE +#define WDG_USE_TIMEOUT_CALLBACK TRUE + + #endif /* _MCUCONF_H_ */ -- cgit v1.2.3