Trick to reset wdt on new AVR core.
[bertos.git] / examples / triface / boot / main.c
index dc105baf0374a10c02de0ee5ce608012b89edc5b..1382ab9e55ca2867d4c17c9508c01925d9ab0b34 100644 (file)
  * \author Daniele Basile <asterix@develer.com>
  */
 
+#include "hw/hw_boot.h"
+#include "cfg/cfg_ser.h"
+
 #include <net/xmodem.h>
+
 #include <cfg/compiler.h>
 #include <cfg/debug.h>
 #include <cfg/macros.h> /* BV() */
 
-#include <drv/wdt.h>
 #include <drv/ser.h>
 #include <drv/timer.h>
 #include <drv/flash_avr.h>
 
-#include "hw/hw_boot.h"
-#include "cfg/cfg_boot.h"
-
 #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;
@@ -77,11 +103,10 @@ int main(void)
        kdbg_init();
        timer_init();
 
-
        /* Open the main communication port */
 
-       ser_init(&ser, CONFIG_SER_HOSTPORT);
-       ser_setbaudrate(&ser, CONFIG_SER_HOSTPORTBAUDRATE);
+       ser_init(&ser, CONFIG_BOOT_PORT);
+       ser_setbaudrate(&ser, CONFIG_BOOT_BAUDRATE);
 
        xmodem_recv(&ser, &flash.fd);
        kfile_close(&flash.fd);