///////////////////////////////////////////////////////////////////////////// // The uIP Task is executed each mS ///////////////////////////////////////////////////////////////////////////// static void UIP_TASK_Handler(void *pvParameters) { int i; struct timer periodic_timer, arp_timer; // take over exclusive access to UIP functions MUTEX_UIP_TAKE; // init uIP timers timer_set(&periodic_timer, CLOCK_SECOND / 2); timer_set(&arp_timer, CLOCK_SECOND * 10); // init the network driver network_device_init(); // init uIP uip_init(); uip_arp_init(); // set my ethernet address unsigned char *mac_addr = network_device_mac_addr(); { int i; for(i=0; i<6; ++i) uip_ethaddr.addr[i] = mac_addr[i]; } // enable dhcp mode (can be changed during runtime) UIP_TASK_DHCP_EnableSet(dhcp_enabled); // release exclusive access to UIP functions MUTEX_UIP_GIVE; #if 0 // wait until HW config has been loaded do { vTaskDelay(1 / portTICK_RATE_MS); } while( !SEQ_FILE_HW_ConfigLocked() ); #endif // Initialise the xLastExecutionTime variable on task entry portTickType xLastExecutionTime = xTaskGetTickCount(); // endless loop while( 1 ) { #if 0 do { vTaskDelayUntil(&xLastExecutionTime, 1 / portTICK_RATE_MS); } while( TASK_MSD_EnableGet() ); // don't service ethernet if MSD mode enabled for faster transfer speed #else vTaskDelayUntil(&xLastExecutionTime, 1 / portTICK_RATE_MS); #endif // take over exclusive access to UIP functions MUTEX_UIP_TAKE; if( !(clock_time_tick() % 100) ) { // each 100 mS: check availablility of network device #if defined(MIOS32_BOARD_MBHP_CORE_LPC17) || defined(MIOS32_BOARD_LPCXPRESSO) network_device_check(); // TK: on STM32 no auto-detection for MBSEQ for best performance if no MBHP_ETH module connected // the user has to reboot MBSEQ to restart module detection #endif } if( network_device_available() ) { uip_len = network_device_read(); if( uip_len > 0 ) { if(BUF->type == HTONS(UIP_ETHTYPE_IP) ) { uip_arp_ipin(); uip_input(); /* If the above function invocation resulted in data that should be sent out on the network, the global variable uip_len is set to a value > 0. */ if( uip_len > 0 ) { uip_arp_out(); network_device_send(); } } else if(BUF->type == HTONS(UIP_ETHTYPE_ARP)) { uip_arp_arpin(); /* If the above function invocation resulted in data that should be sent out on the network, the global variable uip_len is set to a value > 0. */ if(uip_len > 0) { network_device_send(); } } } else if(timer_expired(&periodic_timer)) { timer_reset(&periodic_timer); for(i = 0; i < UIP_CONNS; i++) { uip_periodic(i); /* If the above function invocation resulted in data that should be sent out on the network, the global variable uip_len is set to a value > 0. */ if(uip_len > 0) { uip_arp_out(); network_device_send(); } } #if UIP_UDP for(i = 0; i < UIP_UDP_CONNS; i++) { uip_udp_periodic(i); /* If the above function invocation resulted in data that should be sent out on the network, the global variable uip_len is set to a value > 0. */ if(uip_len > 0) { uip_arp_out(); network_device_send(); } } #endif /* UIP_UDP */ /* Call the ARP timer function every 10 seconds. */ if(timer_expired(&arp_timer)) { timer_reset(&arp_timer); uip_arp_timer(); } } } // release exclusive access to UIP functions MUTEX_UIP_GIVE; } }
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 = ( long ) 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 ); } } } }
void uip_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 ); network_init(); /* Create the semaphore used to wake the uIP task. */ vSemaphoreCreateBinary( xEMACSemaphore ); /* Initialise the MAC. */ while( lEMACInit() != pdPASS ) { vTaskDelay( uipINIT_WAIT ); } portENTER_CRITICAL(); { LPC_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 ); } } 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(); 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 ); } } } }
/*-----------------------------------------------------------------------------------*/ int main(void) { idata u8_t i, arptimer; idata u16_t j; // idata int i; InitGraphic();//putchar(0,62,0); //while(1) for(i=0;i<100;i++) { putstring(6,0, "Welcome to http://shop34480016.taobao.com www.dianshijin.cn"); } init_uart(); printu("starting......\r\n"); /* Initialize the device driver. */ // rtl8019as_init(); dev_init(); uip_arp_init(); /* Initialize the uIP TCP/IP stack. */ uip_init(); printu("11111111111111111111111\r\n"); /* Initialize the HTTP server. */ // httpd_init(); tcp_server_init(); arptimer = 0; printu("222222222222222222222222222\r\n"); while(1) { /* Let the tapdev network device driver read an entire IP packet into the uip_buf. If it must wait for more than 0.5 seconds, it will return with the return value 0. If so, we know that it is time to call upon the uip_periodic(). Otherwise, the tapdev has received an IP packet that is to be processed by uIP. */ uip_len = dev_poll(); for(j=0;j<500;j++); /* if(uip_len > 0) { printuf("--------------- uip_len = 0x%x", uip_len); printuf("%x ----------\r\n", uip_len); for(i=0;i<uip_len;i++) { printuf("%x ", uip_buf[i]); if((i+1)%16==0) printu("\r\n"); } printu("\r\n"); } */ if(uip_len == 0) { for(i = 0; i < UIP_CONNS; i++) { uip_periodic(i); /* If the above function invocation resulted in data that should be sent out on the network, the global variable uip_len is set to a value > 0. */ if(uip_len > 0) { uip_arp_out(); dev_send(); } } #if UIP_UDP for(i = 0; i < UIP_UDP_CONNS; i++) { uip_udp_periodic(i); /* If the above function invocation resulted in data that should be sent out on the network, the global variable uip_len is set to a value > 0. */ if(uip_len > 0) { uip_arp_out(); dev_send(); } } #endif /* UIP_UDP */ /* Call the ARP timer function every 10 seconds. */ if(++arptimer == 20) { uip_arp_timer(); arptimer = 0; } } else { if(BUF->type == htons(UIP_ETHTYPE_IP)) { uip_arp_ipin(); uip_input(); /* If the above function invocation resulted in data that should be sent out on the network, the global variable uip_len is set to a value > 0. */ if(uip_len > 0) { uip_arp_out(); dev_send(); } } else if(BUF->type == htons(UIP_ETHTYPE_ARP)) { uip_arp_arpin(); /* If the above function invocation resulted in data that should be sent out on the network, the global variable uip_len is set to a value > 0. */ if(uip_len > 0) { dev_send(); } } } } return 0; }
// 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(); } }
/***************************************************************************** * 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; }
/*---------------------------------------------------------------------------*/ 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(); } } } }
/*----------------------------------------------------------------------------*/ int main(void) { int i; // Renesas -- uip_ipaddr_t ipaddr; struct timer periodic_timer, arp_timer; struct uip_eth_addr my_mac; uint32_t ch = 0; // Renesas ++ InitialiseLCD(); DisplayuIPDemo(); timer_init(); timer_set(&periodic_timer, CLOCK_SECOND / 2); timer_set(&arp_timer, CLOCK_SECOND * 10); Exosite_Get_MAC((unsigned char *)&my_mac); // Renesas -- network_device_init(); /* Wait until Ether device initailize succesfully. Make sure Ethernet cable is plugged in. */ while (R_ETHER_ERROR == R_Ether_Open(ch, (uint8_t*)&my_mac)); // Renesas ++ set Ethernet address uip_setethaddr(my_mac); uip_init(); // Renesas -- //uip_ipaddr(ipaddr, 192,168,0,2); //uip_sethostaddr(ipaddr); dhcpc_init(&my_mac, 6); if (!Exosite_Init(APP_NAME, APP_VERSION)) DisplayLCD(LCD_LINE8, "==NEED CIK=="); while (1) { // Renesas -- uip_len = network_device_read(); uip_len = R_Ether_Read(ch, (void *)uip_buf); 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(); // Renesas -- network_device_send(); R_Ether_Write(ch, (void *)uip_buf, (uint32_t)uip_len); } } 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) { // Renesas -- network_device_send(); R_Ether_Write(ch, (void *)uip_buf, (uint32_t)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(); // Renesas -- network_device_send(); R_Ether_Write(ch, (void *)uip_buf, (uint32_t)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(); // Renesas -- network_device_send(); R_Ether_Write(ch, (void *)uip_buf, (uint32_t)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(); } } // Insert user aplications here. // Call WEB application that controls LEDs on the target board. user_app(); } return 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 #if MY_DEBUG uartInit(); uartSetBaudRate(9600); rprintfInit(uartSendByte); #endif 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); telnetd_init(); #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; }
int main(void) { sei(); uint8_t resetSource = MCUSR; MCUSR = 0; wdt_reset(); wdt_disable(); wdt_enable(WDTO_1S); WDTCSR |= (1 << WDIE); //enable watchdog interrupt wdt_reset(); cli(); clock_init(); usart_init(1000000, 9600); stdout = &uart_str; stderr = &uart_str; stdin = &uart_str; uip_ipaddr_t ipaddr; struct timer periodic_timer, arp_timer; uint16_t timer_OW, timer_Simple, timer_Count, timer_EEProm, timer_SendData, timer_IOalarm, timer_network; timer_OW = 0; timer_Simple = 0; timer_Count = 0; timer_EEProm = 0; timer_SendData = 0; timer_IOalarm = 0; timer_network = 0; if(resetSource & (1<<WDRF)) { printf("Mega was reset by watchdog...\r\n"); } if(resetSource & (1<<BORF)) { printf("Mega was reset by brownout...\r\n"); } if(resetSource & (1<<EXTRF)) { printf("Mega was reset by external...\r\n"); } if(resetSource & (1<<PORF)) { printf("Mega was reset by power on...\r\n"); } //else jtag (disabled) //sensorScan = (uint8_t*) & tempbuf; if (eepromReadByte(0) == 255 || eepromReadByte(11) == 255) { printf_P(PSTR("Setting default values\r\n")); //Set defaults eepromWriteByte(0, 0); //init myip[0] = 192; myip[1] = 168; myip[2] = 1; myip[3] = 67; //47 in final versions netmask[0] = 255; netmask[1] = 255; netmask[2] = 255; netmask[3] = 0; gwip[0] = 192; gwip[1] = 168; gwip[2] = 1; gwip[3] = 1; dnsip[0] = 8; dnsip[1] = 8; dnsip[2] = 8; dnsip[3] = 8; eepromWriteByte(29, 80); //web port eepromWriteByte(10, 0); //dhcp off save_ip_addresses(); wdt_reset(); eepromWriteStr(200, "SBNG", 4); //default password eepromWriteByte(204, '\0'); eepromWriteByte(205, '\0'); eepromWriteByte(206, '\0'); eepromWriteByte(207, '\0'); eepromWriteByte(208, '\0'); eepromWriteByte(209, '\0'); eepromWriteByte(100, 1); //Analog port 0 = ADC eepromWriteByte(101, 1); //Analog port 1 = ADC eepromWriteByte(102, 1); //Analog port 2 = ADC eepromWriteByte(103, 1); //Analog port 3 = ADC eepromWriteByte(104, 1); //Analog port 4 = ADC eepromWriteByte(105, 1); //Analog port 5 = ADC eepromWriteByte(106, 1); //Analog port 6 = ADC eepromWriteByte(107, 1); //Analog port 7 = ADC eepromWriteByte(110, 0); //Digital port 0 = OUT eepromWriteByte(111, 0); //Digital port 1 = OUT eepromWriteByte(112, 0); //Digital port 2 = OUT eepromWriteByte(113, 0); //Digital port 3 = OUT wdt_reset(); for (uint8_t alarm=1; alarm<=4; alarm++) { uint16_t pos = 400 + ((alarm-1)*15); //400 415 430 445 eepromWriteByte(pos+0, 0); //enabled eepromWriteByte(pos+1, 0); //sensorid eepromWriteByte(pos+2, 0); //sensorid eepromWriteByte(pos+3, 0); //sensorid eepromWriteByte(pos+4, 0); //sensorid eepromWriteByte(pos+5, 0); //sensorid eepromWriteByte(pos+6, 0); //sensorid eepromWriteByte(pos+7, 0); //sensorid eepromWriteByte(pos+8, 0); //sensorid eepromWriteByte(pos+9, '<'); //type eepromWriteByte(pos+10, 0); //value eepromWriteByte(pos+11, 0); //target eepromWriteByte(pos+12, 0); //state eepromWriteByte(pos+13, 0); //reverse eepromWriteByte(pos+14, 0); //not-used } eepromWriteByte(1, EEPROM_VERSION); } /* findSystemID(systemID); if (systemID[0] == 0) { printf_P(PSTR("No system id found, add a DS2401 or use old software")); // fprintf(&lcd_str, "?f?y0?x00No system id found?nAdd a DS2401 or use old software?n"); wdt_disable(); wdt_reset(); while (true); } else { */ //MAC will be 56 51 99 36 14 00 with example system id mymac[1] = systemID[1]; mymac[2] = systemID[2]; mymac[3] = systemID[3]; mymac[4] = systemID[4]; mymac[5] = systemID[5]; // } // fprintf(&lcd_str, "?y1?x00ID: %02X%02X%02X%02X%02X%02X%02X%02X?n", systemID[0], systemID[1], systemID[2], systemID[3], systemID[4], systemID[5], systemID[6], systemID[7]); loadSimpleSensorData(); //Set digital pins based on selections... for (uint8_t i=8; i<=11; i++) { if (simpleSensorTypes[i] == 0) { //output SETBIT(DDRC, (i-6)); } else { //input CLEARBIT(DDRC, (i-6)); } } network_init(); timer_set(&periodic_timer, CLOCK_SECOND / 2); timer_set(&arp_timer, CLOCK_SECOND * 10); uip_init(); //sættes hvert for sig for uip og enc, skal rettes til en samlet setting, så vi kan bruge mymac struct uip_eth_addr mac = { {UIP_ETHADDR0, UIP_ETHADDR1, UIP_ETHADDR2, UIP_ETHADDR3, UIP_ETHADDR4, UIP_ETHADDR5} }; // struct uip_eth_addr mac = {mymac[0], mymac[1], mymac[2], mymac[3], mymac[4], mymac[5]}; uip_setethaddr(mac); httpd_init(); /* #ifdef __DHCPC_H__ dhcpc_init(&mac, 6); #else */ uip_ipaddr(ipaddr, myip[0], myip[1], myip[2], myip[3]); uip_sethostaddr(ipaddr); uip_ipaddr(ipaddr, gwip[0], gwip[1], gwip[2], gwip[3]); uip_setdraddr(ipaddr); uip_ipaddr(ipaddr, netmask[0], netmask[1], netmask[2], netmask[3]); uip_setnetmask(ipaddr); //#endif /*__DHCPC_H__*/ printf("Setting ip to %u.%u.%u.%u \r\n", myip[0], myip[1], myip[2], myip[3]); resolv_init(); uip_ipaddr(ipaddr, dnsip[0], dnsip[1], dnsip[2], dnsip[3]); resolv_conf(ipaddr); webclient_init(); printf("Stokerbot NG R3 ready - Firmware %u.%u ...\r\n", SBNG_VERSION_MAJOR, SBNG_VERSION_MINOR); // fprintf(&lcd_str, "?y2?x00Firmware %u.%u ready.", SBNG_VERSION_MAJOR, SBNG_VERSION_MINOR); // SPILCD_init(); wdt_reset(); while (1) { //Only one event may fire per loop, listed in order of importance //If an event is skipped, it will be run next loop if (tickDiff(timer_Count) >= 1) { timer_Count = tick; wdt_reset(); //sikre at watchdog resetter os hvis timer systemet fejler, vi når her hvert 2ms updateCounters(); //bør ske i en interrupt istedet, for at garentere 2ms aflæsning } else if (tickDiffS(timer_IOalarm) >= 5) { printf("Timer : IO alarm \r\n"); timer_IOalarm = tickS; timedAlarmCheck(); } else if (tickDiffS(timer_OW) >= 2) { printf("Timer : OW \r\n"); timer_OW = tickS; updateOWSensors(); } else if (tickDiffS(timer_Simple) >= 5) { printf("Timer : Simple\r\n"); timer_Simple = tickS; updateSimpleSensors(); } else if (tickDiffS(timer_SendData) >= 59) { printf("Timer : webclient \r\n"); timer_SendData = tickS; webclient_connect(); } else if (tickDiffS(timer_EEProm) >= 60 * 30) { printf("Timer : eeprom \r\n"); timer_EEProm = tickS; timedSaveEeprom(); } //Net handling below if (tickDiff(timer_network) >= 1) { timer_network = tick; 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); //FLIPBIT(PORTC,5); // printf("Timers : %u %u \r\n", tick, tickS); for (uint8_t i = 0; i < UIP_CONNS; i++) { uip_periodic(i); if (uip_len > 0) { uip_arp_out(); network_send(); } } #if UIP_UDP for (uint8_t 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; }
/* ----------------------------------------------------------------------------- * \brief Deliver an incoming packet to the TCP/IP stack * * This function is called by theServer to * deliver an incoming packet to the TCP/IP stack. The * incoming packet must be present in the uip_buf buffer, * and the length of the packet must be in the global * uip_len variable. * -------------------------------------------------------------------------- */ void xtcpip_input(chanend mac_tx) { /*_______________*/ #if UIP_CONF_IPV4 /* ORIGINAL_XMOS */ if (BUF->type == htons(UIP_ETHTYPE_IP)) { uip_arp_ipin(); uip_input(); if (uip_len > 0) { if (uip_udpconnection() && (TCPBUF->proto != UIP_PROTO_ICMP) && (TCPBUF->proto != UIP_PROTO_IGMP)) uip_arp_out( uip_udp_conn); else uip_arp_out( NULL); xtcp_tx_buffer(mac_tx); } } else if (BUF->type == htons(UIP_ETHTYPE_ARP)) { uip_arp_arpin(); if (uip_len > 0) { xtcp_tx_buffer(mac_tx); } for (int i = 0; i < UIP_UDP_CONNS; i++) { uip_udp_arp_event(i); if (uip_len > 0) { uip_arp_out(&uip_udp_conns[i]); xtcp_tx_buffer(mac_tx); } } } #endif /* UIP_CONF_IPV4 ORIGINAL_XMOS */ /*_______________*/ /* contiki tcpip.c */ #if UIP_CONF_IP_FORWARD if(uip_len > 0) { tcpip_is_forwarding = 1; if(uip_fw_forward() == UIP_FW_LOCAL) { tcpip_is_forwarding = 0; check_for_tcp_syn(); uip_input(); if(uip_len > 0) { #if UIP_CONF_TCP_SPLIT uip_split_output(mac_tx); #else /* UIP_CONF_TCP_SPLIT */ #if UIP_CONF_IPV6 xtcpip_ipv6_output(mac_tx); #else PRINTF("tcpip packet_input forward output len %d\n", uip_len); xtcpip_output(mac_tx); #endif #endif /* UIP_CONF_TCP_SPLIT */ } } tcpip_is_forwarding = 0; } #else /* UIP_CONF_IP_FORWARD */ if(uip_len > 0) { uip_input(); if(uip_len > 0) { #if UIP_CONF_TCP_SPLIT uip_split_output(mac_tx); #else /* UIP_CONF_TCP_SPLIT */ #if UIP_CONF_IPV6 xtcpip_ipv6_output(mac_tx); #else PRINTF("tcpip packet_input output len %d\n", uip_len); tcpip_output(); #endif #endif /* UIP_CONF_TCP_SPLIT */ } } #endif /* UIP_CONF_IP_FORWARD */ }
/* * This is a co-operative task. This function must NEVER return */ void uip_task_main(void) { //initialise all the connections to point to the invalid handle for( i = 0 ; i < UIP_CONNS; i++) { uip_conns[i].appstate[0] = FILE_INVALID_HANDLE; } while(1) { task_yield(); if( UIP_DMA_RX_PACKET_READY ) { UIP_DMA_RX_PACKET_READY = 0; uip_len = uip_dma_rx_last_packet_length; // packet received - buffer is already acquired // 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(); } else nic_rx_maybe(); } else if(BUF->type == HTONS(UIP_ETHTYPE_ARP)) { // process an ARP packet uip_arp_arpin(); // transmit a packet, if one is ready if(uip_len > 0) { nic_send(); } else { nic_rx_maybe(); } } else //don't know how to process this packet. Discard { puts("Unknown packet discarded"); nic_rx_maybe(); } } else if(UIP_DMA_PERIODIC_TIMEOUT && uip_acquireBuffer()) { if( next_conn_id != UIP_CONNS ) { uip_len = 0; while( uip_len == 0 && next_conn_id < UIP_CONNS ) { uip_periodic( next_conn_id ); // transmit a packet, if one is ready if(uip_len > 0) { uip_arp_out(); nic_send(); } next_conn_id++; } } if( next_conn_id == UIP_CONNS ) { UIP_DMA_PERIODIC_TIMEOUT=0; //blink LED to show we're alive LD1_O = !LD1_O; next_conn_id = 0; /* Call the ARP timer function every 10 seconds. */ if(++arptimer == 20) { uip_arp_timer(); arptimer = 0; } uip_releaseBuffer(); //possibly change test below to if( uip_len == 0)?? if( ENC_DMACONbits.CHEN == 0 ) nic_rx_maybe(); } } else { //anyone need to send something or close? unsigned char loop_end = next_send_id; do { struct uip_conn *connptr = &uip_conns[next_send_id]; file_handle_t fh = connptr->appstate[0]; struct file_t *f = file_get_by_handle(fh); if(f != NULL && ( f->state == ClosePending || (f->write_buffer != NULL && buffer_available( f->write_buffer) > 0 && connptr->len == 0 ) ) ) { #ifdef __DEBUG printf("\n TCP conn id: %hhd state: %hhd. File State: %hhx", next_send_id, connptr->tcpstateflags, f->state); #endif if( connptr->tcpstateflags == CLOSED ) { #ifdef __DEBUG puts("\r\nFreed tcp conn and file "); #endif file_free( fh ); connptr->appstate[0] = FILE_INVALID_HANDLE; } if( uip_acquireBuffer() ) { uip_periodic_conn(connptr); if(uip_len > 0) { #ifdef __DEBUG printf("\n id %hhd sending", next_send_id); #endif uip_arp_out(); nic_send(); break; } else uip_releaseBuffer(); } break; //this connection wants to write. try again later } next_send_id = ++next_send_id < UIP_CONNS ? next_send_id : 0; } while( next_send_id != loop_end ); } } //end while }
/** * \brief gmac_uip_helloworld example entry point. * * \return Unused (ANSI-C compatibility). */ int main(void) { uip_ipaddr_t ipaddr; struct timer periodic_timer, arp_timer; uint32_t i; struct uip_eth_addr OrigiGMacAddr; /* Disable watchdog */ WDT_Disable(WDT); SCB_EnableICache(); SCB_EnableDCache(); printf("-- GMAC uIP Hello World Example %s --\n\r", SOFTPACK_VERSION); printf("-- %s\n\r", BOARD_NAME); printf("-- Compiled: %s %s With %s--\n\r", __DATE__, __TIME__ , COMPILER_NAME); /* Configure systick for 1 ms. */ TimeTick_Configure(); /* Configure TWI pins. */ PIO_Configure(twiPins, PIO_LISTSIZE(twiPins)); /* Enable TWI */ PMC_EnablePeripheral(BOARD_ID_TWI_EEPROM); TWI_ConfigureMaster(BOARD_BASE_TWI_EEPROM, TWCK, BOARD_MCK); TWID_Initialize(&twid, BOARD_BASE_TWI_EEPROM); /* Display MAC & IP settings */ TWID_Read(&twid, AT24MAC_SERIAL_NUM_ADD, 0x9A, 1, OrigiGMacAddr.addr, PAGE_SIZE, 0); if ((OrigiGMacAddr.addr[0] == 0xFC) && (OrigiGMacAddr.addr[1] == 0xC2) && (OrigiGMacAddr.addr[2] == 0x3D)) { for (i = 0; i < 6; i++) GMacAddress.addr[i] = OrigiGMacAddr.addr[i]; } printf("-- MAC %x:%x:%x:%x:%x:%x\n\r", GMacAddress.addr[0], GMacAddress.addr[1], GMacAddress.addr[2], GMacAddress.addr[3], GMacAddress.addr[4], GMacAddress.addr[5]); #ifndef __DHCPC_H__ printf(" - Host IP %d.%d.%d.%d\n\r", HostIpAddress[0], HostIpAddress[1], HostIpAddress[2], HostIpAddress[3]); printf(" - Router IP %d.%d.%d.%d\n\r", RoutIpAddress[0], RoutIpAddress[1], RoutIpAddress[2], RoutIpAddress[3]); printf(" - Net Mask %d.%d.%d.%d\n\r", NetMask[0], NetMask[1], NetMask[2], NetMask[3]); #endif /* System devices initialize */ gmac_tapdev_setmac((uint8_t *)GMacAddress.addr); gmac_tapdev_init(); clock_init(); timer_set(&periodic_timer, CLOCK_SECOND / 2); timer_set(&arp_timer, CLOCK_SECOND * 10); /* Init uIP */ uip_init(); #ifdef __DHCPC_H__ printf("P: DHCP Supported\n\r"); uip_ipaddr(ipaddr, 0, 0, 0, 0); uip_sethostaddr(ipaddr); uip_ipaddr(ipaddr, 0, 0, 0, 0); uip_setdraddr(ipaddr); uip_ipaddr(ipaddr, 0, 0, 0, 0); uip_setnetmask(ipaddr); #else /* Set the IP address of this host */ uip_ipaddr(ipaddr, HostIpAddress[0], HostIpAddress[1], HostIpAddress[2], HostIpAddress[3]); uip_sethostaddr(ipaddr); uip_ipaddr(ipaddr, RoutIpAddress[0], RoutIpAddress[1], RoutIpAddress[2], RoutIpAddress[3]); uip_setdraddr(ipaddr); uip_ipaddr(ipaddr, NetMask[0], NetMask[1], NetMask[2], NetMask[3]); uip_setnetmask(ipaddr); #endif uip_setethaddr(GMacAddress); _app_init(); while (1) { uip_len = gmac_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(); gmac_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) gmac_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(); gmac_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(); gmac_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(); } } } }
/************************************************************************* * Function Name: main * Parameters: none * * Return: none * * Description: main * *************************************************************************/ int c_entry(void) { UNS_32 i, delay; uip_ipaddr_t ipaddr; struct timer periodic_timer, arp_timer; /* Initialize debug via UART0 * – 115200bps * – 8 data bit * – No parity * – 1 stop bit * – No flow control */ debug_frmwrk_init(); _DBG_("Hello NXP Semiconductors"); _DBG_("uIP porting on LPC17xx"); // Initialize LED for system tick timer LED_Init(); _DBG_("Init Clock"); // Sys timer init 1/100 sec tick clock_init(); timer_set(&periodic_timer, CLOCK_SECOND / 2); /*0.5s */ timer_set(&arp_timer, CLOCK_SECOND * 10); /*10s */ _DBG_("Init EMAC"); // Initialize the ethernet device driver while(!tapdev_init()){ // Delay for a while then continue initializing EMAC module _DBG_("Error during initializing EMAC, restart after a while"); for (delay = 0x100000; delay; delay--); } #if 1 _DBG_("Init uIP"); // Initialize the uIP TCP/IP stack. uip_init(); // init MAC address uip_ethaddr.addr[0] = EMAC_ADDR0; uip_ethaddr.addr[1] = EMAC_ADDR1; uip_ethaddr.addr[2] = EMAC_ADDR2; uip_ethaddr.addr[3] = EMAC_ADDR3; uip_ethaddr.addr[4] = EMAC_ADDR4; uip_ethaddr.addr[5] = EMAC_ADDR5; uip_setethaddr(uip_ethaddr); uip_ipaddr(ipaddr, 192,168,0,100); sprintf(_db, "Set own IP address: %d.%d.%d.%d \n\r", \ ((uint8_t *)ipaddr)[0], ((uint8_t *)ipaddr)[1], \ ((uint8_t *)ipaddr)[2], ((uint8_t *)ipaddr)[3]); DB; uip_sethostaddr(ipaddr); uip_ipaddr(ipaddr, 192,168,0,1); sprintf(_db, "Set Router IP address: %d.%d.%d.%d \n\r", \ ((uint8_t *)ipaddr)[0], ((uint8_t *)ipaddr)[1], \ ((uint8_t *)ipaddr)[2], ((uint8_t *)ipaddr)[3]); DB; uip_setdraddr(ipaddr); uip_ipaddr(ipaddr, 255,255,255,0); sprintf(_db, "Set Subnet mask: %d.%d.%d.%d \n\r", \ ((uint8_t *)ipaddr)[0], ((uint8_t *)ipaddr)[1], \ ((uint8_t *)ipaddr)[2], ((uint8_t *)ipaddr)[3]); DB; uip_setnetmask(ipaddr); // Initialize the HTTP server ---------------------------- _DBG_("Init HTTP"); httpd_init(); _DBG_("Init complete!"); while(1) { uip_len = tapdev_read(uip_buf); 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(uip_buf,uip_len); } } 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(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(); tapdev_send(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(); 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(); } } } #endif while (1); }
void vuIP_TASK( void *pvParameters ) { /* The semaphore used by the EMAC ISR to indicate that an Rx frame is ready for processing. */ xSemaphoreHandle xSemaphore = NULL; portBASE_TYPE xARPTimer; unsigned portBASE_TYPE uxPriority; static volatile portTickType xStartTime, xCurrentTime; /* Initialize the uIP TCP/IP stack. */ uip_init(); uip_arp_init(); /* Initialize the HTTP server. */ httpd_init(); /* Initialise the local timers. */ xStartTime = xTaskGetTickCount(); xARPTimer = 0; /* Initialise the EMAC. A semaphore will be returned when this is successful. This routine contains code that polls status bits. If the Ethernet cable is not plugged in then this can take a considerable time. To prevent this starving lower priority tasks of processing time we lower our priority prior to the call, then raise it back again once the initialisation is complete. */ uxPriority = uxTaskPriorityGet( NULL ); vTaskPrioritySet( NULL, tskIDLE_PRIORITY ); while( xSemaphore == NULL ) { xSemaphore = xEMACInit(); } vTaskPrioritySet( NULL, uxPriority ); for( ;; ) { /* Let the network device driver read an entire IP packet into the uip_buf. If it returns > 0, there is a packet in the uip_buf buffer. */ uip_len = ulEMACPoll(); /* Was a packet placed in the uIP buffer? */ if( uip_len > 0 ) { /* A packet is present in the uIP buffer. We call the appropriate ARP functions depending on what kind of packet we have received. If the packet is an IP packet, we should call uip_input() as well. */ if( pucUIP_Buffer->type == htons( UIP_ETHTYPE_IP ) ) { uip_arp_ipin(); uip_input(); /* If the above function invocation resulted in data that should be sent out on the network, the global variable uip_len is set to a value > 0. */ if( uip_len > 0 ) { uip_arp_out(); lEMACSend(); } } else if( pucUIP_Buffer->type == htons( UIP_ETHTYPE_ARP ) ) { uip_arp_arpin(); /* If the above function invocation resulted in data that should be sent out on the network, the global variable uip_len is set to a value > 0. */ if( uip_len > 0 ) { lEMACSend(); } } } else { /* The poll function returned 0, so no packet was received. Instead we check if it is time that we do the periodic processing. */ xCurrentTime = xTaskGetTickCount(); if( ( xCurrentTime - xStartTime ) >= RT_CLOCK_SECOND ) { portBASE_TYPE i; /* Reset the timer. */ xStartTime = xCurrentTime; /* Periodic check of all connections. */ for( i = 0; i < UIP_CONNS; i++ ) { uip_periodic( i ); /* If the above function invocation resulted in data that should be sent out on the network, the global variable uip_len is set to a value > 0. */ if( uip_len > 0 ) { uip_arp_out(); lEMACSend(); } } #if UIP_UDP for( i = 0; i < UIP_UDP_CONNS; i++ ) { uip_udp_periodic( i ); /* If the above function invocation resulted in data that should be sent out on the network, the global variable uip_len is set to a value > 0. */ if( uip_len > 0 ) { uip_arp_out(); tapdev_send(); } } #endif /* UIP_UDP */ /* Periodically call the ARP timer function. */ if( ++xARPTimer == uipARP_FREQUENCY ) { uip_arp_timer(); xARPTimer = 0; } } else { /* We did not receive a packet, and there was no periodic processing to perform. Block for a fixed period. If a packet is received during this period we will be woken by the ISR giving us the Semaphore. */ xSemaphoreTake( xSemaphore, uipMAX_BLOCK_TIME ); } } } }
int IpStack_Thread_Call( void ) { static int iDataLen=0; switch( IpStack_Thread_Data.iEtape ) { default: IpStack_Thread_Data.iEtape=kETAPE_Init; case kETAPE_Init: IpStack_Thread_Data.iEtape = kETAPE_Wait_Input_Packet; break; case kETAPE_Wait_Input_Packet: if(DRV_Uart_RXDataReceived(IpStack_Thread_Data.hUart)) { iDataLen=UIP_CONF_BUFFER_SIZE; DRV_Uart_Receive(IpStack_Thread_Data.hUart ,uip_buf , &iDataLen); uip_len = iDataLen; 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. */ IpStack_Thread_Data.iPrevious =IpStack_Thread_Data.iEtape; IpStack_Thread_Data.iEtape=kETAPE_Packet_Send; } else { if( !DRV_SoftTimer_GetValue(IpStack_Thread_Data.hTimer)) { DRV_SoftTimer_Reset(IpStack_Thread_Data.hTimer); IpStack_Thread_Data.iEtape=kETAPE_Periodic_Uip; IpStack_Thread_Data.iConnectionCount=0; } } break; case kETAPE_Periodic_Uip: for(;IpStack_Thread_Data.iConnectionCount<UIP_CONNS;IpStack_Thread_Data.iConnectionCount++) { uip_periodic(IpStack_Thread_Data.iConnectionCount++); /* 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) { IpStack_Thread_Data.iPrevious =IpStack_Thread_Data.iEtape; IpStack_Thread_Data.iEtape = kETAPE_Packet_Send; break; } } if(IpStack_Thread_Data.iConnectionCount>=UIP_CONNS) { #if UIP_CONF_UDP IpStack_Thread_Data.iEtape = kETAPE_Periodic_Udp_Uip; #else IpStack_Thread_Data.iEtape = kETAPE_Wait_Input_Packet; #endif IpStack_Thread_Data.iConnectionCount=0; } break; #if UIP_CONF_UDP case kETAPE_Periodic_Udp_Uip: for(;IpStack_Thread_Data.iConnectionCount<UIP_CONNS;IpStack_Thread_Data.iConnectionCount++) { uip_udp_periodic(IpStack_Thread_Data.iConnectionCount); /* 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) { IpStack_Thread_Data.iPrevious =IpStack_Thread_Data.iEtape; IpStack_Thread_Data.iEtape = kETAPE_Packet_Send; break; } } if(IpStack_Thread_Data.iConnectionCount>=UIP_CONNS) { IpStack_Thread_Data.iEtape = kETAPE_Wait_Input_Packet; } break; #endif case kETAPE_Packet_Send: if( !DRV_Uart_TXBusy(IpStack_Thread_Data.hUart)) { DRV_Uart_Send(IpStack_Thread_Data.hUart , uip_buf , uip_len); IpStack_Thread_Data.iEtape=IpStack_Thread_Data.iPrevious; } break; } return 1; }
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 ); prvSetMACAddress(); httpd_init(); /* Create the semaphore used to wake the uIP task. */ vSemaphoreCreateBinary( xEMACSemaphore ); /* Initialise the MAC. */ vInitEmac(); while( lEMACWaitForLink() != pdPASS ) { vTaskDelay( uipINIT_WAIT ); } for( ;; ) { /* 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 { 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(); vEMACWrite(); } } /* 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 ); } } } }
int main(void) { // clock init clock_init(); // two timers for tcp/ip timer_set(&periodic_timer, CLOCK_SECOND / 2); /* 0.5s */ timer_set(&arp_timer, CLOCK_SECOND * 10); /* 10s */ diag_init(); // ethernet init tapdev_init(); // Initialize the uIP TCP/IP stack. uip_init(); uip_ipaddr(ipaddr, MYIP1,MYIP2,MYIP3,MYIP4); uip_sethostaddr(ipaddr); uip_ipaddr(ipaddr, DRTR1,DRTR2,DRTR3,DRTR4); uip_setdraddr(ipaddr); uip_ipaddr(ipaddr, SMSK1, SMSK2, SMSK3, SMSK4); uip_setnetmask(ipaddr); bl_init(); while(1) { diag_appcall(); bl_appcall(); /* receive packet and put in uip_buf */ uip_len = tapdev_read(uip_buf); if(uip_len > 0) /* received packet */ { if(BUF->type == htons(UIP_ETHTYPE_IP)) /* IP packet */ { 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(uip_buf,uip_len); } } else if(BUF->type == htons(UIP_ETHTYPE_ARP)) /*ARP packet */ { 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(uip_buf,uip_len); /* ARP ack*/ } } } else if(timer_expired(&periodic_timer)) /* no packet but periodic_timer time out (0.5s)*/ { 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(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(); tapdev_send(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(); } } } return 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; }
int main(void){ // Init buffer for (int i=0; i<BUFFER_SIZE; i++){ Buffer[i] = 0; } //uIP unsigned int i; uip_ipaddr_t ipaddr; struct timer periodic_timer, arp_timer; clock_init(2); timer_set(&periodic_timer, CLOCK_SECOND / 2); timer_set(&arp_timer, CLOCK_SECOND * 10); init(); // Touch init ToushRes_t XY_Touch; Boolean Touch = FALSE; TouchScrInit(); // Init font GLCD_SetFont(&Terminal_9_12_6,0xFFFFFF,0x000000); // Init UART UART_init(UART_0,4,NORM); // Init Real Time Clock RTC_init(); // Init animations Animation_init(); // Init navigationBar navigationBar = initNavigationBar(); // Init pages mainLayout = initMainLayout(); learningLayout = initLearningLayout(); graphLayout = initGraphLayout(); devicesLayout = initDevicesLayout(); swapToLayout(0); // Initialize the ethernet device driver do{ GLCD_TextSetPos(0,0); } while(!tapdev_init()); GLCD_TextSetPos(0,0); // uIP web server // Initialize the uIP TCP/IP stack. uip_init(); uip_ipaddr(ipaddr, 192,168,0,100); uip_sethostaddr(ipaddr); uip_ipaddr(ipaddr, 192,168,0,1); uip_setdraddr(ipaddr); uip_ipaddr(ipaddr, 255,255,255,0); uip_setnetmask(ipaddr); // Initialize the HTTP server. httpd_init(); while(1){ if(TouchGet(&XY_Touch)) { // Check if the current Layout accepts the touch if (!Layout_dispatchTouch(currentLayout, XY_Touch.X, XY_Touch.Y)){ // Touch not accepted, pass it on to the navigationBar Layout_dispatchTouch(navigationBar, XY_Touch.X, XY_Touch.Y); } if (Touch == FALSE){ Touch = TRUE; } } else if(Touch) { USB_H_LINK_LED_FSET = USB_H_LINK_LED_MASK; Touch = FALSE; } // Data from UART0 UART_Check(Buffer); if (Buffer[0] != 'E'){ Parsing_parse(Buffer, &measurement); // Notify the graph updateGraphLayout(&measurement, currentLayout == graphLayout); checkDevices(&measurement, currentLayout); double vRMS = measurement.voltage; double iRMS = measurement.current; double pACT = measurement.P_power; double pREAC = measurement.Q_power; double pHAR = measurement.H_power; if (currentLayout == mainLayout){ GLCD_SetWindow(0, 0, 150, 70); GLCD_TextSetPos(0,0); GLCD_SetFont(&Terminal_9_12_6,0xFFFFFF,0x000000); GLCD_print(" Voltage: %f\r\n Current: %f\r\n Power: \t%f\r\n Reac: \t%f\r\n Har: \t%f", vRMS, iRMS, pACT, pREAC, pHAR); } } // HANDLE uIP uip_len = tapdev_read(uip_buf); 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(uip_buf,uip_len); } } 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(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(); tapdev_send(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(); 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(); } } } }
/*---------------------------------------------------------------------------*/ 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; }
/** Processes Incoming packets to the server from the connected RNDIS device, creating responses as needed. */ static void uIPManagement_ProcessIncomingPacket(void) { /* Determine which USB mode the system is currently initialized in */ if (USB_CurrentMode == USB_MODE_Device) { /* If no packet received, exit processing routine */ if (!(RNDIS_Device_IsPacketReceived(&Ethernet_RNDIS_Interface_Device))) return; LEDs_SetAllLEDs(LEDMASK_USB_BUSY); /* Read the Incoming packet straight into the UIP packet buffer */ RNDIS_Device_ReadPacket(&Ethernet_RNDIS_Interface_Device, uip_buf, &uip_len); } else { /* If no packet received, exit processing routine */ if (!(RNDIS_Host_IsPacketReceived(&Ethernet_RNDIS_Interface_Host))) return; LEDs_SetAllLEDs(LEDMASK_USB_BUSY); /* Read the Incoming packet straight into the UIP packet buffer */ RNDIS_Host_ReadPacket(&Ethernet_RNDIS_Interface_Host, uip_buf, &uip_len); } /* If the packet contains an Ethernet frame, process it */ if (uip_len > 0) { switch (((struct uip_eth_hdr*)uip_buf)->type) { case HTONS(UIP_ETHTYPE_IP): /* Filter packet by MAC destination */ uip_arp_ipin(); /* Process Incoming packet */ uip_input(); /* If a response was generated, send it */ if (uip_len > 0) { /* Add destination MAC to outgoing packet */ uip_arp_out(); uip_split_output(); } break; case HTONS(UIP_ETHTYPE_ARP): /* Process ARP packet */ uip_arp_arpin(); /* If a response was generated, send it */ if (uip_len > 0) uip_split_output(); break; } } LEDs_SetAllLEDs(LEDMASK_USB_READY); }
void vuIP_Task( void *pvParameters ) { portBASE_TYPE i; unsigned long ulNewEvent = 0UL, ulUIP_Events = 0UL; long lPacketLength; /* 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. */ prvInitEmac(); for( ;; ) { /* Is there received data ready to be processed? */ lPacketLength = MSS_MAC_rx_packet(); /* Statements to be executed if data has been received on the Ethernet. */ if( ( lPacketLength > 0 ) && ( uip_buf != NULL ) ) { uip_len = ( u16_t ) lPacketLength; /* 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 { /* 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; } } }
/*---------------------------------------------------------------------------*/ static void packet_input(void) { #if FORWARDER rpl_instance_t *instance; uint8_t octet; uint8_t ip6id; int rssi_temp; uint8_t send_rssi; rimeaddr_t packet_from_addr; packet_from_addr = *packetbuf_addr(PACKETBUF_ADDR_SENDER); instance = &instance_table[0]; octet = packet_from_addr.u8[7]; ip6id = (octet & 0b00111111) << 2; tcp_rssi = packetbuf_attr(PACKETBUF_ATTR_RSSI); if(is_mobile_node(octet) == 1) { packet_input_count++; rssi_temp = tcp_rssi - 45; if(tcp_rssi > 200) { rssi_temp = tcp_rssi - 255 - 46; } rssi_sum += rssi_temp; if(packet_input_count == WINDOW_SIZE) { rssi_sum = rssi_sum / WINDOW_SIZE; PRINTF("RSSI = %d\n", rssi_sum); PRINTF("packet input count = %d\n", packet_input_count); if(rssi_sum <= -90) { send_rssi = rssi_sum + 255 + 46; dis_output(NULL, 1, 0, send_rssi, ip6id); } rssi_sum = 0; packet_input_count = 0; } } #endif #if UIP_CONF_IP_FORWARD if(uip_len > 0) { tcpip_is_forwarding = 1; if(uip_fw_forward() == UIP_FW_LOCAL) { tcpip_is_forwarding = 0; check_for_tcp_syn(); uip_input(); if(uip_len > 0) { #if UIP_CONF_TCP_SPLIT uip_split_output(); #else /* UIP_CONF_TCP_SPLIT */ #if UIP_CONF_IPV6 tcpip_ipv6_output(); #else PRINTF("tcpip packet_input forward output len %d\n", uip_len); tcpip_output(); #endif #endif /* UIP_CONF_TCP_SPLIT */ } } tcpip_is_forwarding = 0; } #else /* UIP_CONF_IP_FORWARD */ if(uip_len > 0) { check_for_tcp_syn(); uip_input(); if(uip_len > 0) { #if UIP_CONF_TCP_SPLIT uip_split_output(); #else /* UIP_CONF_TCP_SPLIT */ #if UIP_CONF_IPV6 tcpip_ipv6_output(); #else PRINTF("tcpip packet_input output len %d\n", uip_len); tcpip_output(); #endif #endif /* UIP_CONF_TCP_SPLIT */ } } #endif /* UIP_CONF_IP_FORWARD */ }
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 ); } } } }
void vuIP_Task( void *pvParameters ) { portBASE_TYPE i; uip_ipaddr_t xIPAddr; struct timer periodic_timer, arp_timer; extern void ( vEMAC_ISR )( void ); /* Just to get rid of the compiler warning. */ ( void ) pvParameters; /* Enable/Reset the Ethernet Controller */ /* Create the semaphore used by the ISR to wake this task. */ vSemaphoreCreateBinary( xFECSemaphore ); /* 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(); vInitFEC(); for( ;; ) { /* Is there received data ready to be processed? */ uip_len = ( unsigned short ) ulFECRx(); 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(); vFECTx(); } } 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 ) { vFECTx(); } } } 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(); vFECTx(); } } /* 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 ); } } } }
/*---------------------------------------------------------------------------*/ int main(void) { int i; uip_ipaddr_t ipaddr; struct uip_timer periodic_timer, arp_timer; timer_set(&periodic_timer, CLOCK_SECOND / 2); timer_set(&arp_timer, CLOCK_SECOND * 10); network_device_init(); uip_init(); uip_ipaddr(ipaddr, 192,168,0,2); uip_sethostaddr(ipaddr); httpd_init(); 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(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(); } } } return 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 ); } } } }
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; } } }
void router_input(uint8_t origin) { #ifdef IPCHAIR_HAVE_PREROUTING ipchair_PREROUTING_chair(); if(!uip_len) return; #endif /* uip_len is set to the number of received bytes, including the LLH. For RFM12, ZBus, etc. it's the full 14-byte Ethernet LLH even also. */ /* Check if packet is addressed to one stack's configured host address. */ uint8_t dest = router_find_stack(NULL); if (dest < 255) { uip_stack_set_active(dest); #ifdef IPCHAIR_HAVE_INPUT ipchair_INPUT_chair(); if(!uip_len) return; #endif uip_input (); } #if UIP_CONF_IPV6 && defined(ENC28J60_SUPPORT) else if (BUF->destipaddr[0] == HTONS(0xff02)) { /* Packet is addressed to one of the multicast addresses. */ uip_stack_set_active (STACK_ENC); uip_input (); } #endif /* UIP_CONF_IPV6 */ else { #ifdef IP_FORWARDING_SUPPORT /* Packet not addressed to us, check destination address to where the packet has to be routed. */ uint8_t dest = router_find_stack(&BUF->destipaddr); if (dest == 255) { uip_len = 0; return; /* Packet was dropped by the router */ } if (origin == dest) goto drop; if (-- BUF->ttl == 0) { /* TODO send ICMP message */ printf ("ttl exceeded, should send ICMP message.\n"); goto drop; } #ifdef IPCHAIR_HAVE_FORWARD ipchair_FORWARD_chair(); if(!uip_len) return; #endif #if !UIP_CONF_IPV6 /* For IPv4 we must adjust the chksum */ if(BUF->ipchksum >= HTONS(0xffff - (1 << 8))) BUF->ipchksum += HTONS(1 << 8) + 1; else BUF->ipchksum += HTONS(1 << 8); #endif /* For router_output_to uip_len must be set to the number of bytes to send, excluding the LLH (since it'll generate the needed one itself). However uip_len is currently set to the number of received bytes, i.e. including the LLH. */ uip_len -= UIP_LLH_LEN; /* TODO check MTU and send suitable ICMP message if needed. */ router_output_to (dest); #endif /* IP_FORWARDING_SUPPORT */ goto drop; } return; drop: uip_len = 0; return; }