Example #1
0
int network_init() {
#if DEBUG
    tcpip_init(tcpip_init_done, (void*) ((uintptr_t) timer_getms()));
#else
    tcpip_init(tcpip_init_done, NULL);
#endif

    return 0;
}
Example #2
0
int system_socket_init(void)
{
	struct ip_addr ipaddr, gw, netmask;
    	LWIP_CONFIG lwip_cfg;

	net_dm9ka_attach();
	
	ipaddr.addr=inet_addr(IP_ADDRESS);
	netmask.addr=inet_addr(NM_ADDRESS);
	gw.addr=inet_addr(GW_ADDRESS);

	lwip_cfg.mem.enable = TRUE;
	lwip_cfg.mem.start = __MM_SUB_PB_START_ADDR;//LWIP_MEM_ADDR can be a Macro to define a address value.
	lwip_cfg.mem.length = 32*1024;//At least 32*1024;
	
	lwip_cfg.memp.enable = TRUE;
	lwip_cfg.memp.start =  __MM_LWIP_MEMP_ADDR;//LWIP_MEMP_ADDR can be a Macro to define a address value.
	lwip_cfg.memp.length = __MM_LWIP_MEMP_LEN;//At least 1532*256;	
	tcpip_init(NULL, NULL, &lwip_cfg);
    
	if (ERR_OK != sys_add_netif(&ipaddr, &netmask, &gw))
	{
		return -1;
	}
	
	return 0;
}
Example #3
0
void
serve_init(uint32_t ipaddr, uint32_t netmask, uint32_t gw)
{
	int r;
	lwip_core_lock();

	uint32_t done = 0;
	tcpip_init(&tcpip_init_done, &done);
	lwip_core_unlock();
	thread_wait(&done, 0, (uint32_t)~0);
	lwip_core_lock();

	lwip_init(&nif, &output_envid, ipaddr, netmask, gw);

	start_timer(&t_arp, &etharp_tmr, "arp timer", ARP_TMR_INTERVAL);
	start_timer(&t_tcpf, &tcp_fasttmr, "tcp f timer", TCP_FAST_INTERVAL);
	start_timer(&t_tcps, &tcp_slowtmr, "tcp s timer", TCP_SLOW_INTERVAL);

	struct in_addr ia = {ipaddr};
	cprintf("ns: %02x:%02x:%02x:%02x:%02x:%02x"
		" bound to static IP %s\n",
		nif.hwaddr[0], nif.hwaddr[1], nif.hwaddr[2],
		nif.hwaddr[3], nif.hwaddr[4], nif.hwaddr[5],
		inet_ntoa(ia));

	lwip_core_unlock();

	cprintf("NS: TCP/IP initialized.\n");
}
Example #4
0
static void _lwip_sys_init(void)
{
    struct ip_addr ipaddr, netmask, gw;
    unsigned char *ip;

    ip = getCfgIP();
    IP4_ADDR(&ipaddr,ip[0],ip[1],ip[2],ip[3]);
    ip = getCfgGateWay();
    IP4_ADDR(&gw, ip[0],ip[1],ip[2],ip[3]);
    ip = getCfgNetMask();
    IP4_ADDR(&netmask,ip[0],ip[1],ip[2],ip[3]);

    tcpip_init(RT_NULL, RT_NULL);

    netif_set_addr(netif_default, &ipaddr, &netmask, &gw);
    // We SHOULD define an IP address (udp setup should work any time).
    // So, it may send DHCP packets of src_addr not all zero, tested ok.
    /*
       if( isDHCPEnabled() )
       {
    // when DHCP is enabled, ip/netmask/gateway should be set to all 0.
    IP4_ADDR(&ipaddr,0,0,0,0);
    netif_set_addr(netif_default, &ipaddr, &ipaddr, &ipaddr);
    }
    else
    {
    netif_set_addr(netif_default, &ipaddr, &netmask, &gw);
    }*/
    netif_set_up(netif_default);

    if( isDHCPEnabled() )
        dhcp_start(netif_default);
    else
        dhcp_stop(netif_default);
}
Example #5
0
/***************************************************************************************************************************
**函数名称:	 	ip_input
**函数功能:	 	
				eth_hdr:
				+----------------------------------------------------------------------------------------+
				+  desMAC[6]  |  srcMAC[6]  |  type[2]( ARP / IP)  |  	数据[46-1500]   |	校验[4]      +
				+----------------------------------------------------------------------------------------+
				*注: 
					desMAC[6]: 目的MAC地址;
					srcMAC[6]: 源MAC地址;
					type[2]: 类型(IP:0X800/ARP:0X806)
					数据[46-1500]:具体数据;
					校验[4]:校验;


				etharp_hdr:
				+-----------------------------------------------------------------------------------------------------+
				+ hwhdr[2] | porotl[2] | hwlen[1] | porotllen[1] | op[2] | srcMAC[6] | srcIP[4] |desMAC[6] | desIP[4] +
				+-----------------------------------------------------------------------------------------------------+
				*注: 
					hwhdr[2]:硬件类型字段-表示硬件地址的类型,它的值为1即表示以太网MAC地址,长度为6个字节;
					porotl[2]:协议类型字段表示要映射的协议地址类型,它的值为0X800即表示要映射的IP地址;
					hwlen[1]: 硬件地址长度,对于以太网ARP请求或者应答来说,他的值为6;
					porotllen[1]:协议地址长度,对于以太网ARP请求或者应答来说,他的值为4;
					op[2]:操作类型 ARP请求=1,ARP应答=2,RARP请求=3,RARP=4;
					srcMAC[6]:发送端MAC地址;
					srcIP[4]: 发送端IP地址;
					desMAC[6]:目的端MAC地址
					desIP[4]: 目的端IP地址;
				ip_hdr:
				+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
				+ v(bit4) | hdrlen(bit4) | TOS[1] | len[2] | flag0[2] | flag1(bit3) | offset(bit13) | ttl[1] | porotl[1] |  hdrchecsum[2] | srcIP[4] | desIP[4] | 选项[...] | data[N] +																								  +
				+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
				*注: 
				v(bit4): 版本号,目前的版本号是4即IPv4;
				hdrlen(bit4): 首部长度-指首部站32Bit字的数目,包括可选项,由于它是个4bit因此首部最长60字节;
				TOS[1]:包括一个3bit的优先字段,4bit TOS字段和1 bit未使用但必须为0,如果所有4bit都为0,即一般服务;
				len[2]:整个IP数据报的长度以字节为单位;
				flag0[2]:指唯一标示主机发送的每一份数据报,通常每发送一份报文值就会加1;
				flag1(bit3): 用于在IP数据包分片时使用;
				offset(bit13):  用于在IP数据包分片时使用;
				ttl[1]:描述该IP数据包最多能被转发多少次,每经过一次转发,该值就会减1,当该值为0时,一个ICMP报文会被返回至源主机;
				porotl[1]: 协议字段描述该IP数据包是来自上层哪个协议,改值为1表示为ICMP,2=IGMP,6=TCP,17=UDP;
				hdrchecsum[2]:首部校验和只针对IP首部做校验,它并不关心其内部数据在传输过程中出错与否,对于数据校验是上层协议负责的;
				srcIP[4]:源IP地址;
				desIP[4]:目标IP地址;
				选项[...]:选项,可有可无;
				data[N]:数据data;
				
				icmp_hdr:
				+--------------------------------------------------------------------------------+
				+ type[1] | code[1] | checksum[2] | 	others[N](不同的类型和代码有不同的内容)  |
				+--------------------------------------------------------------------------------+
				
				
**入口参数:
**返回参数:
***************************************************************************************************************************/
void ipcFlyEthernetInit(void)
{
	struct ip_addr ip_computer;
	memset(&flyEhternetInfo,0,sizeof(flyEhternetInfo));
	
	flyEhternetInfo.LwIPSem = OSSemCreate(0);
	if(NULL == flyEhternetInfo.LwIPSem)
	{
		LIBMCU_DEBUG(ETHERNTE_DEBUG,("\r\n OSSemCreate Fail"));
	}
	
	tcpip_init(NULL,NULL);
	
	IP4_ADDR(&flyEhternetInfo.ipaddr,  192, 168, 8, 7);
	IP4_ADDR(&flyEhternetInfo.netmask, 255, 255, 0, 0);
	IP4_ADDR(&flyEhternetInfo.gw, 192, 168, 1, 1);
	
	
	netif_add(&flyEhternetInfo.netif, &flyEhternetInfo.ipaddr, &flyEhternetInfo.netmask, &flyEhternetInfo.gw, NULL, ethernetif_init, ethernet_input);
	netif_set_default(&flyEhternetInfo.netif);
	netif_set_up(&flyEhternetInfo.netif);
	FlyEthernetCreate();
	LwipTaskCreate();
	EMAC_IntStart();

}
Example #6
0
static void vWebTask( void *pvParameters )
{
    struct ip_addr ipaddr;
    struct ip_addr netmask;
    struct ip_addr gw;

    IP4_ADDR(&gw, 192,168,1,1);
    IP4_ADDR(&ipaddr, 192,168,1,2);
    IP4_ADDR(&netmask, 255,255,255,0);

    printf("Local IP:192.168.1.2\n");

    tcpip_init(NULL, NULL);

    netif_add(&netif, &ipaddr, &netmask, &gw, NULL, ethernetif_init, tcpip_input);

    netif_set_default(&netif);
#ifdef USE_DHCP
    dhcp_start(&netif);
#else
    netif_set_up(&netif);
#endif
    //NVIC_SetPriority(EMAC_TX_IRQn, configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY );
    NVIC_EnableIRQ(EMAC_TX_IRQn);
    //NVIC_SetPriority(EMAC_RX_IRQn, configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY );
    NVIC_EnableIRQ(EMAC_RX_IRQn);

    tcp_echoserver_netconn_init();

    vTaskSuspend( NULL );

}
Example #7
0
void ip_stack_init(void)
{
    /* Netif configuration */
    static ip_addr_t ipaddr, netmask, gw;

    IP4_ADDR(&gw, 10, 0, 0, 11); // toradex board IP
    IP4_ADDR(&ipaddr, 10, 0, 0, 10);
    IP4_ADDR(&netmask, 255,255,255,255);

    /* Creates the "Init done" semaphore. */
    sys_sem_new(&lwip_init_done, 0);

    /* We start the init of the IP stack. */
    tcpip_init(ipinit_done_cb, NULL);

    /* We wait for the IP stack to be fully initialized. */
    printf("Waiting for LWIP init...\n");
    sys_sem_wait(&lwip_init_done);

    /* Deletes the init done semaphore. */
    sys_sem_free(&lwip_init_done);
    printf("LWIP init complete\n");

    /* Adds a tap pseudo interface for unix debugging. */
    netif_add(&slipf, &ipaddr, &netmask, &gw, NULL, slipif_init, tcpip_input);

    netif_set_default(&slipf);
    netif_set_up(&slipf);

}
Example #8
0
void DEBUG_Init(s32 device_type,s32 channel_port)
{
    u32 level;
    struct uip_ip_addr localip,netmask,gateway;

    UIP_LOG("DEBUG_Init()\n");

    __lwp_thread_dispatchdisable();

    bp_init();

    if(device_type==GDBSTUB_DEVICE_USB) {
        current_device = usb_init(channel_port);
    } else {
        localip.addr = uip_ipaddr((const u8_t*)tcp_localip);
        netmask.addr = uip_ipaddr((const u8_t*)tcp_netmask);
        gateway.addr = uip_ipaddr((const u8_t*)tcp_gateway);

        current_device = tcpip_init(&localip,&netmask,&gateway,(u16)channel_port);
    }

    if(current_device!=NULL) {
        _CPU_ISR_Disable(level);
        __exception_sethandler(EX_DSI,dbg_exceptionhandler);
        __exception_sethandler(EX_PRG,dbg_exceptionhandler);
        __exception_sethandler(EX_TRACE,dbg_exceptionhandler);
        __exception_sethandler(EX_IABR,dbg_exceptionhandler);
        _CPU_ISR_Restore(level);

        dbg_initialized = 1;

    }
    __lwp_thread_dispatchenable();
}
/* init function */
void MX_LWIP_Init(void)
{ 
  tcpip_init( NULL, NULL );	
 
  /* add the network interface */
  netif_add(&gnetif, &ipaddr, &netmask, &gw, NULL, &ethernetif_init, &tcpip_input);
 
 
  /*  Registers the default network interface */
  netif_set_default(&gnetif);

  if (netif_is_link_up(&gnetif))
  {
    /* When the netif is fully configured this function must be called */
    netif_set_up(&gnetif);
  }
  else
  {
    /* When the netif link is down this function must be called */
       netif_set_down(&gnetif);
  }  
  

dhcp_start(&gnetif);
  

/* USER CODE BEGIN 3 */

/* USER CODE END 3 */
}
Example #10
0
File: main.c Project: DINKIN/bertos
static void init(void)
{
	/* Enable all the interrupts */
	IRQ_ENABLE;

	/* Initialize debugging module (allow kprintf(), etc.) */
	kdbg_init();
	/* Initialize system timer */
	timer_init();
	/* Initialize UART0 */
	ser_init(&out, SER_UART0);
	/* Configure UART0 to work at 115.200 bps */
	ser_setbaudrate(&out, 115200);
	/* Initialize LED driver */
	LED_INIT();

	/*
	 * Kernel initialization: processes (allow to create and dispatch
	 * processes using proc_new()).
	 */
	proc_init();

	/* Initialize TCP/IP stack */
	tcpip_init(NULL, NULL);

	/* Bring up the network interface */
	netif_add(&netif, &ipaddr, &netmask, &gw, NULL, ethernetif_init, tcpip_input);
	netif_set_default(&netif);
	netif_set_up(&netif);
}
Example #11
0
/*******************************************************************************
*
* networkInit
*
* Initializes the network interface configuration and creates the TCP/IP thread.
*
*
* RETURNS: None
* 
*******************************************************************************/
void networkInit( void )
{
#if defined(CUTE) && defined (INCLUDE_NETWORK)
	static ETH_DEV_PARAMS ethDevParms;
	
	u32_t addr;
	u32_t size;
	
	NETDBG(("lwIP Initializing...\n"));
	
	geifGetMemInfo( &addr, &size );
	NETDBG(("geif mem:  Pool: 0x%08x-0x%08x  size: %u bytes\n", addr, (addr + size - 1), size));
	
	/* Setup the network interface configuration     */
	/* Note: if DHCP is configured, it will override */
	/* the IP address settings made here              */		
			
	memset( &ethDevParms, 0, sizeof(ETH_DEV_PARAMS) );
	
	ethDevParms.num = 1;					/* Number of devices to start */
			
	ethDevParms.devices[0].vid = 0x8086;
	ethDevParms.devices[0].did = 0x1521;	/* 82579LM */
	ethDevParms.devices[0].irqNo = 18;
	ethDevParms.devices[0].instance = 1;
	IP4_ADDR((&ethDevParms.devices[0].ipAddr), 192,67,84,250);
	IP4_ADDR((&ethDevParms.devices[0].netMask), 255,255,255,0);
	IP4_ADDR((&ethDevParms.devices[0].gateway), 192,67,84,21);
	

	/* Creates the TCP/IP thread and start the interfaces */
	tcpip_init( 1, lwIPAppsInit, (void *) &ethDevParms );
#endif
}
Example #12
0
/*******************************************************************************
** Name: WebEthIntit
** Input:void
** Return: void
** Owner:zhuzhe
** Date: 2014.6.24
** Time: 11:08:41
*******************************************************************************/
_WEB_TASK_WEBTASK_INIT_
INIT FUN void WebEthIntit(void)
{
    WEB_TASK_CTRL_BLOCK*  pWebTaskControlBlock = gpstWebCtrlBlock;
    WEB_EVENT_CLASS TempWebEventItem;
    struct netif * pNetif  =  pWebTaskControlBlock->pWifiNetif;
    uint32 timeout;


    tcpip_init(NULL, NULL);
    memset(pWebTaskControlBlock->pWifiNetif, 0, sizeof(struct netif));
	netif_add(pWebTaskControlBlock->pWifiNetif, NULL, NULL, NULL, NULL,ethernetif_init, ethernet_input);
    netif_set_default(pWebTaskControlBlock->pWifiNetif);
    netif_set_link_up(pWebTaskControlBlock->pWifiNetif);
    dhcp_start(pWebTaskControlBlock->pWifiNetif);

    do
    {
        vTaskDelay(100);
        if ( netif_is_up(pWebTaskControlBlock->pWifiNetif))
        {
                   rk_printf("IP %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n",
                   ip4_addr1_16(&(pNetif->ip_addr)), ip4_addr2_16(&(pNetif->ip_addr)),
                   ip4_addr3_16(&(pNetif->ip_addr)), ip4_addr4_16(&(pNetif->ip_addr)));
                   rk_printf("GW %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n",
                          ip4_addr1_16(&(pNetif->ip_addr)), ip4_addr2_16(&(pNetif->ip_addr)),
                          ip4_addr3_16(&(pNetif->ip_addr)), ip4_addr4_16(&(pNetif->ip_addr)));
                          break;
                      }
                  }
                  while (1);


}
Example #13
0
/**
  * @brief  Start thread
  * @param  argument: not used
  * @retval None
  */
