Example #1
0
/** Configures the uIP stack ready for network traffic processing. */
void uIPManagement_Init(void)
{
	/* uIP Timing Initialization */
	clock_init();
	timer_set(&ConnectionTimer, CLOCK_SECOND / 2);
	timer_set(&ARPTimer, CLOCK_SECOND * 10);

	/* uIP Stack Initialization */
	uip_init();
	uip_arp_init();
	uip_setethaddr(MACAddress);

	/* DHCP/Server IP Settings Initialization */
	#if defined(ENABLE_DHCP_CLIENT)
	HaveIPConfiguration = false;
	DHCPClientApp_Init();
	#else
	HaveIPConfiguration = true;
	uip_ipaddr_t IPAddress, Netmask, GatewayIPAddress;
	uip_ipaddr(&IPAddress,        DEVICE_IP_ADDRESS[0], DEVICE_IP_ADDRESS[1], DEVICE_IP_ADDRESS[2], DEVICE_IP_ADDRESS[3]);
	uip_ipaddr(&Netmask,          DEVICE_NETMASK[0],    DEVICE_NETMASK[1],    DEVICE_NETMASK[2],    DEVICE_NETMASK[3]);
	uip_ipaddr(&GatewayIPAddress, DEVICE_GATEWAY[0],    DEVICE_GATEWAY[1],    DEVICE_GATEWAY[2],    DEVICE_GATEWAY[3]);
	uip_sethostaddr(&IPAddress);
	uip_setnetmask(&Netmask);
	uip_setdraddr(&GatewayIPAddress);
	#endif

	/* HTTP Webserver Initialization */
	HTTPServerApp_Init();

	/* TELNET Server Initialization */
	#if defined(ENABLE_TELNET_SERVER)
	TELNETServerApp_Init();
	#endif
}
Example #2
0
void Test_uip_arp_arpout(CuTest *tc) {

	u8_t temp_buf[]= "\x11\x22\x33\x44\x55\x66\x77\x88\x99\x00\xAA\xBB\x08\x00"
	"\x45"  //ipv4, 4*5=20byte
	"\x00"
	"\x00\x14" //fra
	"\x00\x00"
	"\x00\x00"
	"\x11" //ttl
	"\x06" //tcp
	"\x00\x00"  //header checksum,dont fit now
	"\xC0\xA8\x00\x02"
	"\xff\xff\xff\x00" //ip broadcast,subnet broad cast
	"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
	"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";

	iprintf_s(temp_buf,sizeof(temp_buf));
	uip_arp_init();
	memcpy(uip_buf,temp_buf,60);//broad cast,=dest ip equeals mask
	uip_arp_out();
    CuAssertHexEquals_Msg(tc,"arp out 1",0xFF,IPBUF->ethhdr.dest.addr[0]);
    IPBUF->destipaddr[0]=0xA8C0;
    IPBUF->destipaddr[1]=0x0300;
    uip_arp_out();
    CuAssertHexEquals_Msg(tc,"arp out 2",0xFF,IPBUF->ethhdr.dest.addr[0]);
    CuAssertHexEquals_Msg(tc,"arp out 3",0xFF,IPBUF->ethhdr.dest.addr[1]);
    CuAssertHexEquals_Msg(tc,"arp out 4",0xFF,IPBUF->ethhdr.dest.addr[2]);
    CuAssertHexEquals_Msg(tc,"arp out 5",0xFF,IPBUF->ethhdr.dest.addr[3]);
    CuAssertHexEquals_Msg(tc,"arp out 6",0xFF,IPBUF->ethhdr.dest.addr[4]);
    CuAssertHexEquals_Msg(tc,"arp out 7",0xFF,IPBUF->ethhdr.dest.addr[5]);
    CuAssertHexEquals_Msg(tc,"arp out 8",HTONS(UIP_ETHTYPE_ARP),BUF->ethhdr.type);
    CuAssertHexEquals_Msg(tc,"arp out 8",0x0608,BUF->ethhdr.type);
}
Example #3
0
/** Configures the uIP stack ready for network traffic processing. */
void uIPManagement_Init(void)
{
	/* uIP Timing Initialization */
	clock_init();
	timer_set(&ConnectionTimer, CLOCK_SECOND / 2);
	timer_set(&ARPTimer, CLOCK_SECOND * 10);

	/* uIP Stack Initialization */
	uip_init();
	uip_arp_init();

	/* DHCP/Server IP Settings Initialization */
	if (USB_CurrentMode == USB_MODE_Device)
	{
		MACAddress.addr[0] = SERVER_MAC_ADDRESS[0];
		MACAddress.addr[1] = SERVER_MAC_ADDRESS[1];
		MACAddress.addr[2] = SERVER_MAC_ADDRESS[2];
		MACAddress.addr[3] = SERVER_MAC_ADDRESS[3];
		MACAddress.addr[4] = SERVER_MAC_ADDRESS[4];
		MACAddress.addr[5] = SERVER_MAC_ADDRESS[5];

		#if defined(ENABLE_DHCP_SERVER)
		DHCPServerApp_Init();
		#endif

		uip_ipaddr_t IPAddress, Netmask, GatewayIPAddress;
		uip_ipaddr(&IPAddress,        DEVICE_IP_ADDRESS[0], DEVICE_IP_ADDRESS[1], DEVICE_IP_ADDRESS[2], DEVICE_IP_ADDRESS[3]);
		uip_ipaddr(&Netmask,          DEVICE_NETMASK[0],    DEVICE_NETMASK[1],    DEVICE_NETMASK[2],    DEVICE_NETMASK[3]);
		uip_ipaddr(&GatewayIPAddress, DEVICE_GATEWAY[0],    DEVICE_GATEWAY[1],    DEVICE_GATEWAY[2],    DEVICE_GATEWAY[3]);
		uip_sethostaddr(&IPAddress);
		uip_setnetmask(&Netmask);
		uip_setdraddr(&GatewayIPAddress);
	}
	else
	{
		#if defined(ENABLE_DHCP_CLIENT)
		DHCPClientApp_Init();
		#else
		uip_ipaddr_t IPAddress, Netmask, GatewayIPAddress;
		uip_ipaddr(&IPAddress,        DEVICE_IP_ADDRESS[0], DEVICE_IP_ADDRESS[1], DEVICE_IP_ADDRESS[2], DEVICE_IP_ADDRESS[3]);
		uip_ipaddr(&Netmask,          DEVICE_NETMASK[0],    DEVICE_NETMASK[1],    DEVICE_NETMASK[2],    DEVICE_NETMASK[3]);
		uip_ipaddr(&GatewayIPAddress, DEVICE_GATEWAY[0],    DEVICE_GATEWAY[1],    DEVICE_GATEWAY[2],    DEVICE_GATEWAY[3]);
		uip_sethostaddr(&IPAddress);
		uip_setnetmask(&Netmask);
		uip_setdraddr(&GatewayIPAddress);
		#endif
	}

	/* Virtual Webserver Ethernet Address Configuration */
	uip_setethaddr(MACAddress);

	/* HTTP Webserver Initialization */
	HTTPServerApp_Init();

	/* TELNET Server Initialization */
	#if defined(ENABLE_TELNET_SERVER)
	TELNETServerApp_Init();
	#endif
}
Example #4
0
void vNet_Init_M1()
{	
	// Init the uIP stack
	uip_init();

	// Init the ARP table
	uip_arp_init();	
	
	// Init the Wifi controller
	nic_init();
	
	// Connect as per configuration options
	nic_connect();
}
Example #5
0
/*-------------------------------------------
| Name:uip_sock_init
| Description:
| Parameters:
| Return Type:
| Comments:
| See:
---------------------------------------------*/
int uip_sock_init(void) {
#if defined (USE_UIP)
   int i;
   socketList = (socket_t*)&_socketList;
   socksconn_state_list = (struct socksconn_state*)&_socksconn_state_list;
   uip_init();
   #if UIP_CONF_IPV6
   {
      uip_ip6addr_t ip6addr;
      memcpy(uip_lladdr.addr, "\x00\x0c\x29\x28\x23\x45", 6); // Set in zigbeestack.cpp (UID)    
      uip_ip6addr(&ip6addr, 0xfe80,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0002);
      uip_sethostaddr(&ip6addr);
      uip_ipaddr_copy(&uip_hostaddr, &ip6addr);

      tcpip_init();  // rpl_init() is called inside tcpip_init()
      clock_init();
      uip_ds6_addr_add(&ip6addr, 0, ADDR_MANUAL);
   }
   #endif
   //ethernet
   #if defined(USE_IF_ETHERNET)
      #if !UIP_CONF_IPV6
   uip_arp_init();
   #endif
#endif
 
   for(i=0; i<MAX_SOCKET; i++) {
      #if UIP_CONF_IPV6
      socketList[i].addr_in.sin6_port=0;
      #else
      socketList[i].addr_in.sin_port=0;
      #endif
      socketList[i].socksconn=NULL;
      socketList[i].desc = -1;
   }

   for(i=0; i<UIP_CONNS; i++) {
      socksconn_state_list[i].hsocks=NULL;
      uip_conns[i].appstate.state = &socksconn_state_list[i];
   }
   for(;i<(UIP_CONNS+UIP_UDP_CONNS);i++){
      socksconn_state_list[i].hsocks=NULL;
      uip_udp_conns[i-UIP_CONNS].appstate.state = &socksconn_state_list[i];
   }
#else
   return -1;
#endif
   return 0;
}
Example #6
0
void netInit()
{
  POSTASK_t t;
  int i;

  uipGiant = posSemaCreate(0);
  uipMutex = posMutexCreate();

  pollTicks = INFINITE;
  P_ASSERT("netInit", uipGiant != NULL && uipMutex != NULL);

  POS_SETEVENTNAME(uipGiant, "uip:giant");
  POS_SETEVENTNAME(uipMutex, "uip:mutex");

// uosFS setup

  netFS.base.mountPoint = "/socket";
  netFS.base.cf = &netFSConf;
 
  uosMount(&netFS.base);
  
// Initialize contiki-style timers (used by uip code)

  etimer_init();

  dataToSend = 0;

  for(i = 0; i < UIP_CONNS; i++)
    uip_conns[i].appstate.file = NULL;

#if UIP_UDP
  for(i = 0; i < UIP_UDP_CONNS; i++)
    uip_udp_conns[i].appstate.file = NULL;
#endif /* UIP_UDP */

  netInterfaceInit();
  uip_init();

#if NETSTACK_CONF_WITH_IPV6 == 0
  uip_arp_init();
#endif

  t = posTaskCreate(netMainThread, NULL, NETCFG_TASK_PRIORITY, NETCFG_STACK_SIZE);
  P_ASSERT("netInit2", t != NULL);
  POS_SETTASKNAME(t, "uip:main");
}
Example #7
0
File: TcpIp.c Project: AndTH/GCA
void TcpIpInit(void)
{
   uint8_t                                 IpAddress[4];
   uint8_t                                 NetMask[4];
   uint8_t                                 RouterIp[4];

   /* Set up the network interface */
   UserIoIpSettingsGet(IpAddress, NetMask, RouterIp);
   nic_init();
   uip_init(IpAddress, NetMask, RouterIp);
   uip_arp_init();
   uip_listen(HTONS(ETH_LOC_BUFFER_BUFFER_TCP_PORT));

   TcpIpUipTimerCounter = 0;
   TcpIpUipArpTimerCounter = 0;

   TCCR0B = (1 << CS01) | (1<<CS00);
   TIMSK0 |= (1<<TOIE0);
}
Example #8
0
/**
 * @brief   Configure Network
 * @param   None
 * @retval  None
 */
