*/\r
int main(void)\r
{\r
+ /* Setup hardware required for the bootloader */\r
+ SetupHardware();\r
+ \r
+ while (RunBootloader)\r
+ USB_USBTask();\r
+ \r
+ /* Reset all configured hardware to their default states for the user app */\r
+ ResetHardware();\r
+\r
+ /* Wait 100ms to give the host time to register the disconnection */\r
+ _delay_ms(100);\r
+\r
+ /* Enable the watchdog and force a timeout to reset the AVR */\r
+ wdt_enable(WDTO_250MS);\r
+ \r
+ for (;;);\r
+}\r
+\r
+/** Configures all hardware required for the bootloader. */\r
+void SetupHardware(void)\r
+{\r
/* Disable watchdog if enabled by bootloader/fuses */\r
MCUSR &= ~(1 << WDRF);\r
wdt_disable();\r
\r
/* Initialize USB subsystem */\r
USB_Init();\r
- \r
- while (RunBootloader)\r
- USB_USBTask();\r
- \r
- /* Shut down the USB interface, so that the host will register the disconnection */\r
- USB_ShutDown();\r
-\r
- /* Wait 100ms to give the host time to register the disconnection */\r
- _delay_ms(100);\r
+}\r
\r
- /* Enable the watchdog and force a timeout to reset the AVR */\r
- wdt_enable(WDTO_250MS);\r
- \r
- for (;;);\r
+/** Resets all configured hardware required for the bootloader back to their original states. */\r
+void ResetHardware(void)\r
+{\r
+ /* Shut down the USB subsystem */\r
+ USB_ShutDown();\r
}\r
\r
/** Event handler for the USB_ConfigurationChanged event. This configures the device's endpoints ready\r