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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Demo/] [lwIP_MCF5235_GCC/] [web.c] - Blame information for rev 583

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 583 jeremybenn
/*
2
    FreeRTOS V4.6.1 - copyright (C) 2003-2006 Richard Barry.
3
 
4
    This file is part of the FreeRTOS distribution.
5
 
6
    FreeRTOS is free software; you can redistribute it and/or modify
7
    it under the terms of the GNU General Public License** as published by
8
    the Free Software Foundation; either version 2 of the License, or
9
    (at your option) any later version.
10
 
11
    FreeRTOS is distributed in the hope that it will be useful,
12
    but WITHOUT ANY WARRANTY; without even the implied warranty of
13
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
    GNU General Public License for more details.
15
 
16
    You should have received a copy of the GNU General Public License
17
    along with FreeRTOS; if not, write to the Free Software
18
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19
 
20
    A special exception to the GPL can be applied should you wish to distribute
21
    a combined work that includes FreeRTOS, without being obliged to provide
22
    the source code for any proprietary components.  See the licensing section
23
    of http://www.FreeRTOS.org for full details of how and when the exception
24
    can be applied.
25
 
26
    ***************************************************************************
27
    ***************************************************************************
28
    *                                                                         *
29
    * Get the FreeRTOS eBook!  See http://www.FreeRTOS.org/Documentation      *
30
        *                                                                         *
31
        * This is a concise, step by step, 'hands on' guide that describes both   *
32
        * general multitasking concepts and FreeRTOS specifics. It presents and   *
33
        * explains numerous examples that are written using the FreeRTOS API.     *
34
        * Full source code for all the examples is provided in an accompanying    *
35
        * .zip file.                                                              *
36
    *                                                                         *
37
    ***************************************************************************
38
    ***************************************************************************
39
 
40
        Please ensure to read the configuration and relevant port sections of the
41
        online documentation.
42
 
43
        http://www.FreeRTOS.org - Documentation, latest information, license and
44
        contact details.
45
 
46
        http://www.SafeRTOS.com - A version that is certified for use in safety
47
        critical systems.
48
 
49
        http://www.OpenRTOS.com - Commercial support, development, porting,
50
        licensing and training services.
51
*/
52
 
53
/*
54
    Implements a simplistic WEB server.  Every time a connection is made and
55
    data is received a dynamic page that shows the current TCP/IP statistics
56
    is generated and returned.  The connection is then closed.
57
 
58
    This file was adapted from a FreeRTOS lwIP slip demo supplied by a third
59
    party.
60
*/
61
 
62
/* ------------------------ System includes ------------------------------- */
63
#include <stdio.h>
64
#include <string.h>
65
 
66
/* ------------------------ FreeRTOS includes ----------------------------- */
67
#include "FreeRTOS.h"
68
#include "task.h"
69
#include "semphr.h"
70
 
71
/* ------------------------ lwIP includes --------------------------------- */
72
#include "lwip/api.h"
73
#include "lwip/tcpip.h"
74
#include "lwip/memp.h"
75
#include "lwip/stats.h"
76
#include "netif/loopif.h"
77
 
78
/* ------------------------ Project includes ------------------------------ */
79
#include "mcf5xxx.h"
80
#include "mcf523x.h"
81
#include "netif/fec.h"
82
 
83
#include "web.h"
84
 
85
/* ------------------------ Defines --------------------------------------- */
86
/* The size of the buffer in which the dynamic WEB page is created. */
87
#define webMAX_PAGE_SIZE        ( 2048 )
88
 
89
/* Standard GET response. */
90
#define webHTTP_OK  "HTTP/1.0 200 OK\r\nContent-type: text/html\r\n\r\n"
91
 
92
/* The port on which we listen. */
93
#define webHTTP_PORT            ( 80 )
94
 
95
/* Delay on close error. */
96
#define webSHORT_DELAY          ( 10 )
97
 
98
/* Format of the dynamic page that is returned on each connection. */
99
#define webHTML_START \
100
"<html>\
101
<head>\
102
</head>\
103
<BODY onLoad=\"window.setTimeout(&quot;location.href='index.html'&quot;,1000)\"bgcolor=\"#CCCCff\">\
104
\r\nPage Hits = "
105
 
106
#define webHTML_END \
107
"\r\n" \
108
"FreeRTOS MCF5235 port (c) 2006 by Christian Walter &lt;wolti@sil.at&gt;\r\n" \
109
"</pre>\r\n" \
110
"</BODY>\r\n" \
111
"</html>"
112
 
