Fixed invalid USB controller PLL prescaler values for the ATMEGAxxU2 controllers
authorDean Camera <dean@fourwalledcubicle.com>
Fri, 15 Jan 2010 02:42:54 +0000 (02:42 +0000)
committerDean Camera <dean@fourwalledcubicle.com>
Fri, 15 Jan 2010 02:42:54 +0000 (02:42 +0000)
Fixed lack of support for the ATMEGA32U2 in the DFU and CDC class bootloaders

Changed incomplete Webserver project over to using the uIP timer library.

Bootloaders/CDC/Descriptors.h
Bootloaders/DFU/Descriptors.h
LUFA/Drivers/Peripheral/AVRU4U6U7/ADC.h
LUFA/Drivers/USB/LowLevel/LowLevel.h
LUFA/ManPages/ChangeLog.txt
Projects/Incomplete/Webserver/Lib/uip/conf/clock-arch.c
Projects/Incomplete/Webserver/Lib/uip/conf/clock-arch.h
Projects/Incomplete/Webserver/Webserver.c
Projects/Incomplete/Webserver/Webserver.h
Projects/Incomplete/Webserver/makefile

index 94883be..ac02ff6 100644 (file)
                #include <LUFA/Drivers/USB/USB.h>\r
 \r
        /* Macros: */\r
                #include <LUFA/Drivers/USB/USB.h>\r
 \r
        /* Macros: */\r
-               #if defined(__AVR_AT90USB1286__)\r
+               #if defined(__AVR_AT90USB1287__)\r
                        #define AVR_SIGNATURE_1               0x1E\r
                        #define AVR_SIGNATURE_2               0x97\r
                        #define AVR_SIGNATURE_3               0x82\r
                        #define AVR_SIGNATURE_1               0x1E\r
                        #define AVR_SIGNATURE_2               0x97\r
                        #define AVR_SIGNATURE_3               0x82\r
-               #elif defined(__AVR_AT90USB1287__)\r
-                       #define AVR_SIGNATURE_1               0x1E\r
-                       #define AVR_SIGNATURE_2               0x97\r
-                       #define AVR_SIGNATURE_3               0x82\r
-               #elif defined(__AVR_AT90USB646__)\r
-                       #define AVR_SIGNATURE_1               0x1E\r
-                       #define AVR_SIGNATURE_2               0x96\r
-                       #define AVR_SIGNATURE_3               0x82\r
                #elif defined(__AVR_AT90USB647__)\r
                        #define AVR_SIGNATURE_1               0x1E\r
                        #define AVR_SIGNATURE_2               0x96\r
                        #define AVR_SIGNATURE_3               0x82\r
                #elif defined(__AVR_AT90USB647__)\r
                        #define AVR_SIGNATURE_1               0x1E\r
                        #define AVR_SIGNATURE_2               0x96\r
                        #define AVR_SIGNATURE_3               0x82\r
-               #elif defined(__AVR_AT90USB162__)\r
+               #elif defined(__AVR_AT90USB1286__)\r
                        #define AVR_SIGNATURE_1               0x1E\r
                        #define AVR_SIGNATURE_1               0x1E\r
-                       #define AVR_SIGNATURE_2               0x94\r
+                       #define AVR_SIGNATURE_2               0x97\r
                        #define AVR_SIGNATURE_3               0x82\r
                        #define AVR_SIGNATURE_3               0x82\r
-               #elif defined(__AVR_AT90USB82__)\r
+               #elif defined(__AVR_AT90USB646__)\r
                        #define AVR_SIGNATURE_1               0x1E\r
                        #define AVR_SIGNATURE_1               0x1E\r
-                       #define AVR_SIGNATURE_2               0x94\r
+                       #define AVR_SIGNATURE_2               0x96\r
                        #define AVR_SIGNATURE_3               0x82\r
                #elif defined(__AVR_ATmega32U6__)\r
                        #define AVR_SIGNATURE_1               0x1E\r
                        #define AVR_SIGNATURE_3               0x82\r
                #elif defined(__AVR_ATmega32U6__)\r
                        #define AVR_SIGNATURE_1               0x1E\r
                        #define AVR_SIGNATURE_1               0x1E\r
                        #define AVR_SIGNATURE_2               0x94\r
                        #define AVR_SIGNATURE_3               0x88\r
                        #define AVR_SIGNATURE_1               0x1E\r
                        #define AVR_SIGNATURE_2               0x94\r
                        #define AVR_SIGNATURE_3               0x88\r
