Пример #1
0
void tcpip_periodic_timer()
{
	int i;
    MT_TimerExpired();

	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();
				mt76xx_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();
				mt76xx_dev_send();
			}
		}
#endif /* UIP_UDP */

		/* Call the ARP timer function every 10 seconds. */
		if(timer_expired(&arp_timer)) {
			timer_reset(&arp_timer);
			uip_arp_timer();
		}
    }
#if 0
	if(timer_expired(&cli_timer)) {
		clk = (clk > (CLOCK_SECOND*60))?clk:(clk*2);
		timer_set(&cli_timer, clk);
		
		if ((cli_fd == -1) && 
			memcmp(uip_hostaddr, 0x00000000, sizeof(uip_hostaddr))) {
			struct uip_conn *conn = NULL;
			uip_ipaddr_t srv_ip;
			
			uip_ipaddr(srv_ip, IoTpAd.ComCfg.IoT_ServeIP[0], IoTpAd.ComCfg.IoT_ServeIP[1],
					IoTpAd.ComCfg.IoT_ServeIP[2], IoTpAd.ComCfg.IoT_ServeIP[3]);
			conn = uip_connect(&srv_ip, HTONS(IoTpAd.ComCfg.IoT_TCP_Srv_Port));
			if(conn) {
				conn->lport = HTONS(7682);
				cli_fd = conn->fd;
			} else {
				printf("connect fail\n");
			}	
		}
	}
#endif	
}
Пример #2
0
void Network::on_idle(void *argument)
{
    if (!ethernet->isUp()) return;

    int len= sizeof(uip_buf); // set maximum size
    if (ethernet->_receive_frame(uip_buf, &len)) {
        uip_len = len;
        this->handlePacket();

    } else {

        if (timer_expired(&periodic_timer)) { /* no packet but periodic_timer time out (0.1s)*/
            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();
                    tapdev_send(uip_buf, uip_len);
                }
            }

#if UIP_CONF_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();
                    tapdev_send(uip_buf, uip_len);
                }
            }
#endif
        }
/*
        This didn't work actually made it worse,it should have worked though
        else{
            // TODO if the command queue is below a certain amount we should poll any stopped connections
            if(command_q->size() < 4) {
                for (struct uip_conn *connr = &uip_conns[0]; connr <= &uip_conns[UIP_CONNS - 1]; ++connr) {
                    if(uip_stopped(connr)){
                        // Force a poll of this
                        printf("Force poll of connection\n");
                        uip_poll_conn(connr);
                    }
                }
            }
        }
*/
        /* Call the ARP timer function every 10 seconds. */
        if (timer_expired(&arp_timer)) {
            timer_reset(&arp_timer);
            uip_arp_timer();
        }
    }
}
Пример #3
0
void ethernet_service(void) {
	int i;
	struct uip_eth_hdr *buf = (struct uip_eth_hdr *)&uip_buf[0];

	etimer_request_poll();
	process_run();

	uip_len = liteethmac_poll();
	if(uip_len > 0) {
		if(buf->type == uip_htons(UIP_ETHTYPE_IP)) {
			uip_arp_ipin();
			uip_input();
			if(uip_len > 0) {
				uip_arp_out();
				liteethmac_send();
			}
		} else if(buf->type == uip_htons(UIP_ETHTYPE_ARP)) {
			uip_arp_arpin();
			if(uip_len > 0)
				liteethmac_send();
		}
	} else if (elapsed(&uip_periodic_event, uip_periodic_period)) {
		for(i = 0; i < UIP_CONNS; i++) {
			uip_periodic(i);

			if(uip_len > 0) {
				uip_arp_out();
				liteethmac_send();
			}
		}
	}
	if (elapsed(&uip_arp_event, uip_arp_period)) {
		uip_arp_timer();
	}
}
Пример #4
0
void deal(){
    int i;
    if(uip_len > 0) {
        if(BUF_IF->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();
                current_dev->eth_tx(current_dev, uip_buf, uip_len);
            }
        } else if(BUF_IF->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) {
                current_dev->eth_tx(current_dev, uip_buf, uip_len);
            }
        }

    } 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();
                current_dev->eth_tx(current_dev, uip_buf, uip_len);	
            }
        }

#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();
                current_dev->eth_tx(current_dev, uip_buf, uip_len);	
            }
        }
#endif /* UIP_UDP */

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

    return 0;
}
void uip_server(chanend mac_rx, chanend mac_tx, chanend xtcp[], int num_xtcp,
		xtcp_ipconfig_t *ipconfig, chanend connect_status) {

	struct uip_timer periodic_timer, arp_timer, autoip_timer;
	unsigned char hwaddr[6];

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

	xcoredev_init(mac_rx, mac_tx);

	mac_get_macaddr(mac_tx, hwaddr);

	uip_server_init(xtcp, num_xtcp, ipconfig, hwaddr);

	// Main uIP service loop
	while (1)
	{
		xtcpd_service_clients(xtcp, num_xtcp);

		xtcpd_check_connection_poll(mac_tx);

		uip_xtcp_checkstate();
		uip_xtcp_checklink(connect_status);
		uip_len = xcoredev_read(mac_rx, UIP_CONF_BUFFER_SIZE);
		if (uip_len > 0) {
			xtcp_process_incoming_packet(mac_tx);
		}

		xtcp_process_udp_acks(mac_tx);


		if (timer_expired(&arp_timer)) {
			timer_reset(&arp_timer);
			uip_arp_timer();
		}

#if UIP_USE_AUTOIP
		if (timer_expired(&autoip_timer)) {
			timer_reset(&autoip_timer);
			autoip_periodic();
			if (uip_len > 0) {
				xtcp_tx_buffer(mac_tx);
			}
		}
#endif

		if (timer_expired(&periodic_timer)) {

			xtcp_process_periodic_timer(mac_tx);

			timer_reset(&periodic_timer);
		}

	}
	return;
}
Пример #6
0
void NanodeUIP::poll(void) {
  int i;

  uip_len = enc28j60PacketReceive(UIP_BUFSIZE,uip_buf);
  if(uip_len > 0) {
    if(BUF->type == UIP_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(uip_len,uip_buf);
      }
    } 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) {
	enc28j60PacketSend(uip_len,uip_buf);
      }
    }
  } 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(uip_len,uip_buf);
      }
    }