static void StartThread(void const * argument)
{
  /* Initialize LCD and LEDs */
  BSP_Config();
  
  /* Create tcp_ip stack thread */
  tcpip_init(NULL, NULL);
  
  /* Initilaize the LwIP stack */
  Netif_Config();
  
  /* Notify user about the netwoek interface config */
  User_notification(&gnetif);

  /* Start SSL Server task */
  osThreadDef(Server, ssl_server, osPriorityAboveNormal, 0, configMINIMAL_STACK_SIZE * 20);
  osThreadCreate (osThread(Server), NULL);

#ifdef USE_DHCP
  /* Start DHCPClient */
  osThreadDef(DHCP, DHCP_thread, osPriorityBelowNormal, 0, configMINIMAL_STACK_SIZE * 2);
  osThreadCreate (osThread(DHCP), &gnetif);
#endif
  
  /* Start toogleLed4 task : Toggle LED4  every 250ms */
  osThreadDef(LED4, ToggleLed4, osPriorityLow, 0, configMINIMAL_STACK_SIZE);
  osThreadCreate (osThread(LED4), NULL);
  
  for( ;; )
  {
    /* Delete the Start Thread */ 
    osThreadTerminate(NULL);
  }
}
Example #14
0
nsapi_error_t mbed_lwip_init(emac_interface_t *emac)
{
    // Check if we've already brought up lwip
    if (!mbed_lwip_get_mac_address()) {
        // Set up network
        mbed_lwip_set_mac_address();

        sys_sem_new(&lwip_tcpip_inited, 0);
        sys_sem_new(&lwip_netif_linked, 0);
        sys_sem_new(&lwip_netif_has_addr, 0);

        tcpip_init(mbed_lwip_tcpip_init_irq, NULL);
        sys_arch_sem_wait(&lwip_tcpip_inited, 0);

        memset(&lwip_netif, 0, sizeof lwip_netif);
        if (!netif_add(&lwip_netif,
#if LWIP_IPV4
                       0, 0, 0,
#endif
                       emac, MBED_NETIF_INIT_FN, tcpip_input)) {
            return NSAPI_ERROR_DEVICE_ERROR;
        }

        netif_set_default(&lwip_netif);

        netif_set_link_callback(&lwip_netif, mbed_lwip_netif_link_irq);
        netif_set_status_callback(&lwip_netif, mbed_lwip_netif_status_irq);

#if !DEVICE_EMAC
        eth_arch_enable_interrupts();
#endif
    }

    return NSAPI_ERROR_OK;
}
Example #15
0
static void mbed_lwip_core_init(void)
{

    // Check if we've already brought up lwip
    if (!lwip_inited) {
	// Seed lwip random
        lwip_seed_random();

        // Initialise TCP sequence number
        uint32_t tcp_isn_secret[4];
        for (int i = 0; i < 4; i++) {
            tcp_isn_secret[i] = LWIP_RAND();
        }
        lwip_init_tcp_isn(0, (u8_t *) &tcp_isn_secret);

        sys_sem_new(&lwip_tcpip_inited, 0);
        sys_sem_new(&lwip_netif_linked, 0);
        sys_sem_new(&lwip_netif_unlinked, 0);
        sys_sem_new(&lwip_netif_has_any_addr, 0);
#if PREF_ADDR_TIMEOUT
        sys_sem_new(&lwip_netif_has_pref_addr, 0);
#endif
#if BOTH_ADDR_TIMEOUT
        sys_sem_new(&lwip_netif_has_both_addr, 0);
#endif
        tcpip_init(mbed_lwip_tcpip_init_irq, NULL);
        sys_arch_sem_wait(&lwip_tcpip_inited, 0);

        lwip_inited = true;
    }
}
Example #16
0
int main( void )
{
	/* Configure any generic parameters needed to run the demo. */
	prvSetupHardware();

	/* Start the timers that demonstrate FreeRTOS software timers and basic
	GPIO functionality. */
	vGPIOSoftwareTimersStart();

	/* Start the task that demonstrates the SPI port being used to implement a
	disk IO interface to an SD card. */
//	vStartSPIInterfaceToSDCardTask();

	/* This call creates the TCP/IP thread. */
	tcpip_init( lwIPAppsInit, NULL );

	/* Register two command line commands to show task stats and run time stats
	respectively. */
	FreeRTOS_CLIRegisterCommand( &xTaskStats );
	FreeRTOS_CLIRegisterCommand( &xRunTimeStats );

	/* Start the FreeRTOS scheduler. */
	vTaskStartScheduler();

	/* The following line should never execute.  If it does, it means there was
	insufficient FreeRTOS heap memory available to create the Idle and/or timer
	tasks.  See the memory management section on the http://www.FreeRTOS.org web
	site for more information. */
	for( ;; );
}
Example #17
0
/**
  * @brief  Main task
  * @param  pvParameters not used
  * @retval None
  */
