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