Ejemplo n.º 1
0
Archivo: TcpIp.c Proyecto: 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;
   }
}
Ejemplo n.º 2
0
/*---------------------------------------------------------------------------*/
int
main(void)
{
  EEPROM_main();

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

  memcpy (&uip_ethaddr.addr[0], &eeprom.MAC[0], 6);

  AVR_init();
  egpio_init();

  clock_init();
  mbuf_init();
  adlc_init();
  GICR = (1 << INT0);

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

  nic_init();


  uip_ipaddr(ipaddr, eeprom.IPAddr[0],eeprom.IPAddr[1],eeprom.IPAddr[2],eeprom.IPAddr[3]);
  uip_sethostaddr(ipaddr);
  uip_ipaddr(ipaddr, eeprom.Gateway[0],eeprom.Gateway[1],eeprom.Gateway[2],eeprom.Gateway[3]);
  uip_setdraddr(ipaddr);
  uip_ipaddr(ipaddr, eeprom.Subnet[0],eeprom.Subnet[1],eeprom.Subnet[2],eeprom.Subnet[3]);
  uip_setnetmask(ipaddr);

  telnetd_init();
  aun_init();
  internet_init();

  egpio_write (EGPIO_STATUS_GREEN);

  while(1) {

// check the econet for complete packets
    adlc_poller();
    aun_poller ();

    uip_len = nic_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. */
	maybe_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) {
	  nic_send(NULL);
	}
      }

    } else if(timer_expired(&periodic_timer)) {
      timer_reset(&periodic_timer);
      for(i = 0; i < UIP_CONNS; i++) {
	uip_periodic(i);
	maybe_send();
      }

#if UIP_UDP
      for(i = 0; i < UIP_UDP_CONNS; i++) {
	uip_udp_periodic(i);
	maybe_send();
      }
#endif /* UIP_UDP */

      /* Call the ARP timer function every 10 seconds. */
      if(timer_expired(&arp_timer)) {
	timer_reset(&arp_timer);
	uip_arp_timer();
      }
    }
  }
}
Ejemplo n.º 3
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;
}
Ejemplo n.º 4
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;
}