static void StartThread(void const * argument)
{
  /* Initialize LCD and LEDs */
  BSP_Config();
  
  /* Create tcp_ip stack thread */
  tcpip_init(NULL, NULL);
  
  /* Initilaize the LwIP stack */
  Netif_Config();
  
  /* Initialize tcp echo server */
  tcpecho_init();

  /* Initialize udp echo server */
  udpecho_init();
  
  /* Notify user about the netwoek interface config */
  User_notification(&gnetif);
  
   /* Start toogleLed4 task : Toggle LED4  every 250ms */
  osThreadDef(LED4, ToggleLed4, osPriorityLow, 0, configMINIMAL_STACK_SIZE);
  osThreadCreate (osThread(LED4), NULL);

  for( ;; )
  {
    /* Delete the Init Thread*/ 
    osThreadTerminate(NULL);
  }
}
Example #18
0
static inline int InitializeLWIP(void){
	sys_sem_t	Sema;
	int		iRet;

	dbgprintf("PS2IP: Module Loaded.\n");

	if ((iRet=RegisterLibraryEntries(&_exp_ps2ip))!=0)
	{
		printf("PS2IP: RegisterLibraryEntries returned: %d\n", iRet);
	}

	RxPBufsFree=LWIP_STACK_MAX_RX_PBUFS;
	NetManRxPacketBufferPoolFreeStart=0;
	recv_pbuf_queue_start=recv_pbuf_queue_end=NULL;

	sys_sem_new(&Sema, 0);
	dbgprintf("PS2IP: Calling tcpip_init\n");
	tcpip_init(InitDone,&Sema);

	sys_arch_sem_wait(&Sema, 0);
	sys_sem_free(&Sema);

	dbgprintf("PS2IP: tcpip_init called\n");
#if NOSYS
	InitTimer();
#endif

	dbgprintf("PS2IP: System Initialised\n");

	return 0;
}
Example #19
0
void main_lwIP( void )
{
TimerHandle_t xTimer;

	/* Init lwIP and start lwIP tasks. */
	tcpip_init( lwIPAppsInit, NULL );

	/* A timer is used to toggle an LED just to show the application is
	executing. */
	xTimer = xTimerCreate( 	"LED", 					/* Text name to make debugging easier. */
							mainTIMER_PERIOD_MS, 	/* The timer's period. */
							pdTRUE,					/* This is an auto reload timer. */
							NULL,					/* ID is not used. */
							prvLEDToggleTimer );	/* The callback function. */

	/* Start the timer. */
	configASSERT( xTimer );
	xTimerStart( xTimer, mainDONT_BLOCK );

	/* Start the tasks and timer running. */
	vTaskStartScheduler();

	/* If all is well, the scheduler will now be running, and the following
	line will never be reached.  If the following line does execute, then
	there was either insufficient FreeRTOS heap memory available for the idle
	and/or timer tasks to be created, or vTaskStartScheduler() was called from
	User mode.  See the memory management section on the FreeRTOS web site for
	more details on the FreeRTOS heap http://www.freertos.org/a00111.html.  The
	mode from which main() is called is set in the C start up code and must be
	a privileged mode (not user mode). */
	for( ;; );
}
Example #20
0
/**
 *
 * @brief Initializes the lwIP TCP/IP stack.
 *
 * @param lwipIf  The interface structure for lwIP
 *
 * @return true if everything ok, false otherwise.
*/
static bool lwIPInit(LWIP_IF *const lwipIf, const unsigned int ifNum)
{
    static unsigned int lwipInitFlag = LWIP_NOT_INITIALIZED;
    bool ret = true;

    /* do lwip library init only once */
    if(LWIP_NOT_INITIALIZED == lwipInitFlag)
    {
        tcpip_init(NULL, NULL);
    }
    setPortIf(lwipIf, ifNum);

    if(netif_add(&cpswNetIF[ifNum], &lwipIf->ipAddr, &lwipIf->netMask, 
            &lwipIf->gwAddr,&cpswPortIf[ifNum], cpswif_init, tcpip_input) != NULL)
    {
        if(LWIP_NOT_INITIALIZED == lwipInitFlag)
        {
            netif_set_default(&cpswNetIF[ifNum]);
            lwipInitFlag = LWIP_INITIALIZED;
        }
	lwipIf->ipMode = IPADDR_USE_DHCP;
        ret = netifStart(lwipIf, ifNum);
    }
    else
    {
        LWIP_PRINTF("\n\rUnable to add interface for interface %d", ifNum);
        ret = false;
    }
    return ret;
}
Example #21
0
/*-----------------------------------------------------------------------------------*/
static void
main_thread(void *arg)
{
  sys_sem_t sem;
  LWIP_UNUSED_ARG(arg);

  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);
  printf("TCP/IP initialized.\n");