+               #elif defined(__AVR_ATmega32U2__)\r
+                       #define AVR_SIGNATURE_1               0x1E\r
+                       #define AVR_SIGNATURE_2               0x94\r
+                       #define AVR_SIGNATURE_3               0x82\r
+               #elif defined(__AVR_ATmega16U2__)\r
+                       #define AVR_SIGNATURE_1               0x1E\r
+                       #define AVR_SIGNATURE_2               0x94\r
+                       #define AVR_SIGNATURE_3               0x89\r
+               #elif defined(__AVR_AT90USB162__)\r
+                       #define AVR_SIGNATURE_1               0x1E\r
+                       #define AVR_SIGNATURE_2               0x94\r
+                       #define AVR_SIGNATURE_3               0x82\r
+               #elif defined(__AVR_ATmega8U2__)\r
+                       #define AVR_SIGNATURE_1               0x1E\r
+                       #define AVR_SIGNATURE_2               0x93\r
+                       #define AVR_SIGNATURE_3               0x82\r
+               #elif defined(__AVR_AT90USB82__)\r
+                       #define AVR_SIGNATURE_1               0x1E\r
+                       #define AVR_SIGNATURE_2               0x93\r
+                       #define AVR_SIGNATURE_3               0x89\r
                #else\r
                        #error The selected AVR part is not currently supported by this bootloader.\r
                #endif\r
                #else\r
                        #error The selected AVR part is not currently supported by this bootloader.\r
                #endif\r
index 4faea42..32d5828 100644 (file)
                 */             \r
                #define ATTR_CAN_DOWNLOAD                 (1 << 0)\r
 \r
                 */             \r
                #define ATTR_CAN_DOWNLOAD                 (1 << 0)\r
 \r
-               #if defined(__AVR_AT90USB1286__)\r
+               #if defined(__AVR_AT90USB1287__)\r
                        #define PRODUCT_ID_CODE               0x2FFB\r
                        #define AVR_SIGNATURE_1               0x1E\r
                        #define AVR_SIGNATURE_2               0x97\r
                        #define AVR_SIGNATURE_3               0x82\r
                        #define PRODUCT_ID_CODE               0x2FFB\r
                        #define AVR_SIGNATURE_1               0x1E\r
                        #define AVR_SIGNATURE_2               0x97\r
                        #define AVR_SIGNATURE_3               0x82\r
-               #elif defined(__AVR_AT90USB1287__)\r
+               #elif defined(__AVR_AT90USB647__)\r
+                       #define PRODUCT_ID_CODE               0x2FF9\r
+                       #define AVR_SIGNATURE_1               0x1E\r
+                       #define AVR_SIGNATURE_2               0x96\r
+                       #define AVR_SIGNATURE_3               0x82\r
+               #elif defined(__AVR_AT90USB1286__)\r
                        #define PRODUCT_ID_CODE               0x2FFB\r
                        #define AVR_SIGNATURE_1               0x1E\r
                        #define AVR_SIGNATURE_2               0x97\r
                        #define PRODUCT_ID_CODE               0x2FFB\r
                        #define AVR_SIGNATURE_1               0x1E\r
                        #define AVR_SIGNATURE_2               0x97\r
                        #define AVR_SIGNATURE_1               0x1E\r
                        #define AVR_SIGNATURE_2               0x95\r
                        #define AVR_SIGNATURE_3               0x88\r
                        #define AVR_SIGNATURE_1               0x1E\r
                        #define AVR_SIGNATURE_2               0x95\r
                        #define AVR_SIGNATURE_3               0x88\r
