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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Demo/] [ARM7_LPC2368_Eclipse/] [RTOSDemo/] [webserver/] [uIP_Task.c] - Blame information for rev 590

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

Line No. Rev Author Line
1 577 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
/* Standard includes. */
54
#include <string.h>
55
 
56
/* Scheduler includes. */
57
#include "FreeRTOS.h"
58
#include "task.h"
59
#include "semphr.h"
60
 
61
/* uip includes. */
62
#include "uip.h"
63
#include "uip_arp.h"
64
#include "httpd.h"
65
#include "timer.h"
66
#include "clock-arch.h"
67
 
68
/* Demo includes. */
69
#include "emac.h"
70
#include "partest.h"
71
 
72
/*-----------------------------------------------------------*/
73
 
74
/* MAC address configuration. */
75
#define uipMAC_ADDR0    0x00
76
#define uipMAC_ADDR1    0x12
77
#define uipMAC_ADDR2    0x13
78
#define uipMAC_ADDR3    0x10
79
#define uipMAC_ADDR4    0x15
80
#define uipMAC_ADDR5    0x11
81
 
82
/* IP address configuration. */
83
#define uipIP_ADDR0             172
84
#define uipIP_ADDR1             25
85
#define uipIP_ADDR2             218
86
#define uipIP_ADDR3             16      
87
 
88
/* How long to wait before attempting to connect the MAC again. */
89
#define uipINIT_WAIT    100
90
 
91
/* Shortcut to the header within the Rx buffer. */
92
#define xHeader ((struct uip_eth_hdr *) &uip_buf[ 0 ])
93
 
94
/* Standard constant. */
95
#define uipTOTAL_FRAME_HEADER_SIZE      54
96
 
97
/*-----------------------------------------------------------*/
98
 
99
/*
100
 * Send the uIP buffer to the MAC.
101
 */
102
static void prvENET_Send(void);
103
 
104
/*
105
 * Setup the MAC address in the MAC itself, and in the uIP stack.
106
 */
107
static void prvSetMACAddress( void );
108
 
109
/*
110
 * Port functions required by the uIP stack.
111
 */
112
void clock_init( void );
113
clock_time_t clock_time( void );
114
 
115
/*-----------------------------------------------------------*/
116
 
117
/* The semaphore used by the ISR to wake the uIP task. */
118
extern xSemaphoreHandle xEMACSemaphore;
119
 
120
/*-----------------------------------------------------------*/
121
 
122
void clock_init(void)
123
{
124
        /* This is done when the scheduler starts. */
125
}
126
/*-----------------------------------------------------------*/
127
 
128
clock_time_t clock_time( void )
129
{
130
        return xTaskGetTickCount();
131
}
132
/*-----------------------------------------------------------*/
133
 
134
void vuIP_Task( void *pvParameters )
135
{
136
portBASE_TYPE i;
137
uip_ipaddr_t xIPAddr;
138
struct timer periodic_timer, arp_timer;
139
extern void ( vEMAC_ISR_Wrapper )( void );
140
 
141
        /* Create the semaphore used by the ISR to wake this task. */
142
        vSemaphoreCreateBinary( xEMACSemaphore );
143
 
144
        /* Initialise the uIP stack. */
145
        timer_set( &periodic_timer, configTICK_RATE_HZ / 2 );
146
        timer_set( &arp_timer, configTICK_RATE_HZ * 10 );
147
        uip_init();
148
        uip_ipaddr( xIPAddr, uipIP_ADDR0, uipIP_ADDR1, uipIP_ADDR2, uipIP_ADDR3 );
149
        uip_sethostaddr( xIPAddr );
150
        httpd_init();
151
 
152
        /* Initialise the MAC. */
153
        while( Init_EMAC() != pdPASS )
154
    {
155
        vTaskDelay( uipINIT_WAIT );
156
    }
157
 
158
        portENTER_CRITICAL();
159
        {
160
                MAC_INTENABLE = INT_RX_DONE;
161
        VICIntEnable |= 0x00200000;
162
        VICVectAddr21 = ( portLONG ) vEMAC_ISR_Wrapper;
163
                prvSetMACAddress();
164
        }
165
        portEXIT_CRITICAL();
166
 
167
 
168
        for( ;; )
169
        {
170
                /* Is there received data ready to be processed? */
171
                uip_len = uiGetEMACRxData( uip_buf );
172
 
173
                if( uip_len > 0 )
174
                {
175
                        /* Standard uIP loop taken from the uIP manual. */
176
                        if( xHeader->type == htons( UIP_ETHTYPE_IP ) )
177
                        {
178
                                uip_arp_ipin();
179
                                uip_input();
180
 
181
                                /* If the above function invocation resulted in data that
182
                                should be sent out on the network, the global variable
183
                                uip_len is set to a value > 0. */
184
                                if( uip_len > 0 )
185
                                {
186
                                        uip_arp_out();
187
                                        prvENET_Send();
188
                                }
189
                        }
190
                        else if( xHeader->type == htons( UIP_ETHTYPE_ARP ) )
191
                        {
192
                                uip_arp_arpin();
193
 
194
                                /* If the above function invocation resulted in data that
195
                                should be sent out on the network, the global variable
196
                                uip_len is set to a value > 0. */
197
                                if( uip_len > 0 )
198
                                {
199
                                        prvENET_Send();
200
                                }
201
                        }
202
                }
203
                else
204
                {
205
                        if( timer_expired( &periodic_timer ) )
206
                        {
207
                                timer_reset( &periodic_timer );
208
                                for( i = 0; i < UIP_CONNS; i++ )
209
                                {
210
                                        uip_periodic( i );
211
 
212
                                        /* If the above function invocation resulted in data that
213
                                        should be sent out on the network, the global variable
214
                                        uip_len is set to a value > 0. */
215
                                        if( uip_len > 0 )
216
                                        {
217
                                                uip_arp_out();
218
                                                prvENET_Send();
219
                                        }
220
                                }
221
 
222
                                /* Call the ARP timer function every 10 seconds. */
223
                                if( timer_expired( &arp_timer ) )
224
                                {
225
                                        timer_reset( &arp_timer );
226
                                        uip_arp_timer();
227
                                }
228
                        }
229
                        else
230
                        {
231
                                /* We did not receive a packet, and there was no periodic
232
                                processing to perform.  Block for a fixed period.  If a packet
233
                                is received during this period we will be woken by the ISR
234
                                giving us the Semaphore. */
235
                                xSemaphoreTake( xEMACSemaphore, configTICK_RATE_HZ / 2 );
236
                        }
237
                }
238
        }
239
}
240
/*-----------------------------------------------------------*/
241
 
