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