Example #1
0
int main(int argc, char *argv[])
{
    initPLL();
    initGPIO();
    vicInit();
    uart0Init(CLOCKS_PCLK, UART0_BAUD_RATE);
    boot_mode_t bootMode = selectBootMode();
    bootMode == APP_CON ? led_on(ADMIN_LED) : led_off(ADMIN_LED);
    
    LOG_INFO("Initializing USB Stack");
    usbUserDriver = bootMode == APP_NET ? usbNetDriver : usbConDriver;
    usbInit();
    
    if(bootMode == APP_NET) {
      LOG_INFO("Initializing Ethernet stack");
      enc28j60_init(&IODIR, &IOPIN, MACAddress);
    
      // Print MAC address
      enc28j60_get_mac_address((uint8_t*)MACAddress);
      LOG_INFO("MAC address: %X-%X-%X-%X-%X-%X\n", MACAddress[0], MACAddress[1], MACAddress[2], MACAddress[3], MACAddress[4], MACAddress[5]);
    }
      
    LOG_INFO("Starting USB Stack");
    interruptsEnable();
    
    usbConnect();
    
    LOG_INFO("Entering main loop");
    
    bootMode == APP_NET ? appnet_loop() : appcon_loop();
    
    return 0;
}
Example #2
0
void prvInit( void *pvParameters )
{
    vTaskSuspendAll();

	GPIO_InitTypeDef GPIO_InitStruct;

    // Initialize button int
	GPIO_InitStruct.Pin       = GPIO_PIN_0;
    GPIO_InitStruct.Mode      = GPIO_MODE_IT_RISING;
    GPIO_InitStruct.Pull      = GPIO_NOPULL;
    GPIO_InitStruct.Speed     = GPIO_SPEED_LOW;
    GPIO_InitStruct.Alternate = 0;

    HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

    IRQn_Type irqn_line = EXTI0_IRQn;
    HAL_NVIC_SetPriority(irqn_line, 7, 7);
    HAL_NVIC_EnableIRQ(irqn_line);

    debug("enc28j60: init\n");
    enc28j60_init(ucMACAddress);
    uint8_t revision_id = 0;
    revision_id = enc28j60_rcr(EREVID);
    debug("enc28j60: revision %#x\n", revision_id);
    debug("enc28j60: checked MAC address %x:%x:%x:%x:%x:%x filter: %x\n",
            enc28j60_rcr(MAADR5), enc28j60_rcr(MAADR4), enc28j60_rcr(MAADR3),
            enc28j60_rcr(MAADR2), enc28j60_rcr(MAADR1), enc28j60_rcr(MAADR0),
            enc28j60_rcr(ERXFCON));
    xTaskResumeAll();
    //xTaskCreate(prvCheckFlagsTask, "Check", 1000, NULL, 2, NULL);
    vTaskDelete(NULL);
}
/*---------------------------------------------------------------------------*/
static void
init(void)
{
  uint8_t eui64[8];
  uint8_t macaddr[6];

  /* Assume that rimeaddr_node_addr holds the EUI64 of this device. */
  memcpy(eui64, &linkaddr_node_addr, sizeof(eui64));

  /* Mangle the EUI64 into a 48-bit Ethernet address. */
  memcpy(&macaddr[0], &eui64[0], 3);
  memcpy(&macaddr[3], &eui64[5], 3);

  /* In case the OUI happens to contain a broadcast bit, we mask that
     out here. */
  macaddr[0] = (macaddr[0] & 0xfe);

  memcpy(ip64_eth_addr.addr, macaddr, sizeof(macaddr));

  printf("MAC addr %02x:%02x:%02x:%02x:%02x:%02x\n",
         macaddr[0], macaddr[1], macaddr[2],
         macaddr[3], macaddr[4], macaddr[5]);
  enc28j60_init(macaddr);
  process_start(&enc28j60_ip64_driver_process, NULL);
}
Example #4
0
int main(int argc, char *argv[])
{
    if (argc != 5) {
        printf("Usage: ./ethapp <eth-port-my> <eth-port-other> <usb-port-my> <usb-port-other>\n");
        return 1;
    }
    
    LOG_INFO("Initializing USB Stack");
    usbnet_init(argv[3], argv[4]);
    
	LOG_INFO("Initializing Ethernet stack");
	enc28j60_init(0, 0, MACAddress, argv[1], argv[2]);
	
	LOG_INFO("Starting USB Stack");
    
    LOG_INFO("Entering main loop");
    
    struct sigaction act;
    memset(&act, 0, sizeof(act));
    act.sa_handler = sigint_handler;
    //sigaction(SIGINT, &act, NULL);
    
    appnet_loop();
	return 0;
}
Example #5
0
/*---------------------------------------------------------------------------*/
void
eth_drv_init()
{
  LOG6LBR_INFO("ENC28J60 init\n");

  linkaddr_copy((linkaddr_t *) & wsn_mac_addr, &linkaddr_node_addr);
  mac_createEthernetAddr((uint8_t *) eth_mac_addr, &wsn_mac_addr);
  LOG6LBR_ETHADDR(INFO, &eth_mac_addr, "Eth MAC address : ");
  eth_mac_addr_ready = 1;

  enc28j60_init(eth_mac_addr);
  process_start(&eth_drv_process, NULL);
  ethernet_ready = 1;
}
Example #6
0
extern "C" int main(void)
{
	rc522_pcd_select(RC522_PCD_1);
	mfrc522_init();

	rc522_pcd_select(RC522_PCD_2);
	mfrc522_init();

	enc28j60_init(mac_addr);

	dhcp_retry_time = RTC_GetCounter() + 1;

	// Check if timer started.
	uint8_t status = mfrc522_read(Status1Reg);
	uint32_t poll_time, dns_time;

	__enable_irq();

	rc522_irq_prepare();

	rc522_pcd_select(RC522_PCD_1);
	rc522_irq_prepare();

	// Workers.
	while (1)
	{
		// If DHCPD expired or still not assigng request for new net settings.
		while (dhcp_status != DHCP_ASSIGNED) {
			dhcp_poll();
		}

		// If cached tag did request, the even is stored to queue, send it to server
		// in main thread.
		tag_event_queue_processor();

		if (ticks - poll_time > 600)
		{
			poll_time = ticks;
			tcp_poll();
		}

		if (ticks - dns_time > 600)
		{
			dns_time = ticks;
			//dns_query("com");
		}
	}
}
Example #7
0
/**
 * initialize - Performs all initialization procedures
 *
 * Returns a CHARLIE_STAT_* constant that indicates the succes or
 * failure of the initialization.
 */
