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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Demo/] [ColdFire_MCF52259_CodeWarrior/] [HTTPDemo.c] - Blame information for rev 578

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 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
/* ------------------------ System includes ------------------------------- */
64
 
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/ip.h"
75
#include "lwip/memp.h"
76
#include "lwip/stats.h"
77
#include "netif/loopif.h"
78
 
79
/* ------------------------ Project includes ------------------------------ */
80
#include "common.h"
81
 
82
#include "HTTPDemo.h"
83
 
84
/* ------------------------ Defines --------------------------------------- */
85
/* The size of the buffer in which the dynamic WEB page is created. */
86
#define webMAX_PAGE_SIZE        ( 1024 ) /*FSL: buffer containing array*/
87
 
88
/* Standard GET response. */
89
#define webHTTP_OK  "HTTP/1.0 200 OK\r\nContent-type: text/html\r\n\r\n"
90
 
91
/* The port on which we listen. */
92
#define webHTTP_PORT            ( 80 )
93
 
94
/* Delay on close error. */
95
#define webSHORT_DELAY          ( 10 )
96
 
97
/* Format of the dynamic page that is returned on each connection. */
98
#define webHTML_START \
99
"<html>\
100
<head>\
101
</head>\
102
<BODY onLoad=\"window.setTimeout(&quot;location.href='index.html'&quot;,1000)\"bgcolor=\"#CCCCff\">\
103
\r\n\r\nPage Hits = "
104
 
105
#define webHTML_END \
106
"\r\n" \
107
"</pre>\r\n" \
108
"</BODY>\r\n" \
109
"</html>"
110
 
111
#if INCLUDE_uxTaskGetStackHighWaterMark
112
        static volatile unsigned portBASE_TYPE uxHighWaterMark_web = 0;
113
#endif
114
 
115
/* ------------------------ Prototypes ------------------------------------ */
116
static void     vProcessConnection( struct netconn *pxNetCon );
117
 
118
/*------------------------------------------------------------*/
119
 
120
/*
121
 * Process an incoming connection on port 80.
122
 *
123
 * This simply checks to see if the incoming data contains a GET request, and
124
 * if so sends back a single dynamically created page.  The connection is then
125
 * closed.  A more complete implementation could create a task for each
126
 * connection.
127
 */
128
static void vProcessConnection( struct netconn *pxNetCon )
129
{
130
    static portCHAR cDynamicPage[webMAX_PAGE_SIZE], cPageHits[11];
131
    struct netbuf  *pxRxBuffer;
132
    portCHAR       *pcRxString;
133
    unsigned portSHORT usLength;
134
    static unsigned portLONG ulPageHits = 0;
135
 
136
    /* We expect to immediately get data. */
137
    pxRxBuffer = netconn_recv( pxNetCon );
138
 
139
    if( pxRxBuffer != NULL )
140
    {
141
        /* Where is the data? */
142
        netbuf_data( pxRxBuffer, ( void * )&pcRxString, &usLength );
143
 
144
        /* Is this a GET?  We don't handle anything else. */
145
        if( !strncmp( pcRxString, "GET", 3 ) )
146
        {
147
            pcRxString = cDynamicPage;
148
 
149
            /* Update the hit count. */
150
            ulPageHits++;
151
            sprintf( cPageHits, "%d", (int)ulPageHits );
152
 
153
            /* Write out the HTTP OK header. */
154
            netconn_write( pxNetCon, webHTTP_OK, ( u16_t ) strlen( webHTTP_OK ), NETCONN_COPY );
155
 
156
            /* Generate the dynamic page...
157
 
158
               ... First the page header. */
159
            strcpy( cDynamicPage, webHTML_START );
160
            /* ... Then the hit count... */
161
            strcat( cDynamicPage, cPageHits );
162
 
163
            strcat( cDynamicPage,
164
                    "<p><pre>Task          State  Priority  Stack      #<br>************************************************<br>" );
165
            /* ... Then the list of tasks and their status... */
166
            vTaskList( ( signed portCHAR * )cDynamicPage + strlen( cDynamicPage ) );
167
 
168
            /* ... Finally the page footer. */
169
            strcat( cDynamicPage, webHTML_END );
170
 
171
            /* Write out the dynamically generated page. */
172
            netconn_write( pxNetCon, cDynamicPage, ( u16_t ) strlen( cDynamicPage ), NETCONN_COPY );
173
        }
174
        netbuf_delete( pxRxBuffer );
175
    }
176
    netconn_close( pxNetCon );
177
}
178
 
179
/*------------------------------------------------------------*/
180
 
181
void vlwIPInit( void )
182
{
183
    /* Initialize lwIP and its interface layer. */
184
    tcpip_init( NULL, NULL );
185
}
186
 
187
/*------------------------------------------------------------*/
188
 
189
void vBasicWEBServer( void *pvParameters )
190
{
191
    struct netconn *pxHTTPListener, *pxNewConnection;
192
    struct ip_addr  xIpAddr, xNetMast, xGateway;
193
    static struct netif fec523x_if;
194
        extern err_t ethernetif_init(struct netif *netif);
195
 
196
    /* Parameters are not used - suppress compiler error. */
197
    ( void )pvParameters;
198
 
199
        vlwIPInit();
200
 
201
    /* Create and configure the FEC interface. */
202
    IP4_ADDR( &xIpAddr, configIP_ADDR0, configIP_ADDR1, configIP_ADDR2, configIP_ADDR3 );
203
    IP4_ADDR( &xNetMast, configNET_MASK0, configNET_MASK1, configNET_MASK2, configNET_MASK3 );
204
    IP4_ADDR( &xGateway, configGW_ADDR0, configGW_ADDR1, configGW_ADDR2, configGW_ADDR3 );
205
    netif_add( &fec523x_if, &xIpAddr, &xNetMast, &xGateway, NULL, ethernetif_init, tcpip_input );
206
 
207
    /* make it the default interface */
208
    netif_set_default( &fec523x_if );
209
 
210
    /* bring it up */
211
    netif_set_up( &fec523x_if );
212
 
213
    /* Create a new tcp connection handle */
214
    pxHTTPListener = netconn_new( NETCONN_TCP );
215
    netconn_bind( pxHTTPListener, NULL, webHTTP_PORT );
216
    netconn_listen( pxHTTPListener );
217
 
218
    /* Loop forever */
219
    for( ;; )
220
    {
221
        /* Wait for connection. */
222
        pxNewConnection = netconn_accept( pxHTTPListener );
223
 
224
        if( pxNewConnection != NULL )
225
        {
226
            /* Service connection. */
227
            vProcessConnection( pxNewConnection );
228
            while( netconn_delete( pxNewConnection ) != ERR_OK )
229
            {
230
                vTaskDelay( webSHORT_DELAY );
231
            }
232
        }
233
    }
234
}

powered by: WebSVN 2.1.0

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