Updated bootloaders to use the new main() function layout and remove any references...
authorDean Camera <dean@fourwalledcubicle.com>
Tue, 9 Jun 2009 06:05:01 +0000 (06:05 +0000)
committerDean Camera <dean@fourwalledcubicle.com>
Tue, 9 Jun 2009 06:05:01 +0000 (06:05 +0000)
Bootloaders/CDC/BootloaderCDC.c
Bootloaders/CDC/BootloaderCDC.h
Bootloaders/DFU/BootloaderDFU.c
Bootloaders/DFU/BootloaderDFU.h
Bootloaders/TeensyHID/TeensyHID.c
Bootloaders/TeensyHID/TeensyHID.h

index d797915..d72d128 100644 (file)
@@ -67,6 +67,26 @@ bool RunBootloader = true;
  */\r
 int main(void)\r
 {\r
  */\r
 int main(void)\r
 {\r
+       /* Setup hardware required for the bootloader */\r
+       SetupHardware();\r
+\r
+       while (RunBootloader)\r
+       {\r
+               CDC_Task();\r
+               USB_USBTask();\r
+       }\r
+       \r
+       /* Reset all configured hardware to their default states for the user app */\r
+       ResetHardware();\r
+\r
+       /* Start the user application */\r
+       AppPtr_t AppStartPtr = (AppPtr_t)0x0000;\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
        /* Disable watchdog if enabled by bootloader/fuses */\r
        MCUSR &= ~(1 << WDRF);\r
        wdt_disable();\r
@@ -80,18 +100,11 @@ int main(void)
        \r
        /* Initialize USB Subsystem */\r
        USB_Init();\r
        \r
        /* Initialize USB Subsystem */\r
        USB_Init();\r
+}\r
 \r
 \r
-       while (RunBootloader)\r
-       {\r
-               USB_USBTask();\r
-               CDC_Task();\r
-       }\r
-       \r
-       Endpoint_SelectEndpoint(CDC_TX_EPNUM);\r
-\r
-       /* Wait until any pending transmissions have completed before shutting down */\r
-       while (!(Endpoint_IsINReady()));\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
        /* Shut down the USB subsystem */\r
        USB_ShutDown();\r
        \r
@@ -99,21 +112,8 @@ int main(void)
        MCUCR = (1 << IVCE);\r
        MCUCR = 0;\r
 \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
        /* Re-enable RWW section */\r
        boot_rww_enable();\r
        /* Re-enable RWW section */\r
        boot_rww_enable();\r
-\r
-       /* Start the user application */\r
-       AppPtr_t AppStartPtr = (AppPtr_t)0x0000;\r
-       AppStartPtr();  \r
 }\r
 \r
 /** Event handler for the USB_Disconnect event. This indicates that the bootloader should exit and the user\r
 }\r
 \r
 /** Event handler for the USB_Disconnect event. This indicates that the bootloader should exit and the user\r
@@ -364,7 +364,7 @@ static void WriteNextResponseByte(const uint8_t Response)
 /** Task to read in AVR910 commands from the CDC data OUT endpoint, process them, perform the required actions\r
  *  and send the appropriate response back to the host.\r
  */\r
 /** Task to read in AVR910 commands from the CDC data OUT endpoint, process them, perform the required actions\r
  *  and send the appropriate response back to the host.\r
  */\r
-TASK(CDC_Task)\r
+void CDC_Task(void)\r
 {\r
        /* Select the OUT endpoint */\r
        Endpoint_SelectEndpoint(CDC_RX_EPNUM);\r
 {\r
        /* Select the OUT endpoint */\r
        Endpoint_SelectEndpoint(CDC_RX_EPNUM);\r
@@ -566,6 +566,9 @@ TASK(CDC_Task)
                        while (!(Endpoint_IsINReady()));\r
                        Endpoint_ClearIN();\r
                }\r
                        while (!(Endpoint_IsINReady()));\r
                        Endpoint_ClearIN();\r
                }\r
