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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [net/] [lwip_tcpip/] [current/] [src/] [ecos/] [sequential.c] - Blame information for rev 865

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

Line No. Rev Author Line
1 786 skrzyp
//==========================================================================
2
//
3
//      sequential.c
4
//
5
//      lwIP sequential mode (multi-threaded) support.
6
//
7
//==========================================================================
8
//####ECOSGPLCOPYRIGHTBEGIN####
9
// -------------------------------------------
10
// This file is part of eCos, the Embedded Configurable Operating System.
11
// Copyright (C) 2008, 2009 Free Software Foundation
12
//
13
// eCos is free software; you can redistribute it and/or modify it under
14
// the terms of the GNU General Public License as published by the Free
15
// Software Foundation; either version 2 or (at your option) any later version.
16
//
17
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
18
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
19
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
20
// for more details.
21
//
22
// You should have received a copy of the GNU General Public License along
23
// with eCos; if not, write to the Free Software Foundation, Inc.,
24
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
25
//
26
// As a special exception, if other files instantiate templates or use macros
27
// or inline functions from this file, or you compile this file and link it
28
// with other works to produce a work based on this file, this file does not
29
// by itself cause the resulting work to be covered by the GNU General Public
30
// License. However the source code for this file must still be made available
31
// in accordance with section (3) of the GNU General Public License.
32
//
33
// This exception does not invalidate any other reasons why a work based on
34
// this file might be covered by the GNU General Public License.
35
// -------------------------------------------
36
//####ECOSGPLCOPYRIGHTEND####
37
//==========================================================================
38
//#####DESCRIPTIONBEGIN####
39
//
40
// Author(s):    Simon Kallweit
41
// Contributors:
42
// Date:         2008-12-02
43
// Purpose:
44
// Description:  lwIP sequential mode (multi-threaded) support.
45
//
46
//####DESCRIPTIONEND####
47
//
48
//==========================================================================
49
 
50
#include <pkgconf/system.h>
51
#include <pkgconf/net_lwip.h>
52
 
53
#include "lwip.h"
54
#include "lwip/opt.h"
55
#include "lwip/sys.h"
56
#include "lwip/memp.h"
57
#include "lwip/ip_addr.h"
58
#include "lwip/init.h"
59
#include "lwip/tcp.h"
60
#include "lwip/ip_frag.h"
61
#include "lwip/dhcp.h"
62
#include "lwip/autoip.h"
63
#include "lwip/igmp.h"
64
#include "lwip/dns.h"
65
#include "lwip/memp.h"
66
#include "lwip/tcpip.h"
67
 
68
#include "netif/loopif.h"
69
#include "netif/slipif.h"
70
#include "netif/etharp.h"
71
#include "netif/ppp/ppp.h"
72
 
73
#include <cyg/infra/diag.h>
74
#include <cyg/kernel/kapi.h>
75
 
76
#ifdef CYGDBG_HAL_DEBUG_GDB_CTRLC_SUPPORT
77
#include <cyg/hal/hal_if.h>            // HAL_CTRLC_CHECK
78
#endif
79
 
80
#ifdef CYGPKG_LWIP_ETH
81
#include <cyg/io/eth/eth_drv.h>
82
#include <cyg/io/eth/netdev.h>
83
#endif
84
 
85
#if LWIP_HAVE_LOOPIF && defined(CYGIMP_LWIP_LOOPIF_INSTANCE)
86
static struct netif loopif;
87
#endif
88
 
89
#if LWIP_HAVE_SLIPIF && defined(CYGIMP_LWIP_SLIPIF_INSTANCE)
90
static struct netif slipif;
91
#endif
92
 
93
#ifdef CYGPKG_LWIP_ETH
94
 
95
// Ethernet driver table
96
CYG_HAL_TABLE_BEGIN(__NETDEVTAB__, netdev);
97
CYG_HAL_TABLE_END(__NETDEVTAB_END__, netdev);
98
 
99
static sys_thread_t eth_thread_handle;
100
static cyg_sem_t eth_thread_sem;
101
 
102
static void eth_thread(void *data);
103
 
104
#endif
105
 
106
#if (LWIP_HAVE_LOOPIF && defined(CYGIMP_LWIP_LOOPIF_INSTANCE)) || \
107
    (LWIP_HAVE_SLIPIF && defined(CYGIMP_LWIP_SLIPIF_INSTANCE))
