]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/MicroBlaze_Spartan-6_EthernetLite/SDKProjects/RTOSDemo/lwIP/lwIP_Apps/lwIP_Apps.c
Prepare for V7.2.0 release.
[freertos] / FreeRTOS / Demo / MicroBlaze_Spartan-6_EthernetLite / SDKProjects / RTOSDemo / lwIP / lwIP_Apps / lwIP_Apps.c
1 /*\r
2     FreeRTOS V7.2.0 - Copyright (C) 2012 Real Time Engineers Ltd.\r
3         \r
4 \r
5     ***************************************************************************\r
6      *                                                                       *\r
7      *    FreeRTOS tutorial books are available in pdf and paperback.        *\r
8      *    Complete, revised, and edited pdf reference manuals are also       *\r
9      *    available.                                                         *\r
10      *                                                                       *\r
11      *    Purchasing FreeRTOS documentation will not only help you, by       *\r
12      *    ensuring you get running as quickly as possible and with an        *\r
13      *    in-depth knowledge of how to use FreeRTOS, it will also help       *\r
14      *    the FreeRTOS project to continue with its mission of providing     *\r
15      *    professional grade, cross platform, de facto standard solutions    *\r
16      *    for microcontrollers - completely free of charge!                  *\r
17      *                                                                       *\r
18      *    >>> See http://www.FreeRTOS.org/Documentation for details. <<<     *\r
19      *                                                                       *\r
20      *    Thank you for using FreeRTOS, and thank you for your support!      *\r
21      *                                                                       *\r
22     ***************************************************************************\r
23 \r
24 \r
25     This file is part of the FreeRTOS distribution.\r
26 \r
27     FreeRTOS is free software; you can redistribute it and/or modify it under\r
28     the terms of the GNU General Public License (version 2) as published by the\r
29     Free Software Foundation AND MODIFIED BY the FreeRTOS exception.\r
30     >>>NOTE<<< The modification to the GPL is included to allow you to\r
31     distribute a combined work that includes FreeRTOS without being obliged to\r
32     provide the source code for proprietary components outside of the FreeRTOS\r
33     kernel.  FreeRTOS is distributed in the hope that it will be useful, but\r
34     WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\r
35     or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for\r
36     more details. You should have received a copy of the GNU General Public\r
37     License and the FreeRTOS license exception along with FreeRTOS; if not it\r
38     can be viewed here: http://www.freertos.org/a00114.html and also obtained\r
39     by writing to Richard Barry, contact details for whom are available on the\r
40     FreeRTOS WEB site.\r
41 \r
42     1 tab == 4 spaces!\r
43     \r
44     ***************************************************************************\r
45      *                                                                       *\r
46      *    Having a problem?  Start by reading the FAQ "My application does   *\r
47      *    not run, what could be wrong?                                      *\r
48      *                                                                       *\r
49      *    http://www.FreeRTOS.org/FAQHelp.html                               *\r
50      *                                                                       *\r
51     ***************************************************************************\r
52 \r
53     \r
54     http://www.FreeRTOS.org - Documentation, training, latest information, \r
55     license and contact details.\r
56     \r
57     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
58     including FreeRTOS+Trace - an indispensable productivity tool.\r
59 \r
60     Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell \r
61     the code with commercial support, indemnification, and middleware, under \r
62     the OpenRTOS brand: http://www.OpenRTOS.com.  High Integrity Systems also\r
63     provide a safety engineered and independently SIL3 certified version under \r
64     the SafeRTOS brand: http://www.SafeRTOS.com.\r
65 */\r
66 \r
67 /* Standard includes. */\r
68 #include <string.h>\r
69 \r
70 /* FreeRTOS includes. */\r
71 #include "FreeRTOS.h"\r
72 #include "task.h"\r
73 #include "semphr.h"\r
74 \r
75 /* lwIP core includes */\r
76 #include "lwip/opt.h"\r
77 #include "lwip/tcpip.h"\r
78 \r
79 /* lwIP netif includes */\r
80 #include "netif/etharp.h"\r
81 \r
82 /* applications includes */\r
83 #include "apps/httpserver_raw/httpd.h"\r
84 \r
85 /* The constants that define the IP address, net mask, gateway address and MAC\r
86 address are located at the bottom of FreeRTOSConfig.h. */\r
87 #define LWIP_PORT_INIT_IPADDR(addr)   IP4_ADDR((addr), configIP_ADDR0, configIP_ADDR1, configIP_ADDR2, configIP_ADDR3 )\r
88 #define LWIP_PORT_INIT_GW(addr)       IP4_ADDR((addr), configGW_IP_ADDR0, configGW_IP_ADDR1, configGW_IP_ADDR2, configGW_IP_ADDR3 )\r
89 #define LWIP_PORT_INIT_NETMASK(addr)  IP4_ADDR((addr), configNET_MASK0,configNET_MASK1,configNET_MASK2,configNET_MASK3)\r
90 #define LWIP_MAC_ADDR_BASE            { configMAC_ADDR0, configMAC_ADDR1, configMAC_ADDR2, configMAC_ADDR3, configMAC_ADDR4, configMAC_ADDR5 }\r
91 \r
92 /* Definitions of the various SSI callback functions within the pccSSITags \r
93 array.  If pccSSITags is updated, then these definitions must also be updated. */\r
94 #define ssiTASK_STATS_INDEX                     0\r
95 #define ssiRUN_TIME_STATS_INDEX         1\r
96 \r
97 /*\r
98  * The SSI handler callback function passed to lwIP.\r
99  */\r
100 static unsigned short uslwIPAppsSSIHandler( int iIndex, char *pcBuffer, int iBufferLength );\r
101 \r
102 /*-----------------------------------------------------------*/\r
103 \r
104 /* The SSI strings that are embedded in the served html files.  If this array\r
105 is changed, then the index position defined by the #defines such as \r
106 ssiTASK_STATS_INDEX above must also be updated. */\r
107 static const char *pccSSITags[] = \r
108 {\r
109         "rtos_stats",\r
110         "run_stats"\r
111 };\r
112 \r
113 /*-----------------------------------------------------------*/\r
114 \r
115 /* Called from the TCP/IP thread. */\r
116 void lwIPAppsInit( void *pvArgument )\r
117 {\r
118 ip_addr_t xIPAddr, xNetMask, xGateway;\r
119 extern err_t ethernetif_init( struct netif *xNetIf );\r
120 static struct netif xNetIf;\r
121 \r
122         ( void ) pvArgument;\r
123 \r
124         /* Set up the network interface. */\r
125         ip_addr_set_zero( &xGateway );\r
126         ip_addr_set_zero( &xIPAddr );\r
127         ip_addr_set_zero( &xNetMask );\r
128 \r
129         LWIP_PORT_INIT_GW(&xGateway);\r
130         LWIP_PORT_INIT_IPADDR(&xIPAddr);\r
131         LWIP_PORT_INIT_NETMASK(&xNetMask);\r
132 \r
133         netif_set_default( netif_add( &xNetIf, &xIPAddr, &xNetMask, &xGateway, NULL, ethernetif_init, tcpip_input ) );\r
134         netif_set_up( &xNetIf );\r
135 \r
136         /* Initialise the raw http server. */\r
137         httpd_init();\r
138 \r
139         /* Install the server side include handler. */\r
140         http_set_ssi_handler( uslwIPAppsSSIHandler, pccSSITags, sizeof( pccSSITags ) / sizeof( char * ) );\r
141 }\r
142 /*-----------------------------------------------------------*/\r
143 \r
144 static unsigned short uslwIPAppsSSIHandler( int iIndex, char *pcBuffer, int iBufferLength )\r
145 {\r
146 static unsigned int uiUpdateCount = 0;\r
147 static char cUpdateString[ 200 ];\r
148 extern char *pcMainGetTaskStatusMessage( void );\r
149 \r
150         /* Unused parameter. */\r
151         ( void ) iBufferLength;\r
152 \r
153         /* The SSI handler function that generates text depending on the index of\r
154         the SSI tag encountered. */\r
155         \r
156         switch( iIndex )\r
157         {\r
158                 case ssiTASK_STATS_INDEX :\r
159                         vTaskList( ( signed char * ) pcBuffer );\r
160                         break;\r
161 \r
162                 case ssiRUN_TIME_STATS_INDEX :\r
163                         vTaskGetRunTimeStats( ( signed char * ) pcBuffer );\r
164                         break;\r
165         }\r
166 \r
167         /* Include a count of the number of times an SSI function has been executed\r
168         in the returned string. */\r
169         uiUpdateCount++;\r
170         sprintf( cUpdateString, "\r\n\r\n%u\r\nStatus - %s", uiUpdateCount, pcMainGetTaskStatusMessage() );\r
171         strcat( pcBuffer, cUpdateString );\r
172         return strlen( pcBuffer );\r
173 }\r
174 \r