+\r
+               /* Wait until the data has been sent to the host */\r
+               while (!(Endpoint_IsINReady()));\r
                \r
                /* Select the OUT endpoint */\r
                Endpoint_SelectEndpoint(CDC_RX_EPNUM);\r
                \r
                /* Select the OUT endpoint */\r
                Endpoint_SelectEndpoint(CDC_RX_EPNUM);\r
index da75593..97e32e9 100644 (file)
                        Parity_Space        = 4, /**< Space data parity checking */\r
                };\r
                \r
                        Parity_Space        = 4, /**< Space data parity checking */\r
                };\r
                \r
-       /* Tasks: */\r
-               TASK(CDC_Task);\r
-\r
        /* Function Prototypes: */\r
        /* Function Prototypes: */\r
+               void CDC_Task(void);\r
+               void SetupHardware(void);\r
+               void ResetHardware(void);\r
+\r
                void EVENT_USB_Disconnect(void);\r
                void EVENT_USB_ConfigurationChanged(void);\r
                void EVENT_USB_UnhandledControlPacket(void);\r
                void EVENT_USB_Disconnect(void);\r
                void EVENT_USB_ConfigurationChanged(void);\r
                void EVENT_USB_UnhandledControlPacket(void);\r
index 6da741e..58a7511 100644 (file)
@@ -98,6 +98,23 @@ uint16_t EndAddr = 0x0000;
  */\r
 int main (void)\r
 {\r
  */\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
        /* Disable watchdog if enabled by bootloader/fuses */\r
        MCUSR &= ~(1 << WDRF);\r
        wdt_disable();\r
@@ -111,29 +128,17 @@ int main (void)
 \r
        /* Initialize the USB subsystem */\r
        USB_Init();\r
 \r
        /* Initialize the USB subsystem */\r
        USB_Init();\r
+}\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
        /* 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
 }\r
 \r
 /** Event handler for the USB_Disconnect event. This indicates that the bootloader should exit and the user\r
index a78d80d..776281e 100644 (file)
                };\r
                                \r
        /* Function Prototypes: */\r
                };\r
                                \r
        /* Function Prototypes: */\r
+               void SetupHardware(void);\r
+               void ResetHardware(void);\r
+\r
                void EVENT_USB_Disconnect(void);\r
                void EVENT_USB_UnhandledControlPacket(void);\r
 \r
                void EVENT_USB_Disconnect(void);\r
                void EVENT_USB_UnhandledControlPacket(void);\r
 \r
index ee6c91a..12d5c0d 100644 (file)
@@ -49,6 +49,27 @@ bool RunBootloader = true;
  */\r
 int main(void)\r
 {\r
  */\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
        /* Disable watchdog if enabled by bootloader/fuses */\r
        MCUSR &= ~(1 << WDRF);\r
        wdt_disable();\r
@@ -62,20 +83,13 @@ int main(void)
 \r
        /* Initialize USB subsystem */\r
        USB_Init();\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
 \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
 }\r
 \r
 /** Event handler for the USB_ConfigurationChanged event. This configures the device's endpoints ready\r
index 0dd5852..9414eec 100644 (file)
                /** HID Class specific request to send the next HID report to the device. */\r
                #define REQ_SetReport             0x09\r
                \r
                /** HID Class specific request to send the next HID report to the device. */\r
                #define REQ_SetReport             0x09\r
                \r
+               /** Teensy Bootloader special address to start the user application */\r
                #define TEENSY_STARTAPPLICATION   0xFFFF\r
                \r
        /* Function Prototypes: */\r
                #define TEENSY_STARTAPPLICATION   0xFFFF\r
                \r
        /* Function Prototypes: */\r
+               void SetupHardware(void);\r
+               void ResetHardware(void);\r
+\r
                void EVENT_USB_ConfigurationChanged(void);\r
                void EVENT_USB_UnhandledControlPacket(void);\r
                \r
                void EVENT_USB_ConfigurationChanged(void);\r
                void EVENT_USB_UnhandledControlPacket(void);\r
                \r