242
static void prvENET_Send(void)
243
{
244
    RequestSend();
245
 
246
    /* Copy the header into the Tx buffer. */
247
    CopyToFrame_EMAC( uip_buf, uipTOTAL_FRAME_HEADER_SIZE );
248
    if( uip_len > uipTOTAL_FRAME_HEADER_SIZE )
249
    {
250
        CopyToFrame_EMAC( uip_appdata, ( uip_len - uipTOTAL_FRAME_HEADER_SIZE ) );
251
    }
252
 
253
    DoSend_EMAC( uip_len );
254
}
255
/*-----------------------------------------------------------*/
256
 
257
static void prvSetMACAddress( void )
258
{
259
struct uip_eth_addr xAddr;
260
 
261
        /* Configure the MAC address in the uIP stack. */
262
        xAddr.addr[ 0 ] = uipMAC_ADDR0;
263
        xAddr.addr[ 1 ] = uipMAC_ADDR1;
264
        xAddr.addr[ 2 ] = uipMAC_ADDR2;
265
        xAddr.addr[ 3 ] = uipMAC_ADDR3;
266
        xAddr.addr[ 4 ] = uipMAC_ADDR4;
267
        xAddr.addr[ 5 ] = uipMAC_ADDR5;
268
        uip_setethaddr( xAddr );
269
}
270
/*-----------------------------------------------------------*/
271
 
272
void vApplicationProcessFormInput( portCHAR *pcInputString, portBASE_TYPE xInputLength )
273
{
274
char *c, *pcText;
275
static portCHAR cMessageForDisplay[ 32 ];
276
extern xQueueHandle xLCDQueue;
277
xLCDMessage xLCDMessage;
278
 
279
        /* Process the form input sent by the IO page of the served HTML. */
280
 
281
        c = strstr( pcInputString, "?" );
282
    if( c )
283
    {
284
                /* Turn LED's on or off in accordance with the check box status. */
285
                if( strstr( c, "LED0=1" ) != NULL )
286
                {
287
                        vParTestSetLED( 5, 0 );
288
                }
289
                else
290
                {
291
                        vParTestSetLED( 5, 1 );
292
                }
293
 
294
                if( strstr( c, "LED1=1" ) != NULL )
295
                {
296
                        vParTestSetLED( 6, 0 );
297
                }
298
                else
299
                {
300
                        vParTestSetLED( 6, 1 );
301
                }
302
 
303
                if( strstr( c, "LED2=1" ) != NULL )
304
                {
305
                        vParTestSetLED( 7, 0 );
306
                }
307
                else
308
                {
309
                        vParTestSetLED( 7, 1 );
310
                }
311
 
312
                /* Find the start of the text to be displayed on the LCD. */
313
        pcText = strstr( c, "LCD=" );
314
        pcText += strlen( "LCD=" );
315
 
316
        /* Terminate the file name for further processing within uIP. */
317
        *c = 0x00;
318
 
319
        /* Terminate the LCD string. */
320
        c = strstr( pcText, " " );
321
        if( c != NULL )
322
        {
323
            *c = 0x00;
324
        }
325
 
326
        /* Add required spaces. */
327
        while( ( c = strstr( pcText, "+" ) ) != NULL )
328
        {
329
            *c = ' ';
330
        }
331
 
332
        /* Write the message to the LCD. */
333
                strcpy( cMessageForDisplay, pcText );
334
                xLCDMessage.xColumn = 0;
335
                xLCDMessage.pcMessage = cMessageForDisplay;
336
        xQueueSend( xLCDQueue, &xLCDMessage, portMAX_DELAY );
337
    }
338
}
339
 

powered by: WebSVN 2.1.0

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