*/\r
int main (void)\r
{\r
+ /* Configure hardware required by the bootloader */\r
+ SetupHardware();\r
+\r
+ /* Run the USB management task while the bootloader is supposed to be running */\r
+ while (RunBootloader || WaitForExit)\r
+ USB_USBTask();\r
+ \r
+ /* Reset configured hardware back to their original states for the user application */\r
+ ResetHardware();\r
+ \r
+ /* Start the user application */\r
+ AppStartPtr();\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 the USB subsystem */\r
USB_Init();\r
+}\r
\r
- /* Run the USB management task while the bootloader is supposed to be running */\r
- while (RunBootloader || WaitForExit)\r
- USB_USBTask();\r
- \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
/* Relocate the interrupt vector table back to the application section */\r
MCUCR = (1 << IVCE);\r
MCUCR = 0;\r
-\r
- /* Reset any used hardware ports back to their defaults */\r
- PORTD = 0;\r
- DDRD = 0;\r
- \r
- #if defined(PORTE)\r
- PORTE = 0;\r
- DDRE = 0;\r
- #endif\r
- \r
- /* Start the user application */\r
- AppStartPtr();\r
}\r
\r
/** Event handler for the USB_Disconnect event. This indicates that the bootloader should exit and the user\r