]> git.sur5r.net Git - freertos/blobdiff - Demo/RX600_RX62N-RSK_IAR/uIP_Task.c
Start to re-arrange files to include FreeRTOS+ in main download.
[freertos] / Demo / RX600_RX62N-RSK_IAR / uIP_Task.c
index a09782decd2ae25e800565fcd8ccfdc9c02f6aee..4bfc532dcb03c180f15922166ccb5cca44a668b6 100644 (file)
@@ -1,5 +1,5 @@
 /*\r
-    FreeRTOS V7.0.0 - Copyright (C) 2011 Real Time Engineers Ltd.\r
+    FreeRTOS V7.1.1 - Copyright (C) 2012 Real Time Engineers Ltd.\r
        \r
 \r
     ***************************************************************************\r
     FreeRTOS WEB site.\r
 \r
     1 tab == 4 spaces!\r
+    \r
+    ***************************************************************************\r
+     *                                                                       *\r
+     *    Having a problem?  Start by reading the FAQ "My application does   *\r
+     *    not run, what could be wrong?                                      *\r
+     *                                                                       *\r
+     *    http://www.FreeRTOS.org/FAQHelp.html                               *\r
+     *                                                                       *\r
+    ***************************************************************************\r
 \r
-    http://www.FreeRTOS.org - Documentation, latest information, license and\r
-    contact details.\r
-\r
-    http://www.SafeRTOS.com - A version that is certified for use in safety\r
-    critical systems.\r
-\r
-    http://www.OpenRTOS.com - Commercial support, development, porting,\r
-    licensing and training services.\r
+    \r
+    http://www.FreeRTOS.org - Documentation, training, latest information, \r
+    license and contact details.\r
+    \r
+    http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
+    including FreeRTOS+Trace - an indispensable productivity tool.\r
+\r
+    Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell \r
+    the code with commercial support, indemnification, and middleware, under \r
+    the OpenRTOS brand: http://www.OpenRTOS.com.  High Integrity Systems also\r
+    provide a safety engineered and independently SIL3 certified version under \r
+    the SafeRTOS brand: http://www.SafeRTOS.com.\r
 */\r
 \r
 /* Standard includes. */\r
@@ -57,7 +70,8 @@
 /* Scheduler includes. */\r
 #include "FreeRTOS.h"\r
 #include "task.h"\r
-#include "semphr.h"\r
+#include "timers.h"\r
+#include "queue.h"\r
 \r
 /* uip includes. */\r
 #include "net/uip.h"\r
 /* Standard constant. */\r
 #define uipTOTAL_FRAME_HEADER_SIZE     54\r
 \r
+/* The ARP timer and the periodic timer share a callback function, so the\r
+respective timer IDs are used to determine which timer actually expired.  These\r
+constants are assigned to the timer IDs. */\r
+#define uipARP_TIMER                           0\r
+#define uipPERIODIC_TIMER                      1\r
+\r
+/* A block time of zero ticks simply means, "don't block". */\r
+#define uipDONT_BLOCK                          0UL\r
+\r
 /*-----------------------------------------------------------*/\r
 \r
 /*\r
  */\r
 static void prvSetMACAddress( void );\r
 \r
+/*\r
+ * Perform any uIP initialisation necessary.\r
+ */\r
+static void prvInitialise_uIP( void );\r
+\r
+/*\r
+ * The callback function that is assigned to both the periodic timer and the\r
+ * ARP timer.\r
+ */\r
+static void prvUIPTimerCallback( xTimerHandle xTimer );\r
+\r
 /*\r
  * Port functions required by the uIP stack.\r
  */\r
-void clock_init( void );\r
 clock_time_t clock_time( void );\r
 \r
 /*-----------------------------------------------------------*/\r
 \r
-/* The semaphore used by the ISR to wake the uIP task. */\r
-xSemaphoreHandle xEMACSemaphore = NULL;\r
+/* The queue used to send TCP/IP events to the uIP stack. */\r
+xQueueHandle xEMACEventQueue = NULL;\r
 \r
 /*-----------------------------------------------------------*/\r
 \r
