OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Demo/] [lwIP_Demo_Rowley_ARM7/] [BasicWEB.c] - Blame information for rev 866

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 583 jeremybenn
/*
2
    FreeRTOS V6.1.1 - Copyright (C) 2011 Real Time Engineers Ltd.
3
 
4
    ***************************************************************************
5
    *                                                                         *
6
    * If you are:                                                             *
7
    *                                                                         *
8
    *    + New to FreeRTOS,                                                   *
9
    *    + Wanting to learn FreeRTOS or multitasking in general quickly       *
10
    *    + Looking for basic training,                                        *
11
    *    + Wanting to improve your FreeRTOS skills and productivity           *
12
    *                                                                         *
13
    * then take a look at the FreeRTOS books - available as PDF or paperback  *
14
    *                                                                         *
15
    *        "Using the FreeRTOS Real Time Kernel - a Practical Guide"        *
16
    *                  http://www.FreeRTOS.org/Documentation                  *
17
    *                                                                         *
18
    * A pdf reference manual is also available.  Both are usually delivered   *
19
    * to your inbox within 20 minutes to two hours when purchased between 8am *
20
    * and 8pm GMT (although please allow up to 24 hours in case of            *
21
    * exceptional circumstances).  Thank you for your support!                *
22
    *                                                                         *
23
    ***************************************************************************
24
 
25
    This file is part of the FreeRTOS distribution.
26
 
27
    FreeRTOS is free software; you can redistribute it and/or modify it under
28
    the terms of the GNU General Public License (version 2) as published by the
29
    Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
30
    ***NOTE*** The exception to the GPL is included to allow you to distribute
31
    a combined work that includes FreeRTOS without being obliged to provide the
32
    source code for proprietary components outside of the FreeRTOS kernel.
33
    FreeRTOS is distributed in the hope that it will be useful, but WITHOUT
34
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
35
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
36
    more details. You should have received a copy of the GNU General Public
37
    License and the FreeRTOS license exception along with FreeRTOS; if not it
38
    can be viewed here: http://www.freertos.org/a00114.html and also obtained
39
    by writing to Richard Barry, contact details for whom are available on the
40
    FreeRTOS WEB site.
41
 
42
    1 tab == 4 spaces!
43
 
44
    http://www.FreeRTOS.org - Documentation, latest information, license and
45
    contact details.
46
 
47
    http://www.SafeRTOS.com - A version that is certified for use in safety
48
    critical systems.
49
 
50
    http://www.OpenRTOS.com - Commercial support, development, porting,
51
    licensing and training services.
52
*/
53
 
54
/*
55
        Implements a simplistic WEB server.  Every time a connection is made and
56
        data is received a dynamic page that shows the current TCP/IP statistics
57
        is generated and returned.  The connection is then closed.
58
 
59
        This file was adapted from a FreeRTOS lwIP slip demo supplied by a third
60
        party.
61
*/
62
 
63
/*
64
        Changes from V3.2.2
65
 
66
        + Changed the page returned by the lwIP WEB server demo to display the
67
          task status table rather than the TCP/IP statistics.
68
*/
69
 
70
 
71
/* Standard includes. */
72
#include <stdio.h>
73
#include <string.h>
74
 
75
/* Scheduler includes. */
76
#include "FreeRTOS.h"
77
#include "task.h"
78
#include "semphr.h"
79
 
80
/* Demo includes. */
81
#include "BasicWEB.h"
82
#include "SAM7_EMAC.h"
83
 
84
/* lwIP includes. */
85
#include "lwip/api.h" 
86
#include "lwip/tcpip.h"
87
#include "lwip/memp.h" 
88
#include "lwip/stats.h"
89
#include "netif/loopif.h"
90
 
91
/* The size of the buffer in which the dynamic WEB page is created. */
92
#define webMAX_PAGE_SIZE        2048
93
 
94
/* Standard GET response. */
95
#define webHTTP_OK      "HTTP/1.0 200 OK\r\nContent-type: text/html\r\n\r\n"
96
 
97
/* The port on which we listen. */
98
#define webHTTP_PORT            ( 80 )
99
 
100
/* Delay on close error. */
101
#define webSHORT_DELAY          ( 10 )
102
 
103
/* Format of the dynamic page that is returned on each connection. */
104
#define webHTML_START \
105
"<html>\
106
<head>\
107
</head>\
108
<BODY onLoad=\"window.setTimeout(&quot;location.href='index.html'&quot;,1000)\"bgcolor=\"#CCCCff\">\
109
\r\nPage Hits = "
110
 
111
#define webHTML_END \
112
"\r\n</pre>\
113
\r\n</BODY>\
114
</html>"
115
 
116
/*------------------------------------------------------------*/
117
 
118
/*
119
 * Process an incoming connection on port 80.
120
 *
121
 * This simply checks to see if the incoming data contains a GET request, and
122
 * if so sends back a single dynamically created page.  The connection is then
123
 * closed.  A more complete implementation could create a task for each
124
 * connection.
125
 */
