summaryrefslogtreecommitdiff
path: root/wdt.c
diff options
context:
space:
mode:
authorDavid Lamparter <equinox@diac24.net>2012-09-20 05:16:46 +0200
committerDavid Lamparter <equinox@diac24.net>2012-09-20 05:18:52 +0200
commit2bae1f8a73bdd5fca71fd3e60807d6b618e675d1 (patch)
tree435a2c9595cf12542c9ede44f77f95432b955c1d /wdt.c
parentb42baac581ade81def3f40ab7256efdcba94ad5e (diff)
lightctrl: use WDT
the CPU seems to get stuck for no apparent reason, right in the middle of a line on the serial console... weird. let's enable the WDT as a temporary band-aid.
Diffstat (limited to 'wdt.c')
-rw-r--r--wdt.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/wdt.c b/wdt.c
new file mode 100644
index 0000000..f815b71
--- /dev/null
+++ b/wdt.c
@@ -0,0 +1,25 @@
+
+static uint8_t wdt_generation __attribute__((section (".noinit")));
+
+static void wdt_init(void)
+{
+ uint8_t temp;
+ /* timed sequence. bit 4: WDCE, bit 3: WDE,
+ * 0x07 = WDP2 | WDP1 | WDP0 = 2s */
+ asm volatile ("\n\
+WDTCSR = 0x60\n\
+WDCE = 4\n\
+WDE = 3\n\
+ wdr \n\
+ \n\
+ ldi %[temp], (1 << WDCE) | (1 << WDE) \n\
+ sts WDTCSR, %[temp] \n\
+ \n\
+ ldi %[temp], (1 << WDE) | 0x07 \n\
+ sts WDTCSR, %[temp] \n\
+ " : [temp] "=r" (temp) : : "memory");
+
+ if (MCUSR & (1 << WDRF))
+ wdt_generation++;
+}
+