#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(uip_len,uip_buf);
      }
    }
#endif /* UIP_UDP */

    /* Call the ARP timer function every 10 seconds. */
    if(timer_expired(&arp_timer)) {
      timer_reset(&arp_timer);
      uip_arp_timer();
    }
  }
}
Пример #7
0
/**
 * @brief   Process Network
 * @param   None
 * @retval  None
 */
void Network_Process(void)
{
	static uint8_t arp_counter = 0;

	int i;
	for (i = 0; i < UIP_CONNS; i++)
	{
		uip_periodic(i);
		if (uip_len > 0)
		{
			uip_arp_out();
			enc28j60_send_packet((uint8_t *)uip_buf, uip_len);
		}
	}

	#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 (++arp_counter >= 50)
	{
		arp_counter = 0;
		uip_arp_timer();
	}

	uip_len = enc28j60_recv_packet((uint8_t *)uip_buf, UIP_BUFSIZE);
	if (uip_len > 0)
	{
		if (((struct uip_eth_hdr *)&uip_buf[0])->type == htons(UIP_ETHTYPE_IP))
		{
			uip_arp_ipin();
			uip_input();
			if (uip_len > 0)
			{
				uip_arp_out();
				enc28j60_send_packet((uint8_t *)uip_buf, uip_len);
			}
		}
		else if (((struct uip_eth_hdr *)&uip_buf[0])->type == htons(UIP_ETHTYPE_ARP))
		{
			uip_arp_arpin();
			if (uip_len > 0)
			{
				enc28j60_send_packet((uint8_t *)uip_buf, uip_len);
			}
		}
	}
}
Пример #8
0
static void arptimer_poll(int argc, uint32_t arg, ...)
{
  /* Call the ARP timer function every 10 seconds. */

  uip_arp_timer();

  /* Setup the watchdog timer again */

  (void)wd_start(g_arptimer, ARPTIMER_WDINTERVAL, arptimer_poll, 0);
}
Пример #9
0
Файл: TcpIp.c Проект: AndTH/GCA
/**
 *******************************************************************************************
 * @fn         void TcpIpMain(void)
 * @brief      Update the uIP stack.
 * @return     None
 * @attention
 *******************************************************************************************
 */
void TcpIpMain(void)
{
   uint8_t                                 Index;

   uip_len = nic_poll();
   if (uip_len == 0)
   {
         // If timed out, call periodic function for each connection
         if (TcpIpUipTimerCounter >= TCP_IP_CNT_TIME)
         {
            TcpIpUipTimerCounter = 0;
            for (Index = 0; Index < UIP_CONNS; Index++)
            {
               uip_periodic(Index);
               if (uip_len > 0)
               {
                  uip_arp_out();
                  nic_send();
               }
            }

            /* Call the ARP timer function every ~10 seconds. */
            if (++TcpIpUipArpTimerCounter >= TCP_IP_ARP_CNT_TIME)
            {
               uip_arp_timer();
               TcpIpUipArpTimerCounter = 0;
            }
         }
   }
   else                                                                        // packet received
   {
      // process an IP packet
      if (TCP_IP_BUF->type == htons(UIP_ETHTYPE_IP))
      {
         uip_arp_ipin();
         uip_input();
         if (uip_len > 0)
         {
            uip_arp_out();
            nic_send();
         }
      }
      // process an ARP packet
      else if (TCP_IP_BUF->type == htons(UIP_ETHTYPE_ARP))
      {
         uip_arp_arpin();
         if (uip_len > 0)
            nic_send();
      }

      TcpIpUipTimerCounter = 0;
   }
}
Пример #10
0
void uip_timeout_entry(void* parameter)//由于TIMEOUT函数,不参与调度
{
   // struct timer periodic_timer, arp_timer;
    static uint8_t cnt;
    int i;
	/* post message to ethernet thread */

    //if ((rt_sem_take(msg,RT_WAITING_NO)) != -RT_ETIMEOUT) 
    //if (timer_expired(&periodic_timer)) //5s enter once
    {
       //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();
	      TransmitPacket();
	  }
       }
#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();
	      TransmitPacket();
	    }
        }
#endif /* UIP_UDP */
      
       /* Call the ARP timer function every 10 seconds. */
       //if (timer_expired(&arp_timer)) 
       if (++cnt >= 2) //t
       {
	  //timer_reset(&arp_timer);
	  uip_arp_timer();
          cnt = 0;
       }
    }
  
}
Пример #11
0
void HttpdHandler(void){
	int i;

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

		if(uip_len > 0){
			uip_arp_out();
			NetSendHttpd();
		}
	}

	if(++arptimer == 20){
		uip_arp_timer();
		arptimer = 0;
	}
}
Пример #12
0
void
Ethernet_Task(void) {
     int i;

     ethernet_process();
     
     if(timer_expired(&periodic_timer)) {
	  timer_reset(&periodic_timer);
	  
	  for(i = 0; i < UIP_CONNS; i++) {
	       uip_periodic(i);
	       if(uip_len > 0) {
		    uip_arp_out();
		    network_send();
	       }
	  }
	  
	  for(i = 0; i < UIP_UDP_CONNS; i++) {
	       uip_udp_periodic(i);
	       if(uip_len > 0) {
		    uip_arp_out();
		    network_send();
	       }
	  }

	  interface_periodic();
	  
     }
     
     
     if(timer_expired(&arp_timer)) {
	  timer_reset(&arp_timer);
	  uip_arp_timer();
	  
     }
     
}
Пример #13
0
void uip_tcpip_thread(void *parameter)
{
    int i;
    static u8_t cnt;
    while(1)
    {
        rt_thread_delay(CLOCK_SECOND*5);
        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();
                TransmitPacket();
	    }
        }
#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();
              TransmitPacket();
	   }
        }