-               #elif defined(__AVR_AT90USB647__)\r
-                       #define PRODUCT_ID_CODE               0x2FF9\r
-                       #define AVR_SIGNATURE_1               0x1E\r
-                       #define AVR_SIGNATURE_2               0x96\r
-                       #define AVR_SIGNATURE_3               0x82\r
                #elif defined(__AVR_ATmega32U4__)\r
                        #define PRODUCT_ID_CODE               0x2FF4\r
                        #define AVR_SIGNATURE_1               0x1E\r
                #elif defined(__AVR_ATmega32U4__)\r
                        #define PRODUCT_ID_CODE               0x2FF4\r
                        #define AVR_SIGNATURE_1               0x1E\r
                        #define AVR_SIGNATURE_1               0x1E\r
                        #define AVR_SIGNATURE_2               0x94\r
                        #define AVR_SIGNATURE_3               0x88\r
                        #define AVR_SIGNATURE_1               0x1E\r
                        #define AVR_SIGNATURE_2               0x94\r
                        #define AVR_SIGNATURE_3               0x88\r
+               #elif defined(__AVR_ATmega32U2__)\r
+                       #define PRODUCT_ID_CODE               0x2FF0\r
+                       #define AVR_SIGNATURE_1               0x1E\r
+                       #define AVR_SIGNATURE_2               0x94\r
+                       #define AVR_SIGNATURE_3               0x82\r
+               #elif defined(__AVR_ATmega16U2__)\r
+                       #define PRODUCT_ID_CODE               0x2FEF\r
+                       #define AVR_SIGNATURE_1               0x1E\r
+                       #define AVR_SIGNATURE_2               0x94\r
+                       #define AVR_SIGNATURE_3               0x89\r
                #elif defined(__AVR_AT90USB162__)\r
                        #define PRODUCT_ID_CODE               0x2FFA\r
                        #define AVR_SIGNATURE_1               0x1E\r
                #elif defined(__AVR_AT90USB162__)\r
                        #define PRODUCT_ID_CODE               0x2FFA\r
                        #define AVR_SIGNATURE_1               0x1E\r
                        #define AVR_SIGNATURE_1               0x1E\r
                        #define AVR_SIGNATURE_2               0x93\r
                        #define AVR_SIGNATURE_3               0x82\r
                        #define AVR_SIGNATURE_1               0x1E\r
                        #define AVR_SIGNATURE_2               0x93\r
                        #define AVR_SIGNATURE_3               0x82\r
-               #elif defined(__AVR_ATmega16U2__)\r
-                       #define PRODUCT_ID_CODE               0x2FEF\r
-                       #define AVR_SIGNATURE_1               0x1E\r
-                       #define AVR_SIGNATURE_2               0x94\r
-                       #define AVR_SIGNATURE_3               0x89\r
                #elif defined(__AVR_AT90USB82__)\r
                        #define PRODUCT_ID_CODE               0x2FEE\r
                        #define AVR_SIGNATURE_1               0x1E\r
                #elif defined(__AVR_AT90USB82__)\r
                        #define PRODUCT_ID_CODE               0x2FEE\r
                        #define AVR_SIGNATURE_1               0x1E\r
index f02281f..472e1df 100644 (file)
                                \r
                                #define  ADC_GetStatus()               ((ADCSRA & (1 << ADEN)) ? true : false)\r
 \r
                                \r
                                #define  ADC_GetStatus()               ((ADCSRA & (1 << ADEN)) ? true : false)\r
 \r
-                               #define  ADC_IsReadingComplete()         (ADCSRA & (1 << ADSC))\r
+                               #define  ADC_IsReadingComplete()        (ADCSRA & (1 << ADSC))\r
                                \r
                                #define  ADC_GetResult()                 ADC                    \r
                        #endif\r
                                \r
                                #define  ADC_GetResult()                 ADC                    \r
                        #endif\r
index f20cb72..aa760cd 100644 (file)
@@ -76,7 +76,8 @@
        \r
                #if (F_CLOCK == 8000000)\r
                        #if (defined(__AVR_AT90USB82__) || defined(__AVR_AT90USB162__) || \\r
        \r
                #if (F_CLOCK == 8000000)\r
                        #if (defined(__AVR_AT90USB82__) || defined(__AVR_AT90USB162__) || \\r