void Network_Configuration(void)
{
	struct uip_eth_addr mac = {{ 0xeb, 0xa0, 0x00, 0x00, 0x00, 0x00 }};
	enc28j60_init(mac.addr);

	uip_init();
	uip_arp_init();
	uip_setethaddr(mac);

	uip_ipaddr_t ipaddr;
	uip_ipaddr(ipaddr, 192, 168, 0, 100);
	uip_sethostaddr(ipaddr);
	uip_ipaddr(ipaddr, 255, 255, 255, 0);
	uip_setnetmask(ipaddr);
	uip_ipaddr(ipaddr, 192, 168, 0, 1);
	uip_setdraddr(ipaddr);

	uip_listen(HTONS(4000));
}
void uip_task_init(const uint8 *ipbuf, const uint8 *netmask, const uint8 *mac)
{
  	uip_ipaddr_t ipaddr;
  		
  	uip_init();
  	uip_arp_init();
  	
  	uip_ipaddr(ipaddr, ipbuf[0], ipbuf[1], ipbuf[2], ipbuf[3]);
  	uip_sethostaddr(ipaddr);
  	
  	uip_ipaddr(ipaddr, netmask[0], netmask[1], netmask[2], netmask[3]);
  	uip_setnetmask(ipaddr);  		

	uip_ethaddr.addr[0] = mac[0];
	uip_ethaddr.addr[1] = mac[1];
	uip_ethaddr.addr[2] = mac[2];
	uip_ethaddr.addr[3] = mac[3];
	uip_ethaddr.addr[4] = mac[4];
	uip_ethaddr.addr[5] = mac[5];
  		
}
Example #10
0
// Init application
void elua_uip_init( const struct uip_eth_addr *paddr )
{
  // Set hardware address
  uip_setethaddr( (*paddr) );
  
  // Initialize the uIP TCP/IP stack.
  uip_init();
  uip_arp_init();  
  
#ifdef BUILD_DHCPC
  dhcpc_init( paddr->addr, sizeof( *paddr ) );
  dhcpc_request();
#else
  elua_uip_conf_static();
#endif
  
  resolv_init();
  
#ifdef BUILD_CON_TCP
  uip_listen( HTONS( ELUA_NET_TELNET_PORT ) );
#endif  
}
Example #11
0
void network_setup() {
  printf("network_setup\n");
  
  uip_ipaddr_t ipaddr;
  uip_ipaddr_t gatewayAddr;
  uip_ipaddr_t netmaskAddr;

  uip_lladdr.addr[0] = MAC_ADDRESS[0];
  uip_lladdr.addr[1] = MAC_ADDRESS[1];
  uip_lladdr.addr[2] = MAC_ADDRESS[2];
  uip_lladdr.addr[3] = MAC_ADDRESS[3];
  uip_lladdr.addr[4] = MAC_ADDRESS[4];
  uip_lladdr.addr[5] = MAC_ADDRESS[5];

  uip_ipaddr(&ipaddr, 192, 168, 0, 101);
  uip_sethostaddr(&ipaddr);

  uip_ipaddr(&gatewayAddr, 192, 168, 0, 1);
  uip_setdraddr(&gatewayAddr);

  uip_ipaddr(&netmaskAddr, 255, 255, 255, 0);
  uip_setnetmask(&netmaskAddr);

  tcpip_set_outputfunc(enc28j60_tcp_output);
  enc28j60_init(uip_lladdr.addr);
  
  uip_init();

  uip_arp_init();
  
  printf("Start RS232UDP Process\n");
  process_start(&rs232udp_process, NULL);

  printf("Start network Process\n");
  process_start(&network_process, NULL);

  printf("END network_setup\n");
}
Example #12
0
/////////////////////////////////////////////////////////////////////////////
// The uIP Task is executed each mS
/////////////////////////////////////////////////////////////////////////////
static void UIP_TASK_Handler(void *pvParameters)
{
  int i;
  struct timer periodic_timer, arp_timer;

  // Initialise the xLastExecutionTime variable on task entry
  portTickType xLastExecutionTime = xTaskGetTickCount();

  // take over exclusive access to UIP functions
  MUTEX_UIP_TAKE;

  // init uIP timers
  timer_set(&periodic_timer, CLOCK_SECOND / 2);
  timer_set(&arp_timer, CLOCK_SECOND * 10);

  // init the network driver
  network_device_init();

  // init uIP
  uip_init();
  uip_arp_init();

  // set my ethernet address
  unsigned char *mac_addr = network_device_mac_addr();
  {
    int i;
    for(i=0; i<6; ++i)
      uip_ethaddr.addr[i] = mac_addr[i];
  }

#ifndef DONT_USE_DHCP
  dhcpc_init(uip_ethaddr.addr, sizeof(uip_ethaddr.addr));
  MIOS32_MIDI_SendDebugMessage("[UIP_TASK] DHCP Client requests the IP settings...\n");
#else
  uip_ipaddr_t ipaddr;
  // set my IP address
  uip_ipaddr(ipaddr,
	     ((MY_IP_ADDRESS)>>24) & 0xff,
	     ((MY_IP_ADDRESS)>>16) & 0xff,
	     ((MY_IP_ADDRESS)>> 8) & 0xff,
	     ((MY_IP_ADDRESS)>> 0) & 0xff);
  uip_sethostaddr(ipaddr);

  // set my netmask
  uip_ipaddr(ipaddr,
	     ((MY_NETMASK)>>24) & 0xff,
	     ((MY_NETMASK)>>16) & 0xff,
	     ((MY_NETMASK)>> 8) & 0xff,
	     ((MY_NETMASK)>> 0) & 0xff);
  uip_setnetmask(ipaddr);

  // default router
  uip_ipaddr(ipaddr,
	     ((MY_GATEWAY)>>24) & 0xff,
	     ((MY_GATEWAY)>>16) & 0xff,
	     ((MY_GATEWAY)>> 8) & 0xff,
	     ((MY_GATEWAY)>> 0) & 0xff);
  uip_setdraddr(ipaddr);

  MIOS32_MIDI_SendDebugMessage("[UIP_TASK] IP Address statically set:\n");

  // start services immediately
  UIP_TASK_StartServices();
#endif

  // release exclusive access to UIP functions
  MUTEX_UIP_GIVE;

  // endless loop
  while( 1 ) {
    vTaskDelayUntil(&xLastExecutionTime, 1 / portTICK_RATE_MS);

    // take over exclusive access to UIP functions
    MUTEX_UIP_TAKE;

    if( !(clock_time_tick() % 100) ) {
      // each 100 mS: check availablility of network device
      network_device_check();
    }

    if( network_device_available() ) {
      uip_len = network_device_read();

      if( uip_len > 0 ) {
	if(BUF->type == htons(UIP_ETHTYPE_IP) ) {
	  uip_arp_ipin();
	  uip_input();

	  /* If the above function invocation resulted in data that
	     should be sent out on the network, the global variable
	     uip_len is set to a value > 0. */
	  if( uip_len > 0 ) {
	    uip_arp_out();
	    network_device_send();
	  }
	} else if(BUF->type == htons(UIP_ETHTYPE_ARP)) {
	  uip_arp_arpin();
	  /* If the above function invocation resulted in data that
	     should be sent out on the network, the global variable
	     uip_len is set to a value > 0. */
	  if(uip_len > 0) {
	    network_device_send();
	  }
	}

      } else if(timer_expired(&periodic_timer)) {
	timer_reset(&periodic_timer);
	for(i = 0; i < UIP_CONNS; i++) {
	  uip_periodic(i);
	  /* If the above function invocation resulted in data that
	     should be sent out on the network, the global variable
	     uip_len is set to a value > 0. */
	  if(uip_len > 0) {
	    uip_arp_out();
	    network_device_send();
	  }
	}

#if UIP_UDP
	for(i = 0; i < UIP_UDP_CONNS; i++) {
	  uip_udp_periodic(i);
	  /* If the above function invocation resulted in data that
	     should be sent out on the network, the global variable
	     uip_len is set to a value > 0. */
	  if(uip_len > 0) {
	    uip_arp_out();
	    network_device_send();
	  }
	}
#endif /* UIP_UDP */

	/* Call the ARP timer function every 10 seconds. */
	if(timer_expired(&arp_timer)) {
	  timer_reset(&arp_timer);
	  uip_arp_timer();
	}
      }
    }

    // release exclusive access to UIP functions
    MUTEX_UIP_GIVE;

  }
}
Example #13
0
int main(void)
{
	uint8_t i;
        
  P5DIR|=BIT1;
  //P5OUT&=~BIT1;
  P5OUT|=BIT1;
  _DINT();                                //Disable Interrupts   -- For initlization purposes
   WDTCTL = WDTPW + WDTHOLD;               //Stop WDT

   /*
   Set System Clock Frequency to (121+1) * 32786 * 2 = 7.995392Mhz
   This freq. allows for 2400 - 230400 bit rate UART operation with less than 0.86% error
   */
   FLL_CTL0 = (DCOPLUS | XCAP18PF);       //Enable Frequency Multiplier (DCO+) and XIN/XOUT caps to 18pF
   SCFI0 = (FLLD_2 | FN_8);               //Set Multiplier to 2, and DCO range to 8MHz nominal
   SCFQCTL = 121;                         //7.995392Mhz Operation with No Modulation
  
  //setup serial port 
  
#if DEBUG_SERIAL
    debug_serial_init();
    printf("asd  %i",23244);
#endif 
	
	for(i=0;i<6;i++)
		uNet_eth_address.addr[i]=_eth_addr[i];
	
  // init NIC device driver
#if DEBUG_SERIAL
 	
	printf("MAC address:%x:%x:%x:%x:%x:%x\r\n",\
			(int)_eth_addr[0],(int)_eth_addr[1],(int)_eth_addr[2],\
			(int)_eth_addr[3],(int)_eth_addr[4],(int)_eth_addr[5]);

        printf("Initializing NIC...\r\n");
  
#endif

  nic_init(_eth_addr);

  uip_ipaddr_t ipaddr;

  uip_setethaddr(uNet_eth_address);

#if DEBUG_SERIAL
  printf("Initializing uIP...\r\n");
#endif 
  //init uIP
  uip_init();

#if DEBUG_SERIAL
  printf("Initializing ARP...\r\n");
#endif 
  //init ARP cache
  uip_arp_init();

#if DEBUG_SERIAL
  printf("Initializing timer...\r\n");
#endif 
  // init periodic timer
  clock_init();

//#if DEBUG_SERIAL
  printf("Initializing webclient...\r\n");
//#endif 
    webclient_init();
    
  _EINT();                               // reenable interrupts


	if(!_enable_dhcp)
	{

#if DEBUG_SERIAL
  	printf("Initializing tcp/ip settings\r\n");
#endif
	
//#if DEBUG_SERIAL

  	printf("IP %i.%i.%i.%i\r\n",
			(int)_ip_addr[0],(int)_ip_addr[1],(int)_ip_addr[2],(int)_ip_addr[3]);

  	printf("NetMask %i.%i.%i.%i\r\n",
			(int)_net_mask[0],(int)_net_mask[1],(int)_net_mask[2],(int)_net_mask[3]);

  	printf("Gateway %i.%i.%i.%i\r\n",
			(int)_gateway[0],(int)_gateway[1],(int)_gateway[2],(int)_gateway[3]);

//#endif

		uip_ipaddr(ipaddr, _ip_addr[0], _ip_addr[1], _ip_addr[2], _ip_addr[3]);
    uip_sethostaddr(ipaddr);

    uip_ipaddr(ipaddr, _net_mask[0], _net_mask[1], _net_mask[2], _net_mask[3]);
    uip_setnetmask(ipaddr);

		uip_ipaddr(ipaddr, _gateway[0], _gateway[1], _gateway[2], _gateway[3]);
		uip_setdraddr(ipaddr);
	} else {
#if DEBUG_SERIAL
		printf("Going to query DHCP server...\r\n");
#endif

    uip_ipaddr(ipaddr, 0, 0, 0, 0);
    uip_sethostaddr(ipaddr);
    uip_setnetmask(ipaddr);
		uip_setdraddr(ipaddr);
	}

  timer_set(&periodic_timer, CLOCK_SECOND * 2 );
  timer_set(&arp_timer, CLOCK_SECOND * 10);

	
/*
	if(_enable_dhcp)
	{
		dhcpc_init(&uNet_eth_address.addr[0], 6);
		dhcpc_request();
	}
*/
	/* Initialize Scheduler so that it can be used */
	//Scheduler_Init();

	/* Initialize USB Subsystem */
	//USB_Init();

	//Scheduler_SetTaskMode(NetTask, TASK_RUN);


	/* Scheduling - routine never returns, so put this last in the main function */
	//Scheduler_Start();
//#if DEBUG_SERIAL
		printf("Starting main loop...\r\n");
//#endif
	while(1) {
		NetTask();
                webclient_get("www", SERVER_PORT,"/");
	}
}
Example #14
0
PROCESS_THREAD(usb_eth_process, ev , data)
{
    PROCESS_BEGIN();
    usb_register_request_handler(&cdc_eth_request_hook);
    usb_setup();
    usb_set_ep_event_process(DATA_OUT, process_current);
    usb_set_global_event_process(process_current);
    uip_fw_default(&usbethif);
    uip_setethaddr(default_uip_ethaddr);
    uip_arp_init();

    while(1) {
        PROCESS_WAIT_EVENT();
        if (ev == PROCESS_EVENT_EXIT) break;
        if (ev == PROCESS_EVENT_POLL) {
            unsigned int events = usb_get_global_events();
            if (events) {
                if (events & USB_EVENT_CONFIG) {
                    if (usb_get_current_configuration() != 0) {
                        printf("Configured\n");
                        usb_setup_bulk_endpoint(DATA_IN);
                        usb_setup_bulk_endpoint(DATA_OUT);
                        usb_setup_interrupt_endpoint(INTERRUPT_IN);
                        init_recv_buffer();
                        usb_submit_recv_buffer(DATA_OUT, &recv_buffer);
#if 0
                        {
                            static const uint8_t foo[4] = {0x12,0x34,0x56,0x78};
                            xmit_buffer[0].next = NULL;
                            xmit_buffer[0].left = sizeof(foo);
                            xmit_buffer[0].flags = USB_BUFFER_SHORT_END;
                            xmit_buffer[0].data = &foo;

                            usb_submit_xmit_buffer(DATA_IN, &xmit_buffer[0]);
                        }
#endif
                    } else {
                        usb_disable_endpoint(DATA_IN);
                        usb_disable_endpoint(DATA_OUT);
                        usb_disable_endpoint(INTERRUPT_IN);
                    }
                }
            }
            events = usb_get_ep_events(DATA_OUT);
            if (events & USB_EP_EVENT_NOTIFICATION) {
                uip_len = sizeof(recv_data) - recv_buffer.left;
                /* printf("Received: %d bytes\n", uip_len);  */
                memcpy(uip_buf, recv_data, uip_len);
#if UIP_CONF_IPV6
                if(BUF->type == uip_htons(UIP_ETHTYPE_IPV6)) {
                    uip_neighbor_add(&IPBUF->srcipaddr, &BUF->src);
                    tcpip_input();
                } else
#endif /* UIP_CONF_IPV6 */
                    if(BUF->type == uip_htons(UIP_ETHTYPE_IP)) {
                        uip_len -= sizeof(struct uip_eth_hdr);
                        tcpip_input();
                    } else if(BUF->type == uip_htons(UIP_ETHTYPE_ARP)) {
                        uip_arp_arpin();
                        /* If the above function invocation resulted in data that
                           should be sent out on the network, the global variable
                           uip_len is set to a value > 0. */
                        if (uip_len > 0) {
                            memcpy(xmit_data, uip_buf, uip_len);
                            xmit_buffer[0].next = NULL;
                            xmit_buffer[0].data = xmit_data;
                            xmit_buffer[0].left = uip_len;
                            xmit_buffer[0].flags = USB_BUFFER_SHORT_END;

                            usb_submit_xmit_buffer(DATA_IN, &xmit_buffer[0]);
                            /* printf("Sent: %d bytes\n", uip_len); */
                        }
                    }

                init_recv_buffer();
                usb_submit_recv_buffer(DATA_OUT, &recv_buffer);
            }
        }
    }
    PROCESS_END();
}
Example #15
0
asmlinkage void sys_uip_arp_init_k()
{
  uip_arp_init();
  return;
}
Example #16
0
void vuIP_TASK( void *pvParameters )
{
/* The semaphore used by the EMAC ISR to indicate that an Rx frame is ready
for processing. */
xSemaphoreHandle xSemaphore = NULL;
portBASE_TYPE xARPTimer;
unsigned portBASE_TYPE uxPriority;
static volatile portTickType xStartTime, xCurrentTime;

	/* Initialize the uIP TCP/IP stack. */
	uip_init();
	uip_arp_init();
	
	/* Initialize the HTTP server. */
	httpd_init();

	/* Initialise the local timers. */
	xStartTime = xTaskGetTickCount();
	xARPTimer = 0;

	/* Initialise the EMAC.  A semaphore will be returned when this is
	successful. This routine contains code that polls status bits.  If the
	Ethernet cable is not plugged in then this can take a considerable time.
	To prevent this starving lower priority tasks of processing time we
	lower our priority prior to the call, then raise it back again once the
	initialisation is complete. */
	uxPriority = uxTaskPriorityGet( NULL );
	vTaskPrioritySet( NULL, tskIDLE_PRIORITY );
	while( xSemaphore == NULL )
	{
		xSemaphore = xEMACInit();
	}
	vTaskPrioritySet( NULL, uxPriority );

	for( ;; )
	{
		/* Let the network device driver read an entire IP packet
		into the uip_buf. If it returns > 0, there is a packet in the
		uip_buf buffer. */
		uip_len = ulEMACPoll();

		/* Was a packet placed in the uIP buffer? */
		if( uip_len > 0 )
		{
			/* A packet is present in the uIP buffer. We call the
			appropriate ARP functions depending on what kind of packet we
			have received. If the packet is an IP packet, we should call
			uip_input() as well. */
			if( pucUIP_Buffer->type == htons( UIP_ETHTYPE_IP ) )
			{
				uip_arp_ipin();
				uip_input();

				/* If the above function invocation resulted in data that
				should be sent out on the network, the global variable
				uip_len is set to a value > 0. */
				if( uip_len > 0 )
				{
					uip_arp_out();
					lEMACSend();
				}
			}
			else if( pucUIP_Buffer->type == htons( UIP_ETHTYPE_ARP ) )
			{
				uip_arp_arpin();

				/* If the above function invocation resulted in data that
				should be sent out on the network, the global variable
				uip_len is set to a value > 0. */	
				if( uip_len > 0 )
				{	
					lEMACSend();
				}
			}
		}
		else
		{
			/* The poll function returned 0, so no packet was
			received. Instead we check if it is time that we do the
			periodic processing. */
			xCurrentTime = xTaskGetTickCount();

			if( ( xCurrentTime - xStartTime ) >= RT_CLOCK_SECOND )
			{
				portBASE_TYPE i;

				/* Reset the timer. */
				xStartTime = xCurrentTime;

				/* Periodic check of all connections. */
				for( i = 0; i < UIP_CONNS; i++ )
				{
					uip_periodic( i );

					/* If the above function invocation resulted in data that
					should be sent out on the network, the global variable
					uip_len is set to a value > 0. */					
					if( uip_len > 0 )
					{
						uip_arp_out();
						lEMACSend();
					}
				}

				#if UIP_UDP
					for( i = 0; i < UIP_UDP_CONNS; i++ )
					{
						uip_udp_periodic( i );

						/* If the above function invocation resulted in data that
						should be sent out on the network, the global variable
						uip_len is set to a value > 0. */
						if( uip_len > 0 )
						{
							uip_arp_out();
							tapdev_send();
						}
					}
				#endif /* UIP_UDP */

				/* Periodically call the ARP timer function. */
				if( ++xARPTimer == uipARP_FREQUENCY )
				{	
					uip_arp_timer();
					xARPTimer = 0;
				}
			}
			else
			{				
				/* We did not receive a packet, and there was no periodic
				processing to perform.  Block for a fixed period.  If a packet
				is received during this period we will be woken by the ISR
				giving us the Semaphore. */
				xSemaphoreTake( xSemaphore, uipMAX_BLOCK_TIME );
			}
		}
	}
}
Example #17
0
void vuIP_TASK( void *pvParameters )
{
      int i;
      struct uip_eth_addr MacAddr = *(struct uip_eth_addr *)pvParameters;
      uip_ipaddr_t ipaddr;
      struct timer periodic_timer, arp_timer;
      
      clock_init();  
      timer_set(&periodic_timer, CLOCK_SECOND / 2);
      timer_set(&arp_timer, CLOCK_SECOND * 10);

      /* Initialise the Enc28j60*/
      enc28j60Init(MacAddr.addr);
      
      /* Initialize the uIP TCP/IP stack. */
      uip_init();
      uip_arp_init();
      
      /*init mac addr to uip*/
      uip_setethaddr(MacAddr);
      
      uip_ipaddr(ipaddr, 192,168,1,101);
      uip_sethostaddr(ipaddr);
      uip_ipaddr(ipaddr, 192,168,1,1);
      uip_setdraddr(ipaddr);
      uip_ipaddr(ipaddr, 255,255,255,0);
      uip_setnetmask(ipaddr);
      
      /* Initialize the HTTP server. */
      telnetd_init();

      while(1) {
        uip_len = enc28j60PacketReceive();
        if(uip_len > 0) 
        {
          if(pucUIP_Buffer->type == htons(UIP_ETHTYPE_IP)) 
          {
            uip_arp_ipin();
            uip_input();
            /* If the above function invocation resulted in data that
            should be sent out on the network, the global variable
            uip_len is set to a value > 0. */
            if(uip_len > 0) {
              uip_arp_out();
              enc28j60PacketSend();
            }
          }
          else if(pucUIP_Buffer->type == htons(UIP_ETHTYPE_ARP)) 
          {
            uip_arp_arpin();
            /* If the above function invocation resulted in data that
            should be sent out on the network, the global variable
            uip_len is set to a value > 0. */
            if(uip_len > 0) {
              enc28j60PacketSend();
            }
          }
          
        }
        else if(timer_expired(&periodic_timer)) 
        {
          timer_reset(&periodic_timer);
          for(i = 0; i < UIP_CONNS; i++) 
          {
            uip_periodic(i);
            /* If the above function invocation resulted in data that
            should be sent out on the network, the global variable
            uip_len is set to a value > 0. */
            if(uip_len > 0) 
            {
              uip_arp_out();
              enc28j60PacketSend();
            }
          }
          
#if UIP_UDP
          for(i = 0; i < UIP_UDP_CONNS; i++) 
          {
            uip_udp_periodic(i);
            /* If the above function invocation resulted in data that
            should be sent out on the network, the global variable
            uip_len is set to a value > 0. */
            if(uip_len > 0) 
            {
              uip_arp_out();
              enc28j60PacketSend();
            }
          }
#endif /* UIP_UDP */
          
          /* Call the ARP timer function every 10 seconds. */
          if(timer_expired(&arp_timer)) 
          {
            timer_reset(&arp_timer);
            uip_arp_timer();
          }
        }
      }
}
Example #18
0
void
network_init(void)
{
    uip_ipaddr_t ip;
    (void) ip;			/* Keep GCC quiet. */

    uip_init();

#if defined(RFM12_IP_SUPPORT) && defined(UIP_MULTI_STACK)
    uip_stack_set_active(STACK_RFM12);
    rfm12_stack_init();
#endif

#if defined(ZBUS_SUPPORT) && defined(UIP_MULTI_STACK)
    uip_stack_set_active(STACK_ZBUS);
    zbus_stack_init();
#endif

#ifdef OPENVPN_SUPPORT
    uip_stack_set_active(STACK_OPENVPN);
    openvpn_init();
#endif

    /* load base network settings */
#   ifdef DEBUG_NET_CONFIG
    debug_printf("net: loading base network settings\n");
#   endif

#ifdef ETHERNET_SUPPORT
# ifdef ENC28J60_SUPPORT
    uip_stack_set_active(STACK_ENC);
# else  /* TAP_SUPPORT */
    uip_stack_set_active(STACK_TAP);
#endif

    /* use uip buffer as generic space here, since when this function is called,
     * no network packets will be processed */

#ifdef EEPROM_SUPPORT
    /* use global network packet buffer for configuration */
    uint8_t checksum = eeprom_get_chksum();
    uint8_t saved_checksum;
    eeprom_restore_char(crc, &saved_checksum);


    if (checksum != saved_checksum)
      eeprom_init();
#endif

#ifdef ETHERNET_SUPPORT
    network_config_load();
#endif



    /* Do the autoconfiguration after the MAC is set */
#   if UIP_CONF_IPV6 && !defined(IPV6_STATIC_SUPPORT)
    uip_setprefixlen(64);
    uip_ip6autoconfig(0xFE80, 0x0000, 0x0000, 0x0000);
#   endif

#   if defined(IPV6_STATIC_SUPPORT) && defined(TFTPOMATIC_SUPPORT)
    const char *filename = CONF_TFTP_IMAGE;
    set_CONF_TFTP_IP(&ip);

    tftp_fire_tftpomatic(&ip, filename);
    bootload_delay = CONF_BOOTLOAD_DELAY;
#   endif /* IPV6_STATIC_SUPPORT && TFTPOMATIC_SUPPORT */


#   elif !defined(ROUTER_SUPPORT) /* and not ETHERNET_SUPPORT */
    /* Don't allow for eeprom-based configuration of rfm12/zbus IP address,
       mainly for code size reasons. */
    set_CONF_ETHERRAPE_IP(&ip);
    uip_sethostaddr(&ip);

#   endif /* not ETHERNET_SUPPORT and not ROUTER_SUPPORT */

    ethersex_meta_netinit();

#   ifdef ENC28J60_SUPPORT
    init_enc28j60();
#   endif

#   ifdef ETHERNET_SUPPORT
#   if UIP_CONF_IPV6
    uip_neighbor_init();
#   else
    uip_arp_init();
#   endif
#   else /* ETHERNET_SUPPORT */
    /* set at least fixed default gateway address
     * to allow multi stack routing */
    set_CONF_ETHERRAPE_GATEWAY(&ip);
    uip_setdraddr(&ip);
#   endif  /* ETHERNET_SUPPORT */

}
Example #19
0
void Test_uip_arp_init(CuTest *tc) {
    uip_arp_init();
    CuAssertIntEquals(tc,arp_table[0].ipaddr[0],0);
    CuAssertIntEquals(tc,arp_table[0].ipaddr[1],0);
}
Example #20
0
/*-----------------------------------------------------------------------------------*/
int
main(void)
{
	idata u8_t i, arptimer;
	idata u16_t j;
//	idata int i;
	InitGraphic();//putchar(0,62,0);
	//while(1)
	for(i=0;i<100;i++)
	{
		putstring(6,0, "Welcome to http://shop34480016.taobao.com  www.dianshijin.cn");
	}

	init_uart();
	printu("starting......\r\n");
	/* Initialize the device driver. */ 
	//  rtl8019as_init();
	dev_init();
	uip_arp_init();
	/* Initialize the uIP TCP/IP stack. */
	uip_init();
	printu("11111111111111111111111\r\n");
	/* Initialize the HTTP server. */
//	httpd_init();
	tcp_server_init();
	
	arptimer = 0;
	printu("222222222222222222222222222\r\n");
  while(1) {
    /* Let the tapdev network device driver read an entire IP packet
       into the uip_buf. If it must wait for more than 0.5 seconds, it
       will return with the return value 0. If so, we know that it is
       time to call upon the uip_periodic(). Otherwise, the tapdev has
       received an IP packet that is to be processed by uIP. */
    uip_len = dev_poll();
	for(j=0;j<500;j++);
/*
	if(uip_len > 0)
	{
		printuf("--------------- uip_len = 0x%x", uip_len);
		printuf("%x ----------\r\n", uip_len);
		for(i=0;i<uip_len;i++)
		{
			printuf("%x ", uip_buf[i]);
			if((i+1)%16==0) printu("\r\n");			
		}
		printu("\r\n");			
	}
*/
    if(uip_len == 0) {
      for(i = 0; i < UIP_CONNS; i++) {
	uip_periodic(i);
	/* If the above function invocation resulted in data that
	   should be sent out on the network, the global variable
	   uip_len is set to a value > 0. */
	if(uip_len > 0) {
	  uip_arp_out();
	  dev_send();
	}
      }

#if UIP_UDP
      for(i = 0; i < UIP_UDP_CONNS; i++) {
	uip_udp_periodic(i);
	/* If the above function invocation resulted in data that
	   should be sent out on the network, the global variable
	   uip_len is set to a value > 0. */
	if(uip_len > 0) {
	  uip_arp_out();
	  dev_send();
	}
      }
#endif /* UIP_UDP */
      
      /* Call the ARP timer function every 10 seconds. */
      if(++arptimer == 20) {	
	uip_arp_timer();
	arptimer = 0;
      }
      
    } else {
      if(BUF->type == htons(UIP_ETHTYPE_IP)) {
	uip_arp_ipin();
	uip_input();
	/* If the above function invocation resulted in data that
	   should be sent out on the network, the global variable
	   uip_len is set to a value > 0. */
	if(uip_len > 0) {
	  uip_arp_out();
	  dev_send();
	}
      } else if(BUF->type == htons(UIP_ETHTYPE_ARP)) {
	uip_arp_arpin();
	/* If the above function invocation resulted in data that
	   should be sent out on the network, the global variable
	   uip_len is set to a value > 0. */	
	if(uip_len > 0) {	
	  dev_send();
	}
      }
    }
    
  }
  return 0;
}
Example #21
0
/*****************************************************************************
*  Main Control Loop
*
*  
*****************************************************************************/
int main(void)
{
 	//led PB4
	// Pins als Ausgänge definieren:
	DDRB  |= (1 << 4);

    PORTB |= (0 << 4);

//DDRD |= (1 << 7);
//PORTD |= (1 << 7);   
  
  unsigned char i;
  unsigned char arptimer=0;

   // init NIC device driver
  nic_init();

  // init uIP
  uip_init();

  // init app
  services_init();

  // init ARP cache
  uip_arp_init();

  // init periodic timer
  initTimer();

  SET_USART_9600();
  //PORTB |= (1 << 4); //LED PB4 ein
  sei();

//  if((mca25_stat.init=mca25_init())==0) mca25_stat.init=mca25_configure();
//  if(mca25_stat.init) {

    // print error message?;
//  }
#if USE_MCA25_CAM
//DEBUG:
	MCA25_ERROR_LED_OFF();
	MCA25_CLOCK_LED_OFF();
	//DDRB = 0xFF;
	
	MCA25_STATUS_LED_ON();
	mca25_init();
	mca25_configure();	
	MCA25_STATUS_LED_OFF();
	MCA25_ERROR_LED_ON();
	MCA25_CLOCK_LED_ON();
#endif	
//	#if USE_CLOCK
//		Start_Clock();
	//#endif  
#if USE_SERVO
	servo_init();
#endif	
//PORTD |= (1 << 7);
  while(1)
  {
    // look for a packet
    uip_len = nic_poll();
    if(uip_len == 0)
    {
      // if timed out, call periodic function for each connection
      if(timerCounter > TIMERCOUNTER_PERIODIC_TIMEOUT)
      {
        timerCounter = 0;
        
        for(i = 0; i < UIP_CONNS; i++)
        {
          uip_periodic(i);
		
          // transmit a packet, if one is ready
          if(uip_len > 0)
          {
            uip_arp_out();
            nic_send();
          }
        }

        /* Call the ARP timer function every 10 seconds. */
        if(++arptimer == 20)
        {	
          uip_arp_timer();
          arptimer = 0;
        }
      }
    }
    else  // packet received
    {
      // process an IP packet
      if(BUF->type == htons(UIP_ETHTYPE_IP))
      {
        // add the source to the ARP cache
        // also correctly set the ethernet packet length before processing
        uip_arp_ipin();
        uip_input();

        // transmit a packet, if one is ready
        if(uip_len > 0)
        {
          uip_arp_out();
          nic_send();
        }
      }
      // process an ARP packet
      else if(BUF->type == htons(UIP_ETHTYPE_ARP))
      {
        uip_arp_arpin();

        // transmit a packet, if one is ready
        if(uip_len > 0)
          nic_send();
      }
    }
  }

  return 1;
}
Example #22
0
/*****************************************************************************
*  Main Control Loop
*
*  
*****************************************************************************/
int main(void)
{
  unsigned char i;
  unsigned char arptimer=0;

	// PORTB PB5 als Ausgang (in use LED)
	DDRB=(1<<PB5);
	PORTB=(1<<PB5);

	init_sensors();

  // init NIC device driver
  nic_init();

  // init uIP
  uip_init();

  // init app
  example1_init();

  // init ARP cache
  uip_arp_init();

  // init periodic timer
  initTimer();
  
  sei();

	// initialisierendes lesen der Temperatur(en)
	read_temp_sensors();

  while(1)
  {

	if(minInt==1){
		minInt=0;
		read_temp_sensors();
	}
    // look for a packet
    uip_len = nic_poll();
    if(uip_len == 0)
    {
      // if timed out, call periodic function for each connection
      //if(timerCounter > TIMERCOUNTER_PERIODIC_TIMEOUT)
	  if(tInt)
      {
        
		tInt = 0;
		//timerCounter = 0;
        
        for(i = 0; i < UIP_CONNS; i++)
        {
          uip_periodic(i);
		
          // transmit a packet, if one is ready
          if(uip_len > 0)
          {
            uip_arp_out();
            nic_send();
          }
        }

        /* Call the ARP timer function every 10 seconds. */
        if(++arptimer == 20)
        {	
          uip_arp_timer();
          arptimer = 0;
        }
      }
    }
    else  // packet received
    {
      // process an IP packet
      if(BUF->type == htons(UIP_ETHTYPE_IP))
      {
        // add the source to the ARP cache
        // also correctly set the ethernet packet length before processing
        uip_arp_ipin();
        uip_input();

        // transmit a packet, if one is ready
        if(uip_len > 0)
        {
          uip_arp_out();
          nic_send();
        }
      }
      // process an ARP packet
      else if(BUF->type == htons(UIP_ETHTYPE_ARP))
      {
        uip_arp_arpin();

        // transmit a packet, if one is ready
        if(uip_len > 0)
          nic_send();
      }
    }
  }

  return 1;
}
Example #23
0
int main(void) {
    struct timer periodic_timer, arp_timer;
          
    // Flash the status LED two times to indicate that the AVR controller is living
    STATUS_LED_on();
    _delay_ms(20);
    STATUS_LED_off();
    _delay_ms(100);
    STATUS_LED_on();
    _delay_ms(20);
    STATUS_LED_off();

    // Initialize direction and level of I/O pins
    init_io_pins(); 

    #if ADC_CHANNELS > 0
        // initialize ADC converter
        initADC();
    #endif
    
    // enable io functions
    isBusy=0;
  
    // Initialize system clock timers.
    clock_init();
    timer_set(&periodic_timer, CLOCK_SECOND); 
    timer_set(&arp_timer, CLOCK_SECOND*10);

    // check if the config reset jumper is connected.
    check_for_reset_jumper();    
    
#ifdef SERIAL
    // start the serial port server
    seriald_init();
#endif // SERIAL
    
    // initialize ethernet controller
    // loop until link comes up
    while (init_CP2200()==0) {
       _delay_ms(200);
    }
    
    // replace config by hardcoded defaults if the flash is unprogrammed (all bits 1)
    if (uip_ipaddr_cmp(config.ipaddr, all_ones_addr) &&
        uip_ipaddr_cmp(config.netmask, all_ones_addr) &&
        uip_ipaddr_cmp(config.gateway, all_ones_addr)) {
        set_defaults();
    }

    // initialize uIP protocol
    uip_arp_init();
    uip_init();
    
    // Configure the IP-Adrdess
    IP_config();
    
 #ifdef EMAIL_APP
    // Initialize the email application
    email_app_init();
#endif // EMAIL_APP

    // Initialize the inetd
    inetd_init();

    // main loop, dispatches network and timer events
    while (1) {
        uip_len = network_device_read();
        if (uip_len > 0) {
            if (BUF->type == htons(UIP_ETHTYPE_IP)) {
                uip_arp_ipin();
                uip_input();
                // If the above function invocation resulted in data that
                // should be sent out on the network, the global variable
                // uip_len is set to a value > 0. 
                if (uip_len > 0) {
                    uip_arp_out();
                    network_device_send();
                }
            } else if (BUF->type == htons(UIP_ETHTYPE_ARP)) {
                uip_arp_arpin();
                // If the above function invocation resulted in data that
                // should be sent out on the network, the global variable
                // uip_len is set to a value > 0. 
                if (uip_len > 0) {
                    network_device_send();
                }
            }
        }
        else if (timer_expired(&periodic_timer)) {
            timer_reset(&periodic_timer);

            for (int i = 0; i < UIP_CONNS; i++) {
                uip_periodic(i);
                // If the above function invocation resulted in data that
                // should be sent out on the network, the global variable
                // uip_len is set to a value > 0. 
                if (uip_len > 0) {
                    uip_arp_out();
                    network_device_send();
                }
            }

#if UIP_UDP
            for (int i = 0; i < UIP_UDP_CONNS; i++) {
                uip_udp_periodic(i);
                // If the above function invocation resulted in data that
                // should be sent out on the network, the global variable
                // uip_len is set to a value > 0.
                if (uip_len > 0) {
                    uip_arp_out();
                    network_device_send();
                }
            }
#endif // UIP_UDP

            // Call the ARP timer function every 10 seconds. 
            if (timer_expired(&arp_timer)) {
                timer_reset(&arp_timer);
                uip_arp_timer();
            }
        }
        
#ifdef EMAIL_APP
        email_app_main_loop();
#endif //EMAIL_APP
		
    }
    return 0;
}
Example #24
0
int main(void)
{
	led_conf();

	int i;
	uip_ipaddr_t ipaddr;
	struct timer periodic_timer, arp_timer;

    /* Disable watchdog if enabled by bootloader/fuses */
    MCUSR &= ~(1 << WDRF);
    WDTCSR |= _BV(_WD_CHANGE_BIT) | _BV(WDE); 
    WDTCSR = 0; 

	network_init();
	clock_init();

	timer_set(&periodic_timer, CLOCK_SECOND / 2);
	timer_set(&arp_timer, CLOCK_SECOND * 10);

	uip_init();
    phys_init();
    // must be done or sometimes arp doesn't work
    uip_arp_init();

    _enable_dhcp=eeprom_read_byte(&ee_enable_dhcp);
    if ((_enable_dhcp != 1) && (_enable_dhcp != 0))
    {   // if the setting is invalid, enable by default
        _enable_dhcp = 1;
        eeprom_write_byte(&ee_enable_dhcp,_enable_dhcp);
    }
    eeprom_read_block ((void *)_eth_addr, (const void *)&ee_eth_addr,6);

    // if the mac address in eeprom looks good, use it.
    if((_eth_addr[0] != 255) && (_eth_addr[0] != 0))
    {
        my_eth_addr.addr[0] = _eth_addr[0];
        my_eth_addr.addr[1] = _eth_addr[1];
        my_eth_addr.addr[2] = _eth_addr[2];
        my_eth_addr.addr[3] = _eth_addr[3];
        my_eth_addr.addr[4] = _eth_addr[4];
        my_eth_addr.addr[5] = _eth_addr[5];
    }

	uip_setethaddr(my_eth_addr);
    _enable_dhcp = 1;
    if (_enable_dhcp)
    {
#ifdef __DHCPC_H__
        // setup the dhcp renew timer the make the first request
        timer_set(&dhcp_timer, CLOCK_SECOND * 600);
	    dhcpc_init(&my_eth_addr, 6);
        dhcpc_request();
#endif
    }
    else
    {
        eeprom_read_block ((void *)_ip_addr, (const void *)&ee_ip_addr,4);
        eeprom_read_block ((void *)_net_mask,(const void *)&ee_net_mask,4);
        eeprom_read_block ((void *)_gateway, (const void *)&ee_gateway,4);

        // if the IP looks good in flash, use it
        if ((_ip_addr[0] != 255) && (_ip_addr[0] != 0))
        {
            uip_ipaddr(ipaddr, _ip_addr[0], _ip_addr[1], _ip_addr[2], _ip_addr[3]);
            uip_sethostaddr(ipaddr);
            uip_ipaddr(ipaddr, _gateway[0], _gateway[1], _gateway[2], _gateway[3]);
            uip_setdraddr(ipaddr);
            uip_ipaddr(ipaddr, _net_mask[0], _net_mask[1], _net_mask[2], _net_mask[3]);
            uip_setnetmask(ipaddr);
        }
        else
        { // ip in flash didn't look good... use default
            uip_ipaddr(ipaddr, UIP_IPADDR0, UIP_IPADDR1, UIP_IPADDR2, UIP_IPADDR3);
            uip_sethostaddr(ipaddr);
            uip_ipaddr(ipaddr, UIP_DRIPADDR0, UIP_DRIPADDR1, UIP_DRIPADDR2, UIP_DRIPADDR3);
            uip_setdraddr(ipaddr);
            uip_ipaddr(ipaddr, UIP_NETMASK0, UIP_NETMASK1, UIP_NETMASK2, UIP_NETMASK3);
            uip_setnetmask(ipaddr);
        }
    }

	jsoncmd_init();

    while (1) { 
		uip_len = network_read();

		if(uip_len > 0) {
			if(BUF->type == htons(UIP_ETHTYPE_IP))
            {
                led_on(5);
				uip_arp_ipin(); // arp seems to have issues w/o this
                uip_input();
				if(uip_len > 0)
                {
					uip_arp_out();
					network_send();
				}
			}
            else if(BUF->type == htons(UIP_ETHTYPE_ARP))
            {
                led_on(4);
				uip_arp_arpin(); // this is correct
				if(uip_len > 0)
                {
					network_send();
				}
			}

		}
        else if(timer_expired(&periodic_timer))
        {
            led_off(4);
            led_off(5);
			timer_reset(&periodic_timer);
			for(i = 0; i < UIP_CONNS; i++)
            {
				uip_periodic(i);
				if(uip_len > 0)
                {
					uip_arp_out();
					network_send();
				}
			}

#if UIP_UDP
			for(i = 0; i < UIP_UDP_CONNS; i++)
            {
				uip_udp_periodic(i);
				if(uip_len > 0)
                {
					uip_arp_out();
					network_send();
				}
			}
#endif /* UIP_UDP */

			if(timer_expired(&arp_timer))
            {
				timer_reset(&arp_timer);
				uip_arp_timer();
			}
		}
        else if (_enable_dhcp && timer_expired(&dhcp_timer))
        {
#ifdef __DHCPC_H__
            led_on(3);
            // for now turn off the led when we start the dhcp process
            dhcpc_renew();
            timer_reset(&dhcp_timer);
#endif
        }
	}
	return 0;
}
Example #25
0
static portTASK_FUNCTION( tunggu, pvParameters )
{
	struct t_env *envx;
	envx = (char *) ALMT_ENV;
	
	portBASE_TYPE xARPTimer;
	uip_ipaddr_t xIPAddr;
	int loop;
	int mul;
	unsigned int timer_menit=0;
	unsigned int loop_menit=0;	
	static volatile portTickType xStartTime, xCurrentTime;
	
	vTaskDelay(200);
	
	/* baca environtment (dapat IP dll dulu) */
	baca_env(0);
	printf("UIP : uip_init\r\n");

	uip_init ();
	
	//uip_ipaddr( xIPAddr, uipIP_ADDR0, uipIP_ADDR1, uipIP_ADDR2, uipIP_ADDR3 );
	uip_ipaddr( xIPAddr, envx->IP0, envx->IP1, envx->IP2, envx->IP3 );
	uip_sethostaddr( xIPAddr );

	printf("ARP : arp_init\r\n");
	uip_arp_init ();
	
	printf("Init ENC28J .. ");

	if (enc28j60Init() == 1)	{
		 printf(" .. ENC OK\r\n");
	}	else
		printf("ENC tidak respons !\r\n");

	#ifdef PAKE_HTTP
	printf("SIMPLE HTTP : init\r\n");
	httpd_init ();
	#endif
	
	#ifdef PAKE_TELNETD
	printf("SIMPLE TELNET : init\r\n");
    telnetd_init ();
	#endif

#ifdef BOARD_KOMON
    printf("MONITA : monita init\r\n");
//    monita_init();
#endif
	
#if (PAKAI_KONTROL == 1)
	printf("MONITA : monita kontrol init\r\n");
	kontrol_init();
#endif

//#ifdef BOARD_TAMPILAN
//#ifdef CARI_SUMBERNYA
#ifdef SAMPURASUN_SERVER
	printf("MONITA : sambungan_aktif init\r\n");
	sambungan_init();
	mul = 0;
#endif

#ifdef SAMPURASUN_CLIENT
    //printf("MONITA : monita init\r\n");
    printf("Monita : sampurasun client init !\r\n");
    monita_init();
#endif

#ifdef PAKAI_WEBCLIENT
		int ngitung=0;
		webclient_init();
		printf("webclient inited !\r\n");
		unsigned char datakeserver[512];
		int wclient=0, jmlData=0, nos=0, flag_nos=0, flag_sumber=0, jmlsumbernya=0;
		//int noPMaktif[JML_SUMBER];
		char il[256], dl[256];
		char ipdest[15], angkaangka[5];
		extern int kirimURL;
		extern char terkirimURL;
		extern int  noawal;
		int tiapKirim=950;
		int maxkirim=12;
#endif

#ifdef PAKAI_KIRIM_BALIK
	
	int anginkecil=0;
	int giliran;
	extern int sumber_datanya;
	extern int target_kirim;
	target_kirim = 4-1;
	sumber_datanya=3-1;

	//giliran=1-1;
	
	printf("Kirim Balik inited, Target data: sumber %d, target kirim: %d !\r\n", sumber_datanya+1, target_kirim+1);
#endif

	/*  Initialise the local timers */
	xStartTime = xTaskGetTickCount ();
	xARPTimer = 0;
	
	/* supaya cukup waktu buat siap2 */
	loop = -1000;
	
	#ifdef BOARD_KOMON_420_SABANG
	vTaskDelay(200);
	#endif

	#ifdef PAKAI_WEBCLIENT
		vTaskDelay(2000);
		vTaskDelay(2000);
	#endif
	//printf("mau loop for\r\n");
	for (;;)
	{
		vTaskDelay(1);
		//portYIELD();
		#if 1
		#ifdef PAKAI_WEBCLIENT
		if (envx->statusWebClient==1) {
			wclient++;
			if (envx->burst==1) {
				jmlData=kirimModul(1, 0, 0, il, dl);
				//jmlsumbernya=1;
				tiapKirim = 500;
			} else 
			{			// kirim 1-1
				/*
				#ifdef BANYAK_SUMBER
					struct t_sumber *pmx;
					pmx = (char *) ALMT_SUMBER;
					jmlsumbernya=0;
					for(selang=0; selang<JML_SUMBER; selang++) {
						if (pmx[selang].status==1) {
							printf("selang: %d, status: %d\r\n", selang, pmx[selang].status);
							noPMaktif[jmlsumbernya]=selang;
							jmlsumbernya++;
						}
					}
					if (jmlsumbernya==0) {
						jmlsumbernya=1;
					}
					//jmlData=kirimModul(0, noPMaktif[sumbernya], 0, il, dl);
					printf("jml Data: %d, sumbernya: %d\r\n", jmlData, sumbernya);
					// kenapa ini ??? harusnya tiap detik, knapa jadi tiap 4 detik ????
					//tiapKirim = (int) (100/jmlsumbernya);
					tiapKirim = (int) (195/jmlsumbernya);
					//printf("wclient: %d\r\n", wclient);
				#endif
				//*/
			}	
			if (wclient == tiapKirim) {
				ngitung++;
				
				struct t_sumber *sumber;
				sumber = (char *) ALMT_SUMBER;
				if (!flag_nos) {
					nos++;
					while(sumber[nos-1].status!=1) {	// cari modul sumber aktif
						if (nos>JML_SUMBER) {
							nos=0;
							jmlsumbernya=0;
						}
						nos++;
					}
				}
				jmlsumbernya++;
				//printf("kirim: %5d, nos: %d, wclient: %d, sumber.status: %d, jmlsumbernya: %d\r\n", ngitung, nos-1, wclient, sumber[nos-1].status, jmlsumbernya);
				
				// cek datanya PM ?? // <--- ternyata gak cuma PM, modul lain juga bisa
				if (sumber[nos-1].tipe==0 || sumber[nos-1].tipe==1 || sumber[nos-1].tipe==100)	{	// PM710 || PM810
					jmlData=kirimModul(0, nos-1, noawal, il, dl);
					if (jmlData==12) {
						flag_nos=1;
					} else {		// sudah habis, reset ke 0
						flag_nos=0;
						noawal=0;
					}
					//printf("nilai noawal: %d, flagnos: %d\r\n", noawal, flag_nos);
				} else	{
					jmlData=kirimModul(0, nos-1, 0, il, dl);
					noawal=0;
				}
				
				// hitung jml loop kirim ke server
				if (flag_sumber<jmlsumbernya) {
					flag_sumber=jmlsumbernya;
					tiapKirim=950/jmlsumbernya;
				}
				
				
				wclient = 0;				

				if (jmlData>0) {
					
					sprintf(ipdest, "%d.%d.%d.%d", envx->GW0, envx->GW1, envx->GW2, envx->GW3);
					//portENTER_CRITICAL();
					//sprintf(datakeserver, "%s?i=%s&p=diesel&j=%d&%s&%s", envx->berkas, envx->SN, jmlData, il, dl);
					strcpy(datakeserver, envx->berkas);
					strcat(datakeserver, "?i=");
					strcat(datakeserver, envx->SN);
					strcat(datakeserver, "&p=diesel&j=");
					sprintf(angkaangka, "%d", jmlData);
					strcat(datakeserver, angkaangka);
					strcat(datakeserver, "&");
					strcat(datakeserver, il);
					strcat(datakeserver, "&");
					strcat(datakeserver, dl);
					//portEXIT_CRITICAL();
					//printf("datakeserver: %s\r\n",datakeserver);
					webclient_get(ipdest, 80, datakeserver);
					
				}
			}
		}
		#endif
		
		//#if defined(BOARD_TAMPILAN) || defined (TAMPILAN_MALINGPING) 
		#ifdef SAMPURASUN_SERVER
		//#ifdef CARI_SUMBERNYA
		loop++;
		if (loop > 200) 		// 50, 40, 80
		{
			loop = 0;
			
			sambungan_connect(mul);	
			
			mul++;
			if (mul > JML_SUMBER) mul = 0;
			
		}
		#endif
		
		#ifdef PAKAI_KIRIM_BALIK
			anginkecil++;
			if (anginkecil > 2000) {	/* tiap 2 detik */
				
				kirim_balik_connect(target_kirim);
				
				anginkecil=0;
				//giliran++;
				//if (giliran > JML_SUMBER) mul = 0;
			}
		#endif
		
		//if (enc28j60WaitForData (uipMAX_BLOCK_TIME) == pdTRUE)
		if (cek_paket())	{
			//printf("masuk cekpaket \r\n");
			#if 1
			  paket_per_menit++;
			  /* Let the network device driver read an entire IP packet
		         into the uip_buf. If it returns > 0, there is a packet in the
		         uip_buf buffer. */
		      if ((uip_len = enc28j60Receive ()) > 0)
		      {				  
				  if (pucUIP_Buffer->type == htons (UIP_ETHTYPE_IP))
		    	  {
		    	            uip_arp_ipin ();
		    	            uip_input ();

		    	            /* If the above function invocation resulted in data that
		    	               should be sent out on the network, the global variable
		    	               uip_len is set to a value > 0. */
		    	            if (uip_len > 0)
		    	            {
		    	              uip_arp_out ();
		    	              enc28j60Send ();
							  paket_kita++;
		    	            }
		    	     }
		    	     else if (pucUIP_Buffer->type == htons (UIP_ETHTYPE_ARP))
		    	     {
		    	            uip_arp_arpin ();

		    	            /* If the above function invocation resulted in data that
		    	               should be sent out on the network, the global variable
		    	               uip_len is set to a value > 0. */
		    	            if (uip_len > 0)
		    	              enc28j60Send ();
		    	     }

		      }
		      #endif
		}
		else		{
		      /* The poll function returned 0, so no packet was
		         received. Instead we check if it is time that we do the
		         periodic processing. */
		      xCurrentTime = xTaskGetTickCount ();

		      if ((xCurrentTime - xStartTime) >= RT_CLOCK_SECOND)
		      {
		        portBASE_TYPE i;

		        /* Reset the timer. */
		        xStartTime = xCurrentTime;

		        /* Periodic check of all connections. */
		        for (i = 0; i < UIP_CONNS; i++)
		        {
		          uip_periodic (i);

		          /* If the above function invocation resulted in data that
		             should be sent out on the network, the global variable
		             uip_len is set to a value > 0. */
		          if (uip_len > 0)
		          {
		            //printf("S:%d", i);
					uip_arp_out ();
		            enc28j60Send ();
		          }
		        }

		#if UIP_UDP_KU
		        for (i = 0; i < UIP_UDP_CONNS; i++)
		        {
		          uip_udp_periodic (i);

		          /* If the above function invocation resulted in data that
		             should be sent out on the network, the global variable
		             uip_len is set to a value > 0. */
		          if (uip_len > 0)
		          {
		            uip_arp_out ();
		            enc28j60Send ();
		          }
		        }
		#endif /* UIP_UDP */

		        /* Periodically call the ARP timer function. */
		        if (++xARPTimer == uipARP_FREQUENCY)
		        {
		          uip_arp_timer ();
		          xARPTimer = 0;
		        }
		      }
			  
			  	if ((xCurrentTime - timer_menit) >= RT_MENIT)
			  	{
				  	extern unsigned int error_ENC;
					
					timer_menit = xCurrentTime;
					loop_menit++;				
					/*
					printf("%d menit, paket = %d, kita=%d, idle=%d\n", loop_menit, paket_per_menit, paket_kita, loop_idle);
					if (error_ENC != 0)
					{
						printf("ERR ENC = %X\n", error_ENC);	
					}*/
					
					paket_per_menit = 0;
					paket_kita = 0;
				}
		 }	// tanpa paket
		
		/*
		// proses ADC dipindah ke shell 1 Okt 2010// 
		#ifdef PAKAI_ADC
			#ifdef BOARD_KOMON_A_RTD
			proses_data_adc();
			#endif
			 
			#ifdef BOARD_KOMON_B_THERMO
			proses_data_adc();
			#endif
			 
			#ifdef BOARD_KOMON_420_SAJA
			proses_data_adc();
			#endif
		#endif
		//*/
	#endif
	}
}
Example #26
0
File: main.c Project: sli92/netcon
int main(void)
{
    uint32_t lastperiodic = 0;
    uint32_t lastarp = 0;

    uint8_t i;

    sysclk_init();

    clock_init();

    /* Interrupts aktivieren. */
    IE |= (1 << _EA);

    io_init();
    emif_init();
    uart_init();
    cp2200_init();

    uip_init();
    uip_arp_init();


    memcpy(uip_ethaddr.addr, mac_addr, sizeof(uip_ethaddr.addr));

    tcp_app_init();
    udp_app_init();


    while(1 > 0) {
        uip_len = cp2200_receive(uip_buf, UIP_CONF_BUFFER_SIZE);

        if(uip_len > 0) {
            if(UIP_BUFFER->type == HTONS(UIP_ETHTYPE_IP)) {
                uip_arp_ipin();
                uip_input();

                if(uip_len > 0) {
                    uip_arp_out();
                    cp2200_transmit(uip_buf, uip_len);
                }
            } else if(UIP_BUFFER->type == HTONS(UIP_ETHTYPE_ARP)) {
                uip_arp_arpin();
                if(uip_len > 0) {
                    cp2200_transmit(uip_buf, uip_len);
                }
            }
        } else if((get_clock() - lastperiodic) > CLOCK_TICKS_PER_SECOND / 2) {
            lastperiodic = get_clock();

            for(i = 0; i < UIP_CONNS; i++) {
                uip_periodic(i);

                if(uip_len > 0) {
                    uip_arp_out();
                    cp2200_transmit(uip_buf, uip_len);
                }
            }

            for(i = 0; i < UIP_UDP_CONNS; i++) {
                uip_udp_periodic(i);

                if(uip_len > 0) {
                    uip_arp_out();
                    cp2200_transmit(uip_buf, uip_len);
                }
            }

        }

        if((get_clock() - lastarp) > CLOCK_TICKS_PER_SECOND * 10) {
            lastarp = get_clock();
            uip_arp_timer();
        }
    }

    return 0;
}
Example #27
0
File: main.c Project: sli92/netcon
int main(void)
{
        uint32_t lastperiodic = 0;
        uint32_t lastarp = 0;
        uint32_t lastupdate = 0;

        uint8_t i; // , x;
        // char buffer[32];

        uart_init();
        clock_init();
        sei();

        while(get_clock() < CLOCK_TICKS_PER_SECOND * 3);

        serconn_init();
        lastupdate = get_clock();

        memcpy_P(uip_ethaddr.addr, mac_addr, sizeof(uip_ethaddr.addr));

        enc28j60_init(uip_ethaddr.addr);

        uip_init();
        uip_arp_init();

        /* Seed fuer den Zufallsgenerator setzen. */
        srandom(get_seed());

        tcp_app_init();
        udp_app_init();

        while(1 > 0) {
                uip_len = enc28j60_receive(uip_buf, UIP_CONF_BUFFER_SIZE);
                if(uip_len > 0) {
                        if(UIP_BUFFER->type == HTONS(UIP_ETHTYPE_IP)) {
                                uip_arp_ipin();
                                uip_input();

                                if(uip_len > 0) {
                                        uip_arp_out();
                                        enc28j60_transmit(uip_buf, uip_len);
                                }

                        } else if(UIP_BUFFER->type == HTONS(UIP_ETHTYPE_ARP)) {
                                uip_arp_arpin();
                                if(uip_len > 0)
                                        enc28j60_transmit(uip_buf, uip_len);
                        }

                } else if((get_clock() - lastperiodic) > CLOCK_TICKS_PER_SECOND / 2) {
                        lastperiodic = get_clock();

                        for(i = 0; i < UIP_CONNS; i++) {
                                uip_periodic(i);

                                if(uip_len > 0) {
                                        uip_arp_out();
                                        enc28j60_transmit(uip_buf, uip_len);
                                }
                        }


                        for(i = 0; i < UIP_UDP_CONNS; i++) {
                                uip_udp_periodic(i);

                                if(uip_len > 0) {
                                        uip_arp_out();
                                        enc28j60_transmit(uip_buf, uip_len);
                                }
                        }
                }

                if((get_clock() - lastarp) > CLOCK_TICKS_PER_SECOND * 10) {
                        lastarp = get_clock();
                        uip_arp_timer();

/*
                        x = 0;
                        for(i = 0; i < UIP_CONNS; i++) {
                                if(uip_conn_active(i))
                                        x++;
                        }

                        sprintf(buffer, "Active connections: %d\n", x);
                        uart_puts(buffer);
*/
                }

                if((get_clock() - lastupdate) > CLOCK_TICKS_PER_SECOND / 2){
                        serconn_update();
                        lastupdate = get_clock();
                }
        }
}
Example #28
0
/////////////////////////////////////////////////////////////////////////////
// The uIP Task is executed each mS
/////////////////////////////////////////////////////////////////////////////
static void UIP_TASK_Handler(void *pvParameters)
{
  int i;
  struct timer periodic_timer, arp_timer;

  // take over exclusive access to UIP functions
  MUTEX_UIP_TAKE;

  // init uIP timers
  timer_set(&periodic_timer, CLOCK_SECOND / 2);
  timer_set(&arp_timer, CLOCK_SECOND * 10);

  // init the network driver
  network_device_init();

  // init uIP
  uip_init();
  uip_arp_init();

  // set my ethernet address
  unsigned char *mac_addr = network_device_mac_addr();
  {
    int i;
    for(i=0; i<6; ++i)
      uip_ethaddr.addr[i] = mac_addr[i];
  }

  // enable dhcp mode (can be changed during runtime)
  UIP_TASK_DHCP_EnableSet(dhcp_enabled);

  // release exclusive access to UIP functions
  MUTEX_UIP_GIVE;

#if 0
  // wait until HW config has been loaded
  do {
    vTaskDelay(1 / portTICK_RATE_MS);
  } while( !SEQ_FILE_HW_ConfigLocked() );
#endif

  // Initialise the xLastExecutionTime variable on task entry
  portTickType xLastExecutionTime = xTaskGetTickCount();

  // endless loop
  while( 1 ) {
#if 0
    do {
      vTaskDelayUntil(&xLastExecutionTime, 1 / portTICK_RATE_MS);
    } while( TASK_MSD_EnableGet() ); // don't service ethernet if MSD mode enabled for faster transfer speed
#else
    vTaskDelayUntil(&xLastExecutionTime, 1 / portTICK_RATE_MS);
#endif

    // take over exclusive access to UIP functions
    MUTEX_UIP_TAKE;

    if( !(clock_time_tick() % 100) ) {
      // each 100 mS: check availablility of network device
#if defined(MIOS32_BOARD_MBHP_CORE_LPC17) || defined(MIOS32_BOARD_LPCXPRESSO)
      network_device_check();
      // TK: on STM32 no auto-detection for MBSEQ for best performance if no MBHP_ETH module connected
      // the user has to reboot MBSEQ to restart module detection
#endif
    }

    if( network_device_available() ) {
      uip_len = network_device_read();

      if( uip_len > 0 ) {
	if(BUF->type == HTONS(UIP_ETHTYPE_IP) ) {
	  uip_arp_ipin();
	  uip_input();
	
	  /* If the above function invocation resulted in data that
	     should be sent out on the network, the global variable
	     uip_len is set to a value > 0. */
	  if( uip_len > 0 ) {
	    uip_arp_out();
	    network_device_send();
	  }
	} else if(BUF->type == HTONS(UIP_ETHTYPE_ARP)) {
	  uip_arp_arpin();
	  /* If the above function invocation resulted in data that
	     should be sent out on the network, the global variable
	     uip_len is set to a value > 0. */
	  if(uip_len > 0) {
	    network_device_send();
	  }
	}

      } else if(timer_expired(&periodic_timer)) {
	timer_reset(&periodic_timer);
	for(i = 0; i < UIP_CONNS; i++) {
	  uip_periodic(i);
	  /* If the above function invocation resulted in data that
	     should be sent out on the network, the global variable
	     uip_len is set to a value > 0. */
	  if(uip_len > 0) {
	    uip_arp_out();
	    network_device_send();
	  }
	}

#if UIP_UDP
	for(i = 0; i < UIP_UDP_CONNS; i++) {
	  uip_udp_periodic(i);
	  /* If the above function invocation resulted in data that
	     should be sent out on the network, the global variable
	     uip_len is set to a value > 0. */
	  if(uip_len > 0) {
	    uip_arp_out();
	    network_device_send();
	  }
	}
#endif /* UIP_UDP */
      
	/* Call the ARP timer function every 10 seconds. */
	if(timer_expired(&arp_timer)) {
	  timer_reset(&arp_timer);
	  uip_arp_timer();
	}
      }
    }

    // release exclusive access to UIP functions
    MUTEX_UIP_GIVE;
  }
}