#endif /* UIP_UDP */  
      /* Call the ARP timer function every 10 seconds. */
	 if (++cnt > 2) uip_arp_timer();
    }
}
Пример #14
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;
}
Пример #15
0
/** Manages the currently open network connections, including TCP and (if enabled) UDP. */
static void uIPManagement_ManageConnections(void)
{
	/* Poll TCP connections for more data to send back to the host */
	for (uint8_t i = 0; i < UIP_CONNS; i++)
	{
		uip_poll_conn(&uip_conns[i]);

		/* If a response was generated, send it */
		if (uip_len > 0)
		{
			/* Add destination MAC to outgoing packet */
			uip_arp_out();

			/* Split and send the outgoing packet */
			uip_split_output();
		}
	}

	/* Manage open connections for timeouts */
	if (timer_expired(&ConnectionTimer))
	{
		timer_reset(&ConnectionTimer);

		LEDs_SetAllLEDs(LEDMASK_USB_BUSY);

		for (uint8_t i = 0; i < UIP_CONNS; i++)
		{
			/* Run periodic connection management for each TCP connection */
			uip_periodic(i);

			/* If a response was generated, send it */
			if (uip_len > 0)
			{
				/* Add destination MAC to outgoing packet */
				uip_arp_out();

				/* Split and send the outgoing packet */
				uip_split_output();
			}
		}

		#if defined(ENABLE_DHCP_CLIENT)
		for (uint8_t i = 0; i < UIP_UDP_CONNS; i++)
		{
			/* Run periodic connection management for each UDP connection */
			uip_udp_periodic(i);

			/* If a response was generated, send it */
			if (uip_len > 0)
			{
				/* Add destination MAC to outgoing packet */
				uip_arp_out();

				/* Split and send the outgoing packet */
				uip_split_output();
			}
		}
		#endif

		LEDs_SetAllLEDs(LEDMASK_USB_READY);
	}

	/* Manage ARP cache refreshing */
	if (timer_expired(&ARPTimer))
	{
		timer_reset(&ARPTimer);
		uip_arp_timer();
	}
}
Пример #16
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;

  }
}
Пример #17
0
/*---------------------------------------------------------------------------*/
int
main(void)
{
  int i;
  uip_ipaddr_t ipaddr;
  struct timer periodic_timer, arp_timer;

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

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

  httpd_init();
  
  /*  telnetd_init();*/
  
  /*  hello_world_init();*/

  /*  {
      u8_t mac[6] = {1,2,3,4,5,6};
      dhcpc_init(&mac, 6);
      }*/
  
  /*uip_ipaddr(ipaddr, 127,0,0,1);
  smtp_configure("localhost", ipaddr);
  SMTP_SEND("*****@*****.**", NULL, "*****@*****.**",
	    "Testing SMTP from uIP",
	    "Test message sent by uIP\r\n");*/

  /*
    webclient_init();
    resolv_init();
    uip_ipaddr(ipaddr, 195,54,122,204);
    resolv_conf(ipaddr);
    resolv_query("www.sics.se");*/


  
  while(1) {
    uip_len = tapdev_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();
	  tapdev_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) {
	  tapdev_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();
	  tapdev_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();
	  tapdev_send();
	}
      }
#endif /* UIP_UDP */
      
      /* Call the ARP timer function every 10 seconds. */
      if(timer_expired(&arp_timer)) {
	timer_reset(&arp_timer);
	uip_arp_timer();
      }
    }
  }
  return 0;
}
Пример #18
0
void vuIP_Task( void *pvParameters )
{
portBASE_TYPE i;
uip_ipaddr_t xIPAddr;
struct timer periodic_timer, arp_timer;

	/* To prevent compiler warnings. */
	( void ) pvParameters;

	/* Initialise the uIP stack. */
	timer_set( &periodic_timer, configTICK_RATE_HZ / 2 );
	timer_set( &arp_timer, configTICK_RATE_HZ * 10 );
	uip_init();
	uip_ipaddr( xIPAddr, configIP_ADDR0, configIP_ADDR1, configIP_ADDR2, configIP_ADDR3 );
	uip_sethostaddr( xIPAddr );

	/* Initialise the WEB server. */
	httpd_init();

	/* Initialise the Ethernet controller peripheral. */
	vFECInit();

	for( ;; )
	{
		/* Is there received data ready to be processed? */
		uip_len = usFECGetRxedData();

		if( uip_len > 0 )
		{
			/* Standard uIP loop taken from the uIP manual. */

			if( xHeader->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();
					vFECSendData();
				}
				else
				{
					/* If we are not sending data then let the FEC driver know
					the buffer is no longer required. */
					vFECRxProcessingCompleted();
				}
			}
			else if( xHeader->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 )
				{
					vFECSendData();
				}
				else
				{
					/* If we are not sending data then let the FEC driver know
					the buffer is no longer required. */
					vFECRxProcessingCompleted();
				}
			}
			else
			{
				/* If we are not sending data then let the FEC driver know
				the buffer is no longer required. */
				vFECRxProcessingCompleted();
			}
		}
		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();
						vFECSendData();
					}
				}

				/* Call the ARP timer function every 10 seconds. */
				if( timer_expired( &arp_timer ) )
				{
					timer_reset( &arp_timer );
					uip_arp_timer();
				}
			}
			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( xFECSemaphore, configTICK_RATE_HZ / 2 );
			}
		}
	}
}
Пример #19
0
// This gets called on both Ethernet RX interrupts and timer requests,
// but it's called only from the Ethernet interrupt handler
void elua_uip_mainloop()
{
  u32 temp, packet_len;

  // Increment uIP timers
  temp = platform_eth_get_elapsed_time();
  periodic_timer += temp;
  arp_timer += temp;  

  // Check for an RX packet and read it
  if( ( packet_len = platform_eth_get_packet_nb( uip_buf, sizeof( uip_buf ) ) ) > 0 )
  {
    // Set uip_len for uIP stack usage.
    uip_len = ( unsigned short )packet_len;

    // Process incoming IP packets here.
    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();
        device_driver_send();
      }
    }

    // Process incoming ARP packets here.
    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 )
        device_driver_send();
    }
  }
  
  // Process TCP/IP Periodic Timer here.
  // Also process the "force interrupt" events (platform_eth_force_interrupt)
  if( periodic_timer >= UIP_PERIODIC_TIMER_MS )
  {
    periodic_timer = 0;
    uip_set_forced_poll( 0 );
  }
  else
    uip_set_forced_poll( 1 );
  for( temp = 0; temp < UIP_CONNS; temp ++ )
  {
    uip_periodic( temp );

    // 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();
      device_driver_send();
    }
  }

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

      // 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();
        device_driver_send();
      }
    }