-                            defined(__AVR_ATMEGA8U2__) || defined(__AVR_ATMEGA16U2__))\r
+                            defined(__AVR_ATmega8U2__) || defined(__AVR_ATmega16U2__) || \\r
+                                defined(__AVR_ATmega32U2))\r
                                #define USB_PLL_PSC                0\r
                        #elif (defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__))\r
                                #define USB_PLL_PSC                0\r
                                #define USB_PLL_PSC                0\r
                        #elif (defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__))\r
                                #define USB_PLL_PSC                0\r
@@ -87,7 +88,8 @@
                        #endif\r
                #elif (F_CLOCK == 16000000)\r
                        #if (defined(__AVR_AT90USB82__) || defined(__AVR_AT90USB162__) || \\r
                        #endif\r
                #elif (F_CLOCK == 16000000)\r
                        #if (defined(__AVR_AT90USB82__) || defined(__AVR_AT90USB162__) || \\r
-                            defined(__AVR_ATMEGA8U2__) || defined(__AVR_ATMEGA16U2__))\r
+                            defined(__AVR_ATmega8U2__) || defined(__AVR_ATmega16U2__) || \\r
+                                defined(__AVR_ATmega32U2))\r
                                #define USB_PLL_PSC                (1 << PLLP0)\r
                        #elif (defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__))\r
                                #define USB_PLL_PSC                (1 << PINDIV)\r
                                #define USB_PLL_PSC                (1 << PLLP0)\r
                        #elif (defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__))\r
                                #define USB_PLL_PSC                (1 << PINDIV)\r
index 5107768..4c8a2f6 100644 (file)
@@ -35,6 +35,8 @@
   *  - Fixed XPLAIN board Dataflash driver broken due to incorrect preprocessor commands\r
   *  - Fixed inverted XPLAIN LED driver output (LED turned on when it was supposed to be turned off, and vice-versa)\r
   *  - Fixed Class Driver struct interface numbers in the KeyboardMouse and VirtualSerialMouse demos (thanks to Renaud Cerrato)\r
   *  - Fixed XPLAIN board Dataflash driver broken due to incorrect preprocessor commands\r
   *  - Fixed inverted XPLAIN LED driver output (LED turned on when it was supposed to be turned off, and vice-versa)\r
   *  - Fixed Class Driver struct interface numbers in the KeyboardMouse and VirtualSerialMouse demos (thanks to Renaud Cerrato)\r
+  *  - Fixed invalid USB controller PLL prescaler values for the ATMEGAxxU2 controllers\r
+  *  - Fixed lack of support for the ATMEGA32U2 in the DFU and CDC class bootloaders\r
   *\r
   *  \section Sec_ChangeLog091223 Version 091223\r
   *\r
   *\r
   *  \section Sec_ChangeLog091223 Version 091223\r
   *\r
index c3e281e..8363d96 100644 (file)
@@ -12,7 +12,7 @@
 volatile clock_time_t clock_datetime = 0;
 
 //Overflow interrupt
 volatile clock_time_t clock_datetime = 0;
 
 //Overflow interrupt
-ISR(TIMER0_OVF_vect)
+ISR(TIMER1_COMPA_vect)
 {\r
        clock_datetime += 1;
 }
 {\r
        clock_datetime += 1;
 }
@@ -20,14 +20,10 @@ ISR(TIMER0_OVF_vect)
 //Initialise the clock
 void clock_init()\r
 {\r
 //Initialise the clock
 void clock_init()\r
 {\r
-       //Activate overflow interrupt for timer0
-       TIMSK0 |= (1<<TOIE0);
-
-       //Use prescaler 1024
-       TCCR0B |= ((1<<CS12)|(1<<CS10));
-
-       //Activate interrupts
-       sei();
+       OCR1A  = ((F_CPU / 1024) / 100);
+       TCCR1A = (1 << WGM12);
+       TCCR1B = ((1 << CS12) | (1 << CS10));
+       TIMSK1 = (1 << OCIE1A);
 }
 
 //Return time
 }
 
 //Return time