108
 
109
//
110
// Sets an IP address.
111
//
112
static void
113
set_ip_addr(struct ip_addr *addr, u8_t a, u8_t b, u8_t c, u8_t d)
114
{
115
    IP4_ADDR(addr, a, b, c, d);
116
}
117
 
118
#endif // (LWIP_HAVE_LOOPIF && defined(CYGIMP_LWIP_LOOPIF_INSTANCE)) ||
119
       // (LWIP_HAVE_SLIPIF && defined(CYGIMP_LWIP_SLIPIF_INSTANCE))
120
 
121
#ifdef CYGFUN_LWIP_SHOW_NETIF_CONFIG
122
 
123
static void
124
show_netif_config(struct netif *netif)
125
{
126
    diag_printf(
127
        "%c%c%d: IP: %d.%d.%d.%d Submask: %d.%d.%d.%d Gateway: %d.%d.%d.%d\n",
128
        netif->name[0], netif->name[1], netif->num,
129
        ip4_addr1(&netif->ip_addr), ip4_addr2(&netif->ip_addr),
130
        ip4_addr3(&netif->ip_addr), ip4_addr4(&netif->ip_addr),
131
        ip4_addr1(&netif->netmask), ip4_addr2(&netif->netmask),
132
        ip4_addr3(&netif->netmask), ip4_addr4(&netif->netmask),
133
        ip4_addr1(&netif->gw), ip4_addr2(&netif->gw),
134
        ip4_addr3(&netif->gw), ip4_addr4(&netif->gw)
135
    );
136
}
137
 
138
static void
139
netif_status_callback(struct netif *netif)
140
{
141
    if (netif_is_up(netif))
142
        show_netif_config(netif);
143
}
144
 
145
#endif // CYGFUN_LWIP_SHOW_NETIF_CONFIG
146
 
147
 
148
//
149
// Called when initialization of the tcpip thread is done.
150
//
151
static void
152
tcpip_init_done(void *arg)
153
{
154
    cyg_sem_t *sem = arg;
155
 
156
#if LWIP_HAVE_LOOPIF && defined(CYGIMP_LWIP_LOOPIF_INSTANCE)
157
    {
158
        struct ip_addr addr, netmask, gateway;
159
 
160
        // Setup default loopback device instance
161
        set_ip_addr(&addr, CYGDAT_LWIP_LOOPIF_ADDR);
162
        set_ip_addr(&netmask, CYGDAT_LWIP_LOOPIF_NETMASK);
163
        set_ip_addr(&gateway, CYGDAT_LWIP_LOOPIF_GATEWAY);
164
        netif_add(&loopif, &addr, &netmask, &gateway, NULL,
165
                  loopif_init, tcpip_input);
166
#ifdef CYGDAT_LWIP_LOOPIF_DEFAULT
167
        netif_set_default(&loopif);
168
#endif
169
#ifdef CYGFUN_LWIP_SHOW_NETIF_CONFIG
170
        netif_set_status_callback(&loopif, netif_status_callback);
171
#endif
172
        netif_set_up(&loopif);
173
    }
174
#endif
175
 
176
#if LWIP_HAVE_SLIPIF && defined(CYGIMP_LWIP_SLIPIF_INSTANCE)
177
    {
178
        struct ip_addr addr, netmask, gateway;
179
 
180
        // Setup default SLIP device instance
181
        set_ip_addr(&addr, CYGDAT_LWIP_SLIPIF_ADDR);
182
        set_ip_addr(&netmask, CYGDAT_LWIP_SLIPIF_NETMASK);
183
        set_ip_addr(&gateway, CYGDAT_LWIP_SLIPIF_GATEWAY);
184
        netif_add(&slipif, &addr, &netmask, &gateway, NULL,
185
                  slipif_init, tcpip_input);
186
#ifdef CYGDAT_LWIP_SLIPIF_DEFAULT
187
        netif_set_default(&slipif);
188
#endif
189
#ifdef CYGFUN_LWIP_SHOW_NETIF_CONFIG
190
        netif_set_status_callback(&slipif, netif_status_callback);
191
#endif
192
        netif_set_up(&slipif);
193
    }
194
#endif
195
 
196
#if PPP_SUPPORT
197
    {
198
        // Setup PPP instance
199
    }
200
#endif
201
 
202
#ifdef CYGPKG_LWIP_ETH
203
    {
204
        cyg_netdevtab_entry_t *t;
205
 
206
        // Initialize ethernet delivery thread
207
        cyg_semaphore_init(&eth_thread_sem, 0);
208
        eth_thread_handle = sys_thread_new(ETH_THREAD_NAME,
209
                                           eth_thread,
210
                                           NULL,
211
                                           ETH_THREAD_STACKSIZE,
212
                                           ETH_THREAD_PRIO);
213
 
214
        // Initialize network devices
215
        for (t = &__NETDEVTAB__[0]; t != &__NETDEVTAB_END__; t++) {
216
            if (t->init(t)) {
217
                t->status = CYG_NETDEVTAB_STATUS_AVAIL;
218
#ifdef CYGFUN_LWIP_SHOW_NETIF_CONFIG
219
                {
220
                    struct eth_drv_sc* sc = (struct eth_drv_sc*) (t->device_instance);
221
                    struct netif *netif = &sc->sc_arpcom.ac_if;
222
                    netif_set_status_callback(netif, netif_status_callback);
223
                }
224
#endif
225
            } else {
226
                // Device not [currently] available
227
                t->status = 0;
228
            }
229
        }
230
    }
231
#endif
232
 
233
    // Notify initialization thread
234
    cyg_semaphore_post(sem);
235
}
236
 