126
static void vProcessConnection( struct netconn *pxNetCon );
127
 
128
/*------------------------------------------------------------*/
129
 
130
static void vProcessConnection( struct netconn *pxNetCon )
131
{
132
static char cDynamicPage[ webMAX_PAGE_SIZE ], cPageHits[ 11 ];
133
struct netbuf *pxRxBuffer;
134
char *pcRxString;
135
unsigned short usLength;
136
static unsigned long ulPageHits = 0;
137
 
138
        /* We expect to immediately get data. */
139
        pxRxBuffer = netconn_recv( pxNetCon );
140
 
141
        if( pxRxBuffer != NULL )
142
        {
143
                /* Where is the data? */
144
                netbuf_data( pxRxBuffer, ( void * ) &pcRxString, &usLength );
145
 
146
                /* Is this a GET?  We don't handle anything else. */
147
                if( !strncmp( pcRxString, "GET", 3 ) )
148
                {
149
                        pcRxString = cDynamicPage;
150
 
151
                        /* Update the hit count. */
152
                        ulPageHits++;
153
                        sprintf( cPageHits, "%lu", ulPageHits );
154
 
155
                        /* Write out the HTTP OK header. */
156
            netconn_write(pxNetCon, webHTTP_OK, (u16_t)strlen( webHTTP_OK ), NETCONN_COPY );
157
 
158
                        /* Generate the dynamic page...
159
 
160
                        ... First the page header. */
161
                        strcpy( cDynamicPage, webHTML_START );
162
                        /* ... Then the hit count... */
163
                        strcat( cDynamicPage, cPageHits );
164
                        strcat( cDynamicPage, "<p><pre>Task          State  Priority  Stack     #<br>************************************************<br>" );
165
                        /* ... Then the list of tasks and their status... */
166
                        vTaskList( ( signed char * ) cDynamicPage + strlen( cDynamicPage ) );
167
                        /* ... Finally the page footer. */
168
                        strcat( cDynamicPage, webHTML_END );
169
 
170
                        /* Write out the dynamically generated page. */
171
                        netconn_write(pxNetCon, cDynamicPage, (u16_t)strlen( cDynamicPage ), NETCONN_COPY );
172
                }
173
 
174
                netbuf_delete( pxRxBuffer );
175
        }
176
 
177
        netconn_close( pxNetCon );
178
}
179
/*------------------------------------------------------------*/
180
 
181
void vlwIPInit( void )
182
{
183
    /* Initialize lwIP and its interface layer. */
184
        sys_init();
185
        mem_init();
186
        memp_init();
187
        pbuf_init();
188
        netif_init();
189
        ip_init();
190
        tcpip_init( NULL, NULL );
191
}
192
/*------------------------------------------------------------*/
193
 
194
void vBasicWEBServer( void *pvParameters )
195
{
196
struct netconn *pxHTTPListener, *pxNewConnection;
197
struct ip_addr xIpAddr, xNetMast, xGateway;
198
extern err_t ethernetif_init( struct netif *netif );
199
static struct netif EMAC_if;
200
 
201
        /* Parameters are not used - suppress compiler error. */
202
        ( void ) pvParameters;
203
 
204
 
205
        /* Create and configure the EMAC interface. */
206
        IP4_ADDR(&xIpAddr,emacIPADDR0,emacIPADDR1,emacIPADDR2,emacIPADDR3);
207
        IP4_ADDR(&xNetMast,emacNET_MASK0,emacNET_MASK1,emacNET_MASK2,emacNET_MASK3);
208
        IP4_ADDR(&xGateway,emacGATEWAY_ADDR0,emacGATEWAY_ADDR1,emacGATEWAY_ADDR2,emacGATEWAY_ADDR3);
209
        netif_add(&EMAC_if, &xIpAddr, &xNetMast, &xGateway, NULL, ethernetif_init, tcpip_input);
210
 
211
        /* make it the default interface */
212
    netif_set_default(&EMAC_if);
213
 
214
        /* bring it up */
215
    netif_set_up(&EMAC_if);
216
 
217
        /* Create a new tcp connection handle */
218
 
219
        pxHTTPListener = netconn_new( NETCONN_TCP );
220
        netconn_bind(pxHTTPListener, NULL, webHTTP_PORT );
221
        netconn_listen( pxHTTPListener );
222
 
223
        /* Loop forever */
224
        for( ;; )
225
        {
226
                /* Wait for connection. */
227
                pxNewConnection = netconn_accept(pxHTTPListener);
228
 
229
                if(pxNewConnection != NULL)
230
                {
231
                        /* Service connection. */
232
                        vProcessConnection( pxNewConnection );
233
                        while( netconn_delete( pxNewConnection ) != ERR_OK )
234
                        {
235
                                vTaskDelay( webSHORT_DELAY );
236
                        }
237
                }
238
        }
239
}
240
 
241
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.