index c759d01..9c895e5 100644 (file)
@@ -5,7 +5,7 @@
 #include <stdint.h>\r
 \r
 typedef uint16_t clock_time_t;\r
 #include <stdint.h>\r
 \r
 typedef uint16_t clock_time_t;\r
-#define CLOCK_CONF_SECOND (F_CPU / 1024 / 255)  //Freqency divided prescaler and counter register size\r
+#define CLOCK_CONF_SECOND 100\r
 void clock_init(void);\r
 clock_time_t clock_time(void);\r
 \r
 void clock_init(void);\r
 clock_time_t clock_time(void);\r
 \r
index e6ef9f0..97c35d7 100644 (file)
@@ -57,13 +57,13 @@ USB_ClassInfo_RNDIS_Host_t Ethernet_RNDIS_Interface =
                        },\r
        };\r
 \r
                        },\r
        };\r
 \r
-volatile uint8_t uIPManagementTimeout;\r
+struct timer ConnectionTimer, ARPTimer;\r
+uint16_t MillisecondTickCount;\r
 \r
 /** ISR for the management of the connection management timeout counter */\r
 ISR(TIMER0_COMPA_vect, ISR_BLOCK)\r
 {\r
 \r
 /** ISR for the management of the connection management timeout counter */\r
 ISR(TIMER0_COMPA_vect, ISR_BLOCK)\r
 {\r
-       if (uIPManagementTimeout)\r
-         uIPManagementTimeout--;\r
+       MillisecondTickCount++;\r
 }\r
 \r
 void TCPCallback(void)\r
 }\r
 \r
 void TCPCallback(void)\r
@@ -186,9 +186,8 @@ void ProcessIncommingPacket(void)
                  printf("0x%02X ", uip_buf[i]);\r
                printf("\r\n\r\n");\r
 \r
                  printf("0x%02X ", uip_buf[i]);\r
                printf("\r\n\r\n");\r
 \r
-               #define BUF ((struct uip_eth_hdr *)&uip_buf[0])\r
-\r
-               if (BUF->type == HTONS(UIP_ETHTYPE_IP))\r
+               struct uip_eth_hdr* EthernetHeader = (struct uip_eth_hdr*)&uip_buf[0];\r
+               if (EthernetHeader->type == HTONS(UIP_ETHTYPE_IP))\r
                {\r
                        /* Filter packet by MAC destination */\r
                        uip_arp_ipin();\r
                {\r
                        /* Filter packet by MAC destination */\r
                        uip_arp_ipin();\r
@@ -200,7 +199,7 @@ void ProcessIncommingPacket(void)
                        if (uip_len > 0)\r
                          uip_arp_out();\r
                }\r
                        if (uip_len > 0)\r
                          uip_arp_out();\r
                }\r
-               else if (BUF->type == HTONS(UIP_ETHTYPE_ARP))\r
+               else if (EthernetHeader->type == HTONS(UIP_ETHTYPE_ARP))\r
                {\r
                        /* Process ARP packet */\r
                        uip_arp_arpin();\r
                {\r
                        /* Process ARP packet */\r
                        uip_arp_arpin();\r
@@ -221,8 +220,10 @@ void ProcessIncommingPacket(void)
 \r
 void ManageConnections(void)\r
 {\r
 \r
 void ManageConnections(void)\r
 {\r
-       if (!(uIPManagementTimeout))\r
+       if (timer_expired(&ConnectionTimer))\r
        {\r
        {\r
+               timer_reset(&ConnectionTimer);\r
+\r
                LEDs_SetAllLEDs(LEDMASK_USB_BUSY);\r
                \r
                for (uint8_t i = 0; i < UIP_CONNS; i++)\r
                LEDs_SetAllLEDs(LEDMASK_USB_BUSY);\r
                \r
                for (uint8_t i = 0; i < UIP_CONNS; i++)\r
@@ -235,12 +236,14 @@ void ManageConnections(void)
                          RNDIS_Host_SendPacket(&Ethernet_RNDIS_Interface, &uip_buf, uip_len);\r
                }\r
                \r
                          RNDIS_Host_SendPacket(&Ethernet_RNDIS_Interface, &uip_buf, uip_len);\r
                }\r
                \r
-               uip_arp_timer();\r
-               \r
-               uIPManagementTimeout = 250;\r
-\r
                LEDs_SetAllLEDs(LEDMASK_USB_READY);\r
        }\r
                LEDs_SetAllLEDs(LEDMASK_USB_READY);\r
        }\r
+\r
+       if (timer_expired(&ARPTimer))\r
+       {\r
+               timer_reset(&ARPTimer);\r
+               uip_arp_timer();\r
+       }\r
 }\r
 \r
 /** Configures the board hardware and chip peripherals for the demo's functionality. */\r
 }\r
 \r
 /** Configures the board hardware and chip peripherals for the demo's functionality. */\r
