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

Subversion Repositories openrisc

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 577 jeremybenn
/*
2
 * Modified from an original work that is Copyright (c) 2001-2003, Adam Dunkels.
3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
7
 * are met:
8
 * 1. Redistributions of source code must retain the above copyright
9
 *    notice, this list of conditions and the following disclaimer.
10
 * 2. Redistributions in binary form must reproduce the above copyright
11
 *    notice, this list of conditions and the following disclaimer in the
12
 *    documentation and/or other materials provided with the distribution.
13
 * 3. The name of the author may not be used to endorse or promote
14
 *    products derived from this software without specific prior
15
 *    written permission.
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
18
 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
21
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
23
 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
 *
29
 * This file is part of the uIP TCP/IP stack.
30
 *
31
 * $Id: uIP_Task.c 2 2011-07-17 20:13:17Z filepang@gmail.com $
32
 *
33
 */
34
 
35
/* Standard includes. */
36
#include <stdlib.h>
37
#include <string.h>
38
#include <stdio.h>
39
 
40
/* Scheduler includes. */
41
#include "FreeRTOS.h"
42
#include "task.h"
43
#include "semphr.h"
44
 
45
/* uip includes. */
46
#include "uip.h"
47
#include "uip_arp.h"
48
#include "httpd.h"
49
#include "timer.h"
50
#include "clock-arch.h"
51
 
52
/* Demo includes. */
53
#include "SAM7_EMAC.h"
54
#include "partest.h"
55
 
56
/* How long to wait before attempting to connect the MAC again. */
57
#define uipINIT_WAIT    ( 100 / portTICK_RATE_MS )
58
 
59
/* Shortcut to the header within the Rx buffer. */
60
#define xHeader ((struct uip_eth_hdr *) &uip_buf[ 0 ])
61
 
62
/* The semaphore used by the ISR to wake the uIP task. */
63
static xSemaphoreHandle xEMACSemaphore;
64
 
65
/*-----------------------------------------------------------*/
66
 
67
void vuIP_Task( void *pvParameters )
68
{
69
portBASE_TYPE i;
70
uip_ipaddr_t xIPAddr;
71
struct timer periodic_timer, arp_timer;
72
 
73
        /* Initialise the uIP stack. */
74
        timer_set( &periodic_timer, configTICK_RATE_HZ / 2 );
75
        timer_set( &arp_timer, configTICK_RATE_HZ * 10 );
76
        uip_init();
77
        uip_ipaddr( xIPAddr, uipIP_ADDR0, uipIP_ADDR1, uipIP_ADDR2, uipIP_ADDR3 );
78
        uip_sethostaddr( xIPAddr );
79
        httpd_init();
80
 
81
        /* Initialise the MAC. */
82
        do
83
    {
84
                vTaskDelay( uipINIT_WAIT );
85
                xEMACSemaphore = xEMACInit();
86
    } while( xEMACSemaphore == NULL );
87
 
88
        for( ;; )
89
        {
90
                /* Is there received data ready to be processed? */
91
                uip_len = ulEMACPoll();
92
 
93
                if( uip_len > 0 )
94
                {
95
                        /* Standard uIP loop taken from the uIP manual. */
96
                        if( xHeader->type == htons( UIP_ETHTYPE_IP ) )
97
                        {
98
                                uip_arp_ipin();
99
                                uip_input();
100
 
101
                                /* If the above function invocation resulted in data that
102
                                should be sent out on the network, the global variable
103
                                uip_len is set to a value > 0. */
104
                                if( uip_len > 0 )
105
                                {
106
                                        uip_arp_out();
107
                                        lEMACSend();
108
                                }
109
                        }
110
                        else if( xHeader->type == htons( UIP_ETHTYPE_ARP ) )
111
                        {
112
                                uip_arp_arpin();
113
 
114
                                /* If the above function invocation resulted in data that
115
                                should be sent out on the network, the global variable
116
                                uip_len is set to a value > 0. */
117
                                if( uip_len > 0 )
118
                                {
119
                                        lEMACSend();
120
                                }
121
                        }
122
                }
123
                else
124
                {
125
                        if( timer_expired( &periodic_timer ) )
126
                        {
127
                                timer_reset( &periodic_timer );
128
                                for( i = 0; i < UIP_CONNS; i++ )
129
                                {
130
                                        uip_periodic( i );
131
 
132
                                        /* If the above function invocation resulted in data that
133
                                        should be sent out on the network, the global variable
134
                                        uip_len is set to a value > 0. */
135
                                        if( uip_len > 0 )
136
                                        {
137
                                                uip_arp_out();
138
                                                lEMACSend();
139
                                        }
140
                                }
141
 
142
                                /* Call the ARP timer function every 10 seconds. */
143
                                if( timer_expired( &arp_timer ) )
144
                                {
145
                                        timer_reset( &arp_timer );
146
                                        uip_arp_timer();
147
                                }
148
                        }
149
                        else
150
                        {
151
                                /* We did not receive a packet, and there was no periodic
152
                                processing to perform.  Block for a fixed period.  If a packet
153
                                is received during this period we will be woken by the ISR
154
                                giving us the Semaphore. */
155
                                xSemaphoreTake( xEMACSemaphore, configTICK_RATE_HZ / 2 );
156
                        }
157
                }
158
        }
159
}
160
/*-----------------------------------------------------------------------------------*/
161
 
162
void clock_init(void)
163
{
164
        /* This is done when the scheduler starts. */
165
}
166
/*-----------------------------------------------------------*/
167
 
168
clock_time_t clock_time( void )
169
{
170
        return xTaskGetTickCount();
171
}
172
/*-----------------------------------------------------------*/
173
 
174
void vProcessInput( char *pcInput )
175
{
176
char *c;
177
 
178
        /* Turn the LED on or off depending on the checkbox status. */
179
 
180
        c = strstr( pcInput, "?" );
181
        if( c )
182
        {
183
                if( strstr( c, "LED0=1" ) != NULL )
184
                {
185
                        vParTestSetLED( 3, 0 );
186
                }
187
                else
188
                {
189
                        vParTestSetLED( 3, 1 );
190
                }
191
        }
192
}
193
 
194
 
195
 
196
 
197
 

powered by: WebSVN 2.1.0

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