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

Subversion Repositories openrisc

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 581 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
/* uip includes. */
63
#include "uip.h"
64
#include "uip_arp.h"
65
#include "httpd.h"
66
#include "timer.h"
67
#include "clock-arch.h"
68
 
69
/* Demo includes. */
70
#include "EthDev_LPC17xx.h"
71
#include "EthDev.h"
72
#include "ParTest.h"
73
 
74
/*-----------------------------------------------------------*/
75
 
76
/* How long to wait before attempting to connect the MAC again. */
77
#define uipINIT_WAIT    ( 100 / portTICK_RATE_MS )
78
 
79
/* Shortcut to the header within the Rx buffer. */
80
#define xHeader ((struct uip_eth_hdr *) &uip_buf[ 0 ])
81
 
82
/* Standard constant. */
83
#define uipTOTAL_FRAME_HEADER_SIZE      54
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 = NULL;
102
 
103
/*-----------------------------------------------------------*/
104
 
105
void clock_init(void)
106
{
107
        /* This is done when the scheduler starts. */
108
}
109
/*-----------------------------------------------------------*/
110
 
111
clock_time_t clock_time( void )
112
{
113
        return xTaskGetTickCount();
114
}
115
/*-----------------------------------------------------------*/
116
 
117
void vuIP_Task( void *pvParameters )
118
{
119
portBASE_TYPE i;
120
uip_ipaddr_t xIPAddr;
121
struct timer periodic_timer, arp_timer;
122
extern void ( vEMAC_ISR_Wrapper )( void );
123
 
124
        ( void ) pvParameters;
125
 
126
        /* Initialise the uIP stack. */
127
        timer_set( &periodic_timer, configTICK_RATE_HZ / 2 );
128
        timer_set( &arp_timer, configTICK_RATE_HZ * 10 );
129
        uip_init();
130
        uip_ipaddr( xIPAddr, configIP_ADDR0, configIP_ADDR1, configIP_ADDR2, configIP_ADDR3 );
131
        uip_sethostaddr( xIPAddr );
132
        uip_ipaddr( xIPAddr, configNET_MASK0, configNET_MASK1, configNET_MASK2, configNET_MASK3 );
133
        uip_setnetmask( xIPAddr );
134
        httpd_init();
135
 
136
        /* Create the semaphore used to wake the uIP task. */
137
        vSemaphoreCreateBinary( xEMACSemaphore );
138
 
139
        /* Initialise the MAC. */
140
        while( lEMACInit() != pdPASS )
141
    {
142
        vTaskDelay( uipINIT_WAIT );
143
    }
144
 
145
        portENTER_CRITICAL();
146
        {
147
                EMAC->IntEnable = ( INT_RX_DONE | INT_TX_DONE );
148
 
149
                /* Set the interrupt priority to the max permissible to cause some
150
                interrupt nesting. */
151
                NVIC_SetPriority( ENET_IRQn, configEMAC_INTERRUPT_PRIORITY );
152
 
153
                /* Enable the interrupt. */
154
                NVIC_EnableIRQ( ENET_IRQn );
155
                prvSetMACAddress();
156
        }
157
        portEXIT_CRITICAL();
158
 
159
 
160
        for( ;; )
161
        {
162
                /* Is there received data ready to be processed? */
163
                uip_len = ulGetEMACRxData();
164
 
165
                if( ( uip_len > 0 ) && ( uip_buf != NULL ) )
166
                {
167
                        /* Standard uIP loop taken from the uIP manual. */
168
                        if( xHeader->type == htons( UIP_ETHTYPE_IP ) )
169
                        {
170
                                uip_arp_ipin();
171
                                uip_input();
172
 
173
                                /* If the above function invocation resulted in data that
174
                                should be sent out on the network, the global variable
175
                                uip_len is set to a value > 0. */
176
                                if( uip_len > 0 )
177
                                {
178
                                        uip_arp_out();
179
                                        vSendEMACTxData( uip_len );
180
                                }
181
                        }
182
                        else if( xHeader->type == htons( UIP_ETHTYPE_ARP ) )
183
                        {
184
                                uip_arp_arpin();
185
 
186
                                /* If the above function invocation resulted in data that
187
                                should be sent out on the network, the global variable
188
                                uip_len is set to a value > 0. */
189
                                if( uip_len > 0 )
190
                                {
191
                                        vSendEMACTxData( uip_len );
192
                                }
193
                        }
194
                }
195
                else
196
                {
197
                        if( timer_expired( &periodic_timer ) && ( uip_buf != NULL ) )
198
                        {
199
                                timer_reset( &periodic_timer );
200
                                for( i = 0; i < UIP_CONNS; i++ )
201
                                {
202
                                        uip_periodic( i );
203
 
204
                                        /* If the above function invocation resulted in data that
205
                                        should be sent out on the network, the global variable
206
                                        uip_len is set to a value > 0. */
207
                                        if( uip_len > 0 )
208
                                        {
209
                                                uip_arp_out();
210
                                                vSendEMACTxData( uip_len );
211
                                        }
212
                                }
213
 
214
                                /* Call the ARP timer function every 10 seconds. */
215
                                if( timer_expired( &arp_timer ) )
216
                                {
217
                                        timer_reset( &arp_timer );
218
                                        uip_arp_timer();
219
                                }
220
                        }
221
                        else
222
                        {
223
                                /* We did not receive a packet, and there was no periodic
224
                                processing to perform.  Block for a fixed period.  If a packet
225
                                is received during this period we will be woken by the ISR
226
                                giving us the Semaphore. */
227
                                xSemaphoreTake( xEMACSemaphore, configTICK_RATE_HZ / 2 );
228
                        }
229
                }
230
        }
231
}
232
/*-----------------------------------------------------------*/
233
 
234
static void prvSetMACAddress( void )
235
{
236
struct uip_eth_addr xAddr;
237
 
238
        /* Configure the MAC address in the uIP stack. */
239
        xAddr.addr[ 0 ] = configMAC_ADDR0;
240
        xAddr.addr[ 1 ] = configMAC_ADDR1;
241
        xAddr.addr[ 2 ] = configMAC_ADDR2;
242
        xAddr.addr[ 3 ] = configMAC_ADDR3;
243
        xAddr.addr[ 4 ] = configMAC_ADDR4;
244
        xAddr.addr[ 5 ] = configMAC_ADDR5;
245
        uip_setethaddr( xAddr );
246
}
247
/*-----------------------------------------------------------*/
248
 
249
void vApplicationProcessFormInput( char *pcInputString )
250
{
251
char *c;
252
extern void vParTestSetLEDState( long lState );
253
 
254
        /* Process the form input sent by the IO page of the served HTML. */
255
 
256
        c = strstr( pcInputString, "?" );
257
    if( c )
258
    {
259
                /* Turn the FIO1 LED's on or off in accordance with the check box status. */
260
                if( strstr( c, "LED0=1" ) != NULL )
261
                {
262
                        vParTestSetLEDState( pdTRUE );
263
                }
264
                else
265
                {
266
                        vParTestSetLEDState( pdFALSE );
267
                }
268
    }
269
}
270
 

powered by: WebSVN 2.1.0

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