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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Demo/] [CORTEX_STM32F107_GCC_Rowley/] [webserver/] [uIP_Task.c] - Blame information for rev 582

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 582 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
/* Standard includes. */
55
#include <string.h>
56
 
57
/* Scheduler includes. */
58
#include "FreeRTOS.h"
59
#include "task.h"
60
#include "semphr.h"
61
 
62
/* Demo includes. */
63
#include "emac.h"
64
#include "partest.h"
65
 
66
/* uip includes. */
67
#include "uip.h"
68
#include "uip_arp.h"
69
#include "httpd.h"
70
#include "timer.h"
71
#include "clock-arch.h"
72
 
73
/*-----------------------------------------------------------*/
74
 
75
/* How long to wait before attempting to connect the MAC again. */
76
#define uipINIT_WAIT                            ( 100 / portTICK_RATE_MS )
77
 
78
/* Shortcut to the header within the Rx buffer. */
79
#define xHeader ((struct uip_eth_hdr *) &uip_buf[ 0 ])
80
 
81
/* Standard constant. */
82
#define uipTOTAL_FRAME_HEADER_SIZE      54
83
 
84
 
85
/*-----------------------------------------------------------*/
86
 
87
/*
88
 * Setup the MAC address in the MAC itself, and in the uIP stack.
89
 */
90
static void prvSetMACAddress( void );
91
 
92
/*
93
 * Port functions required by the uIP stack.
94
 */
95
void clock_init( void );
96
clock_time_t clock_time( void );
97
 
98
/*-----------------------------------------------------------*/
99
 
100
/* The semaphore used by the ISR to wake the uIP task. */
101
xSemaphoreHandle xEMACSemaphore;
102
 
103
/* The buffer used by the uIP stack.  In this case the pointer is used to
104
point to one of the Rx buffers. */
105
unsigned char *uip_buf = NULL;
106
 
107
/*-----------------------------------------------------------*/
108
 
109
void clock_init(void)
110
{
111
        /* This is done when the scheduler starts. */
112
}
113
/*-----------------------------------------------------------*/
114
 
115
clock_time_t clock_time( void )
116
{
117
        return xTaskGetTickCount();
118
}
119
/*-----------------------------------------------------------*/
120
 
121
void vuIP_Task( void *pvParameters )
122
{
123
portBASE_TYPE i;
124
uip_ipaddr_t xIPAddr;
125
struct timer periodic_timer, arp_timer;
126
 
127
        ( void ) pvParameters;
128
 
129
        /* Create the semaphore used by the ISR to wake this task. */
130
        vSemaphoreCreateBinary( xEMACSemaphore );
131
 
132
        /* Initialise the uIP stack. */
133
        timer_set( &periodic_timer, configTICK_RATE_HZ / 2 );
134
        timer_set( &arp_timer, configTICK_RATE_HZ * 10 );
135
        uip_init();
136
        uip_ipaddr( xIPAddr, configIP_ADDR0, configIP_ADDR1, configIP_ADDR2, configIP_ADDR3 );
137
        uip_sethostaddr( xIPAddr );
138
        uip_ipaddr( xIPAddr, configNET_MASK0, configNET_MASK1, configNET_MASK2, configNET_MASK3 );
139
        uip_setnetmask( xIPAddr );
140
        httpd_init();
141
 
142
        /* Initialise the MAC. */
143
        while( xEthInitialise() != pdPASS )
144
        {
145
                vTaskDelay( uipINIT_WAIT );
146
        }
147
 
148
        prvSetMACAddress();
149
 
150
        for( ;; )
151
        {
152
                /* Is there received data ready to be processed? */
153
                uip_len = usGetMACRxData();
154
 
155
                if( ( uip_len > 0 ) && ( uip_buf != NULL ) )
156
                {
157
                        /* Standard uIP loop taken from the uIP manual. */
158
                        if( xHeader->type == htons( UIP_ETHTYPE_IP ) )
159
                        {
160
                                uip_arp_ipin();
161
                                uip_input();
162
 
163
                                /* If the above function invocation resulted in data that
164
                                should be sent out on the network, the global variable
165
                                uip_len is set to a value > 0. */
166
                                if( uip_len > 0 )
167
                                {
168
                                        uip_arp_out();
169
                                        vSendMACData( uip_len );
170
                                }
171
                        }
172
                        else if( xHeader->type == htons( UIP_ETHTYPE_ARP ) )
173
                        {
174
                                uip_arp_arpin();
175
 
176
                                /* If the above function invocation resulted in data that
177
                                should be sent out on the network, the global variable
178
                                uip_len is set to a value > 0. */
179
                                if( uip_len > 0 )
180
                                {
181
                                        vSendMACData( uip_len );
182
                                }
183
                        }
184
                }
185
                else
186
                {
187
                        if( ( timer_expired( &periodic_timer ) ) && ( uip_buf != NULL ) )
188
                        {
189
                                timer_reset( &periodic_timer );
190
                                for( i = 0; i < UIP_CONNS; i++ )
191
                                {
192
                                        uip_periodic( i );
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
                                                uip_arp_out();
200
                                                vSendMACData( uip_len );
201
                                        }
202
                                }
203
 
204
                                /* Call the ARP timer function every 10 seconds. */
205
                                if( timer_expired( &arp_timer ) )
206
                                {
207
                                        timer_reset( &arp_timer );
208
                                        uip_arp_timer();
209
                                }
210
                        }
211
                        else
212
                        {
213
                                /* We did not receive a packet, and there was no periodic
214
                                processing to perform.  Block for a fixed period.  If a packet
215
                                is received during this period we will be woken by the ISR
216
                                giving us the Semaphore. */
217
                                xSemaphoreTake( xEMACSemaphore, configTICK_RATE_HZ / 2 );
218
                        }
219
                }
220
        }
221
}
222
/*-----------------------------------------------------------*/
223
 
224
static void prvSetMACAddress( void )
225
{
226
struct uip_eth_addr xAddr;
227
 
228
        /* Configure the MAC address in the uIP stack. */
229
        xAddr.addr[ 0 ] = configMAC_ADDR0;
230
        xAddr.addr[ 1 ] = configMAC_ADDR1;
231
        xAddr.addr[ 2 ] = configMAC_ADDR2;
232
        xAddr.addr[ 3 ] = configMAC_ADDR3;
233
        xAddr.addr[ 4 ] = configMAC_ADDR4;
234
        xAddr.addr[ 5 ] = configMAC_ADDR5;
235
        uip_setethaddr( xAddr );
236
}
237
/*-----------------------------------------------------------*/
238
 
239
void vApplicationProcessFormInput( char *pcInputString )
240
{
241
char *c, *pcText;
242
static char cMessageForDisplay[ 32 ];
243
static const char *pcMessage = cMessageForDisplay;
244
extern xQueueHandle xLCDQueue;
245
 
246
        /* Process the form input sent by the IO page of the served HTML. */
247
 
248
        c = strstr( pcInputString, "?" );
249
    if( c )
250
    {
251
                /* Turn LED's on or off in accordance with the check box status. */
252
                if( strstr( c, "LED0=1" ) != NULL )
253
                {
254
                        /* Set LED4. */
255
                        vParTestSetLED( 3, 1 );
256
                }
257
                else
258
                {
259
                        /* Clear LED4. */
260
                        vParTestSetLED( 3, 0 );
261
                }
262
 
263
                /* Find the start of the text to be displayed on the LCD. */
264
        pcText = strstr( c, "LCD=" );
265
        pcText += strlen( "LCD=" );
266
 
267
        /* Terminate the file name for further processing within uIP. */
268
        *c = 0x00;
269
 
270
        /* Terminate the LCD string. */
271
        c = strstr( pcText, " " );
272
        if( c != NULL )
273
        {
274
            *c = 0x00;
275
        }
276
 
277
        /* Add required spaces. */
278
        while( ( c = strstr( pcText, "+" ) ) != NULL )
279
        {
280
            *c = ' ';
281
        }
282
 
283
        /* Write the message to the LCD. */
284
                strcpy( cMessageForDisplay, pcText );
285
        xQueueSend( xLCDQueue, &pcMessage, portMAX_DELAY );
286
    }
287
}
288
 

powered by: WebSVN 2.1.0

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