#if LWIP_SOCKET
  if(ping_flag) {
    sys_thread_new("ping_thread", ping_thread, NULL, DEFAULT_THREAD_STACKSIZE, DEFAULT_THREAD_PRIO);
  }
#endif

  printf("Applications started.\n");


#ifdef MEM_PERF
  mem_perf_init("/tmp/memstats.client");
#endif /* MEM_PERF */
#if 0
    stats_display();
#endif
  /* Block forever. */
  sys_thread_new("pppos_rx_thread", pppos_rx_thread, NULL, DEFAULT_THREAD_STACKSIZE, DEFAULT_THREAD_PRIO);
  sys_sem_wait(&sem);
}
Example #22
0
/**
  * @brief  Initializes the lwIP stack
  * @param  None
  * @retval None
  */
void LwIP_Init(void)
{
	struct ip_addr ipaddr;
	struct ip_addr netmask;
	struct ip_addr gw;
	#ifndef USE_DHCP 
		uint8_t iptab[4];
		uint8_t iptxt[20];
	#endif
	/* Create tcp_ip stack thread */
	tcpip_init( NULL, NULL );	

	/* IP address setting & display on STM32_evalboard LCD*/
	#ifdef USE_DHCP
		ipaddr.addr = 0;
		netmask.addr = 0;
		gw.addr = 0;
	#else
		IP4_ADDR(&ipaddr, IP_ADDR0, IP_ADDR1, IP_ADDR2, IP_ADDR3);
		IP4_ADDR(&netmask, NETMASK_ADDR0, NETMASK_ADDR1 , NETMASK_ADDR2, NETMASK_ADDR3);
		IP4_ADDR(&gw, GW_ADDR0, GW_ADDR1, GW_ADDR2, GW_ADDR3);

		iptab[0] = IP_ADDR3;
		iptab[1] = IP_ADDR2;
		iptab[2] = IP_ADDR1;
		iptab[3] = IP_ADDR0;

		sprintf((char*)iptxt, "  %d.%d.%d.%d", iptab[3], iptab[2], iptab[1], iptab[0]); 

		syslog(SYSTEM_LVL,true, "Static IP address %s", iptxt);
	#endif

	/*
	    - netif_add(struct netif *netif, ip_addr_t *ipaddr,
			ip_addr_t *netmask, ip_addr_t *gw,
			void *state, err_t (* init)(struct netif *netif),
			err_t (* input)(struct pbuf *p, struct netif *netif))

		Adds your network interface to the netif_list. Allocate a struct
		netif and pass a pointer to this structure as the first argument.
		Give pointers to cleared ip_addr structures when using DHCP,
		or fill them with sane numbers otherwise. The state pointer may be NULL.
	
		The init function pointer must point to a initialization function for
		your ethernet netif interface. The following code illustrates it's use.
	*/

	netif_add(&xnetif, &ipaddr, &netmask, &gw, NULL, &ethernetif_init, &tcpip_input);

	/*  Registers the default network interface. */
	netif_set_default(&xnetif);

	/*  When the netif is fully configured this function must be called.*/
	netif_set_up(&xnetif); 

    #if !defined(USE_DHCP)
		netif_status_callback(&xnetif);
	#endif
}
Example #23
0
/*************************************************************************************************
 * ethernet_init_LwIP
 *
 * starts the LwIP layer
 */