#endif // UIP_UDP
  
  // Process ARP Timer here.
  if( arp_timer >= UIP_ARP_TIMER_MS )
  {
    arp_timer = 0;
    uip_arp_timer();
  }  
}
Пример #20
0
void vuIP_Task( void *pvParameters )
{
portBASE_TYPE i;
uip_ipaddr_t xIPAddr;
struct timer periodic_timer, arp_timer;
extern void ( vEMAC_ISR_Wrapper )( void );

	( void ) pvParameters;

	/* Initialise the uIP stack. */
	timer_set( &periodic_timer, configTICK_RATE_HZ / 2 );
	timer_set( &arp_timer, configTICK_RATE_HZ * 10 );
	uip_init();
	uip_ipaddr( xIPAddr, configIP_ADDR0, configIP_ADDR1, configIP_ADDR2, configIP_ADDR3 );
	uip_sethostaddr( xIPAddr );
	uip_ipaddr( xIPAddr, configNET_MASK0, configNET_MASK1, configNET_MASK2, configNET_MASK3 );
	uip_setnetmask( xIPAddr );
	httpd_init();

	/* Create the semaphore used to wake the uIP task. */
	vSemaphoreCreateBinary( xEMACSemaphore );

	/* Initialise the MAC. */
	while( lEMACInit() != pdPASS )
    {
        vTaskDelay( uipINIT_WAIT );
    }

	portENTER_CRITICAL();
	{
		EMAC->IntEnable = ( INT_RX_DONE | INT_TX_DONE );

		/* Set the interrupt priority to the max permissible to cause some
		interrupt nesting. */
		NVIC_SetPriority( ENET_IRQn, configEMAC_INTERRUPT_PRIORITY );

		/* Enable the interrupt. */
		NVIC_EnableIRQ( ENET_IRQn );
		prvSetMACAddress();
	}
	portEXIT_CRITICAL();


	for( ;; )
	{
		/* Is there received data ready to be processed? */
		uip_len = ulGetEMACRxData();

		if( ( uip_len > 0 ) && ( uip_buf != NULL ) )
		{
			/* Standard uIP loop taken from the uIP manual. */
			if( xHeader->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();
					vSendEMACTxData( uip_len );
				}
			}
			else if( xHeader->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 )
				{
					vSendEMACTxData( uip_len );
				}
			}
		}
		else
		{
			if( timer_expired( &periodic_timer ) && ( uip_buf != NULL ) )
			{
				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();
						vSendEMACTxData( uip_len );
					}
				}

				/* Call the ARP timer function every 10 seconds. */
				if( timer_expired( &arp_timer ) )
				{
					timer_reset( &arp_timer );
					uip_arp_timer();
				}
			}
			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( xEMACSemaphore, configTICK_RATE_HZ / 2 );
			}
		}
	}
}
Пример #21
0
void vuIP_Task( void *pvParameters )
{
long i;
unsigned long ulNewEvent = 0UL, ulUIP_Events = 0UL;
unsigned short usPacketLength;

	/* Just to prevent compiler warnings about the unused parameter. */
	( void ) pvParameters;

	/* Initialise the uIP stack, configuring for web server usage. */
	prvInitialise_uIP();

	/* Initialise the MAC and PHY. */
	vEMACInit();

	for( ;; )
	{
		/* Is there received data ready to be processed? */
		usPacketLength = usEMACRead();

		/* Statements to be executed if data has been received on the Ethernet. */
		if( ( usPacketLength > 0U ) && ( uip_buf != NULL ) )
		{
			uip_len = usPacketLength;
			
			if( xHeader->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();
					vEMACWrite();
				}
			}
			else if( xHeader->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 )
				{
					vEMACWrite();
				}
			}
		}
		else
		{
			/* Clear the RX event latched in ulUIP_Events - if one was latched. */
			ulUIP_Events &= ~uipETHERNET_RX_EVENT;
		}

		/* Statements to be executed if the TCP/IP period timer has expired. */
		if( ( ulUIP_Events & uipPERIODIC_TIMER_EVENT ) != 0UL )
		{
			ulUIP_Events &= ~uipPERIODIC_TIMER_EVENT;

			if( uip_buf != NULL )
			{
				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();
						vEMACWrite();
					}
				}
			}
		}

		/* Statements to be executed if the ARP timer has expired. */
		if( ( ulUIP_Events & uipARP_TIMER_EVENT ) != 0 )
		{
			ulUIP_Events &= ~uipARP_TIMER_EVENT;
			uip_arp_timer();
		}

		/* If all latched events have been cleared - block until another event
		occurs. */
		if( ulUIP_Events == pdFALSE )
		{
			xQueueReceive( xEMACEventQueue, &ulNewEvent, portMAX_DELAY );
			ulUIP_Events |= ulNewEvent;
		}
	}
}
Пример #22
0
//*****************************************************************************
//
// This example demonstrates the use of the Ethernet Controller with the uIP
// TCP/IP stack.
//
//*****************************************************************************
int
main(void)
{
    uip_ipaddr_t ipaddr;
    static struct uip_eth_addr sTempAddr;
    long lPeriodicTimer, lARPTimer, lPacketLength;
    unsigned long ulUser0, ulUser1;
    unsigned long ulTemp;

    //
    // Set the clocking to run directly from the crystal.
    //
    SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
                   SYSCTL_XTAL_8MHZ);

    //
    // Initialize the OLED display.
    //
    RIT128x96x4Init(1000000);
    RIT128x96x4StringDraw("Ethernet with uIP", 12, 0, 15);

    //
    // Enable and Reset the Ethernet Controller.
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_ETH);
    SysCtlPeripheralReset(SYSCTL_PERIPH_ETH);

    //
    // Enable Port F for Ethernet LEDs.
    //  LED0        Bit 3   Output
    //  LED1        Bit 2   Output
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
    GPIOPinTypeEthernetLED(GPIO_PORTF_BASE, GPIO_PIN_2 | GPIO_PIN_3);

    //
    // Configure SysTick for a periodic interrupt.
    //
    SysTickPeriodSet(SysCtlClockGet() / SYSTICKHZ);
    SysTickEnable();
    SysTickIntEnable();

    //
    // Intialize the Ethernet Controller and disable all Ethernet Controller
    // interrupt sources.
    //
    EthernetIntDisable(ETH_BASE, (ETH_INT_PHY | ETH_INT_MDIO | ETH_INT_RXER |
                       ETH_INT_RXOF | ETH_INT_TX | ETH_INT_TXER | ETH_INT_RX));
    ulTemp = EthernetIntStatus(ETH_BASE, false);
    EthernetIntClear(ETH_BASE, ulTemp);

    //
    // Initialize the Ethernet Controller for operation.
    //
    EthernetInitExpClk(ETH_BASE, SysCtlClockGet());

    //
    // Configure the Ethernet Controller for normal operation.
    // - Full Duplex
    // - TX CRC Auto Generation
    // - TX Padding Enabled
    //
    EthernetConfigSet(ETH_BASE, (ETH_CFG_TX_DPLXEN | ETH_CFG_TX_CRCEN |
                                 ETH_CFG_TX_PADEN));

    //
    // Wait for the link to become active.
    // 
    RIT128x96x4StringDraw("Waiting for Link", 12, 8, 15);
    ulTemp = EthernetPHYRead(ETH_BASE, PHY_MR1);
    while((ulTemp & 0x0004) == 0)
    {
        ulTemp = EthernetPHYRead(ETH_BASE, PHY_MR1);
    }
    RIT128x96x4StringDraw("Link Established", 12, 16, 15);

    //
    // Enable the Ethernet Controller.
    //
    EthernetEnable(ETH_BASE);

    //
    // Enable the Ethernet interrupt.
    //
    IntEnable(INT_ETH);

    //
    // Enable the Ethernet RX Packet interrupt source.
    //
    EthernetIntEnable(ETH_BASE, ETH_INT_RX);

    //
    // Enable all processor interrupts.
    //
    IntMasterEnable();

    //
    // Initialize the uIP TCP/IP stack.
    //
    uip_init();
