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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Demo/] [SuperH_SH7216_Renesas/] [RTOSDemo/] [uIP_Task.c] - Blame information for rev 724

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

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

powered by: WebSVN 2.1.0

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