@@ -258,22 +261,21 @@ void SetupHardware(void)
        LEDs_Init();\r
        USB_Init();\r
 \r
        LEDs_Init();\r
        USB_Init();\r
 \r
-       /* Millisecond timer initialization for managing the command timeout counter */\r
-       OCR0A  = ((F_CPU / 64) / 1000);\r
-       TCCR0A = (1 << WGM01);\r
-       TCCR0B = ((1 << CS01) | (1 << CS00));\r
-       \r
+       /* uIP Timing Initialization */\r
+       clock_init();\r
+       timer_set(&ConnectionTimer, CLOCK_SECOND / 2);\r
+       timer_set(&ARPTimer, CLOCK_SECOND * 10);        \r
+\r
        /* uIP Stack Initialization */\r
        uip_init();\r
        /* uIP Stack Initialization */\r
        uip_init();\r
-\r
        uip_ipaddr_t IPAddress, Netmask, GatewayIPAddress;\r
        uip_ipaddr_t IPAddress, Netmask, GatewayIPAddress;\r
-       uip_ipaddr(&IPAddress, 192, 168, 1, 10);\r
-       uip_ipaddr(&Netmask, 0xFF, 0xFF, 0xFF, 0x00);\r
+       uip_ipaddr(&IPAddress,        192, 168, 1, 10);\r
+       uip_ipaddr(&Netmask,          255, 255, 255, 0);\r
        uip_ipaddr(&GatewayIPAddress, 192, 168, 1, 1);\r
        uip_sethostaddr(&IPAddress);\r
        uip_setnetmask(&Netmask);\r
        uip_setdraddr(&GatewayIPAddress);\r
        uip_ipaddr(&GatewayIPAddress, 192, 168, 1, 1);\r
        uip_sethostaddr(&IPAddress);\r
        uip_setnetmask(&Netmask);\r
        uip_setdraddr(&GatewayIPAddress);\r
-       \r
+               \r
        /* HTTP Webserver Initialization */\r
        uip_listen(HTONS(80));\r
 }\r
        /* HTTP Webserver Initialization */\r
        uip_listen(HTONS(80));\r
 }\r
index 9da29d6..ef17d4c 100644 (file)
@@ -52,6 +52,7 @@
                \r
                #include <uip.h>\r
                #include <uip_arp.h>\r
                \r
                #include <uip.h>\r
                #include <uip_arp.h>\r
+               #include <timer.h>\r
                \r
        /* Macros: */\r
                /** LED mask for the library LED driver, to indicate that the USB interface is not ready. */\r
                \r
        /* Macros: */\r
                /** LED mask for the library LED driver, to indicate that the USB interface is not ready. */\r
index 6a6e4c9..b51e510 100644 (file)
@@ -142,6 +142,7 @@ SRC = $(TARGET).c                                                 \
          Lib/uip/psock.c                                             \\r
          Lib/uip/timer.c                                             \\r
          Lib/uip/uip-neighbor.c                                      \\r
          Lib/uip/psock.c                                             \\r
          Lib/uip/timer.c                                             \\r
          Lib/uip/uip-neighbor.c                                      \\r
+         Lib/uip/conf/clock-arch.c                                   \\r
          \r
          \r
 # List C++ source files here. (C dependencies are automatically generated.)\r
          \r
          \r
 # List C++ source files here. (C dependencies are automatically generated.)\r