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>
39 #include "lwip/memp.h"
40 #include "lwip/tcpip.h"
41 #include "lwip/ip_addr.h"
44 #include "lwip/dhcp.h"
48 #include "netif/slipif.h"
52 #include "netif/ppp/ppp.h"
55 #include "netif/loopif.h"
56 #include <cyg/hal/hal_if.h>
57 #include <cyg/infra/diag.h>
59 #ifdef CYGPKG_LWIP_ETH
60 #include "netif/etharp.h"
62 #include <cyg/io/eth/eth_drv.h>
63 #include <cyg/io/eth/netdev.h>
66 // Define table boundaries
67 CYG_HAL_TABLE_BEGIN(__NETDEVTAB__, netdev);
68 CYG_HAL_TABLE_END(__NETDEVTAB_END__, netdev);
69 static void ecosglue_init(void);
72 void inline IP_ADDR(struct ip_addr *ipaddr, char a, char b, char c, char d)
74 IP4_ADDR(ipaddr,a,b,c,d);
78 void tcpip_init_done(void * arg)
84 struct netif mynetif, loopif;
85 void lwip_set_addr(struct netif *netif);
87 #define PPP_USER "pppuser"
88 #define PPP_PASS "ppppass"
91 pppMyCallback(void *a , int e, void * arg)
93 diag_printf("callback %d \n",e);
96 /* These temporarily here */
100 return cyg_current_time();
104 ppp_trace(int level, const char *format,...)
109 va_start(args, format);
110 diag_vprintf(format, args);
116 struct netif ecos_loopif;
120 * Called by the eCos application at startup
121 * wraps various init calls
126 struct ip_addr ipaddr, netmask, gw;
127 static int inited = 0;
133 sys_init(); /* eCos specific initialization */
134 mem_init(); /* heap based memory allocator */
135 memp_init(); /* pool based memory allocator */
136 pbuf_init(); /* packet buffer allocator */
137 netif_init(); /* netif layer */
139 /* Start the stack.It will spawn a new dedicated thread */
140 sem = sys_sem_new(0);
141 tcpip_init(tcpip_init_done,&sem);
146 IP4_ADDR(&gw, 127,0,0,1);
147 IP4_ADDR(&ipaddr, 127,0,0,1);
148 IP4_ADDR(&netmask, 255,0,0,0);
150 netif_add(&ecos_loopif, &ipaddr, &netmask, &gw, NULL, loopif_init,
155 lwip_set_addr(&mynetif);
156 slipif_init(&mynetif);
157 netif_set_default(&mynetif);
160 #if PAP_SUPPORT || CHAP_SUPPORT
161 pppSetAuth(PPPAUTHTYPE_PAP, PPP_USER, PPP_PASS);
163 pppOpen(sio_open(2), pppMyCallback, NULL);
171 lwip_set_addr(struct netif *netif)
173 struct ip_addr ipaddr, netmask, gw;
175 IP_ADDR(&gw, CYGPKG_LWIP_SERV_ADDR);
176 IP_ADDR(&ipaddr, CYGPKG_LWIP_MY_ADDR);
177 IP_ADDR(&netmask, CYGPKG_LWIP_NETMASK);
178 netif_set_addr(netif, &ipaddr, &netmask, &gw);
179 netif->next = netif_list;
182 netif->input = tcpip_input;
183 //netif->input = ip_input;
186 #ifdef CYGPKG_LWIP_ETH
194 cyg_semaphore_post(&delivery);
197 //Input thread signalled by DSR calls deliver() on low level drivers
199 input_thread(void *arg)
201 cyg_netdevtab_entry_t *t;
204 cyg_semaphore_wait(&delivery);
206 for (t = &__NETDEVTAB__[0]; t != &__NETDEVTAB_END__; t++) {
207 struct eth_drv_sc *sc = (struct eth_drv_sc *)t->device_instance;
208 if (sc->state & ETH_DRV_NEEDS_DELIVERY) {
209 #if defined(CYGDBG_HAL_DEBUG_GDB_CTRLC_SUPPORT)
210 cyg_bool was_ctrlc_int;
212 sc->state &= ~ETH_DRV_NEEDS_DELIVERY;
213 #if defined(CYGDBG_HAL_DEBUG_GDB_CTRLC_SUPPORT)
214 was_ctrlc_int = HAL_CTRLC_CHECK((*sc->funs->int_vector)(sc), (int)sc);
215 if (!was_ctrlc_int) // Fall through and run normal code
218 (sc->funs->deliver) (sc);
225 // Initialize all network devices
227 init_hw_drivers(void)
229 cyg_netdevtab_entry_t *t;
231 for (t = &__NETDEVTAB__[0]; t != &__NETDEVTAB_END__; t++) {
233 t->status = CYG_NETDEVTAB_STATUS_AVAIL;
235 // What to do if device init fails?
236 t->status = 0; // Device not [currently] available
245 sys_timeout(ARP_TMR_INTERVAL, (sys_timeout_handler) arp_timer, NULL);
252 cyg_semaphore_init(&delivery, 0);
254 sys_thread_new(input_thread, (void*)0, CYGPKG_LWIP_ETH_THREAD_PRIORITY);
256 sys_timeout(ARP_TMR_INTERVAL, (sys_timeout_handler) arp_timer, NULL);
259 #endif //CYGPKG_LWIP_ETH