main.c

Go to the documentation of this file.
00001 
00049 #include "hw/hw_boot.h"
00050 #include "cfg/cfg_ser.h"
00051 
00052 #include <net/xmodem.h>
00053 
00054 #include <cfg/compiler.h>
00055 #include <cfg/debug.h>
00056 #include <cfg/macros.h> /* BV() */
00057 
00058 #include <drv/ser.h>
00059 #include <drv/timer.h>
00060 #include <drv/flash_avr.h>
00061 
00062 #include <string.h>
00063 
00064 #include <avr/wdt.h>
00065 
00066 /*
00067  * Watchdog disable.
00068  *
00069  * This function disable the watchdog timer early after a reset.
00070  * We must do it very soon because new AVR cores do not disable
00071  * the watchdog timer after a cpu reset. In this way the watchdog
00072  * timer is still enabled, continuously resetting the cpu. This is
00073  * necessary only with new AVR cores, for other cores this code has
00074  * no effect.
00075  *
00076  * \{
00077  */
00078 // Function prototype of watchdog reset.
00079 void wdt_init(void) __attribute__((naked)) __attribute__((section(".init3")));
00080 // Function implementation of watchdog reset.
00081 void wdt_init(void)
00082 {
00083     MCUSR = 0;
00084     wdt_disable();
00085 
00086     return;
00087 }
00088 /* \} */
00089 
00090 int main(void)
00091 {
00092     FlashAvr flash;
00093     Serial ser;
00094 
00095 
00096     // Set up flash programming functions.
00097     flash_avr_init(&flash);
00098 
00099     IRQ_ENABLE;
00100 
00101     BOOT_INIT;
00102 
00103     kdbg_init();
00104     timer_init();
00105 
00106     /* Open the main communication port */
00107 
00108     ser_init(&ser, CONFIG_BOOT_PORT);
00109     ser_setbaudrate(&ser, CONFIG_BOOT_BAUDRATE);
00110 
00111     xmodem_recv(&ser.fd, &flash.fd);
00112 
00113     kfile_close(&flash.fd);
00114     kfile_close(&ser.fd);
00115 
00116     IRQ_DISABLE;
00117 
00118     BOOT_END;
00119 
00120     START_APP();
00121 
00122 }
00123