Revert changed version files in /trunk/ now that the LUFA-120219-BETA version has...
[pub/USBasp.git] / Bootloaders / CDC / BootloaderCDC.c
index 8e6a58b..e9ea8ae 100644 (file)
@@ -1,13 +1,13 @@
 /*
              LUFA Library
 /*
              LUFA Library
-     Copyright (C) Dean Camera, 2011.
+     Copyright (C) Dean Camera, 2012.
 
   dean [at] fourwalledcubicle [dot] com
            www.lufa-lib.org
 */
 
 /*
 
   dean [at] fourwalledcubicle [dot] com
            www.lufa-lib.org
 */
 
 /*
-  Copyright 2011  Dean Camera (dean [at] fourwalledcubicle [dot] com)
+  Copyright 2012  Dean Camera (dean [at] fourwalledcubicle [dot] com)
 
   Permission to use, copy, modify, distribute, and sell this
   software and its documentation for any purpose is hereby granted
 
   Permission to use, copy, modify, distribute, and sell this
   software and its documentation for any purpose is hereby granted
@@ -66,6 +66,9 @@ int main(void)
        /* Setup hardware required for the bootloader */
        SetupHardware();
 
        /* Setup hardware required for the bootloader */
        SetupHardware();
 
+       /* Turn on first LED on the board to indicate that the bootloader has started */
+       LEDs_SetAllLEDs(LEDS_LED1);
+
        /* Enable global interrupts so that the USB stack can function */
        sei();
 
        /* Enable global interrupts so that the USB stack can function */
        sei();
 
@@ -85,7 +88,7 @@ int main(void)
 }
 
 /** Configures all hardware required for the bootloader. */
 }
 
 /** Configures all hardware required for the bootloader. */
-void SetupHardware(void)
+static void SetupHardware(void)
 {
        /* Disable watchdog if enabled by bootloader/fuses */
        MCUSR &= ~(1 << WDRF);
 {
        /* Disable watchdog if enabled by bootloader/fuses */
        MCUSR &= ~(1 << WDRF);
@@ -98,8 +101,19 @@ void SetupHardware(void)
        MCUCR = (1 << IVCE);
        MCUCR = (1 << IVSEL);
 
        MCUCR = (1 << IVCE);
        MCUCR = (1 << IVSEL);
 
-       /* Initialize USB Subsystem */
+       /* Initialize the USB and other board hardware drivers */
        USB_Init();
        USB_Init();
+       LEDs_Init();
+
+       /* Bootloader active LED toggle timer initialization */
+       TIMSK1 = (1 << TOIE1);
+       TCCR1B = ((1 << CS11) | (1 << CS10));
+}
+
+/** ISR to periodically toggle the LEDs on the board to indicate that the bootloader is active. */
+ISR(TIMER1_OVF_vect, ISR_BLOCK)
+{
+       LEDs_ToggleLEDs(LEDS_LED1 | LEDS_LED2);
 }
 
 /** Event handler for the USB_ConfigurationChanged event. This configures the device's endpoints ready
 }
 
 /** Event handler for the USB_ConfigurationChanged event. This configures the device's endpoints ready
@@ -134,6 +148,9 @@ void EVENT_USB_Device_ControlRequest(void)
                return;
        }
 
                return;
        }
 
+       /* Activity - toggle indicator LEDs */
+       LEDs_ToggleLEDs(LEDS_LED1 | LEDS_LED2);
+
        /* Process CDC specific control requests */
        switch (USB_ControlRequest.bRequest)
        {
        /* Process CDC specific control requests */
        switch (USB_ControlRequest.bRequest)
        {
@@ -249,7 +266,7 @@ static void ReadWriteMemoryBlock(const uint8_t Command)
                                {
                                        LowByte = FetchNextCommandByte();
                                }
                                {
                                        LowByte = FetchNextCommandByte();
                                }
-                               
+
                                HighByte = !HighByte;
                        }
                        else
                                HighByte = !HighByte;
                        }
                        else
@@ -333,7 +350,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
  *  and send the appropriate response back to the host.
  */
 /** Task to read in AVR910 commands from the CDC data OUT endpoint, process them, perform the required actions
  *  and send the appropriate response back to the host.
  */
-void CDC_Task(void)
+static void CDC_Task(void)
 {
        /* Select the OUT endpoint */
        Endpoint_SelectEndpoint(CDC_RX_EPNUM);
 {
        /* Select the OUT endpoint */
        Endpoint_SelectEndpoint(CDC_RX_EPNUM);
@@ -348,7 +365,7 @@ void CDC_Task(void)
        if (Command == 'E')
        {
                RunBootloader = false;
        if (Command == 'E')
        {
                RunBootloader = false;
-       
+
                /* Send confirmation byte back to the host */
                WriteNextResponseByte('\r');
        }
                /* Send confirmation byte back to the host */
                WriteNextResponseByte('\r');
        }