static void prvSetMACAddress( void ) { struct uip_eth_addr xAddr; /* Configure the MAC address in the uIP stack. */ xAddr.addr[ 0 ] = configMAC_ADDR0; xAddr.addr[ 1 ] = configMAC_ADDR1; xAddr.addr[ 2 ] = configMAC_ADDR2; xAddr.addr[ 3 ] = configMAC_ADDR3; xAddr.addr[ 4 ] = configMAC_ADDR4; xAddr.addr[ 5 ] = configMAC_ADDR5; uip_setethaddr( xAddr ); }
static void network_init(void) { struct uip_eth_addr macaddr; net_event = process_alloc_event(); #if CONFIG_DRIVERS_ENC28J60 // Set our MAC address memcpy_P(&macaddr, &mac, sizeof(mac)); // Set up ethernet enc28j60Init(&macaddr); enc28j60Write(ECOCON, 0 & 0x7); // Disable clock output _delay_ms(10); /* Magjack leds configuration, see enc28j60 datasheet, page 11 */ // LEDA=green LEDB=yellow // // 0x476 is PHLCON LEDA=links status, LEDB=receive/transmit enc28j60PhyWrite(PHLCON, 0x476); _delay_ms(100); #endif #if CONFIG_DRIVERS_ENC424J600 // Initialise the hardware enc424j600Init(); // Disable clock output and set up LED stretch uint16_t econ2 = enc424j600ReadReg(ECON2); econ2 |= ECON2_STRCH; // stretch LED duration econ2 &= ~(ECON2_COCON3 | ECON2_COCON2 | ECON2_COCON1 | ECON2_COCON0); enc424j600WriteReg(ECON2, econ2); // Set up LEDs uint16_t eidled = enc424j600ReadReg(EIDLED); eidled &= 0x00ff; // and-out the high byte (LED config) eidled |= EIDLED_LACFG1 | EIDLED_LBCFG2 | EIDLED_LBCFG1; enc424j600WriteReg(EIDLED, eidled); // Get the MAC address enc424j600GetMACAddr(macaddr.addr); #endif #if !CONFIG_LIB_CONTIKI_IPV6 // Set up timers timer_set(&arp_timer, CLOCK_SECOND * 10); #endif uip_setethaddr(macaddr); }
static void prvSetMACAddress( void ) { struct uip_eth_addr xAddr; /* Configure the MAC address in the uIP stack. */ xAddr.addr[ 0 ] = uipMAC_ADDR0; xAddr.addr[ 1 ] = uipMAC_ADDR1; xAddr.addr[ 2 ] = uipMAC_ADDR2; xAddr.addr[ 3 ] = uipMAC_ADDR3; xAddr.addr[ 4 ] = uipMAC_ADDR4; xAddr.addr[ 5 ] = uipMAC_ADDR5; uip_setethaddr( xAddr ); /* Write the MAC address to the MAC. */ ENET_MAC->MAL = ( uipMAC_ADDR3 << 24 ) | ( uipMAC_ADDR2 << 16 ) | ( uipMAC_ADDR1 << 8 ) | ( uipMAC_ADDR0 ); ENET_MAC->MAH = ( uipMAC_ADDR5 << 8 ) | ( uipMAC_ADDR4 ); }
void dhcpc_configured(const struct dhcpc_state *s) { uip_ipaddr_t addr; // byte swap the network info _ip_addr[0] = (s->ipaddr[0]); _ip_addr[1] = (s->ipaddr[0]) >> 8; _ip_addr[2] = (s->ipaddr[1]); _ip_addr[3] = (s->ipaddr[1]) >> 8; _net_mask[0] = (s->netmask[0]); _net_mask[1] = (s->netmask[0]) >> 8; _net_mask[2] = (s->netmask[1]); _net_mask[3] = (s->netmask[1]) >> 8; _gateway[0] = (s->default_router[0]); _gateway[1] = (s->default_router[0]) >> 8; _gateway[2] = (s->default_router[1]); _gateway[3] = (s->default_router[1]) >> 8; #ifdef DHCP_DEBUG eeprom_write_block (_ip_addr, &ee_ip_addr, 4); eeprom_write_block (_net_mask,&ee_net_mask,4); eeprom_write_block (_gateway, &ee_gateway, 4); #endif // re-init just in case uip_setethaddr(my_eth_addr); // set ip uip_ipaddr(&addr, _ip_addr[0], _ip_addr[1], _ip_addr[2], _ip_addr[3]); uip_sethostaddr(&addr); // set netmask uip_ipaddr(&addr,_net_mask[0], _net_mask[1], _net_mask[2], _net_mask[3]); uip_setnetmask(&addr); // set gateway uip_ipaddr(&addr,_gateway[0], _gateway[1], _gateway[2], _gateway[3]); uip_setdraddr(&addr); // code to use dhcp server lease time removed due to uint16_t overflow // issues with calculating the time. Just use 5 minutes instead. timer_set(&dhcp_timer, 5 * 60 * CLOCK_SECOND); }
/** * @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)); }
/*---------------------------------------------------------------------------*/ EK_EVENTHANDLER(eventhandler, ev, data) { switch(ev) { case EK_EVENT_INIT: case EK_EVENT_REPLACE: uip_setethaddr(addr); cs8900a_init(); break; case EK_EVENT_REQUEST_REPLACE: ek_replace((struct ek_proc *)data, NULL); LOADER_UNLOAD(); break; case EK_EVENT_REQUEST_EXIT: ek_exit(); LOADER_UNLOAD(); break; default: break; } }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(rrnet_drv_process, ev, data) { PROCESS_POLLHANDLER(pollhandler()); PROCESS_BEGIN(); uip_setethaddr(addr); init_rrnet(); cs8900a_init(); SERVICE_REGISTER(rrnet_drv_service); process_poll(&rrnet_drv_process); while(1) { PROCESS_YIELD(); } PROCESS_END(); }
void ethernet_init(void) { // reset Ethernet ENC28J60_RESET_DDR |= _BV( ENC28J60_RESET_BIT ); ENC28J60_RESET_PORT &= ~_BV( ENC28J60_RESET_BIT ); my_delay_ms( 200 ); // unreset Ethernet ENC28J60_RESET_PORT |= _BV( ENC28J60_RESET_BIT ); my_delay_ms( 200 ); network_init(); mac.addr[0] = erb(EE_MAC_ADDR+0); mac.addr[1] = erb(EE_MAC_ADDR+1); mac.addr[2] = erb(EE_MAC_ADDR+2); mac.addr[3] = erb(EE_MAC_ADDR+3); mac.addr[4] = erb(EE_MAC_ADDR+4); mac.addr[5] = erb(EE_MAC_ADDR+5); network_set_MAC(mac.addr); uip_setethaddr(mac); uip_init(); ntp_conn = 0; // setup two periodic timers timer_set(&periodic_timer, CLOCK_SECOND / 4); timer_set(&arp_timer, CLOCK_SECOND * 10); if(erb(EE_USE_DHCP)) { network_set_led(0x4A6);// LED A: Link Status LED B: Blink slow dhcpc_init(&mac); dhcp_state = PT_WAITING; } else { dhcp_state = PT_ENDED; set_eeprom_addr(); } }
msg_t WebThread(void *p) { EvTimer evt1, evt2; EventListener el0, el1, el2; uip_ipaddr_t ipaddr; (void)p; /* * Event sources setup. */ chEvtRegister(macGetReceiveEventSource(ÐD1), &el0, FRAME_RECEIVED_ID); chEvtAddFlags(EVENT_MASK(FRAME_RECEIVED_ID)); /* In case some frames are already buffered */ evtInit(&evt1, MS2ST(500)); evtStart(&evt1); chEvtRegister(&evt1.et_es, &el1, PERIODIC_TIMER_ID); evtInit(&evt2, S2ST(10)); evtStart(&evt2); chEvtRegister(&evt2.et_es, &el2, ARP_TIMER_ID); /* * EMAC driver start. */ macStart(ÐD1, &mac_config); (void)macPollLinkStatus(ÐD1); /* * uIP initialization. */ uip_init(); uip_setethaddr(macaddr); uip_ipaddr(ipaddr, IPADDR0, IPADDR1, IPADDR2, IPADDR3); uip_sethostaddr(ipaddr); httpd_init(); while (TRUE) { chEvtDispatch(evhndl, chEvtWaitOne(ALL_EVENTS)); } return 0; }
void netif_set_addr(struct netif *netif, struct ip_addr *ipaddr, struct ip_addr *netmask, struct ip_addr *gw) { uip_ipaddr_t hipaddr; uip_ipaddr(hipaddr, RT_LWIP_IPADDR0,RT_LWIP_IPADDR1,RT_LWIP_IPADDR2,RT_LWIP_IPADDR3); uip_sethostaddr(hipaddr); uip_ipaddr(hipaddr, RT_LWIP_GWADDR0,RT_LWIP_GWADDR1,RT_LWIP_GWADDR2,RT_LWIP_GWADDR3); uip_setdraddr(hipaddr); uip_ipaddr(hipaddr, RT_LWIP_MSKADDR0,RT_LWIP_MSKADDR1,RT_LWIP_MSKADDR2,RT_LWIP_MSKADDR3); uip_setnetmask(hipaddr); uip_ethaddr.addr[0] = mymac[0]; uip_ethaddr.addr[1] = mymac[1]; uip_ethaddr.addr[2] = mymac[2]; uip_ethaddr.addr[3] = mymac[3]; uip_ethaddr.addr[4] = mymac[4]; uip_ethaddr.addr[5] = mymac[5]; uip_setethaddr(uip_ethaddr); return ; }
void initalise_uipv6(void) { u16_t const* ip_part = &HostIPv6Address[0]; uip_ipaddr_t ipaddr; uip_init(); // Set the IP address of this host uip_ip6addr ( ipaddr , ip_part[0] , ip_part[1] , ip_part[2] , ip_part[3] , ip_part[4] , ip_part[5] , ip_part[6] , ip_part[7] ); uip_sethostaddr(ipaddr); //set Router ip address ip_part = &RoutIPv6Address[0]; uip_ip6addr ( ipaddr , ip_part[0] , ip_part[1] , ip_part[2] , ip_part[3] , ip_part[4] , ip_part[5] , ip_part[6] , ip_part[7] ); uip_setdraddr(ipaddr); uip_setethaddr(MacAddress); }
/*! \brief Inicia aplicação */ void appInit(void) { u16_t dns[2]; //Verifica se o botão de reset está pressionado if(checkResetBt()) { appEraseFlashData(); } //Adquire os dados da memória não volátil appReadFlashData(); //Verifica a consistência dos dados armazenados na memória flash appCheckFlashData(); 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(ðaddr, sizeof(ethaddr)); } else { //Inicia com ip fixo appInitHostIp(); dns[0] = memoryData.dnsAddr[0]; dns[1] = memoryData.dnsAddr[1]; appSetDnsAddr(dns); appSendConnect(); } ciclos = memoryData.tempoPacote/5; }
// Init application void elua_uip_init( const struct uip_eth_addr *paddr ) { // Set hardware address uip_setethaddr( (*paddr) ); // Initialize the uIP TCP/IP stack. uip_init(); uip_arp_init(); #ifdef BUILD_DHCPC dhcpc_init( paddr->addr, sizeof( *paddr ) ); dhcpc_request(); #else elua_uip_conf_static(); #endif resolv_init(); #ifdef BUILD_CON_TCP uip_listen( HTONS( ELUA_NET_TELNET_PORT ) ); #endif }
PROCESS_THREAD(usb_eth_process, ev , data) { PROCESS_BEGIN(); usb_register_request_handler(&cdc_eth_request_hook); usb_setup(); usb_set_ep_event_process(DATA_OUT, process_current); usb_set_global_event_process(process_current); uip_fw_default(&usbethif); uip_setethaddr(default_uip_ethaddr); uip_arp_init(); while(1) { PROCESS_WAIT_EVENT(); if (ev == PROCESS_EVENT_EXIT) break; if (ev == PROCESS_EVENT_POLL) { unsigned int events = usb_get_global_events(); if (events) { if (events & USB_EVENT_CONFIG) { if (usb_get_current_configuration() != 0) { printf("Configured\n"); usb_setup_bulk_endpoint(DATA_IN); usb_setup_bulk_endpoint(DATA_OUT); usb_setup_interrupt_endpoint(INTERRUPT_IN); init_recv_buffer(); usb_submit_recv_buffer(DATA_OUT, &recv_buffer); #if 0 { static const uint8_t foo[4] = {0x12,0x34,0x56,0x78}; xmit_buffer[0].next = NULL; xmit_buffer[0].left = sizeof(foo); xmit_buffer[0].flags = USB_BUFFER_SHORT_END; xmit_buffer[0].data = &foo; usb_submit_xmit_buffer(DATA_IN, &xmit_buffer[0]); } #endif } else { usb_disable_endpoint(DATA_IN); usb_disable_endpoint(DATA_OUT); usb_disable_endpoint(INTERRUPT_IN); } } } events = usb_get_ep_events(DATA_OUT); if (events & USB_EP_EVENT_NOTIFICATION) { uip_len = sizeof(recv_data) - recv_buffer.left; /* printf("Received: %d bytes\n", uip_len); */ memcpy(uip_buf, recv_data, uip_len); #if UIP_CONF_IPV6 if(BUF->type == uip_htons(UIP_ETHTYPE_IPV6)) { uip_neighbor_add(&IPBUF->srcipaddr, &BUF->src); tcpip_input(); } else #endif /* UIP_CONF_IPV6 */ if(BUF->type == uip_htons(UIP_ETHTYPE_IP)) { uip_len -= sizeof(struct uip_eth_hdr); tcpip_input(); } else if(BUF->type == uip_htons(UIP_ETHTYPE_ARP)) { uip_arp_arpin(); /* If the above function invocation resulted in data that should be sent out on the network, the global variable uip_len is set to a value > 0. */ if (uip_len > 0) { memcpy(xmit_data, uip_buf, uip_len); xmit_buffer[0].next = NULL; xmit_buffer[0].data = xmit_data; xmit_buffer[0].left = uip_len; xmit_buffer[0].flags = USB_BUFFER_SHORT_END; usb_submit_xmit_buffer(DATA_IN, &xmit_buffer[0]); /* printf("Sent: %d bytes\n", uip_len); */ } } init_recv_buffer(); usb_submit_recv_buffer(DATA_OUT, &recv_buffer); } } } PROCESS_END(); }
int main(void) { network_init(); //CLKPR = (1<<CLKPCE); //Change prescaler //CLKPR = (1<<CLKPS0); //Use prescaler 2 //clock_prescale_set(clock_div_2); enc28j60Write(ECOCON, 1 & 0x7); //Get a 25MHz signal from enc28j60 uartInit(); uartSetBaudRate(9600); rprintfInit(uartSendByte); int i; uip_ipaddr_t ipaddr; struct timer periodic_timer, arp_timer; clock_init(); timer_set(&periodic_timer, CLOCK_SECOND / 2); timer_set(&arp_timer, CLOCK_SECOND * 10); uip_init(); struct uip_eth_addr mac = {UIP_ETHADDR0, UIP_ETHADDR1, UIP_ETHADDR2, UIP_ETHADDR3, UIP_ETHADDR4, UIP_ETHADDR5}; uip_setethaddr(mac); // set up the udp data stream // configure the target system ip and port uip_ipaddr_t target_ipaddr; uip_ipaddr(&target_ipaddr, 192,168,0,10); udpds_conf(&target_ipaddr, 1000, 1); #ifdef __DHCPC_H__ dhcpc_init(&mac, 6); #else uip_ipaddr(ipaddr, 192,168,0,1); uip_sethostaddr(ipaddr); uip_ipaddr(ipaddr, 192,168,0,1); uip_setdraddr(ipaddr); uip_ipaddr(ipaddr, 255,255,255,0); uip_setnetmask(ipaddr); #endif /*__DHCPC_H__*/ while(1){ uip_len = network_read(); if(uip_len > 0) { if(BUF->type == htons(UIP_ETHTYPE_IP)){ uip_arp_ipin(); uip_input(); if(uip_len > 0) { uip_arp_out(); network_send(); } }else if(BUF->type == htons(UIP_ETHTYPE_ARP)){ uip_arp_arpin(); if(uip_len > 0){ network_send(); } } }else if(timer_expired(&periodic_timer)) { timer_reset(&periodic_timer); for(i = 0; i < UIP_CONNS; i++) { uip_periodic(i); if(uip_len > 0) { uip_arp_out(); network_send(); } } #if UIP_UDP for(i = 0; i < UIP_UDP_CONNS; i++) { uip_udp_periodic(i); if(uip_len > 0) { uip_arp_out(); network_send(); } } #endif /* UIP_UDP */ if(timer_expired(&arp_timer)) { timer_reset(&arp_timer); uip_arp_timer(); } } } return 0; }
int uip_netport_init(void) { struct vmm_netswitch *nsw; struct uip_port_state *s = &uip_port_state; struct uip_fw_netif *netif; uip_ipaddr_t ipaddr; char tname[64]; uip_buf = vmm_malloc(UIP_BUFSIZE + 2); if(!uip_buf) { vmm_panic("%s: uip_buf alloc failed\n", __func__); } INIT_SPIN_LOCK(&s->lock); INIT_LIST_HEAD(&s->rxbuf); INIT_COMPLETION(&s->rx_possible); /* Get the first netswitch */ nsw = vmm_netswitch_get(0); if(!nsw) { vmm_panic("No netswitch found\n"); } /* Create a port-name */ vmm_sprintf(tname, "%s-uip", nsw->name); /* Allocate a netport for this netswitch */ s->port = vmm_netport_alloc(tname); if(!s->port) { vmm_printf("UIP->netport alloc failed\n"); return VMM_EFAIL; } /* Allocate a uip_fw_netif */ netif = vmm_malloc(sizeof(struct uip_fw_netif)); if(!netif) { vmm_printf("UIP->netif alloc failed\n"); return VMM_EFAIL; } /* Register the netport */ s->port->mtu = UIP_BUFSIZE; s->port->link_changed = uip_set_link; s->port->can_receive = uip_can_receive; s->port->switch2port_xfer = uip_switch2port_xfer; s->port->priv = s; s->netif = netif; vmm_netport_register(s->port); /* Attach with the netswitch */ vmm_netswitch_port_add(nsw, s->port); /* Notify our ethernet address */ uip_setethaddr(((struct uip_eth_addr *)(s->port->macaddr))); /* Generate an IP address */ uip_ipaddr(ipaddr, 192,168,0,1); uip_fw_setipaddr(netif, ipaddr); uip_ipaddr(ipaddr, 255,255,255,0); uip_fw_setnetmask(netif, ipaddr); /* Register the netif with uip stack */ netif->output = &uip_netport_output; netif->priv = s; uip_fw_register(netif); /* Set this interface as default one */ uip_fw_default(netif); return 0; }
//***************************************************************************** // // This example demonstrates the use of the Ethernet Controller with the uIP // TCP/IP stack. // //***************************************************************************** int main(void) { uip_ipaddr_t ipaddr; static struct uip_eth_addr sTempAddr; long lPeriodicTimer, lARPTimer, lPacketLength; unsigned long ulUser0, ulUser1; unsigned long ulTemp; // // Set the clocking to run directly from the crystal. // SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_8MHZ); // // Initialize the OLED display. // RIT128x96x4Init(1000000); RIT128x96x4StringDraw("Ethernet with uIP", 12, 0, 15); // // Enable and Reset the Ethernet Controller. // SysCtlPeripheralEnable(SYSCTL_PERIPH_ETH); SysCtlPeripheralReset(SYSCTL_PERIPH_ETH); // // Enable Port F for Ethernet LEDs. // LED0 Bit 3 Output // LED1 Bit 2 Output // SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); GPIOPinTypeEthernetLED(GPIO_PORTF_BASE, GPIO_PIN_2 | GPIO_PIN_3); // // Configure SysTick for a periodic interrupt. // SysTickPeriodSet(SysCtlClockGet() / SYSTICKHZ); SysTickEnable(); SysTickIntEnable(); // // Intialize the Ethernet Controller and disable all Ethernet Controller // interrupt sources. // EthernetIntDisable(ETH_BASE, (ETH_INT_PHY | ETH_INT_MDIO | ETH_INT_RXER | ETH_INT_RXOF | ETH_INT_TX | ETH_INT_TXER | ETH_INT_RX)); ulTemp = EthernetIntStatus(ETH_BASE, false); EthernetIntClear(ETH_BASE, ulTemp); // // Initialize the Ethernet Controller for operation. // EthernetInitExpClk(ETH_BASE, SysCtlClockGet()); // // Configure the Ethernet Controller for normal operation. // - Full Duplex // - TX CRC Auto Generation // - TX Padding Enabled // EthernetConfigSet(ETH_BASE, (ETH_CFG_TX_DPLXEN | ETH_CFG_TX_CRCEN | ETH_CFG_TX_PADEN)); // // Wait for the link to become active. // RIT128x96x4StringDraw("Waiting for Link", 12, 8, 15); ulTemp = EthernetPHYRead(ETH_BASE, PHY_MR1); while((ulTemp & 0x0004) == 0) { ulTemp = EthernetPHYRead(ETH_BASE, PHY_MR1); } RIT128x96x4StringDraw("Link Established", 12, 16, 15); // // Enable the Ethernet Controller. // EthernetEnable(ETH_BASE); // // Enable the Ethernet interrupt. // IntEnable(INT_ETH); // // Enable the Ethernet RX Packet interrupt source. // EthernetIntEnable(ETH_BASE, ETH_INT_RX); // // Enable all processor interrupts. // IntMasterEnable(); // // Initialize the uIP TCP/IP stack. // uip_init(); #ifdef USE_STATIC_IP uip_ipaddr(ipaddr, DEFAULT_IPADDR0, DEFAULT_IPADDR1, DEFAULT_IPADDR2, DEFAULT_IPADDR3); uip_sethostaddr(ipaddr); DisplayIPAddress(ipaddr, 18, 24); uip_ipaddr(ipaddr, DEFAULT_NETMASK0, DEFAULT_NETMASK1, DEFAULT_NETMASK2, DEFAULT_NETMASK3); uip_setnetmask(ipaddr); #else uip_ipaddr(ipaddr, 0, 0, 0, 0); uip_sethostaddr(ipaddr); DisplayIPAddress(ipaddr, 18, 24); uip_ipaddr(ipaddr, 0, 0, 0, 0); uip_setnetmask(ipaddr); #endif // // Configure the hardware MAC address for Ethernet Controller filtering of // incoming packets. // // For the Ethernet Eval Kits, the MAC address will be stored in the // non-volatile USER0 and USER1 registers. These registers can be read // using the FlashUserGet function, as illustrated below. // FlashUserGet(&ulUser0, &ulUser1); if((ulUser0 == 0xffffffff) || (ulUser1 == 0xffffffff)) { // // We should never get here. This is an error if the MAC address has // not been programmed into the device. Exit the program. // RIT128x96x4StringDraw("MAC Address", 0, 16, 15); RIT128x96x4StringDraw("Not Programmed!", 0, 24, 15); while(1) { } } // // Convert the 24/24 split MAC address from NV ram into a 32/16 split MAC // address needed to program the hardware registers, then program the MAC // address into the Ethernet Controller registers. // sTempAddr.addr[0] = ((ulUser0 >> 0) & 0xff); sTempAddr.addr[1] = ((ulUser0 >> 8) & 0xff); sTempAddr.addr[2] = ((ulUser0 >> 16) & 0xff); sTempAddr.addr[3] = ((ulUser1 >> 0) & 0xff); sTempAddr.addr[4] = ((ulUser1 >> 8) & 0xff); sTempAddr.addr[5] = ((ulUser1 >> 16) & 0xff); // // Program the hardware with it's MAC address (for filtering). // EthernetMACAddrSet(ETH_BASE, (unsigned char *)&sTempAddr); uip_setethaddr(sTempAddr); // // Initialize the TCP/IP Application (e.g. web server). // httpd_init(); #ifndef USE_STATIC_IP // // Initialize the DHCP Client Application. // dhcpc_init(&sTempAddr.addr[0], 6); dhcpc_request(); #endif // // Main Application Loop. // lPeriodicTimer = 0; lARPTimer = 0; while(true) { // // Wait for an event to occur. This can be either a System Tick event, // or an RX Packet event. // while(!g_ulFlags) { } // // If SysTick, Clear the SysTick interrupt flag and increment the // timers. // if(HWREGBITW(&g_ulFlags, FLAG_SYSTICK) == 1) { HWREGBITW(&g_ulFlags, FLAG_SYSTICK) = 0; lPeriodicTimer += SYSTICKMS; lARPTimer += SYSTICKMS; } // // Check for an RX Packet and read it. // lPacketLength = EthernetPacketGetNonBlocking(ETH_BASE, uip_buf, sizeof(uip_buf)); if(lPacketLength > 0) { // // Set uip_len for uIP stack usage. // uip_len = (unsigned short)lPacketLength; // // Clear the RX Packet event and renable RX Packet interrupts. // if(HWREGBITW(&g_ulFlags, FLAG_RXPKT) == 1) { HWREGBITW(&g_ulFlags, FLAG_RXPKT) = 0; EthernetIntEnable(ETH_BASE, ETH_INT_RX); } // // Process incoming IP packets here. // if(BUF->type == htons(UIP_ETHTYPE_IP)) { uip_arp_ipin(); uip_input(); // // If the above function invocation resulted in data that // should be sent out on the network, the global variable // uip_len is set to a value > 0. // if(uip_len > 0) { uip_arp_out(); EthernetPacketPut(ETH_BASE, uip_buf, uip_len); uip_len = 0; } } // // Process incoming ARP packets here. // else if(BUF->type == htons(UIP_ETHTYPE_ARP)) { uip_arp_arpin(); // // If the above function invocation resulted in data that // should be sent out on the network, the global variable // uip_len is set to a value > 0. // if(uip_len > 0) { EthernetPacketPut(ETH_BASE, uip_buf, uip_len); uip_len = 0; } } } // // Process TCP/IP Periodic Timer here. // if(lPeriodicTimer > UIP_PERIODIC_TIMER_MS) { lPeriodicTimer = 0; for(ulTemp = 0; ulTemp < UIP_CONNS; ulTemp++) { uip_periodic(ulTemp); // // If the above function invocation resulted in data that // should be sent out on the network, the global variable // uip_len is set to a value > 0. // if(uip_len > 0) { uip_arp_out(); EthernetPacketPut(ETH_BASE, uip_buf, uip_len); uip_len = 0; } } #if UIP_UDP for(ulTemp = 0; ulTemp < UIP_UDP_CONNS; ulTemp++) { uip_udp_periodic(ulTemp); // // If the above function invocation resulted in data that // should be sent out on the network, the global variable // uip_len is set to a value > 0. // if(uip_len > 0) { uip_arp_out(); EthernetPacketPut(ETH_BASE, uip_buf, uip_len); uip_len = 0; } } #endif // UIP_UDP } // // Process ARP Timer here. // if(lARPTimer > UIP_ARP_TIMER_MS) { lARPTimer = 0; uip_arp_timer(); } } }
int main(int argc, char *argv[]) { uint16_t eth_hdr_type; int i; SCS = BIT0 | BIT1; /* use fast I/O registers */ VPBDIV = 0x00000001; /* PCLK = CCLK */ PLLCFG = 0x00000024; /* Fosc=12MHz, CCLK=60MHz */ PLLCON = 0x00000001; /* enable the PLL */ PLLFEED = 0x000000AA; /* feed sequence */ PLLFEED = 0x00000055; while (!(PLLSTAT & 0x00000400)); PLLCON = 3; // enable and connect PLLFEED = 0xAA; PLLFEED = 0x55; //busywaitInit(); //systickInit(); //lcdInit(); vicInit(); uart0Init(); DBG("Initializing USB Stack"); usbInit(); rndisInit(); DBG("init 2"); network_device_init(); DBG("init 3"); uip_init(); /* ipaddr_set = 1; uip_ipaddr(ipaddr, 192, 168, 12, 1); uip_ipaddr(dhcpd_client_ipaddr, 192, 168, 12, 2); uip_sethostaddr(ipaddr); */ uip_setethaddr(ethaddr); //uip_setethaddr(eaddr); //telnetd_init(); //net_timers_init(); #ifdef USE_DHCPD dhcpdInit(); #endif DBG("Starting USB Stack"); interruptsEnable(); usbConnect(); //lcdOn(); //lcdClear(); //int xyz = 0; //printf("Frame number %u ",usbFrameNumber()); while(1) { //if (xyz) DBG("is there a packet? bulk ep status = %x",_usbGetEPStatus(RNDIS_BULK_EP | USB_EP_OUT)); uip_len = network_device_read(); //if (xyz) DBG("len=%d",uip_len); if (uip_len > 0) { eth_hdr_type = (uip_buf[0xc] << 8) | uip_buf[0xd]; if(eth_hdr_type == UIP_ETHTYPE_IP) { //DBG("Hey, got an IP packet!!!"); uip_arp_ipin(); uip_input(); if(uip_len > 0) { uip_arp_out(); //DBG("IP Reply! (%d bytes)",uip_len); //int j; //for (j=0; j<uip_len; j++) { // DBG(">%d %02x ",j,uip_buf[j]); //} //DBG(""); network_device_send(); } } else if (eth_hdr_type == UIP_ETHTYPE_ARP) { //DBG("Hey, got an ARP packet!!!"); uip_arp_arpin(); //xyz = 1; if(uip_len > 0) { //DBG("ARP Reply!"); network_device_send(); } } else { DBG("Hey, got some weird packet, not IP, not ARP, type=%x",eth_hdr_type); } } /* * we reply to DHCP requests on another connection, and the connection * is faster if we don't wait for expiration of the timer. * I tried to call uip_udp_periodic_conn(dhcpd_reply_conn) instead of * the loop, but it did not work. */ //if (dhcpd_state != DHCPD_IDLE) { if (udp_poll_request) { udp_poll_request = 0; for(i = 0; i < UIP_UDP_CONNS; i++) { uip_udp_periodic(i); if(uip_len > 0) { uip_arp_out(); network_device_send(); } } //uip_udp_periodic_conn(dhcpd_reply_conn); } if (net_timers_ip_expired()) { net_timers_ip_reset(); for(i = 0; i < UIP_CONNS; i++) { uip_periodic(i); if(uip_len > 0) { uip_arp_out(); network_device_send(); } } #define USE_UDP_PERIODIC #ifdef USE_UDP_PERIODIC for(i = 0; i < UIP_UDP_CONNS; i++) { uip_udp_periodic(i); if(uip_len > 0) { uip_arp_out(); network_device_send(); } } #endif if(net_timers_arp_expired()) { net_timers_arp_reset(); uip_arp_timer(); } } } return 0; }
/*---------------------------------------------------------------------------*/ void ethernet_init(void) { static const char signature[4] = {0x65, 0x74, 0x68, 0x01}; #ifdef STATIC_DRIVER extern void STATIC_DRIVER; module = &STATIC_DRIVER; module->buffer = uip_buf; module->buffer_size = UIP_BUFSIZE; if(module->init(config.ethernet.addr)) { #define _stringize(arg) #arg #define stringize(arg) _stringize(arg) log_message(stringize(STATIC_DRIVER), ": No hardware"); #undef _stringize #undef stringize error_exit(); } #else /* STATIC_DRIVER */ struct mod_ctrl module_control = {cfs_read}; uint8_t byte; module_control.callerdata = cfs_open(config.ethernet.name, CFS_READ); if(module_control.callerdata < 0) { log_message(config.ethernet.name, ": File not found"); error_exit(); } byte = mod_load(&module_control); if(byte != MLOAD_OK) { log_message(config.ethernet.name, byte == MLOAD_ERR_MEM? ": Out of memory": ": No module"); error_exit(); } cfs_close(module_control.callerdata); module = module_control.module; for(byte = 0; byte < 4; ++byte) { if(module->signature[byte] != signature[byte]) { log_message(config.ethernet.name, ": No ETH driver"); error_exit(); } } module->buffer = uip_buf; module->buffer_size = UIP_BUFSIZE; if(module->init(config.ethernet.addr)) { log_message(config.ethernet.name, ": No hardware"); error_exit(); } #endif /* STATIC_DRIVER */ uip_setethaddr(module->ethernet_address); }
/************************************************************************* * 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); }
int main(void) { network_init(); // network.c // enc28j60Init(); // enc28j60PhyWrite(PHLCON,0x476); //CLKPR = (1<<CLKPCE); //Change prescaler //CLKPR = (1<<CLKPS0); //Use prescaler 2 //clock_prescale_set(clock_div_2); enc28j60Write(ECOCON, 1 & 0x7); // enc28j60.c //Get a 25MHz signal from enc28j60 #ifdef MY_DEBUG uartInit(); uartSetBaudRate(9600); rprintfInit(uartSendByte); #endif int i; uip_ipaddr_t ipaddr; // uip.h // typedef u16_t uip_ip4addr_t[2]; // typedef uip_ip4addr_t uip_ipaddr_t; struct timer periodic_timer, arp_timer; clock_init(); timer_set(&periodic_timer, CLOCK_SECOND / 2); timer_set(&arp_timer, CLOCK_SECOND * 10); uip_init(); // uip.c //uip_arp_init(); // uip_arp.c // must be done or sometimes arp doesn't work struct uip_eth_addr mac = {UIP_ETHADDR0, UIP_ETHADDR1, UIP_ETHADDR2, UIP_ETHADDR3, UIP_ETHADDR4, UIP_ETHADDR5}; uip_setethaddr(mac); simple_httpd_init(); #ifdef __DHCPC_H__ dhcpc_init(&mac, 6); #else uip_ipaddr(ipaddr, 192,168,0,1); // uip.h uip_sethostaddr(ipaddr); // uip.h // #define uip_sethostaddr(addr) uip_ipaddr_copy(uip_hostaddr, (addr)) uip_ipaddr(ipaddr, 192,168,0,1); uip_setdraddr(ipaddr); // #define uip_setdraddr(addr) uip_ipaddr_copy(uip_draddr, (addr)) uip_ipaddr(ipaddr, 255,255,255,0); uip_setnetmask(ipaddr); // #define uip_setnetmask(addr) uip_ipaddr_copy(uip_netmask, (addr)) #endif /*__DHCPC_H__*/ while(1){ uip_len = network_read(); // uip.c : u16_t uip_len; // network.c : return ((unt16_t) enc28j60PacketReceive(UIP_BUFSIZE, (uint8_t *)uip_buf)); // enc28j60.c : enc28j60PacketReceive // uip.c : uint8_t uip_buf[UIP_BUFSIZE+2]; // uipconf.h : UIP_BUFSIZE:300 if(uip_len > 0) { if(BUF->type == htons(UIP_ETHTYPE_IP)){ #ifdef MY_DEBUG //rprintf("eth in : uip_len = %d, proto = %d\n", uip_len, uip_buf[23]); //debugPrintHexTable(uip_len, uip_buf); #endif // struct uip_eth_hdr { // struct uip_eth_addr dest; // struct uip_eth_addr src; // u16_t type; // }; // struct uip_eth_addr { // Representation of a 48-bit Ethernet address // u8_t addr[6]; // }; // http://www.netmanias.com/ko/post/blog/5372/ethernet-ip-tcp-ip/packet-header-ethernet-ip-tcp-ip // UIP_ETHTYPE_IP(0x0800) : IPv4 Packet(ICMP, TCP, UDP) uip_arp_ipin(); #ifdef MY_DEBUG //rprintf("ip in : uip_len = %d, proto = %d\n", uip_len, uip_buf[23]); //debugPrintHexTable(uip_len, uip_buf+14); #endif // uip_arp.c // #define IPBUF ((struct ethip_hdr *)&uip_buf[0]) // struct ethip_hdr { // struct uip_eth_hdr ethhdr; // // IP header // u8_t vhl, // tos, // len[2], // ipid[2], // ipoffset[2], // ttl, // proto; // ICMP: 1, TCP: 6, UDP: 17 // u16_t ipchksum; // u16_t srcipaddr[2], // destipaddr[2]; // } // if ((IBUF->srcipaddr & uip_netmask) != uip_hostaddr & (uip_netmask)) return; // uip_arp_update(IPBUF->srcipaddr, &(IPBUF->ethhdr.src)); uip_input(); #ifdef MY_DEBUG //rprintf("ip out : uip_len = %d, proto = %d\n", uip_len, uip_buf[23]); //debugPrintHexTable(uip_len, uip_buf+14); #endif // ip out packet // eg ICMP // uip_len : 84 // source ip <-> destination ip // type : 8 (Echo (ping) request) -> 0 (Echo (ping) reply) // uip.h // #define uip_input() uip_process(UIP_DATA) // UIP_DATA(1) : Tells uIP that there is incoming // uip_process : The actual uIP function which does all the work. if(uip_len > 0) { uip_arp_out(); #ifdef MY_DEBUG //rprintf("ip out : uip_len = %d, proto = %d\n", uip_len, uip_buf[23]); //debugPrintHexTable(uip_len, uip_buf); #endif // Destination MAC Address <=> Source MAC Address // w/o Ethernet CRC // uip_arp.c network_send(); // network.c // if(uip_len <= UIP_LLH_LEN + 40){ // UIP_LLH_LEN : 14 // enc28j60PacketSend(uip_len, (uint8_t *)uip_buf, 0, 0); // }else{ // enc28j60PacketSend(54, (uint8_t *)uip_buf , uip_len - UIP_LLH_LEN - 40, (uint8_t*)uip_appdata); // } } }else if(BUF->type == htons(UIP_ETHTYPE_ARP)){ // UIP_ETHYPE_ARP(0x0806) #ifdef MY_DEBUG //rprintf("arp in : uip_len = %d\n", uip_len); //debugPrintHexTable(uip_len, uip_buf); #endif // arp in : 64 bytes uip_arp_arpin(); if(uip_len > 0){ // always uip_len > 0 #ifdef MY_DEBUG //rprintf("ip in : uip_len = %d\n", uip_len); //debugPrintHexTable(uip_len, uip_buf); #endif // arp out : 42 bytes // 64 - Ethernet_padding(18) - Ethernet_CRC(4) // Send MAC address <--> Target MAC address // Send IP address <--> Target IP address // uip_arp.c network_send(); } } }else if(timer_expired(&periodic_timer)) { timer_reset(&periodic_timer); for(i = 0; i < UIP_CONNS; i++) { uip_periodic(i); // uip.h // #define uip_udp_periodic(conn) do { uip_udp_conn = &uip_udp_conns[conn]; \ // uip_process(UIP_UDP_TIMER); } while (0) // UIP_UDP_TIMER : 5 // uip.c; uip_process // if(flag == UIP_UDP_TIMER) { // if(uip_udp_conn->lport != 0) { // uip_conn = NULL; // uip_sappdata = uip_appdata = &uip_buf[UIP_LLH_LEN + UIP_IPUDPH_LEN]; // uip_len = uip_slen = 0; // uip_flags = UIP_POLL; // UIP_UDP_APPCALL(); // goto udp_send; // } // } else { // goto drop; // } 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 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(ðaddr, 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++; } } } } }
int main(void) { uint8_t i; P5DIR|=BIT1; //P5OUT&=~BIT1; P5OUT|=BIT1; _DINT(); //Disable Interrupts -- For initlization purposes WDTCTL = WDTPW + WDTHOLD; //Stop WDT /* Set System Clock Frequency to (121+1) * 32786 * 2 = 7.995392Mhz This freq. allows for 2400 - 230400 bit rate UART operation with less than 0.86% error */ FLL_CTL0 = (DCOPLUS | XCAP18PF); //Enable Frequency Multiplier (DCO+) and XIN/XOUT caps to 18pF SCFI0 = (FLLD_2 | FN_8); //Set Multiplier to 2, and DCO range to 8MHz nominal SCFQCTL = 121; //7.995392Mhz Operation with No Modulation //setup serial port #if DEBUG_SERIAL debug_serial_init(); printf("asd %i",23244); #endif for(i=0;i<6;i++) uNet_eth_address.addr[i]=_eth_addr[i]; // init NIC device driver #if DEBUG_SERIAL printf("MAC address:%x:%x:%x:%x:%x:%x\r\n",\ (int)_eth_addr[0],(int)_eth_addr[1],(int)_eth_addr[2],\ (int)_eth_addr[3],(int)_eth_addr[4],(int)_eth_addr[5]); printf("Initializing NIC...\r\n"); #endif nic_init(_eth_addr); uip_ipaddr_t ipaddr; uip_setethaddr(uNet_eth_address); #if DEBUG_SERIAL printf("Initializing uIP...\r\n"); #endif //init uIP uip_init(); #if DEBUG_SERIAL printf("Initializing ARP...\r\n"); #endif //init ARP cache uip_arp_init(); #if DEBUG_SERIAL printf("Initializing timer...\r\n"); #endif // init periodic timer clock_init(); //#if DEBUG_SERIAL printf("Initializing webclient...\r\n"); //#endif webclient_init(); _EINT(); // reenable interrupts if(!_enable_dhcp) { #if DEBUG_SERIAL printf("Initializing tcp/ip settings\r\n"); #endif //#if DEBUG_SERIAL printf("IP %i.%i.%i.%i\r\n", (int)_ip_addr[0],(int)_ip_addr[1],(int)_ip_addr[2],(int)_ip_addr[3]); printf("NetMask %i.%i.%i.%i\r\n", (int)_net_mask[0],(int)_net_mask[1],(int)_net_mask[2],(int)_net_mask[3]); printf("Gateway %i.%i.%i.%i\r\n", (int)_gateway[0],(int)_gateway[1],(int)_gateway[2],(int)_gateway[3]); //#endif uip_ipaddr(ipaddr, _ip_addr[0], _ip_addr[1], _ip_addr[2], _ip_addr[3]); uip_sethostaddr(ipaddr); uip_ipaddr(ipaddr, _net_mask[0], _net_mask[1], _net_mask[2], _net_mask[3]); uip_setnetmask(ipaddr); uip_ipaddr(ipaddr, _gateway[0], _gateway[1], _gateway[2], _gateway[3]); uip_setdraddr(ipaddr); } else { #if DEBUG_SERIAL printf("Going to query DHCP server...\r\n"); #endif uip_ipaddr(ipaddr, 0, 0, 0, 0); uip_sethostaddr(ipaddr); uip_setnetmask(ipaddr); uip_setdraddr(ipaddr); } timer_set(&periodic_timer, CLOCK_SECOND * 2 ); timer_set(&arp_timer, CLOCK_SECOND * 10); /* if(_enable_dhcp) { dhcpc_init(&uNet_eth_address.addr[0], 6); dhcpc_request(); } */ /* Initialize Scheduler so that it can be used */ //Scheduler_Init(); /* Initialize USB Subsystem */ //USB_Init(); //Scheduler_SetTaskMode(NetTask, TASK_RUN); /* Scheduling - routine never returns, so put this last in the main function */ //Scheduler_Start(); //#if DEBUG_SERIAL printf("Starting main loop...\r\n"); //#endif while(1) { NetTask(); webclient_get("www", SERVER_PORT,"/"); } }
void main(void) { static struct uip_eth_addr eth_addr; uip_ipaddr_t ipaddr; cpu_init(); uart_init(); printf("Welcome\n"); spi_init(); enc28j60_comm_init(); printf("Welcome\n"); enc_init(mac_addr); // // Configure SysTick for a periodic interrupt. // MAP_SysTickPeriodSet(MAP_SysCtlClockGet() / SYSTICKHZ); MAP_SysTickEnable(); MAP_SysTickIntEnable(); //MAP_IntEnable(INT_GPIOA); MAP_IntEnable(INT_GPIOE); MAP_IntMasterEnable(); MAP_SysCtlPeripheralClockGating(false); printf("int enabled\n"); MAP_GPIOIntTypeSet(GPIO_PORTE_BASE, ENC_INT, GPIO_FALLING_EDGE); MAP_GPIOPinIntClear(GPIO_PORTE_BASE, ENC_INT); MAP_GPIOPinIntEnable(GPIO_PORTE_BASE, ENC_INT); uip_init(); eth_addr.addr[0] = mac_addr[0]; eth_addr.addr[1] = mac_addr[1]; eth_addr.addr[2] = mac_addr[2]; eth_addr.addr[3] = mac_addr[3]; eth_addr.addr[4] = mac_addr[4]; eth_addr.addr[5] = mac_addr[5]; uip_setethaddr(eth_addr); #define DEFAULT_IPADDR0 10 #define DEFAULT_IPADDR1 0 #define DEFAULT_IPADDR2 0 #define DEFAULT_IPADDR3 201 #define DEFAULT_NETMASK0 255 #define DEFAULT_NETMASK1 255 #define DEFAULT_NETMASK2 255 #define DEFAULT_NETMASK3 0 #undef STATIC_IP #ifdef STATIC_IP uip_ipaddr(ipaddr, DEFAULT_IPADDR0, DEFAULT_IPADDR1, DEFAULT_IPADDR2, DEFAULT_IPADDR3); uip_sethostaddr(ipaddr); printf("IP: %d.%d.%d.%d\n", DEFAULT_IPADDR0, DEFAULT_IPADDR1, DEFAULT_IPADDR2, DEFAULT_IPADDR3); uip_ipaddr(ipaddr, DEFAULT_NETMASK0, DEFAULT_NETMASK1, DEFAULT_NETMASK2, DEFAULT_NETMASK3); uip_setnetmask(ipaddr); #else uip_ipaddr(ipaddr, 0, 0, 0, 0); uip_sethostaddr(ipaddr); printf("Waiting for IP address...\n"); uip_ipaddr(ipaddr, 0, 0, 0, 0); uip_setnetmask(ipaddr); #endif httpd_init(); #ifndef STATIC_IP dhcpc_init(mac_addr, 6); dhcpc_request(); #endif long lPeriodicTimer, lARPTimer; lPeriodicTimer = lARPTimer = 0; int i; // = MAP_GPIOPinRead(GPIO_PORTA_BASE, ENC_INT) & ENC_INT; while(true) { //MAP_IntDisable(INT_UART0); MAP_SysCtlSleep(); //MAP_IntEnable(INT_UART0); //i = MAP_GPIOPinRead(GPIO_PORTA_BASE, ENC_INT) & ENC_INT; /*while(i != 0 && g_ulFlags == 0) { i = MAP_GPIOPinRead(GPIO_PORTA_BASE, ENC_INT) & ENC_INT; }*/ if( HWREGBITW(&g_ulFlags, FLAG_ENC_INT) == 1 ) { HWREGBITW(&g_ulFlags, FLAG_ENC_INT) = 0; enc_action(); } if(HWREGBITW(&g_ulFlags, FLAG_SYSTICK) == 1) { HWREGBITW(&g_ulFlags, FLAG_SYSTICK) = 0; lPeriodicTimer += SYSTICKMS; lARPTimer += SYSTICKMS; //printf("%d %d\n", lPeriodicTimer, lARPTimer); } if( lPeriodicTimer > UIP_PERIODIC_TIMER_MS ) { lPeriodicTimer = 0; int l; for(l = 0; l < UIP_CONNS; l++) { uip_periodic(l); // // If the above function invocation resulted in data that // should be sent out on the network, the global variable // uip_len is set to a value > 0. // if(uip_len > 0) { uip_arp_out(); enc_send_packet(uip_buf, uip_len); uip_len = 0; } } for(l = 0; l < UIP_UDP_CONNS; l++) { uip_udp_periodic(l); if( uip_len > 0) { uip_arp_out(); enc_send_packet(uip_buf, uip_len); uip_len = 0; } } } if( lARPTimer > UIP_ARP_TIMER_MS) { lARPTimer = 0; uip_arp_timer(); } } }
/** * \brief gmac_uip_telnetd 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(); TimeTick_Configure(); printf("-- GMAC uIP Telnetd 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(); } } } }
int main(void) { network_init(); #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) { 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(int argc, char *argv[]) { uip_ipaddr_t ipaddr; int i; struct timer periodic_timer, arp_timer; if(connect_pci() < 0) return 1; printf("Starting up stack!\n"); uip_init(); uip_ipaddr(ipaddr, 192,168,1,8); uip_sethostaddr(ipaddr); uip_ipaddr(ipaddr, 192,168,1,1); uip_setdraddr(ipaddr); uip_ipaddr(ipaddr, 255,255,255,0); uip_setnetmask(ipaddr); uip_setethaddr(rtl8139_mac); resolv_init(); dhcpc_init(rtl8139_mac, 6); // httpd_init(); resolv_query("grindars.org.ru"); printf("Stack started\n"); while(1) { uip_len = rtl8139_poll(); if(uip_len > 0) { if(BUF->type == htons(UIP_ETHTYPE_IP)) { uip_arp_ipin(); uip_input(); /* If the above function invocation resulted in data that should be sent out on the network, the global variable uip_len is set to a value > 0. */ if(uip_len > 0) { uip_arp_out(); rtl8139_transmit(); } } else if(BUF->type == htons(UIP_ETHTYPE_ARP)) { uip_arp_arpin(); /* If the above function invocation resulted in data that should be sent out on the network, the global variable uip_len is set to a value > 0. */ if(uip_len > 0) { rtl8139_transmit(); } } } else if(timer_expired(&periodic_timer)) { timer_reset(&periodic_timer); for(i = 0; i < UIP_CONNS; i++) { uip_periodic(i); /* If the above function invocation resulted in data that should be sent out on the network, the global variable uip_len is set to a value > 0. */ if(uip_len > 0) { uip_arp_out(); rtl8139_transmit(); } } //#if UIP_UDP for(i = 0; i < UIP_UDP_CONNS; i++) { uip_udp_periodic(i); /* If the above function invocation resulted in data that should be sent out on the network, the global variable uip_len is set to a value > 0. */ if(uip_len > 0) { uip_arp_out(); rtl8139_transmit(); } } //#endif /* UIP_UDP */ /* Call the ARP timer function every 10 seconds. */ if(timer_expired(&arp_timer)) { timer_reset(&arp_timer); uip_arp_timer(); } } } return 0; }
int main(void) { led_conf(); int i; uip_ipaddr_t ipaddr; struct timer periodic_timer, arp_timer; /* Disable watchdog if enabled by bootloader/fuses */ MCUSR &= ~(1 << WDRF); WDTCSR |= _BV(_WD_CHANGE_BIT) | _BV(WDE); WDTCSR = 0; network_init(); clock_init(); timer_set(&periodic_timer, CLOCK_SECOND / 2); timer_set(&arp_timer, CLOCK_SECOND * 10); uip_init(); phys_init(); // must be done or sometimes arp doesn't work uip_arp_init(); _enable_dhcp=eeprom_read_byte(&ee_enable_dhcp); if ((_enable_dhcp != 1) && (_enable_dhcp != 0)) { // if the setting is invalid, enable by default _enable_dhcp = 1; eeprom_write_byte(&ee_enable_dhcp,_enable_dhcp); } eeprom_read_block ((void *)_eth_addr, (const void *)&ee_eth_addr,6); // if the mac address in eeprom looks good, use it. if((_eth_addr[0] != 255) && (_eth_addr[0] != 0)) { my_eth_addr.addr[0] = _eth_addr[0]; my_eth_addr.addr[1] = _eth_addr[1]; my_eth_addr.addr[2] = _eth_addr[2]; my_eth_addr.addr[3] = _eth_addr[3]; my_eth_addr.addr[4] = _eth_addr[4]; my_eth_addr.addr[5] = _eth_addr[5]; } uip_setethaddr(my_eth_addr); _enable_dhcp = 1; if (_enable_dhcp) { #ifdef __DHCPC_H__ // setup the dhcp renew timer the make the first request timer_set(&dhcp_timer, CLOCK_SECOND * 600); dhcpc_init(&my_eth_addr, 6); dhcpc_request(); #endif } else { eeprom_read_block ((void *)_ip_addr, (const void *)&ee_ip_addr,4); eeprom_read_block ((void *)_net_mask,(const void *)&ee_net_mask,4); eeprom_read_block ((void *)_gateway, (const void *)&ee_gateway,4); // if the IP looks good in flash, use it if ((_ip_addr[0] != 255) && (_ip_addr[0] != 0)) { uip_ipaddr(ipaddr, _ip_addr[0], _ip_addr[1], _ip_addr[2], _ip_addr[3]); uip_sethostaddr(ipaddr); uip_ipaddr(ipaddr, _gateway[0], _gateway[1], _gateway[2], _gateway[3]); uip_setdraddr(ipaddr); uip_ipaddr(ipaddr, _net_mask[0], _net_mask[1], _net_mask[2], _net_mask[3]); uip_setnetmask(ipaddr); } else { // ip in flash didn't look good... use default uip_ipaddr(ipaddr, UIP_IPADDR0, UIP_IPADDR1, UIP_IPADDR2, UIP_IPADDR3); uip_sethostaddr(ipaddr); uip_ipaddr(ipaddr, UIP_DRIPADDR0, UIP_DRIPADDR1, UIP_DRIPADDR2, UIP_DRIPADDR3); uip_setdraddr(ipaddr); uip_ipaddr(ipaddr, UIP_NETMASK0, UIP_NETMASK1, UIP_NETMASK2, UIP_NETMASK3); uip_setnetmask(ipaddr); } } jsoncmd_init(); while (1) { uip_len = network_read(); if(uip_len > 0) { if(BUF->type == htons(UIP_ETHTYPE_IP)) { led_on(5); uip_arp_ipin(); // arp seems to have issues w/o this uip_input(); if(uip_len > 0) { uip_arp_out(); network_send(); } } else if(BUF->type == htons(UIP_ETHTYPE_ARP)) { led_on(4); uip_arp_arpin(); // this is correct if(uip_len > 0) { network_send(); } } } else if(timer_expired(&periodic_timer)) { led_off(4); led_off(5); timer_reset(&periodic_timer); for(i = 0; i < UIP_CONNS; i++) { uip_periodic(i); if(uip_len > 0) { uip_arp_out(); network_send(); } } #if UIP_UDP for(i = 0; i < UIP_UDP_CONNS; i++) { uip_udp_periodic(i); if(uip_len > 0) { uip_arp_out(); network_send(); } } #endif /* UIP_UDP */ if(timer_expired(&arp_timer)) { timer_reset(&arp_timer); uip_arp_timer(); } } else if (_enable_dhcp && timer_expired(&dhcp_timer)) { #ifdef __DHCPC_H__ led_on(3); // for now turn off the led when we start the dhcp process dhcpc_renew(); timer_reset(&dhcp_timer); #endif } } return 0; }