to solve some DHCP issues, we use same procedure to initialize LwIP like the LwIP examples
This commit is contained in:
parent
4f5e5e2449
commit
8aadb9a426
2 changed files with 90 additions and 64 deletions
|
@ -36,11 +36,8 @@ extern "C" {
|
|||
* initialize the VGA output. If configured.*/
|
||||
int lowlevel_init(void);
|
||||
|
||||
/** @brief Initialize LWIP stack and start a networking task. */
|
||||
int network_init(void);
|
||||
|
||||
/** @brief Shutdown the networking subsystem. */
|
||||
int network_shutdown(void);
|
||||
/** @brief Shutdown the system */
|
||||
int shutdown(void);
|
||||
|
||||
/** @brief Entry point of the init task */
|
||||
int initd(void* arg);
|
||||
|
|
147
kernel/init.c
147
kernel/init.c
|
@ -72,30 +72,14 @@ int lowlevel_init(void)
|
|||
|
||||
#if defined(CONFIG_LWIP) && (defined(CONFIG_PCI) || defined(CONFIG_ROCKCREEK))
|
||||
static struct netif* default_netif = NULL;
|
||||
static volatile uint32_t lwip_initialized = 0;
|
||||
|
||||
static void tcp_init_ok(void* e)
|
||||
static int init_netifs(void)
|
||||
{
|
||||
kputs("TCP/IP init COMPLETE!!\n");
|
||||
lwip_initialized = 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
int network_init(void)
|
||||
{
|
||||
#if defined(CONFIG_LWIP) && (defined(CONFIG_PCI) || defined(CONFIG_ROCKCREEK))
|
||||
struct ip_addr ipaddr;
|
||||
struct ip_addr netmask;
|
||||
struct ip_addr gw;
|
||||
|
||||
kputs("Initialize network...\n");
|
||||
|
||||
// Initialize lwIP modules
|
||||
tcpip_init(tcp_init_ok, NULL);
|
||||
|
||||
while(!lwip_initialized) {
|
||||
reschedule();
|
||||
}
|
||||
kputs("Initialize NICs...\n");
|
||||
|
||||
// Set up the lwIP network interface
|
||||
// Allocate and configure netif
|
||||
|
@ -115,6 +99,14 @@ int network_init(void)
|
|||
|
||||
/* Bring up the network interface */
|
||||
if (!netif_add(default_netif, &ipaddr, &netmask, &gw, NULL, rckemacif_init, tcpip_input)) {
|
||||
kputs("Unable to add network interface\n");
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
netif_set_default(default_netif);
|
||||
netif_set_up(default_netif);
|
||||
|
||||
//mmnif_open();
|
||||
#else
|
||||
/* Clear network address because we use DHCP to get an ip address */
|
||||
IP4_ADDR(&gw, 0,0,0,0);
|
||||
|
@ -123,64 +115,63 @@ int network_init(void)
|
|||
|
||||
/* Bring up the network interface */
|
||||
if (!netif_add(default_netif, &ipaddr, &netmask, &gw, NULL, rtl8139if_init, tcpip_input)) {
|
||||
#endif
|
||||
kputs("Unable to add network interface\n");
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
netif_set_default(default_netif);
|
||||
netif_set_up(default_netif);
|
||||
|
||||
/* test if interface is really up */
|
||||
if (!netif_is_up(default_netif)) {
|
||||
kputs("network interface is not up\n");
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
#ifndef CONFIG_ROCKCREEK
|
||||
kprintf("Starting DHCPCD...\n");
|
||||
dhcp_start(default_netif);
|
||||
|
||||
int mscnt = 0;
|
||||
/* wait for ip address */
|
||||
while(!default_netif->ip_addr.addr) {
|
||||
sys_msleep(DHCP_FINE_TIMER_MSECS);
|
||||
dhcp_fine_tmr();
|
||||
mscnt += DHCP_FINE_TIMER_MSECS;
|
||||
if (mscnt >= DHCP_COARSE_TIMER_SECS*1000) {
|
||||
dhcp_coarse_tmr();
|
||||
mscnt = 0;
|
||||
}
|
||||
}
|
||||
#else
|
||||
//mmnif_open();
|
||||
#endif
|
||||
|
||||
// start echo and ping server
|
||||
echo_init();
|
||||
//ping_init();
|
||||
netio_init();
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int network_shutdown(void)
|
||||
{
|
||||
#ifdef CONFIG_LWIP
|
||||
#ifdef CONFIG_ROCKCREEK
|
||||
//mmnif_close();
|
||||
#elif defined(CONFIG_PCI)
|
||||
dhcp_release(default_netif);
|
||||
dhcp_stop(default_netif);
|
||||
#endif
|
||||
|
||||
mem_free(default_netif);
|
||||
default_netif = NULL;
|
||||
#ifdef CONFIG_LWIP
|
||||
static void tcpip_init_done(void* arg)
|
||||
{
|
||||
sys_sem_t* sem = (sys_sem_t*)arg;
|
||||
|
||||
#if defined(CONFIG_LWIP) && (defined(CONFIG_PCI) || defined(CONFIG_ROCKCREEK))
|
||||
init_netifs();
|
||||
#endif
|
||||
sys_sem_signal(sem);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_LWIP
|
||||
static int network_shutdown(void)
|
||||
{
|
||||
#ifdef CONFIG_ROCKCREEK
|
||||
if (default_netif) {
|
||||
netif_set_link_down(default_netif);
|
||||
mem_free(default_netif);
|
||||
default_netif = NULL;
|
||||
}
|
||||
//mmnif_close();
|
||||
#elif defined(CONFIG_PCI)
|
||||
if (default_netif) {
|
||||
dhcp_release(default_netif);
|
||||
dhcp_stop(default_netif);
|
||||
mem_free(default_netif);
|
||||
default_netif = NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
int shutdown(void)
|
||||
{
|
||||
#ifdef CONFIG_LWIP
|
||||
return network_shutdown();
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
static void list_fs(vfs_node_t* node, uint32_t depth)
|
||||
{
|
||||
|
@ -217,7 +208,45 @@ static void list_root(void) {
|
|||
|
||||
int initd(void* arg)
|
||||
{
|
||||
network_init();
|
||||
#ifdef CONFIG_LWIP
|
||||
sys_sem_t sem;
|
||||
|
||||
// Initialize lwIP modules
|
||||
if(sys_sem_new(&sem, 0) != ERR_OK)
|
||||
LWIP_ASSERT("Failed to create semaphore", 0);
|
||||
tcpip_init(tcpip_init_done, &sem);
|
||||
sys_sem_wait(&sem);
|
||||
kprintf("TCP/IP initialized.\n");
|
||||
sys_sem_free(&sem);
|
||||
|
||||
#if defined(CONFIG_LWIP) && (defined(CONFIG_PCI) || defined(CONFIG_ROCKCREEK))
|
||||
/* test if interface is really up */
|
||||
if (!netif_is_up(default_netif)) {
|
||||
kputs("network interface is not up\n");
|
||||
return -ENODEV;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_ROCKCREEK
|
||||
int mscnt = 0;
|
||||
/* wait for ip address */
|
||||
while(default_netif && !default_netif->ip_addr.addr) {
|
||||
sys_msleep(DHCP_FINE_TIMER_MSECS);
|
||||
dhcp_fine_tmr();
|
||||
mscnt += DHCP_FINE_TIMER_MSECS;
|
||||
if (mscnt >= DHCP_COARSE_TIMER_SECS*1000) {
|
||||
dhcp_coarse_tmr();
|
||||
mscnt = 0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// start echo and ping server
|
||||
echo_init();
|
||||
//ping_init();
|
||||
netio_init();
|
||||
#endif
|
||||
|
||||
list_root();
|
||||
test_init();
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue