diff options
author | Kevin O'Connor <kevin@koconnor.net> | 2016-05-25 11:37:40 -0400 |
---|---|---|
committer | Kevin O'Connor <kevin@koconnor.net> | 2016-05-25 11:37:40 -0400 |
commit | f582a36e4df16d5709943f7df17a900c8bcc12ab (patch) | |
tree | 628d927c4f3e19e54618f7f47c7a44af66bf0c2f /src/avr/watchdog.c | |
parent | 37a91e9c10648208de002c75df304e23ca89e256 (diff) | |
download | kutter-f582a36e4df16d5709943f7df17a900c8bcc12ab.tar.gz kutter-f582a36e4df16d5709943f7df17a900c8bcc12ab.tar.xz kutter-f582a36e4df16d5709943f7df17a900c8bcc12ab.zip |
Initial commit of source code.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'src/avr/watchdog.c')
-rw-r--r-- | src/avr/watchdog.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/avr/watchdog.c b/src/avr/watchdog.c new file mode 100644 index 00000000..f925a8d5 --- /dev/null +++ b/src/avr/watchdog.c @@ -0,0 +1,38 @@ +// Initialization of AVR watchdog timer. +// +// Copyright (C) 2016 Kevin O'Connor <kevin@koconnor.net> +// +// This file may be distributed under the terms of the GNU GPLv3 license. + +#include <avr/interrupt.h> // WDT_vect +#include <avr/wdt.h> // wdt_enable +#include "command.h" // shutdown +#include "sched.h" // DECL_TASK + +static uint8_t watchdog_shutdown; + +ISR(WDT_vect) +{ + watchdog_shutdown = 1; + shutdown("Watchdog timer!"); +} + +static void +watchdog_reset(void) +{ + wdt_reset(); + if (watchdog_shutdown) { + WDTCSR |= 1<<WDIE; + watchdog_shutdown = 0; + } +} +DECL_TASK(watchdog_reset); + +static void +watchdog_init(void) +{ + // 0.5s timeout, interrupt and system reset + wdt_enable(WDTO_500MS); + WDTCSR |= 1<<WDIE; +} +DECL_INIT(watchdog_init); |