Fixed invalid USB controller PLL prescaler values for the ATMEGAxxU2 controllers
[pub/USBasp.git] / Projects / Incomplete / Webserver / Webserver.c
index e6ef9f0..97c35d7 100644 (file)
@@ -57,13 +57,13 @@ USB_ClassInfo_RNDIS_Host_t Ethernet_RNDIS_Interface =
                        },\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
@@ -186,9 +186,8 @@ void ProcessIncommingPacket(void)
                  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
@@ -200,7 +199,7 @@ void ProcessIncommingPacket(void)
                        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
@@ -221,8 +220,10 @@ void ProcessIncommingPacket(void)
 \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
@@ -235,12 +236,14 @@ void ManageConnections(void)
                          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
@@ -258,22 +261,21 @@ void SetupHardware(void)
        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