static void ethernet_init_LwIP(void)
{
	sys_sem_t sem;

	#if ( (LWIP_VERSION) == ((1U << 24) | (3U << 16) | (2U << 8) | (LWIP_VERSION_RC)) )
	  sem = sys_sem_new(0); // Create a new semaphore.
	  tcpip_init(ethernet_tcpip_init_done, &sem);
	  sys_sem_wait(sem);    // Block until the lwIP stack is initialized.
	  sys_sem_free(sem);    // Free the semaphore.
	#else
	  err_t  err_sem;
	  err_sem = sys_sem_new(&sem, 0); // Create a new semaphore.
	  tcpip_init(ethernet_tcpip_init_done, &sem);
	  sys_sem_wait(&sem);    // Block until the lwIP stack is initialized.
	  sys_sem_free(&sem);    // Free the semaphore.
	#endif
}
Example #24
0
/**
 *  \brief start lwIP layer.
 */
static void prvlwIPInit( void )
{
  sys_sem_t sem;

#if ( (LWIP_VERSION) == ((1U << 24) | (3U << 16) | (2U << 8) | (LWIP_VERSION_RC)) )
	sem = sys_sem_new(0);   /* Create a new semaphore. */
	tcpip_init(tcpip_init_done, &sem);
	sys_sem_wait(sem);      /* Block until the lwIP stack is initialized. */
	sys_sem_free(sem);      /* Free the semaphore. */
#else
	err_t err_sem;
	err_sem = sys_sem_new(&sem, 0); /* Create a new semaphore. */
	tcpip_init(tcpip_init_done, &sem);
	sys_sem_wait(&sem);     /* Block until the lwIP stack is initialized. */
	sys_sem_free(&sem);     /* Free the semaphore. */
#endif
}
Example #25
0
/**********************************  LWIP INIT  ****************************************************/
static int __dim_sum_lwip_init(void *argv)
{
	tcpip_init(NULL, NULL);
	dim_sum_netdev_startup();

	printk("LWIP-1.4.1 TCP/IP initialized.\n");
	
	return 0;
}
static void init_netif(ip_addr_t *ipaddr, ip_addr_t *netmask, ip_addr_t *gw) {
    tcpip_init(tcpip_init_done, NULL);
    tcpip_inited.wait();
    
    memset((void*) &lpcNetif, 0, sizeof(lpcNetif));
    netif_add(&lpcNetif, ipaddr, netmask, gw, NULL, lpc_enetif_init, tcpip_input);
    netif_set_default(&lpcNetif);
    netif_set_status_callback(&lpcNetif, netif_status_callback);
}
Example #27
0
/**
 * \brief Initialize ethernet stask.
 */
