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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Demo/] [lwIP_AVR32_UC3/] [NETWORK/] [BasicWEB/] [BasicWEB.c] - Blame information for rev 615

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

Line No. Rev Author Line
1 583 jeremybenn
/*This file has been prepared for Doxygen automatic documentation generation.*/
2
/*! \file *********************************************************************
3
 *
4
 * \brief Basic WEB Server for AVR32 UC3.
5
 *
6
 * - Compiler:           GNU GCC for AVR32
7
 * - Supported devices:  All AVR32 devices can be used.
8
 * - AppNote:
9
 *
10
 * \author               Atmel Corporation: http://www.atmel.com \n
11
 *                       Support and FAQ: http://support.atmel.no/
12
 *
13
 *****************************************************************************/
14
 
15
/* Copyright (c) 2007, Atmel Corporation All rights reserved.
16
 *
17
 * Redistribution and use in source and binary forms, with or without
18
 * modification, are permitted provided that the following conditions are met:
19
 *
20
 * 1. Redistributions of source code must retain the above copyright notice,
21
 * this list of conditions and the following disclaimer.
22
 *
23
 * 2. Redistributions in binary form must reproduce the above copyright notice,
24
 * this list of conditions and the following disclaimer in the documentation
25
 * and/or other materials provided with the distribution.
26
 *
27
 * 3. The name of ATMEL may not be used to endorse or promote products derived
28
 * from this software without specific prior written permission.
29
 *
30
 * THIS SOFTWARE IS PROVIDED BY ATMEL ``AS IS'' AND ANY EXPRESS OR IMPLIED
31
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
32
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY AND
33
 * SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT,
34
 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
35
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
36
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
37
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
39
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40
 */
41
 
42
 
43
/*
44
  Implements a simplistic WEB server.  Every time a connection is made and
45
  data is received a dynamic page that shows the current FreeRTOS.org kernel
46
  statistics is generated and returned.  The connection is then closed.
47
 
48
  This file was adapted from a FreeRTOS lwIP slip demo supplied by a third
49
  party.
50
*/
51
 
52
#if (HTTP_USED == 1)
53
 
54
 
55
/* Standard includes. */
56
#include <stdio.h>
57
#include <string.h>
58
 
59
#include "conf_eth.h"
60
 
61
/* Scheduler includes. */
62
#include "FreeRTOS.h"
63
#include "task.h"
64
#include "semphr.h"
65
#include "partest.h"
66
#include "serial.h"
67
 
68
/* Demo includes. */
69
/* Demo app includes. */
70
#include "portmacro.h"
71
 
72
/* lwIP includes. */
73
#include "lwip/api.h"
74
#include "lwip/tcpip.h"
75
#include "lwip/memp.h"
76
#include "lwip/stats.h"
77
#include "netif/loopif.h"
78
 
79
/* ethernet includes */
80
#include "ethernet.h"
81
 
82
/*! The size of the buffer in which the dynamic WEB page is created. */
83
#define webMAX_PAGE_SIZE        512
84
 
85
/*! Standard GET response. */
86
#define webHTTP_OK      "HTTP/1.0 200 OK\r\nContent-type: text/html\r\n\r\n"
87
 
88
/*! The port on which we listen. */
89
#define webHTTP_PORT            ( 80 )
90
 
91
/*! Delay on close error. */
92
#define webSHORT_DELAY          ( 10 )
93
 
94
/*! Format of the dynamic page that is returned on each connection. */
95
#define webHTML_START \
96
"<html>\
97
<head>\
98
</head>\
99
<BODY onLoad=\"window.setTimeout(&quot;location.href='index.html'&quot;,1000)\" bgcolor=\"#FFFFFF\" text=\"#2477E6\">\
100
\r\nPage Hits = "
101
 
102
#define webHTML_END \
103
"\r\n</pre>\
104
\r\n</font></BODY>\
105
</html>"
106
 