#ifdef USE_STATIC_IP
    uip_ipaddr(ipaddr, DEFAULT_IPADDR0, DEFAULT_IPADDR1, DEFAULT_IPADDR2,
               DEFAULT_IPADDR3);
    uip_sethostaddr(ipaddr);
    DisplayIPAddress(ipaddr, 18, 24);
    uip_ipaddr(ipaddr, DEFAULT_NETMASK0, DEFAULT_NETMASK1, DEFAULT_NETMASK2,
               DEFAULT_NETMASK3);
    uip_setnetmask(ipaddr);
#else
    uip_ipaddr(ipaddr, 0, 0, 0, 0);
    uip_sethostaddr(ipaddr);
    DisplayIPAddress(ipaddr, 18, 24);
    uip_ipaddr(ipaddr, 0, 0, 0, 0);
    uip_setnetmask(ipaddr);
#endif

    //
    // Configure the hardware MAC address for Ethernet Controller filtering of
    // incoming packets.
    //
    // For the Ethernet Eval Kits, the MAC address will be stored in the
    // non-volatile USER0 and USER1 registers.  These registers can be read
    // using the FlashUserGet function, as illustrated below.
    //
    FlashUserGet(&ulUser0, &ulUser1);
    if((ulUser0 == 0xffffffff) || (ulUser1 == 0xffffffff))
    {
        //
        // We should never get here.  This is an error if the MAC address has
        // not been programmed into the device.  Exit the program.
        //
        RIT128x96x4StringDraw("MAC Address", 0, 16, 15);
        RIT128x96x4StringDraw("Not Programmed!", 0, 24, 15);
        while(1)
        {
        }
    }

    //
    // Convert the 24/24 split MAC address from NV ram into a 32/16 split MAC
    // address needed to program the hardware registers, then program the MAC
    // address into the Ethernet Controller registers.
    //
    sTempAddr.addr[0] = ((ulUser0 >>  0) & 0xff);
    sTempAddr.addr[1] = ((ulUser0 >>  8) & 0xff);
    sTempAddr.addr[2] = ((ulUser0 >> 16) & 0xff);
    sTempAddr.addr[3] = ((ulUser1 >>  0) & 0xff);
    sTempAddr.addr[4] = ((ulUser1 >>  8) & 0xff);
    sTempAddr.addr[5] = ((ulUser1 >> 16) & 0xff);

    //
    // Program the hardware with it's MAC address (for filtering).
    //
    EthernetMACAddrSet(ETH_BASE, (unsigned char *)&sTempAddr);
    uip_setethaddr(sTempAddr);

    //
    // Initialize the TCP/IP Application (e.g. web server).
    //
    httpd_init();

#ifndef USE_STATIC_IP
    //
    // Initialize the DHCP Client Application.
    //
    dhcpc_init(&sTempAddr.addr[0], 6);
    dhcpc_request();
