1 //==========================================================================
2 //####ECOSGPLCOPYRIGHTBEGIN####
3 // -------------------------------------------
4 // This file is part of eCos, the Embedded Configurable Operating System.
5 // Copyright (C) 2004 eCosCentric
7 // eCos is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU General Public License as published by the Free
9 // Software Foundation; either version 2 or (at your option) any later version.
11 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
12 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 // You should have received a copy of the GNU General Public License along
17 // with eCos; if not, write to the Free Software Foundation, Inc.,
18 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
20 // As a special exception, if other files instantiate templates or use macros
21 // or inline functions from this file, or you compile this file and link it
22 // with other works to produce a work based on this file, this file does not
23 // by itself cause the resulting work to be covered by the GNU General Public
24 // License. However the source code for this file must still be made available
25 // in accordance with section (3) of the GNU General Public License.
27 // This exception does not invalidate any other reasons why a work based on
28 // this file might be covered by the GNU General Public License.
29 // -------------------------------------------
30 //####ECOSGPLCOPYRIGHTEND####
31 //==========================================================================
34 * init.c - misc lwip ecos glue functions
36 #include <pkgconf/system.h>
37 #include <pkgconf/net_lwip.h>
40 #include "lwip/memp.h"
41 #include "lwip/tcpip.h"
42 #include "lwip/ip_addr.h"
45 #include "lwip/dhcp.h"
49 #include "netif/slipif.h"
53 #include "netif/ppp/ppp.h"
56 #include "netif/loopif.h"
57 #include <cyg/hal/hal_if.h>
58 #include <cyg/infra/diag.h>
60 #ifdef CYGPKG_LWIP_ETH
61 #include "netif/etharp.h"
63 #include <cyg/io/eth/eth_drv.h>
64 #include <cyg/io/eth/netdev.h>
67 // Define table boundaries
68 CYG_HAL_TABLE_BEGIN(__NETDEVTAB__, netdev);
69 CYG_HAL_TABLE_END(__NETDEVTAB_END__, netdev);
70 static void ecosglue_init(void);
73 void inline IP_ADDR(struct ip_addr *ipaddr, char a, char b, char c, char d)
75 IP4_ADDR(ipaddr,a,b,c,d);
79 struct netif mynetif, loopif;
80 void lwip_set_addr(struct netif *netif);
82 #define PPP_USER "pppuser"
83 #define PPP_PASS "ppppass"
86 pppMyCallback(void *a , int e, void * arg)
88 diag_printf("callback %d \n",e);
91 /* These temporarily here */
95 return cyg_current_time();
99 ppp_trace(int level, const char *format,...)
104 va_start(args, format);
105 diag_vprintf(format, args);
111 struct netif ecos_loopif;
114 #ifdef CYGPKG_LWIP_ETH
119 sys_timeout(ARP_TMR_INTERVAL, (sys_timeout_handler) arp_timer, NULL);
124 static void lwip_dhcp_fine_tmr(void *arg)
127 sys_timeout(500, (sys_timeout_handler) lwip_dhcp_fine_tmr, NULL);
130 static void lwip_dhcp_coarse_tmr(void *arg)
133 sys_timeout(60000, (sys_timeout_handler) lwip_dhcp_coarse_tmr, NULL);
139 // This function is called when tcpip thread finished initialisation.
140 // We start several timers here - these timers are all handled in the
141 // tcpip thread. That means that also the DHCP stuff is handled in the
142 // TCPIP thread. If this causes any trouble than it may be necessaray to
143 // use an own DHCP thread insted.
145 void tcpip_init_done(void * arg)
147 #ifdef CYGPKG_LWIP_ETH
148 sys_timeout(ARP_TMR_INTERVAL, (sys_timeout_handler) arp_timer, NULL);
150 #ifdef CYGOPT_LWIP_DHCP_MANAGEMENT
151 sys_timeout(500, (sys_timeout_handler) lwip_dhcp_fine_tmr, NULL);
152 sys_timeout(60000, (sys_timeout_handler) lwip_dhcp_coarse_tmr, NULL);
154 sys_sem_t *sem = arg;
155 sys_sem_signal(*sem);
160 * Called by the eCos application at startup
161 * wraps various init calls
167 struct ip_addr ipaddr, netmask, gw;
169 static int inited = 0;
175 sys_init(); /* eCos specific initialization */
176 mem_init(); /* heap based memory allocator */
177 memp_init(); /* pool based memory allocator */
178 pbuf_init(); /* packet buffer allocator */
179 netif_init(); /* netif layer */
181 /* Start the stack.It will spawn a new dedicated thread */
182 sem = sys_sem_new(0);
183 tcpip_init(tcpip_init_done,&sem);
188 IP4_ADDR(&gw, 127,0,0,1);
189 IP4_ADDR(&ipaddr, 127,0,0,1);
190 IP4_ADDR(&netmask, 255,0,0,0);
192 netif_add(&ecos_loopif, &ipaddr, &netmask, &gw, NULL, loopif_init,
197 lwip_set_addr(&mynetif);
198 slipif_init(&mynetif);
199 netif_set_default(&mynetif);
202 #if PAP_SUPPORT || CHAP_SUPPORT
203 pppSetAuth(PPPAUTHTYPE_PAP, PPP_USER, PPP_PASS);
205 pppOpen(sio_open(2), pppMyCallback, NULL);
213 err_t lwip_dummy_netif_init(struct netif *netif)
220 lwip_set_addr(struct netif *netif)
222 struct ip_addr ipaddr, netmask, gw;
225 IP4_ADDR(&gw, 0,0,0,0);
226 IP4_ADDR(&ipaddr, 0,0,0,0);
227 IP4_ADDR(&netmask, 0,0,0,0);
229 netif_add(netif, &ipaddr, &netmask, &gw, netif->state, lwip_dummy_netif_init, tcpip_input);
230 netif_set_default(netif);
231 netif_set_up(netif); // new step from lwip 1.0.0
233 IP_ADDR(&gw, CYGDAT_LWIP_SERV_ADDR);
234 IP_ADDR(&ipaddr, CYGDAT_LWIP_MY_ADDR);
235 IP_ADDR(&netmask, CYGDAT_LWIP_NETMASK);
237 netif_add(netif, &ipaddr, &netmask, &gw, netif->state, lwip_dummy_netif_init, tcpip_input);
238 netif_set_default(netif);
239 netif_set_up(netif); // new step from lwip 1.0.0
243 void lwip_dhcp_init(struct netif *netif)
245 #ifdef CYGOPT_LWIP_DHCP_MANAGEMENT
251 #ifdef CYGPKG_LWIP_ETH
259 cyg_semaphore_post(&delivery);
262 //Input thread signalled by DSR calls deliver() on low level drivers
264 input_thread(void *arg)
266 cyg_netdevtab_entry_t *t;
269 cyg_semaphore_wait(&delivery);
271 for (t = &__NETDEVTAB__[0]; t != &__NETDEVTAB_END__; t++) {
272 struct eth_drv_sc *sc = (struct eth_drv_sc *)t->device_instance;
273 if (sc->state & ETH_DRV_NEEDS_DELIVERY) {
274 #if defined(CYGDBG_HAL_DEBUG_GDB_CTRLC_SUPPORT)
275 cyg_bool was_ctrlc_int;
277 sc->state &= ~ETH_DRV_NEEDS_DELIVERY;
278 #if defined(CYGDBG_HAL_DEBUG_GDB_CTRLC_SUPPORT)
279 was_ctrlc_int = HAL_CTRLC_CHECK((*sc->funs->int_vector)(sc), (int)sc);
280 if (!was_ctrlc_int) // Fall through and run normal code
283 (sc->funs->deliver) (sc);
291 // Initialize all network devices
293 init_hw_drivers(void)
295 cyg_netdevtab_entry_t *t;
297 for (t = &__NETDEVTAB__[0]; t != &__NETDEVTAB_END__; t++) {
299 t->status = CYG_NETDEVTAB_STATUS_AVAIL;
301 // What to do if device init fails?
302 t->status = 0; // Device not [currently] available
307 extern struct netif *netif_default;
313 cyg_semaphore_init(&delivery, 0);
315 // start input thread before hardware drivers are initialized because
316 // init_hw_drivers() calls dhcp_init() if DHCP support is configured
317 // and dhcp_init() requires a running input thread
319 sys_thread_new(input_thread, (void*)0, CYGNUM_LWIP_ETH_THREAD_PRIORITY);
323 #endif //CYGPKG_LWIP_ETH