107
portCHAR cDynamicPage[ webMAX_PAGE_SIZE ];
108
portCHAR cPageHits[ 11 ];
109
 
110
 
111
/*! Function to process the current connection */
112
static void prvweb_ParseHTMLRequest( struct netconn *pxNetCon );
113
 
114
 
115
/*! \brief WEB server main task
116
 *         check for incoming connection and process it
117
 *
118
 *  \param pvParameters   Input. Not Used.
119
 *
120
 */
121
portTASK_FUNCTION( vBasicWEBServer, pvParameters )
122
{
123
struct netconn *pxHTTPListener, *pxNewConnection;
124
 
125
        /* Create a new tcp connection handle */
126
        pxHTTPListener = netconn_new( NETCONN_TCP );
127
        netconn_bind(pxHTTPListener, NULL, webHTTP_PORT );
128
        netconn_listen( pxHTTPListener );
129
 
130
        /* Loop forever */
131
        for( ;; )
132
        {
133
                /* Wait for a first connection. */
134
                pxNewConnection = netconn_accept(pxHTTPListener);
135
                vParTestSetLED(webCONN_LED, pdTRUE);
136
 
137
                if(pxNewConnection != NULL)
138
                {
139
                        prvweb_ParseHTMLRequest(pxNewConnection);
140
                }/* end if new connection */
141
 
142
                vParTestSetLED(webCONN_LED, pdFALSE);
143
 
144
        } /* end infinite loop */
145
}
146
 
147
 
148
/*! \brief parse the incoming request
149
 *         parse the HTML request and send file
150
 *
151
 *  \param pxNetCon   Input. The netconn to use to send and receive data.
152
 *
153
 */
154
static void prvweb_ParseHTMLRequest( struct netconn *pxNetCon )
155
{
156
struct netbuf *pxRxBuffer;
157
portCHAR *pcRxString;
158
unsigned portSHORT usLength;
159
static unsigned portLONG ulPageHits = 0;
160
 
161
        /* We expect to immediately get data. */
162
        pxRxBuffer = netconn_recv( pxNetCon );
163
 
164
        if( pxRxBuffer != NULL )
165
        {
166
                /* Where is the data? */
167
                netbuf_data( pxRxBuffer, ( void * ) &pcRxString, &usLength );
168
 
169
                /* Is this a GET?  We don't handle anything else. */
170
                if( !strncmp( pcRxString, "GET", 3 ) )
171
                {
172
                        pcRxString = cDynamicPage;
173
 
174
                        /* Update the hit count. */
175
                        ulPageHits++;
176
                        sprintf( cPageHits, "%d", (int)ulPageHits );
177
 
178
                        /* Write out the HTTP OK header. */
179
                        netconn_write( pxNetCon, webHTTP_OK, (u16_t) strlen( webHTTP_OK ), NETCONN_COPY );
180
 
181
                        /* Generate the dynamic page... First the page header. */
182
                        strcpy( cDynamicPage, webHTML_START );
183
 
184
                        /* ... Then the hit count... */
185
                        strcat( cDynamicPage, cPageHits );
186
                        strcat( cDynamicPage, "<p><pre>Task          State  Priority  Stack     #<br>************************************************<br>" );
187
 
188
                        /* ... Then the list of tasks and their status... */
189
                        vTaskList( ( signed portCHAR * ) cDynamicPage + strlen( cDynamicPage ) );
190
 
191
                        /* ... Finally the page footer. */
192
                        strcat( cDynamicPage, webHTML_END );
193
 
194
                        /* Write out the dynamically generated page. */
195
                        netconn_write( pxNetCon, cDynamicPage, (u16_t) strlen( cDynamicPage ), NETCONN_COPY );
196
                }
197
                netbuf_delete( pxRxBuffer );
198
        }
199
 
200
        netconn_close( pxNetCon );
201
        netconn_delete( pxNetCon );
202
}
203
 
204
#endif
205
 

powered by: WebSVN 2.1.0

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