#endif

    //
    // Main Application Loop.
    //
    lPeriodicTimer = 0;
    lARPTimer = 0;
    while(true)
    {
        //
        // Wait for an event to occur.  This can be either a System Tick event,
        // or an RX Packet event.
        //
        while(!g_ulFlags)
        {
        }

        //
        // If SysTick, Clear the SysTick interrupt flag and increment the
        // timers.
        //
        if(HWREGBITW(&g_ulFlags, FLAG_SYSTICK) == 1)
        {
            HWREGBITW(&g_ulFlags, FLAG_SYSTICK) = 0;
            lPeriodicTimer += SYSTICKMS;
            lARPTimer += SYSTICKMS;
        }

        //
        // Check for an RX Packet and read it.
        //
        lPacketLength = EthernetPacketGetNonBlocking(ETH_BASE, uip_buf,
                                                     sizeof(uip_buf));
        if(lPacketLength > 0)
        {
            //
            // Set uip_len for uIP stack usage.
            //
            uip_len = (unsigned short)lPacketLength;

            //
            // Clear the RX Packet event and renable RX Packet interrupts.
            //
            if(HWREGBITW(&g_ulFlags, FLAG_RXPKT) == 1)
            {
                HWREGBITW(&g_ulFlags, FLAG_RXPKT) = 0;
                EthernetIntEnable(ETH_BASE, ETH_INT_RX);
            }

            //
            // Process incoming IP packets here.
            //
            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();
                    EthernetPacketPut(ETH_BASE, uip_buf, uip_len);
                    uip_len = 0;
                }
            }

            //
            // Process incoming ARP packets here.
            //
            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)
                {
                    EthernetPacketPut(ETH_BASE, uip_buf, uip_len);
                    uip_len = 0;
                }
            }
        }

        //
        // Process TCP/IP Periodic Timer here.
        //
        if(lPeriodicTimer > UIP_PERIODIC_TIMER_MS)
        {
            lPeriodicTimer = 0;
            for(ulTemp = 0; ulTemp < UIP_CONNS; ulTemp++)
            {
                uip_periodic(ulTemp);

                //
                // 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();
                    EthernetPacketPut(ETH_BASE, uip_buf, uip_len);
                    uip_len = 0;
                }
            }

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

                //
                // 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();
                    EthernetPacketPut(ETH_BASE, uip_buf, uip_len);
                    uip_len = 0;
                }
            }
#endif // UIP_UDP
        }

        //
        // Process ARP Timer here.
        //
        if(lARPTimer > UIP_ARP_TIMER_MS)
        {
            lARPTimer = 0;
            uip_arp_timer();
        }
    }
}
Пример #23
0
/*
 * ARP periodic timer.
 */
static void ARPTimerHandler(eventid_t id) {

  (void)id;
  (void)macPollLinkStatus(&ETHD1);
  uip_arp_timer();
}
Пример #24
0
void vuIP_Task( void *pvParameters )
{
portBASE_TYPE i;
uip_ipaddr_t xIPAddr;
struct timer periodic_timer, arp_timer;
extern void ( vEMAC_ISR_Wrapper )( void );

	/* Create the semaphore used by the ISR to wake this task. */
	vSemaphoreCreateBinary( xEMACSemaphore );
	
	/* Initialise the uIP stack. */
	timer_set( &periodic_timer, configTICK_RATE_HZ / 2 );
	timer_set( &arp_timer, configTICK_RATE_HZ * 10 );
	uip_init();
	uip_ipaddr( xIPAddr, uipIP_ADDR0, uipIP_ADDR1, uipIP_ADDR2, uipIP_ADDR3 );
	uip_sethostaddr( xIPAddr );
	httpd_init();

	/* Initialise the MAC. */
	while( Init_EMAC() != pdPASS )
    {
        vTaskDelay( uipINIT_WAIT );
    }

	portENTER_CRITICAL();
	{
		MAC_INTENABLE = INT_RX_DONE;
        VICIntEnable |= 0x00200000;
        VICVectAddr21 = ( portLONG ) vEMAC_ISR_Wrapper;
		prvSetMACAddress();
	}
	portEXIT_CRITICAL();
	

	for( ;; )
	{
		/* Is there received data ready to be processed? */
		uip_len = uiGetEMACRxData( uip_buf );
		
		if( uip_len > 0 )
		{
			/* Standard uIP loop taken from the uIP manual. */
			if( xHeader->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();
					prvENET_Send();
				}
			}
			else if( xHeader->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 )
				{
					prvENET_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();
						prvENET_Send();
					}
				}	
	
				/* Call the ARP timer function every 10 seconds. */
				if( timer_expired( &arp_timer ) )
				{
					timer_reset( &arp_timer );
					uip_arp_timer();
				}
			}
			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( xEMACSemaphore, configTICK_RATE_HZ / 2 );			
			}
		}
	}
}
Пример #25
0
Файл: main.c Проект: orlv/fos
int main(int argc, char *argv[]) {
  uip_ipaddr_t ipaddr;
  int i;
  struct timer periodic_timer, arp_timer;
	if(connect_pci() < 0) return 1;
	printf("Starting up stack!\n");
	uip_init();
  uip_ipaddr(ipaddr, 192,168,1,8);
  uip_sethostaddr(ipaddr);
  uip_ipaddr(ipaddr, 192,168,1,1);
  uip_setdraddr(ipaddr);
  uip_ipaddr(ipaddr, 255,255,255,0);
  uip_setnetmask(ipaddr);
	uip_setethaddr(rtl8139_mac);
	resolv_init();
	dhcpc_init(rtl8139_mac, 6);
//	httpd_init();
	resolv_query("grindars.org.ru");
  printf("Stack started\n");
  while(1) {
    uip_len = rtl8139_poll();

    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();
	  rtl8139_transmit();
	}
      } 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) {
	  rtl8139_transmit();
	}
      }

    } 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();
	  rtl8139_transmit();
	}
      }

//#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();
	  rtl8139_transmit();
	}
      }