-void clock_init(void)\r
-{\r
-       /* This is done when the scheduler starts. */\r
-}\r
-/*-----------------------------------------------------------*/\r
-\r
 clock_time_t clock_time( void )\r
 {\r
        return xTaskGetTickCount();\r
@@ -115,25 +142,14 @@ clock_time_t clock_time( void )
 \r
 void vuIP_Task( void *pvParameters )\r
 {\r
-portBASE_TYPE i, xDoneSomething;\r
-uip_ipaddr_t xIPAddr;\r
-struct timer periodic_timer, arp_timer;\r
+portBASE_TYPE i;\r
+unsigned long ulNewEvent = 0UL;\r
+unsigned long ulUIP_Events = 0UL;\r
 \r
        ( void ) pvParameters;\r
-\r
+       \r
        /* Initialise the uIP stack. */\r
-       timer_set( &periodic_timer, configTICK_RATE_HZ / 2 );\r
-       timer_set( &arp_timer, configTICK_RATE_HZ * 10 );\r
-       uip_init();\r
-       uip_ipaddr( &xIPAddr, configIP_ADDR0, configIP_ADDR1, configIP_ADDR2, configIP_ADDR3 );\r
-       uip_sethostaddr( &xIPAddr );\r
-       uip_ipaddr( &xIPAddr, configNET_MASK0, configNET_MASK1, configNET_MASK2, configNET_MASK3 );\r
-       uip_setnetmask( &xIPAddr );\r
-       prvSetMACAddress();\r
-       httpd_init();\r
-\r
-       /* Create the semaphore used to wake the uIP task. */\r
-       vSemaphoreCreateBinary( xEMACSemaphore );\r
+       prvInitialise_uIP();\r
 \r
        /* Initialise the MAC. */\r
        vInitEmac();\r
@@ -145,49 +161,51 @@ struct timer periodic_timer, arp_timer;
 \r
        for( ;; )\r
        {\r
-               xDoneSomething = pdFALSE;\r
-               \r
-               /* Is there received data ready to be processed? */\r
-               uip_len = ( unsigned short ) ulEMACRead();\r
-               \r
-               if( ( uip_len > 0 ) && ( uip_buf != NULL ) )\r
-               {\r
-                       /* Standard uIP loop taken from the uIP manual. */\r
-                       if( xHeader->type == htons( UIP_ETHTYPE_IP ) )\r
+               if( ( ulUIP_Events & uipETHERNET_RX_EVENT ) != 0UL )\r
+               {               \r
+                       /* Is there received data ready to be processed? */\r
+                       uip_len = ( unsigned short ) ulEMACRead();\r
+                       \r
+                       if( ( uip_len > 0 ) && ( uip_buf != NULL ) )\r
                        {\r
-                               uip_arp_ipin();\r
-                               uip_input();\r
-\r
-                               /* If the above function invocation resulted in data that\r
-                               should be sent out on the network, the global variable\r
-                               uip_len is set to a value > 0. */\r
-                               if( uip_len > 0 )\r
+                               /* Standard uIP loop taken from the uIP manual. */\r
+                               if( xHeader->type == htons( UIP_ETHTYPE_IP ) )\r
                                {\r
-                                       uip_arp_out();\r
-                                       vEMACWrite();\r
+                                       uip_arp_ipin();\r
+                                       uip_input();\r
+\r
+                                       /* If the above function invocation resulted in data that\r
+                                       should be sent out on the network, the global variable\r
+                                       uip_len is set to a value > 0. */\r
+                                       if( uip_len > 0 )\r
+                                       {\r
+                                               uip_arp_out();\r
+                                               vEMACWrite();\r
+                                       }\r
                                }\r
-                               \r
-                               xDoneSomething = pdTRUE;\r
-                       }\r
-                       else if( xHeader->type == htons( UIP_ETHTYPE_ARP ) )\r
-                       {\r
-                               uip_arp_arpin();\r
-\r
-                               /* If the above function invocation resulted in data that\r
-                               should be sent out on the network, the global variable\r
-                               uip_len is set to a value > 0. */\r
-                               if( uip_len > 0 )\r
+                               else if( xHeader->type == htons( UIP_ETHTYPE_ARP ) )\r
                                {\r
-                                       vEMACWrite();\r
+                                       uip_arp_arpin();\r
+\r
+                                       /* If the above function invocation resulted in data that\r
+                                       should be sent out on the network, the global variable\r
+                                       uip_len is set to a value > 0. */\r
+                                       if( uip_len > 0 )\r
+                                       {\r
+                                               vEMACWrite();\r
+                                       }\r
                                }\r
-                               \r
-                               xDoneSomething = pdTRUE;\r
+                       }\r
+                       else\r
+                       {\r
+                               ulUIP_Events &= ~uipETHERNET_RX_EVENT;\r
                        }\r
                }\r
-\r
-               if( timer_expired( &periodic_timer ) && ( uip_buf != NULL ) )\r
+               \r
+               if( ( ulUIP_Events & uipPERIODIC_TIMER_EVENT ) != 0UL )\r
                {\r
-                       timer_reset( &periodic_timer );\r
+                       ulUIP_Events &= ~uipPERIODIC_TIMER_EVENT;\r
+                                       \r
                        for( i = 0; i < UIP_CONNS; i++ )\r
                        {\r
                                uip_periodic( i );\r
@@ -201,29 +219,86 @@ struct timer periodic_timer, arp_timer;
                                        vEMACWrite();\r
                                }\r
                        }\r
-\r
-                       /* Call the ARP timer function every 10 seconds. */\r
-                       if( timer_expired( &arp_timer ) )\r
-                       {\r
-                               timer_reset( &arp_timer );\r
-                               uip_arp_timer();\r
-                       }\r
-                       \r
-                       xDoneSomething = pdTRUE;\r
                }\r
                \r
-               if( xDoneSomething == pdFALSE )\r
+               /* Call the ARP timer function every 10 seconds. */\r
+               if( ( ulUIP_Events & uipARP_TIMER_EVENT ) != 0 )\r
+               {\r
+                       ulUIP_Events &= ~uipARP_TIMER_EVENT;\r
+                       uip_arp_timer();\r
+               }\r
+                       \r
+               if( ulUIP_Events == pdFALSE )\r
                {\r
-                       /* We did not receive a packet, and there was no periodic\r
-                       processing to perform.  Block for a fixed period.  If a packet\r
-                       is received during this period we will be woken by the ISR\r
-                       giving us the Semaphore. */\r
-                       xSemaphoreTake( xEMACSemaphore, configTICK_RATE_HZ / 20 );\r
+                       xQueueReceive( xEMACEventQueue, &ulNewEvent, portMAX_DELAY );\r
+                       ulUIP_Events |= ulNewEvent;\r
                }\r
        }\r
 }\r
 /*-----------------------------------------------------------*/\r
 \r
+static void prvInitialise_uIP( void )\r
+{\r
+xTimerHandle xARPTimer, xPeriodicTimer;\r
+uip_ipaddr_t xIPAddr;\r
+const unsigned long ul_uIPEventQueueLength = 10UL;\r
+\r
+       /* Initialise the uIP stack. */\r
+       uip_init();\r
+       uip_ipaddr( &xIPAddr, configIP_ADDR0, configIP_ADDR1, configIP_ADDR2, configIP_ADDR3 );\r
+       uip_sethostaddr( &xIPAddr );\r
+       uip_ipaddr( &xIPAddr, configNET_MASK0, configNET_MASK1, configNET_MASK2, configNET_MASK3 );\r
+       uip_setnetmask( &xIPAddr );\r
+       prvSetMACAddress();\r
+       httpd_init();\r
+\r
+       /* Create the queue used to sent TCP/IP events to the uIP stack. */\r
+       xEMACEventQueue = xQueueCreate( ul_uIPEventQueueLength, sizeof( unsigned long ) );\r
+\r
+       /* Create and start the uIP timers. */\r
+       xARPTimer = xTimerCreate(       "ARPTimer", /* Just a name that is helpful for debugging, not used by the kernel. */\r
+                                                               ( 10000UL / portTICK_RATE_MS ), /* Timer period. */\r
+                                                               pdTRUE, /* Autor-reload. */\r
+                                                               ( void * ) uipARP_TIMER,\r
+                                                               prvUIPTimerCallback\r
+                                                       );\r
+\r
+       xPeriodicTimer = xTimerCreate(  "PeriodicTimer",\r
+                                                                       ( 50 / portTICK_RATE_MS ),\r
+                                                                       pdTRUE, /* Autor-reload. */\r
+                                                                       ( void * ) uipPERIODIC_TIMER,\r
+                                                                       prvUIPTimerCallback\r
+                                                               );\r
+\r
+       configASSERT( xARPTimer );\r
+       configASSERT( xPeriodicTimer );\r
+\r
+       xTimerStart( xARPTimer, portMAX_DELAY );\r
+       xTimerStart( xPeriodicTimer, portMAX_DELAY );\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+static void prvUIPTimerCallback( xTimerHandle xTimer )\r
+{\r
+static const unsigned long ulARPTimerExpired = uipARP_TIMER_EVENT;\r
+static const unsigned long ulPeriodicTimerExpired = uipPERIODIC_TIMER_EVENT;\r
+\r
+       /* This is a time callback, so calls to xQueueSend() must not attempt to\r
+       block. */\r
+       switch( ( int ) pvTimerGetTimerID( xTimer ) )\r
+       {\r
+               case uipARP_TIMER               :       xQueueSend( xEMACEventQueue, &ulARPTimerExpired, uipDONT_BLOCK );\r
+                                                                       break;\r
+\r
+               case uipPERIODIC_TIMER  :       xQueueSend( xEMACEventQueue, &ulPeriodicTimerExpired, uipDONT_BLOCK );\r
+                                                                       break;\r
+\r
+               default                                 :       /* Should not get here. */\r
+                                                                       break;\r
+       }\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
 static void prvSetMACAddress( void )\r
 {\r
 struct uip_eth_addr xAddr;\r
@@ -250,28 +325,34 @@ char *c;
        {\r
                /* Is there a command in the string? */\r
                c = strstr( pcInputString, "?" );\r
-               if( c )\r
-               {\r
+           if( c )\r
+           {\r
                        /* Turn the LED's on or off in accordance with the check box status. */\r
                        if( strstr( c, "LED0=1" ) != NULL )\r
                        {\r
-                               /* Turn LEDs on. */\r
-                               vParTestSetLED( 3, 1 );\r
-                               vParTestSetLED( 4, 1 );\r
+                               /* Turn the LEDs on. */\r
+                               vParTestSetLED( 7, 1 );\r
+                               vParTestSetLED( 8, 1 );\r
+                               vParTestSetLED( 9, 1 );\r
+                               vParTestSetLED( 10, 1 );\r
                        }\r
                        else\r
                        {\r
-                               /* Turn LED 4 off. */\r
-                               vParTestSetLED( 3, 0 );\r
-                               vParTestSetLED( 4, 0 );\r
+                               /* Turn the LEDs off. */\r
+                               vParTestSetLED( 7, 0 );\r
+                               vParTestSetLED( 8, 0 );\r
+                               vParTestSetLED( 9, 0 );\r
+                               vParTestSetLED( 10, 0 );\r
                        }\r
-               }\r
+           }\r
                else\r
                {\r
-                       /* Commands to turn LEDs off are not always explicit, turn LED 4\r
-                       off. */\r
-                       vParTestSetLED( 3, 0 );\r
-                       vParTestSetLED( 4, 0 );\r
+                       /* Commands to turn LEDs off are not always explicit. */\r
+                       vParTestSetLED( 7, 0 );\r
+                       vParTestSetLED( 8, 0 );\r
+                       vParTestSetLED( 9, 0 );\r
+                       vParTestSetLED( 10, 0 );\r
                }\r
        }\r
 }\r
+\r