#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
- #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_AT90USB162__)\r
+ #elif defined(__AVR_AT90USB1286__)\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
- #elif defined(__AVR_AT90USB82__)\r
+ #elif defined(__AVR_AT90USB646__)\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_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
*/ \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
- #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 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
#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
#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
\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
#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
#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
* - 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
volatile clock_time_t clock_datetime = 0;
//Overflow interrupt
-ISR(TIMER0_OVF_vect)
+ISR(TIMER1_COMPA_vect)
{\r
clock_datetime += 1;
}
//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
#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
},\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
- if (uIPManagementTimeout)\r
- uIPManagementTimeout--;\r
+ MillisecondTickCount++;\r
}\r
\r
void TCPCallback(void)\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
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
void ManageConnections(void)\r
{\r
- if (!(uIPManagementTimeout))\r
+ if (timer_expired(&ConnectionTimer))\r
{\r
+ timer_reset(&ConnectionTimer);\r
+\r
LEDs_SetAllLEDs(LEDMASK_USB_BUSY);\r
\r
for (uint8_t i = 0; i < UIP_CONNS; i++)\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
+\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
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
-\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
- \r
+ \r
/* HTTP Webserver Initialization */\r
uip_listen(HTONS(80));\r
}\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
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