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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Demo/] [uIP_Demo_Rowley_ARM7/] [uip/] [uIP_Task.c] - Blame information for rev 754

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

Line No. Rev Author Line
1 583 jeremybenn
/*
2
 * 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
 
36
#include <stdlib.h>   /* For system(). */
37
#include <stdio.h>    /* For printf(). */
38
 
39
#include "FreeRTOS.h"
40
#include "task.h"
41
 
42
#undef HTONS
43
 
44
#include "cs8900a.h"
45
#include "uip.h"
46
#include "uip_arp.h"
47
#include "tapdev.h"
48
#include "httpd.h"
49
 
50
static const struct uip_eth_addr ethaddr = {{0x00,0x00,0xe2,0x58,0xb6,0x6b}};
51
 
52
#define BUF ((struct uip_eth_hdr *)&uip_buf[0])
53
#define uipSHORT_DELAY          ( ( portTickType ) 2 / portTICK_RATE_MS )
54
 
55
#ifndef NULL
56
#define NULL (void *)0
57
#endif /* NULL */
58
 
59
static volatile portTickType start, current;
60
 
61
#define RT_CLOCK_SECOND ( configTICK_RATE_HZ / 2 )
62
 
63
/*-----------------------------------------------------------------------------------*/
64
/**
65
 * \internal
66
 * A real-time clock.
67
 *
68
 * This example main() function uses polling of a real-time clock in
69
 * order to know when the periodic processing should be
70
 * performed. This is implemented using this function - rt_ticks(). In
71
 * this example unix implementation, it simply calls the unix function
72
 * gettimeofday() which returns the current wall clock time.
73
 *
74
 * For a micro-controller, a simple way to implement this function is
75
 * by having a counter that is incremented by a timer interrupt and
76
 * read by this function.
77
 *
78
 * The macro RT_CLOCK_SECOND should be defined as the approximate
79
 * number of ticks that are elapsed during one second.
80
 */
81
#define rt_ticks xTaskGetTickCount
82
 
83
/*-----------------------------------------------------------------------------------*/
84
void vuIP_TASK( void *pvParameters )
85
{
86
u8_t i, arptimer;
87
u16_t addr[2];
88
int z = 3;
89
 
90
        /* Initialize the uIP TCP/IP stack. */
91
        uip_init();
92
        uip_arp_init();
93
 
94
        /* Initialize the device driver. */
95
        cs8900a_init();
96
 
97
        /* Initialize the HTTP server. */
98
        httpd_init();
99
 
100
        start = rt_ticks();
101
        arptimer = 0;
102
 
103
        while(1)
104
        {
105
                /* Let the network device driver read an entire IP packet
106
                into the uip_buf. If it returns > 0, there is a packet in the
107
                uip_buf buffer. */
108
                uip_len = cs8900a_poll();
109
 
110
                if(uip_len > 0)
111
                {
112
                        /* A packet is present in the packet buffer. We call the
113
                        appropriate ARP functions depending on what kind of packet we
114
                        have received. If the packet is an IP packet, we should call
115
                        uip_input() as well. */
116
                        if(BUF->type == htons(UIP_ETHTYPE_IP))
117
                        {
118
                                uip_arp_ipin();
119
                                uip_input();
120
                                /* If the above function invocation resulted in data that
121
                                should be sent out on the network, the global variable
122
                                uip_len is set to a value > 0. */
123
                                if(uip_len > 0)
124
                                {
125
                                        uip_arp_out();
126
                                        cs8900a_send();
127
                                }
128
                        }
129
                        else if(BUF->type == htons(UIP_ETHTYPE_ARP))
130
                        {
131
                                uip_arp_arpin();
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
                                        cs8900a_send();
138
                                }
139
                        }
140
                }
141
                else
142
                {
143
                        /* The poll function returned 0, so no packet was
144
                        received. Instead we check if there is time that we do the
145
                        periodic processing. */
146
                        current = rt_ticks();
147
 
148
                        if((u16_t)(current - start) >= (u16_t)RT_CLOCK_SECOND / 2)
149
                        {
150
                                start = current;
151
 
152
                                for(i = 0; i < UIP_CONNS; i++)
153
                                {
154
                                        uip_periodic(i);
155
 
156
                                        /* If the above function invocation resulted in data that
157
                                        should be sent out on the network, the global variable
158
                                        uip_len is set to a value > 0. */
159
 
160
                                        if(uip_len > 0)
161
                                        {
162
                                                uip_arp_out();
163
                                                cs8900a_send();
164
                                        }
165
                                }
166
 
167
                                #if UIP_UDP
168
                                        for(i = 0; i < UIP_UDP_CONNS; i++)
169
                                        {
170
                                                uip_udp_periodic(i);
171
 
172
                                                /* If the above function invocation resulted in data that
173
                                                should be sent out on the network, the global variable
174
                                                uip_len is set to a value > 0. */
175
 
176
                                                if(uip_len > 0)
177
                                                {
178
                                                        uip_arp_out();
179
                                                        tapdev_send();
180
                                                }
181
                                        }
182
                                #endif /* UIP_UDP */
183
 
184
                                /* Call the ARP timer function every 10 seconds. */
185
                                if(++arptimer == 20)
186
                                {
187
                                        uip_arp_timer();
188
                                        arptimer = 0;
189
                                }
190
                        }
191
                        else
192
                        {
193
                                vTaskDelay( uipSHORT_DELAY );
194
                }   }
195
        }
196
}
197
/*-----------------------------------------------------------------------------------*/
198
 
199
 
200
 
201
 

powered by: WebSVN 2.1.0

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