Trick to reset wdt on new AVR core.
[bertos.git] / examples / triface / boot / main.c
index f4f05c436ad82ad49d6302502b8cb74d13753828..1382ab9e55ca2867d4c17c9508c01925d9ab0b34 100644 (file)
 
 #include <string.h>
 
+#include <avr/wdt.h>
+
+/*
+ * Watchdog disable.
+ *
+ * This function disable the watchdog timer, after a reset.
+ * We should do it after the software reset (do with watchdog),
+ * because in new AVR core do not reset the watchdog after
+ * a cpu reset, so the watchdog timer remain enable resetting
+ * every timeout time the cpu. This is necessary only with new
+ * AVR core, for the other core this no have effect.
+ *
+ * \{
+ */
+// Function prototype of watchdog reset.
+void wdt_init(void) __attribute__((naked)) __attribute__((section(".init3")));
+// Function implementation of watchdog reset.
+void wdt_init(void)
+{
+    MCUSR = 0;
+    wdt_disable();
+
+    return;
+}
+/* \} */
+
 int main(void)
 {
        FlashAvr flash;