//#endif /* UIP_UDP */
      
      /* Call the ARP timer function every 10 seconds. */
      if(timer_expired(&arp_timer)) {
	timer_reset(&arp_timer);
	uip_arp_timer();
      }
    }
  }

	return 0;
}
Пример #26
0
void vuIP_Task( void *pvParameters )
{
portBASE_TYPE i;
uip_ipaddr_t xIPAddr;
struct timer periodic_timer, arp_timer;

	/* Create the semaphore used by the ISR to wake this task. */
	vSemaphoreCreateBinary( xSemaphore );
	
	/* Initialise the uIP stack. */
	timer_set( &periodic_timer, configTICK_RATE_HZ / 2 );
	timer_set( &arp_timer, configTICK_RATE_HZ * 10 );
	uip_init();
	uip_ipaddr( xIPAddr, uipIP_ADDR0, uipIP_ADDR1, uipIP_ADDR2, uipIP_ADDR3 );
	uip_sethostaddr( xIPAddr );
	uip_ipaddr( xIPAddr, uipNET_MASK0, uipNET_MASK1, uipNET_MASK2, uipNET_MASK3 );
	uip_setnetmask( xIPAddr );
	uip_ipaddr( xIPAddr, uipGATEWAY_ADDR0, uipGATEWAY_ADDR1, uipGATEWAY_ADDR2, uipGATEWAY_ADDR3 );
	uip_setdraddr( xIPAddr );	
	httpd_init();

	/* Initialise the MAC. */
	ENET_InitClocksGPIO();
	ENET_Init();
	portENTER_CRITICAL();
	{
		ENET_Start();
		prvSetMACAddress();
		VIC_Config( ENET_ITLine, VIC_IRQ, 1 );
		VIC_ITCmd( ENET_ITLine, ENABLE );	
		ENET_DMA->ISR = uipDMI_RX_CURRENT_DONE;
 		ENET_DMA->IER = uipDMI_RX_CURRENT_DONE;
	}
	portEXIT_CRITICAL();
	

	while(1)
	{
		/* Is there received data ready to be processed? */
		uip_len = ENET_HandleRxPkt( uip_buf );
		
		if( uip_len > 0 )
		{
			/* Standard uIP loop taken from the uIP manual. */
			if( xHeader->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();
					prvENET_Send();
				}
			}
			else if( xHeader->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 )
				{
					prvENET_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();
						prvENET_Send();
					}
				}	
	
				/* Call the ARP timer function every 10 seconds. */
				if( timer_expired( &arp_timer ) )
				{
					timer_reset( &arp_timer );
					uip_arp_timer();
				}
			}
			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, configTICK_RATE_HZ / 2 );			
			}
		}
	}
}
Пример #27
0
void uip_task(void *p)
{
	int i;
  	struct timer periodic_timer, arp_timer;

  	enc28j60_open();	

  	timer_set(&periodic_timer, CLOCK_SECOND / 2);
  	timer_set(&arp_timer, CLOCK_SECOND * 10);  
  	
  	
  	while(1) 
  	{
  		socket_process_pending_lists_();
  		
    	uip_len = enc28j60_read();
    	
    	if(uip_len > 0) 
    	{
      		if(BUF->type == htons(UIP_ETHTYPE_IP)) 
      		{
        		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();
          			enc28j60_write();
        		}
      		} 
      		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) 
        		{
          			enc28j60_write();
        		}
      		}

		} 
		
		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();
          			enc28j60_write();
        		}
      		}

#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();
          			enc28j60_write();
        		}
        	}
#endif /* UIP_UDP */           
      		/* Call the ARP timer function every 10 seconds. */
      		if(timer_expired(&arp_timer)) 
      		{
      			timer_reset(&arp_timer);
      			uip_arp_timer();
      		}
    	}
    	
    	//yield so that other tasks can do something
    	sys_msleep(UIP_TASK_YIELD_TIME_MS);
	}
  	
}
Пример #28
0
int main(void)
{


	network_init();

	//CLKPR = (1<<CLKPCE);	//Change prescaler
	//CLKPR = (1<<CLKPS0);	//Use prescaler 2
	//clock_prescale_set(clock_div_2);
	enc28j60Write(ECOCON, 1 & 0x7);	//Get a 25MHz signal from enc28j60

	uartInit();
	uartSetBaudRate(9600);
	rprintfInit(uartSendByte);

	int i;
	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);


	uip_init();
	
	struct uip_eth_addr mac = {UIP_ETHADDR0, UIP_ETHADDR1, UIP_ETHADDR2, UIP_ETHADDR3, UIP_ETHADDR4, UIP_ETHADDR5};

	uip_setethaddr(mac);
	
	// set up the udp data stream
	// configure the target system ip and port
	uip_ipaddr_t target_ipaddr;
	uip_ipaddr(&target_ipaddr, 192,168,0,10);
	udpds_conf(&target_ipaddr, 1000, 1);

#ifdef __DHCPC_H__
	dhcpc_init(&mac, 6);
#else
    uip_ipaddr(ipaddr, 192,168,0,1);
	uip_sethostaddr(ipaddr); 
    uip_ipaddr(ipaddr, 192,168,0,1);
    uip_setdraddr(ipaddr);
    uip_ipaddr(ipaddr, 255,255,255,0);
    uip_setnetmask(ipaddr);