static uint8_t initialize(void)
{
    charlie.shutdown = FALSE;
    
    init_atmega();
    init_ports();
    debug_init_ports();
    
    rs232_init();
    spi_init_master();
    i2c_init();
    
    if (rtc_init()) {
        return CHARLIE_STAT_RTC_ERROR;
    }
    time_init();
    time_sync_to_realtime();
    
    sched_init();
    
    if (card_init()) {
        return CHARLIE_STAT_CARD_ERROR;
    }
    if (fsys_init()) {
        return CHARLIE_STAT_FSYS_ERROR;
    }
    if (fsys_check_read_only()) {
        return CHARLIE_STAT_FSYS_READONLY;
    }
    
    cfg_load();
    if (enc28j60_init(&cfg.mac_addr)) {
        return CHARLIE_STAT_NET_ERROR;
    }
    net_init();
    
    adc_init();
    sensors_init();
    pump_init();
    plants_init();
    
    sei();

    return CHARLIE_STAT_OK;
}
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));
}
Example #9
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 #10
0
/*
 * enc28j60_atmega644p_init
 * This function will initialize enc28j60 device for atmega644p platform.
 */
void enc28j60_atmega644p_init()
{
    /* Clear the enc28j60 device structure. */
    memset(&enc28j60, 0, sizeof(ENC28J60));

    /* Set RST (PD.4) as output and INT (PD.2) as input. */
    DDRD |= (1 << 4);
    DDRD &= (uint8_t)~(1 << 2);

    /* Disable INT0 interrupt. */
    EIMSK &= (uint8_t)~(1 << 0);

    /* Setup INT0 to raise an interrupt on falling edge. */
    EICRA &= (uint8_t)~(0x03 << 0);
    EICRA |= (0x02 << 0);

    /* Initialize name for this device. */
    enc28j60.ethernet_device.fs.name = "\\ethernet\\enc28j60";

    /* Do enc28j60 initialization. */
    enc28j60_init(&enc28j60);

} /* enc28j60_atmega644p_init */
Example #11
0
int main(void) {
	DDRB |= 0xFF;
	DDRD |= (1<<5) | (1<<6);

	PORTD = (1<<6);

	uint16_t tmp = 512;

	while(tmp--) {
		lcd_content[tmp] = 0x00;
	}


	spi_init();

	soft_spi_init();

	enc28j60_init();

	nic_init(enc28j60_send_packet, enc28j60_receive_packet, enc28j60_set_mac);

	dhcp_init(dhcpname);

	timer_init();

	sei();


	//char nic_buffer[600];

	while(1) {

		nic_doEvents(nic_buffer);
		dhcp_doEvents(nic_buffer);

	}
}
Example #12
0
//*****************************************************************************************
//
// Function : main
// Description : main program, 
//
//*****************************************************************************************
int main (void)
{
	// change your mac address here
	avr_mac.byte[0] = 'A';
	avr_mac.byte[1] = 'V';
	avr_mac.byte[2] = 'R';
	avr_mac.byte[3] = 'P';
	avr_mac.byte[4] = 'O';
	avr_mac.byte[5] = 'R';

	// read avr and server ip from eeprom
	eeprom_read_block ( &avr_ip, ee_avr_ip, 4 );
	eeprom_read_block ( &server_ip, ee_server_ip, 4 );
	
	// setup port as input and enable pull-up
	SW_DDR &= ~ ( _BV( SW_MENU ) | _BV( SW_EXIT ) | _BV( SW_UP ) | _BV( SW_DW ) );
	SW_PORT |= _BV( SW_MENU ) | _BV( SW_EXIT ) | _BV( SW_UP ) | _BV( SW_DW );
	SFIOR &= ~_BV( PUD );

	// setup lcd backlight as output
	LCD_BL_DDR |= _BV( LCD_BL_PIN );
	// lcd backlight on
	LCD_BL_PORT |= _BV( LCD_BL_PIN );
	
	// setup clock for timer1
	TCCR1B = 0x01;	// clk/1 no prescaling

	// initial adc, lcd, and menu
	adc_init();
	lcd_init ();
	menu_init ();

	// set LED1, LED2 as output */
	LED_DDR |= _BV( LED_PIN1_DDR ) | _BV( LED_PIN2_DDR );
	// set LED pin to "1" ( LED1,LED2 off)
	LED_PORT |= _BV( LED_PIN1 ) | _BV( LED_PIN2 );

	// initial enc28j60
	enc28j60_init( (BYTE*)&avr_mac );
	
	// loop forever
	for(;;)
	{
		// wait until timer1 overflow
		while ( (TIFR & _BV ( TOV1 )) == 0 );
		TIFR |= _BV(TOV1);
		TCNT1 = 1536;	// Timer1 overflow every 1/16MHz * ( 65536 - 1536 ) = 4ms, 250Hz

		// general time base, generate by timer1
		// overflow every 1/250 seconds
		time_base ();
		
		// read temparature
		adc_read_temp();

		// server process response for arp, icmp, http
		server_process ();

		// send temparature to web server unsing http protocol
		// disable by default.
		client_process ();

		// lcd user interface menu
		// setup IP address, countdown timer
		menu_process ();

		// display AVR ethernet status
		// temparature, AVR ip, server ip, countdown time
		standby_display ();
	}

	return 0;
}
Example #13
0
extern "C" void TIM2_IRQHandler()
{
    open_node();
    if (TIM_GetITStatus(TIM2, TIM_IT_Update) != RESET)
    {
        TIM_ClearITPendingBit(TIM2, TIM_IT_Update);

	uint8_t pcd = RC522_PCD_1;

	do {
		// Chose rfid device.
		rc522_pcd_select(pcd);
		uint8_t status = mfrc522_read(Status1Reg);

		__disable_irq();
		// If timer is not running and interrupt timer flag is not active reinit device.
		if (!(status & TRunning))
		{
			uint8_t need_reinit = 0;
			switch (pcd) {
				case RC522_PCD_1:
					if (EXTI_GetITStatus(EXTI_Line10) == RESET) need_reinit = 1;
					break;

				case RC522_PCD_2:
					if (EXTI_GetITStatus(EXTI_Line11) == RESET) need_reinit = 1;
					break;
			}

			if (need_reinit)
			{
				spi_hardware_failure_signal();

				mfrc522_init();
				__enable_irq();
				rc522_irq_prepare();
			}
		}
		__enable_irq();
	} while (pcd++ < RC522_PCD_2);

    	// Check enc28j60 chip and restart if needed.
	if (!enc28j60_revid || (enc28j60_revid != enc28j60_rcr(EREVID)) ||
		(GPIO_ReadInputDataBit(ETH_GPIO, ETH_IRQ_PIN) == RESET && (EXTI_GetITStatus(EXTI_Line2) == RESET)))
	{
		enc28j60_init(mac_addr);
	}

	uint16_t phstat1 = enc28j60_read_phy(PHSTAT1);
	// Если ethernet провод вытаскивали, обновить DHCP.
	// Пока отключено, т.к. по непонятным причинам LLSTAT падает иногда
	// хотя коннект сохраняется, что вызывает провалы в доступности интерфейса на 3-10 секунд,
	// пока интерфейс не поднимится по DHCP заного, однако если согласно LLSTAT линк выключен
	// но мы не гасим интерфейс он продолжает нормально работать.
	if(!(phstat1 & PHSTAT1_LLSTAT))
	{
		static uint16_t link_dhcp_time;
		// Avoid frequently link checks.
		if (ticks - link_dhcp_time > 5000)
		{
			link_dhcp_time = ticks;
			// Обновим адрес через 5 секунд
			//  (после того, как линк появится)
			dhcp_status = DHCP_INIT;
			dhcp_retry_time = RTC_GetCounter() + 2;

			// Линка нет - опускаем интерфейс
			ip_addr = 0;
			ip_mask = 0;
			ip_gateway = 0;

			enc28j60_init(mac_addr);
		}
	}
    }
}
Example #14
0
int main(void)
{
	/* constants */
	const ethernet_address my_mac = {'<','P','A','K','O','>'};
	
	/* init io */
	DDRB = 0xff;
	PORTB = 0xff;
	DDRE &= ~(1<<7);
	PORTE |= (1<<7);

	/* init interrupts */
	interrupt_timer0_init();
	interrupt_timer1_init();
	interrupt_exint_init();
	
	/* init arch */
	uart_init();
	spi_init();
	i2c_init();
	timer_init();

	DBG_INFO("\n\n");
	DBG_INFO(B_IBLUE "avr-net ver %s build time: %s %s\n","1.0",__DATE__,__TIME__);
	
	/* init utils */
	fifo_init();
	
	/* init dev */
	uint8_t ret = ds1338_init();
	DBG_INFO("ds1338_init ret = 0x%x\n",ret);
	enc28j60_init((uint8_t*)&my_mac); 
	
	/* init sys */
//	fat_init();	
	//rtc_init((0<<RTC_FORMAT_12_24)|(0<<RTC_FORMAT_AM_PM));
	
	ethernet_init(&my_mac);
	const ip_address ip = NET_IP_ADDRESS;
	const ip_address gw = NET_IP_GATEWAY;
	const ip_address nm = NET_IP_NETMASK;
	ip_init(&ip, &nm, &gw);		
//	ip_init(0,0,0);
	arp_init();
	udp_init();
//	tcp_init();
	
	
//	echod_start();
	
	stdout = DEBUG_FH;	
	
//	sd_init(sdcallback);
//	sd_interrupt();
//	httpd_start();	
	
	dhcp_start(dhcp_callback);
//	netstat(stdout, NETSTAT_OPT_ALL);
	
//	timer_t timer = timer_alloc(timer_callback);
//	timer_set(timer, 5000, TIMER_MODE_PERIODIC);
	
//	DBG_INFO("Before sei\n");
	/* global interrupt enable */
	sei();
	for(;;)
	{
	}
	return 0;
}
Example #15
0
/*
 * enc28j60_avr_init
 * This function will initialize enc28j60 device for avr platform.
 */