void init_ethernet(void)
{
	/* Initialize lwIP. */
	/* Call tcpip_init for threaded lwIP mode. */
	tcpip_init(NULL, NULL);

	/* Set hw and IP parameters, initialize MAC too */
	ethernet_configure_interface();
}
Example #28
0
/*-----------------------------------------------------------------------------------*/
void
#ifdef __APPLE2__
main(void)
#else /* __APPLE2__ */
main(int argc, char *argv[])
#endif /* __APPLE2__ */
{

#if STACK_SIZE
  memset((void *)(0xBF00 - STACK_SIZE),
         0xA2, STACK_SIZE - (0xBF00 - *(unsigned int *)0x80) - 10);
  atexit(stack_size);
#endif /* STACK_SIZE */

  ek_init();
  ek_start(&init);

  tcpip_init(NULL);
  resolv_init(NULL);
  
  ctk_init();
  
  program_handler_init();

  program_handler_add(&www_dsc,       "Web browser", 1);
  program_handler_add(&email_dsc,     "E-mail",      1);
  program_handler_add(&ftp_dsc,       "FTP client",  1);
  program_handler_add(&directory_dsc, "Directory",   1);

  while(1) {
    if(ek_run() == 0) {

#ifdef __APPLE2__

      program_handler_load("welcome.prg", NULL);

#else /* __APPLE2__ */

      static char *startup;
      static char *slash;

      if(argc == 1) {
        startup = "welcome.prg";
      } else {
	startup = argv[1];
	while(slash = strchr(startup, '/')) {
	  startup = slash + 1;
	}
      }
      program_handler_load(startup, NULL);

#endif /* __APPLE2__ */

      break;
    }
  }
  while(1) {
    ek_run();
  }
}
Example #29
0
void _init(void){
  sys_sem_t sem;

  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);
  sys_sem_free(&sem);
}
void
lwip_sock_init()
{
    volatile unsigned tcpip_init_done_signal = 0;

    tcpip_init(tcpip_init_done, (void *)&tcpip_init_done_signal);

    /* wait until tcpip initialization is complete */
    while (!tcpip_init_done_signal)
        ;
}