#endif /*__DHCPC_H__*/


	while(1){
		uip_len = network_read(); 
		if(uip_len > 0) {
			if(BUF->type == htons(UIP_ETHTYPE_IP)){  
				uip_arp_ipin();
				uip_input();
				if(uip_len > 0) {
					uip_arp_out();
					network_send();
				}

			}else if(BUF->type == htons(UIP_ETHTYPE_ARP)){
				uip_arp_arpin();
				if(uip_len > 0){
					network_send();
				}
			}

		}else if(timer_expired(&periodic_timer)) {
			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();
			}
		}
	}
	return 0;
}
Пример #29
0
void vuIP_Task( void *pvParameters )
{
    portBASE_TYPE i;
    unsigned long ulNewEvent = 0UL;
    unsigned long ulUIP_Events = 0UL;

    ( void ) pvParameters;

    /* Initialise the uIP stack. */
    prvInitialise_uIP();

    /* Initialise the MAC. */
    vInitEmac();

    while( lEMACWaitForLink() != pdPASS )
    {
        vTaskDelay( uipINIT_WAIT );
    }

    for( ;; )
    {
        if( ( ulUIP_Events & uipETHERNET_RX_EVENT ) != 0UL )
        {
            /* Is there received data ready to be processed? */
            uip_len = ( unsigned short ) ulEMACRead();

            if( ( uip_len > 0 ) && ( uip_buf != NULL ) )
            {
                /* Standard uIP loop taken from the uIP manual. */
                if( xHeader->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();
                        vEMACWrite();
                    }
                }
                else if( xHeader->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 )
                    {
                        vEMACWrite();
                    }
                }
            }
            else
            {
                ulUIP_Events &= ~uipETHERNET_RX_EVENT;
            }
        }

        if( ( ulUIP_Events & uipPERIODIC_TIMER_EVENT ) != 0UL )
        {
            ulUIP_Events &= ~uipPERIODIC_TIMER_EVENT;

            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();
                    vEMACWrite();
                }
            }
        }

        /* Call the ARP timer function every 10 seconds. */
        if( ( ulUIP_Events & uipARP_TIMER_EVENT ) != 0 )
        {
            ulUIP_Events &= ~uipARP_TIMER_EVENT;
            uip_arp_timer();
        }

        if( ulUIP_Events == pdFALSE )
        {
            xQueueReceive( xEMACEventQueue, &ulNewEvent, portMAX_DELAY );
            ulUIP_Events |= ulNewEvent;
        }
    }
}
Пример #30
0
void main(void) {
  static struct uip_eth_addr eth_addr;
  uip_ipaddr_t ipaddr;

  cpu_init();
  uart_init();
  printf("Welcome\n");
  spi_init();
  enc28j60_comm_init();

  printf("Welcome\n");

  enc_init(mac_addr);

  //
  // Configure SysTick for a periodic interrupt.
  //
  MAP_SysTickPeriodSet(MAP_SysCtlClockGet() / SYSTICKHZ);
  MAP_SysTickEnable();
  MAP_SysTickIntEnable();

  //MAP_IntEnable(INT_GPIOA);
  MAP_IntEnable(INT_GPIOE);
  MAP_IntMasterEnable();

  MAP_SysCtlPeripheralClockGating(false);

  printf("int enabled\n");

  MAP_GPIOIntTypeSet(GPIO_PORTE_BASE, ENC_INT, GPIO_FALLING_EDGE);
  MAP_GPIOPinIntClear(GPIO_PORTE_BASE, ENC_INT);
  MAP_GPIOPinIntEnable(GPIO_PORTE_BASE, ENC_INT);

  uip_init();

  eth_addr.addr[0] = mac_addr[0];
  eth_addr.addr[1] = mac_addr[1];
  eth_addr.addr[2] = mac_addr[2];
  eth_addr.addr[3] = mac_addr[3];
  eth_addr.addr[4] = mac_addr[4];
  eth_addr.addr[5] = mac_addr[5];

  uip_setethaddr(eth_addr);

#define DEFAULT_IPADDR0 10
#define DEFAULT_IPADDR1 0
#define DEFAULT_IPADDR2 0
#define DEFAULT_IPADDR3 201

#define DEFAULT_NETMASK0 255
#define DEFAULT_NETMASK1 255
#define DEFAULT_NETMASK2 255
#define DEFAULT_NETMASK3 0

#undef STATIC_IP

#ifdef STATIC_IP
  uip_ipaddr(ipaddr, DEFAULT_IPADDR0, DEFAULT_IPADDR1, DEFAULT_IPADDR2,
	     DEFAULT_IPADDR3);
  uip_sethostaddr(ipaddr);
  printf("IP: %d.%d.%d.%d\n", DEFAULT_IPADDR0, DEFAULT_IPADDR1,
	     DEFAULT_IPADDR2, DEFAULT_IPADDR3);
  uip_ipaddr(ipaddr, DEFAULT_NETMASK0, DEFAULT_NETMASK1, DEFAULT_NETMASK2,
	     DEFAULT_NETMASK3);
  uip_setnetmask(ipaddr);
#else
  uip_ipaddr(ipaddr, 0, 0, 0, 0);
  uip_sethostaddr(ipaddr);
  printf("Waiting for IP address...\n");
  uip_ipaddr(ipaddr, 0, 0, 0, 0);
  uip_setnetmask(ipaddr);
#endif

  httpd_init();

#ifndef STATIC_IP
  dhcpc_init(mac_addr, 6);
  dhcpc_request();
#endif

  long lPeriodicTimer, lARPTimer;
  lPeriodicTimer = lARPTimer = 0;

  int i; // = MAP_GPIOPinRead(GPIO_PORTA_BASE, ENC_INT) & ENC_INT;
  while(true) {
    //MAP_IntDisable(INT_UART0);
    MAP_SysCtlSleep();
    //MAP_IntEnable(INT_UART0);

    //i = MAP_GPIOPinRead(GPIO_PORTA_BASE, ENC_INT) & ENC_INT;
    /*while(i != 0 && g_ulFlags == 0) {
      i = MAP_GPIOPinRead(GPIO_PORTA_BASE, ENC_INT) & ENC_INT;
      }*/

    if( HWREGBITW(&g_ulFlags, FLAG_ENC_INT) == 1 ) {
      HWREGBITW(&g_ulFlags, FLAG_ENC_INT) = 0;
      enc_action();
    }

    if(HWREGBITW(&g_ulFlags, FLAG_SYSTICK) == 1) {
      HWREGBITW(&g_ulFlags, FLAG_SYSTICK) = 0;
      lPeriodicTimer += SYSTICKMS;
      lARPTimer += SYSTICKMS;
      //printf("%d %d\n", lPeriodicTimer, lARPTimer);
    }

    if( lPeriodicTimer > UIP_PERIODIC_TIMER_MS ) {
      lPeriodicTimer = 0;
      int l;
      for(l = 0; l < UIP_CONNS; l++) {
	uip_periodic(l);

	//
	// 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();
	  enc_send_packet(uip_buf, uip_len);
	  uip_len = 0;
	}
      }

      for(l = 0; l < UIP_UDP_CONNS; l++) {
	uip_udp_periodic(l);
	if( uip_len > 0) {
	  uip_arp_out();
	  enc_send_packet(uip_buf, uip_len);
	  uip_len = 0;
	}
      }
    }

    if( lARPTimer > UIP_ARP_TIMER_MS) {
      lARPTimer = 0;
      uip_arp_timer();
    }

  }

}