void enc28j60_avr_init(void)
{
    /* Clear the enc28j60 device structure. */
    memset(&enc28j60, 0, sizeof(ENC28J60));

    /* Set RST (PD.4) as output and INT (PD.2) as input. */
    DDRD |= (1 << 4);
    DDRD &= (uint8_t)~(1 << 2);

#if (ENC28J60_INT_POLL == FALSE)
    /* Disable INT0 interrupt. */
    EIMSK &= (uint8_t)~(1 << 0);

    /* Setup INT0 to raise an interrupt on falling edge. */
    EICRA &= (uint8_t)~(0x03 << 0);
    EICRA |= (0x02 << 0);
#endif

    /* Initialize device APIs. */
#if (ENC28J60_INT_POLL == FALSE)
    enc28j60.enable_interrupts = &enc28j60_avr_enable_interrupt;
    enc28j60.disable_interrupts = &enc28j60_avr_disable_interrupt;
#endif
    enc28j60.interrupt_pin = &enc28j60_avr_interrupt_pin;
    enc28j60.reset = &enc28j60_avr_reset;
    enc28j60.get_mac = &enc28j60_avr_get_mac;

    /* Hook-up SPI for this device. */
#if (ENC28J60_USE_SPI_BB == TRUE)
    /* Populate the SPI bit-bang interface. */
    spi_bb_enc28j60.pin_num_ss = ENC28J60_AVR_SPI_SS_BB;
    spi_bb_enc28j60.pin_num_mosi = ENC28J60_AVR_SPI_MOSI_BB;
    spi_bb_enc28j60.pin_num_miso = ENC28J60_AVR_SPI_MISO_BB;
    spi_bb_enc28j60.pin_num_sclk = ENC28J60_AVR_SPI_SCLK_BB;
    spi_bb_enc28j60.pin_ss = ENC28J60_AVR_SPI_PIN_SS_BB;
    spi_bb_enc28j60.pin_mosi = ENC28J60_AVR_SPI_PIN_MOSI_BB;
    spi_bb_enc28j60.pin_miso = ENC28J60_AVR_SPI_PIN_MISO_BB;
    spi_bb_enc28j60.pin_sclk = ENC28J60_AVR_SPI_PIN_SCLK_BB;
    spi_bb_enc28j60.ddr_ss = ENC28J60_AVR_SPI_DDR_SS_BB;
    spi_bb_enc28j60.ddr_mosi = ENC28J60_AVR_SPI_DDR_MOSI_BB;
    spi_bb_enc28j60.ddr_miso = ENC28J60_AVR_SPI_DDR_MISO_BB;
    spi_bb_enc28j60.ddr_sclk = ENC28J60_AVR_SPI_DDR_SCLK_BB;
    spi_bb_enc28j60.port_ss = ENC28J60_AVR_SPI_PORT_SS_BB;
    spi_bb_enc28j60.port_mosi = ENC28J60_AVR_SPI_PORT_MOSI_BB;
    spi_bb_enc28j60.port_miso = ENC28J60_AVR_SPI_PORT_MISO_BB;
    spi_bb_enc28j60.port_sclk = ENC28J60_AVR_SPI_PORT_SCLK_BB;

    /* Initialize enc28j60 SPI device. */
    enc28j60.spi.data = &spi_bb_enc28j60;
    enc28j60.spi.init = &spi_bb_avr_init;
    enc28j60.spi.slave_select = &spi_bb_avr_slave_select;
    enc28j60.spi.slave_unselect = &spi_bb_avr_slave_unselect;
    enc28j60.spi.msg = &spi_bb_avr_message;
#else
    /* Initialize enc28j60 SPI device. */
    enc28j60.spi.init = &spi_avr_init;
    enc28j60.spi.slave_select = &spi_avr_slave_select;
    enc28j60.spi.slave_unselect = &spi_avr_slave_unselect;
    enc28j60.spi.msg = &spi_avr_message;
#endif

    /* Initialize name for this device. */
    enc28j60.ethernet_device.fs.name = "\\ethernet\\enc28j60";

    /* Do enc28j60 initialization. */
    enc28j60_init(&enc28j60);

} /* enc28j60_avr_init */
Example #16
0
/*!  \brief Executa a aplicação que controla a conexão de rede */
void appCall(void)
{
  //Se conexão foi abortada envia reset e reboot do pc
  if(uip_aborted())
  {
      reboot = 1;
      connected = 0;
      dataSent = 0;
  }

  //Verifica se houve algum problema na conexão
  if(uip_timedout())
  {
    //Flag que indica erro na conexão
    connected = 0;
    //lcdPutString("D",1,15);
    dataSent = 0;
    enc28j60_init();

    //appSendConnect();
    if(memoryData.ipTipo == '0')
    {
       //Inicia o DHCP
       ethaddr.addr[0] = ENC28J60_MAC0;
       ethaddr.addr[1] = ENC28J60_MAC1;
       ethaddr.addr[2] = MAC_CONC[0];
       ethaddr.addr[3] = MAC_CONC[1];
       ethaddr.addr[4] = MAC_CONC[2];
       ethaddr.addr[5] = MAC_CONC[3];
       uip_setethaddr(ethaddr);
       dhcpc_init(&ethaddr, sizeof(ethaddr));
    }
    else
    {
       u16_t dns[2];

       //Inicia com ip fixo
       appInitHostIp();
       dns[0] = memoryData.dnsAddr[0];
       dns[1] = memoryData.dnsAddr[1];
       appSetDnsAddr(dns);
       appSendConnect();
    }
  }

  if(uip_closed())
  {
     WDTCTL = 0;
  }

  //Caso a conexão com o servidor acabou de ocorrer
  if(uip_connected())
  {
    connected = 1;
    //lcdPutString("C",1,15);
    dataSent = 0;
  }

  //Recebe os dados enviados pelo servidor
  if(uip_newdata() && connected)
  {
    rcvSensorData(uip_appdata,uip_len);
  }

  if(connected && (uip_acked()) && dataSent && (!repetAck))
  {
    dataSent = 0;

    //Diz que valor dos sensores já foi enviado
    sensorClear();
  }

  if(uip_rexmit() && connected && (uip_len == 0))
  {
    //Evita travamento da interface de rede
    enc28j60_init();

    //Envia os dados do sensor no caso de retransmissão
    sendSensorData();

    return;
  }

  //Transmite dados para o servidor
  if(uip_poll() && connected && (uip_len==0))
  {
    //Envia os dados dos sensores caso seja modo síncrono
    if(memoryData.tempoPacote != 0)
    {
      if(ciclos >= 1)
      {
        if(countBaud >= (ciclos -1))
        {
           countBaud = 0;
           sendSensorData();
           dataSent = 1;
        }
        else
        {
           countBaud++;
        }
      }
    }
  }
}
Example #17
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();
                }
        }
}