113
/* ------------------------ Prototypes ------------------------------------ */
114
static void     vProcessConnection( struct netconn *pxNetCon );
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
127
vProcessConnection( struct netconn *pxNetCon )
128
{
129
    static char cDynamicPage[webMAX_PAGE_SIZE], cPageHits[11];
130
    struct netbuf  *pxRxBuffer;
131
    char       *pcRxString;
132
    unsigned short usLength;
133
    static unsigned long ulPageHits = 0;
134
 
135
    /* We expect to immediately get data. */
136
    pxRxBuffer = netconn_recv( pxNetCon );
137
 
138
    if( pxRxBuffer != NULL )
139
    {
140
        /* Where is the data? */
141
        netbuf_data( pxRxBuffer, ( void * )&pcRxString, &usLength );
142
 
143
        /* Is this a GET?  We don't handle anything else. */
144
        if( !strncmp( pcRxString, "GET", 3 ) )
145
        {
146
            pcRxString = cDynamicPage;
147
 
148
            /* Update the hit count. */
149
            ulPageHits++;
150
            sprintf( cPageHits, "%lu", ulPageHits );
151
 
152
            /* Write out the HTTP OK header. */
153
            netconn_write( pxNetCon, webHTTP_OK, ( u16_t ) strlen( webHTTP_OK ), NETCONN_COPY );
154
 
155
            /* Generate the dynamic page...
156
 
157
               ... First the page header. */
158
            strcpy( cDynamicPage, webHTML_START );
159
            /* ... Then the hit count... */
160
            strcat( cDynamicPage, cPageHits );
161
            strcat( cDynamicPage,
162
                    "<p><pre>Task          State  Priority  Stack #<br>************************************************<br>" );
163
            /* ... Then the list of tasks and their status... */
164
            vTaskList( ( signed char * )cDynamicPage + strlen( cDynamicPage ) );
165
            /* ... Finally the page footer. */
166
            strcat( cDynamicPage, webHTML_END );
167
 
168
            /* Write out the dynamically generated page. */
169
            netconn_write( pxNetCon, cDynamicPage, ( u16_t ) strlen( cDynamicPage ), NETCONN_COPY );
170
        }
171
 
172
        netbuf_delete( pxRxBuffer );
173
    }
174
 
175
    netconn_close( pxNetCon );
176
}
177
 
178
/*------------------------------------------------------------*/
179
 
180
void
181
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
 
195
void
196
vBasicWEBServer( void *pvParameters )
197
{
198
    struct netconn *pxHTTPListener, *pxNewConnection;
199
    struct ip_addr  xIpAddr, xNetMast, xGateway;
200
    static struct netif fec523x_if;
201
 
202
    /* Parameters are not used - suppress compiler error. */
203
    ( void )pvParameters;
204
 
205
    /* Create and configure the EMAC interface. */
206
    IP4_ADDR( &xIpAddr, 10, 0, 10, 2 );
207
    IP4_ADDR( &xNetMast, 255, 255, 255, 0 );
208
    IP4_ADDR( &xGateway, 10, 0, 10, 1 );
209
    netif_add( &fec523x_if, &xIpAddr, &xNetMast, &xGateway, NULL, mcf523xfec_init, tcpip_input );
210
 
211
    /* make it the default interface */
212
    netif_set_default( &fec523x_if );
213
 
214
    /* bring it up */
215
    netif_set_up( &fec523x_if );
216
 
217
    /* Create a new tcp connection handle */
218
    pxHTTPListener = netconn_new( NETCONN_TCP );
219
    netconn_bind( pxHTTPListener, NULL, webHTTP_PORT );
220
    netconn_listen( pxHTTPListener );
221
 
222
    /* Loop forever */
223
    for( ;; )
224
    {
225
        /* Wait for connection. */
226
        pxNewConnection = netconn_accept( pxHTTPListener );
227
 
228
        if( pxNewConnection != NULL )
229
        {
230
            /* Service connection. */
231
            vProcessConnection( pxNewConnection );
232
            while( netconn_delete( pxNewConnection ) != ERR_OK )
233
            {
234
                vTaskDelay( webSHORT_DELAY );
235
            }
236
        }
237
    }
238
}

powered by: WebSVN 2.1.0

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