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