237
//
238
// Initialize lwIP for simple (single-threaded) mode.
239
//
240
void
241
cyg_lwip_sequential_init(void)
242
{
243
    static int initialized;
244
    cyg_sem_t sem;
245
 
246
    // Only initialize once
247
    if (initialized)
248
        return;
249
    initialized = 1;
250
 
251
    // Initialize the lwIP stack
252
    cyg_semaphore_init(&sem, 0);
253
    tcpip_init(tcpip_init_done, (void *) &sem);
254
 
255
    // Wait until initialized
256
    cyg_semaphore_wait(&sem);
257
    cyg_semaphore_destroy(&sem);
258
}
259
 
260
#ifdef CYGPKG_LWIP_ETH
261
 
262
static void
263
eth_thread(void *data)
264
{
265
    cyg_netdevtab_entry_t *t;
266
 
267
    while (1) {
268
        cyg_semaphore_wait(&eth_thread_sem);
269
 
270
        for (t = &__NETDEVTAB__[0]; t != &__NETDEVTAB_END__; t++) {
271
            struct eth_drv_sc *sc = (struct eth_drv_sc *)t->device_instance;
272
            if (sc->state & ETH_DRV_NEEDS_DELIVERY) {
273
#if defined(CYGDBG_HAL_DEBUG_GDB_CTRLC_SUPPORT)
274
                cyg_bool was_ctrlc_int;
275
#endif
276
                sc->state &= ~ETH_DRV_NEEDS_DELIVERY;
277
#if defined(CYGDBG_HAL_DEBUG_GDB_CTRLC_SUPPORT)
278
                was_ctrlc_int = HAL_CTRLC_CHECK(sc->funs->int_vector(sc),
279
                                                (int) sc);
280
                if (!was_ctrlc_int) // Fall through and run normal code
281
#endif
282
                    sc->funs->deliver(sc);
283
            }
284
        }
285
    }
286
}
287
 
288
//
289
// Called from the network driver to indicate a new netif.
290
//
291
void
292
lwip_eth_drv_new(struct netif *netif)
293
{
294
#ifdef CYGFUN_LWIP_SHOW_NETIF_CONFIG
295
    netif_set_status_callback(netif, netif_status_callback);
296
#endif
297
}
298
 
299
//
300
// Called from network driver to indicate interrupt.
301
//
302
void
303
lwip_eth_drv_dsr(void)
304
{
305
    cyg_semaphore_post(&eth_thread_sem);
306
}
307
 
308
//
309
// Called from the network driver when a packet was received.
310
//
311
err_t
312
lwip_eth_drv_input(struct pbuf *p, struct netif *netif)
313
{
314
    return tcpip_input(p, netif);
315
}
316
 
317
#endif // CYGPKG_LWIP_ETH

powered by: WebSVN 2.1.0

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