// ---------------------------------------------------------------------------- // initialization of network settings void artnet_netInit(void) { if (artnet_netConfig == 1) { if (*((unsigned long*)&myip[0]) == IP(127,127,127,127)) { #if USE_DHCP //ARTNET_DEBUG("Setting network address: Custom (DHCP)\r\n"); dhcp_init(); if (dhcp() != 0) { //ARTNET_DEBUG("DHCP fail\r\n"); //use programmed value (*((unsigned long*)&myip[0])) = MYIP; (*((unsigned long*)&netmask[0])) = NETMASK; } #else //ARTNET_DEBUG("Setting network address: Custom\r\n"); (*((unsigned long*)&myip[0])) = MYIP; (*((unsigned long*)&netmask[0])) = NETMASK; #endif //USE_DHCP } else { read_ip_addresses(); } } // calculate broadcast adress (*((unsigned long*)&broadcast_ip[0])) = (((*((unsigned long*)&myip[0])) & (*((unsigned long*)&netmask[0]))) | (~(*((unsigned long*)&netmask[0])))); // remove any existing app from port kill_udp_app(artnet_port); // add port to stack with callback add_udp_app(artnet_port, (void(*)(unsigned char))artnet_get); }
void main(void) { struct netif netif; lwip_init(); netif_add(&netif, IPADDR_ANY, IPADDR_ANY, IPADDR_ANY, NULL, netif_init, netif_input); netif_set_status_callback(&netif, netif_status_callback); netif_set_default(&netif); netif_set_up(&netif); /* Start DHCP and HTTPD */ dhcp_init(); httpd_init(); while(1) { /* Check link state, e.g. via MDIO communication with PHY */ if(link_state_changed()) { if(link_is_up()) { netif_set_link_up(&netif); } else { netif_set_link_down(&netif); } } /* Check for received frames, feed them to lwIP */ lock_interrupts(); struct pbuf* p = queue_try_get(&queue); unlock_interrupts(); if(p != NULL) { LINK_STATS_INC(link.recv); /* Update SNMP stats (only if you use SNMP) */ MIB2_STATS_NETIF_ADD(netif, ifinoctets, p->tot_len); int unicast = ((p->payload[0] & 0x01) == 0); if (unicast) { MIB2_STATS_NETIF_INC(netif, ifinucastpkts); } else { MIB2_STATS_NETIF_INC(netif, ifinnucastpkts); } if(netif.input(p, &netif) != ERR_OK) { pbuf_free(p); } } /* Cyclic lwIP timers check */ sys_check_timeouts(); /* your application goes here */ } }
int main(int argc, char *argv[]) { int rc = inetcfg_init(); if (rc != EOK) { printf("%s: Failed connecting to inetcfg service (%d).\n", NAME, rc); return 1; } rc = dhcp_init(); if (rc != EOK) { printf("%s: Failed connecting to dhcp service (%d).\n", NAME, rc); return 1; } if (argc == 2) { if (!str_cmp(argv[1], "list")) return wifi_list(); } else if (argc > 2) { uint32_t index; rc = str_uint32_t(argv[2], NULL, 10, false, &index); if (rc != EOK) { printf("%s: Invalid argument.\n", NAME); print_syntax(); return EINVAL; } if (!str_cmp(argv[1], "scan")) { bool now = false; if (argc > 3) if (!str_cmp(argv[3], "-n")) now = true; return wifi_scan(index, now); } else if (!str_cmp(argv[1], "connect")) { char *pass = NULL; if (argc > 3) { if (argc > 4) pass = argv[4]; return wifi_connect(index, argv[3], pass); } } else if (!str_cmp(argv[1], "disconnect")) return wifi_disconnect(index); } print_syntax(); return EOK; }
/* * Routine: dhcp * Function: * Do DHCP over the specified interface to retrieve the IP address, * subnet mask, and router. */ int dhcp(struct ifnet * ifp, struct in_addr * iaddr_p, int max_try, struct in_addr * netmask_p, struct in_addr * router_p, struct proc * procp) { int error = 0; struct dhcp_context * context; context = dhcp_context_create(ifp, max_try, procp, &error); if (context == NULL) { return (error); } /* start DHCP in the INIT state */ error = dhcp_init(context); if (error == 0) { *iaddr_p = context->iaddr; *netmask_p = context->netmask; *router_p = context->router; } dhcp_context_free(context, procp); return (error); }
int main(void) { DDRB |= 0xFF; DDRD |= (1<<5) | (1<<6); PORTD = (1<<6); uint16_t tmp = 512; while(tmp--) { lcd_content[tmp] = 0x00; } spi_init(); soft_spi_init(); enc28j60_init(); nic_init(enc28j60_send_packet, enc28j60_receive_packet, enc28j60_set_mac); dhcp_init(dhcpname); timer_init(); sei(); //char nic_buffer[600]; while(1) { nic_doEvents(nic_buffer); dhcp_doEvents(nic_buffer); } }
void main(void) { uint8_t eth_init = ETH_INIT_DEFAULT; uint32_t server; struct timespec time; strncpy(_tz.tzname, TIMEZONE_CODE, sizeof(_tz.tzname) - 1); _tz.timezone = TIMEZONE_SECS; if (doesclrscrafterexit()) { atexit(confirm_exit); } #ifdef __APPLE2__ { int file; printf("\nSetting slot "); file = open("ethernet.slot", O_RDONLY); if (file != -1) { read(file, ð_init, 1); close(file); eth_init &= ~'0'; } printf("- %d\n", eth_init); } #endif printf("\nInitializing "); if (ip65_init(eth_init)) { error_exit(); } printf("- Ok\n\nObtaining IP address "); if (dhcp_init()) { error_exit(); } printf("- Ok\n\nResolving %s ", NTP_SERVER); server = dns_resolve(NTP_SERVER); if (!server) { error_exit(); } printf("- Ok\n\nGetting %s ", _tz.tzname); time.tv_sec = sntp_get_time(server); if (!time.tv_sec) { error_exit(); } // Convert time from seconds since 1900 to // seconds since 1970 according to RFC 868 time.tv_sec -= 2208988800UL; printf("- %s", ctime(&time.tv_sec)); time.tv_nsec = 0; clock_settime(CLOCK_REALTIME, &time); }
void udp_app_init(void) { dhcp_init(); netfind_init(); }
int main(void) { dhcp dhcp_session; int dhcp_state; http_server http; http_socket httpsock[4]; http_content httpcontent[4]; char oled_msg[17]; char *pnt; int step; api_init(); uart_puts(" * eCowLogic firmware \r\n"); hw_systick( hw_getfreq() / 1000 ); dhcp_session.socket = 2; dhcp_session.buffer = (u8 *)buffer_dhcp; dhcp_init(&dhcp_session); oled_pos(1, 0); oled_puts("Reseau (DHCP) "); step = 0; while(1) { dhcp_state = dhcp_run(&dhcp_session); if (dhcp_state == DHCP_IP_LEASED) break; step++; oled_pos(1, 13); if (step == 1) oled_puts(". "); if (step == 2) oled_puts(".. "); if (step == 3) oled_puts("..."); if (step == 4) { step = 0; dhcp_session.tick_1s++; uart_putc('.'); oled_puts(" "); } delay(250); } pnt = oled_msg; pnt += b2ds(pnt, dhcp_session.dhcp_my_ip[0]); *pnt++ = '.'; pnt += b2ds(pnt, dhcp_session.dhcp_my_ip[1]); *pnt++ = '.'; pnt += b2ds(pnt, dhcp_session.dhcp_my_ip[2]); *pnt++ = '.'; pnt += b2ds(pnt, dhcp_session.dhcp_my_ip[3]); for ( ; pnt < (oled_msg + 16); pnt++) *pnt = ' '; oled_msg[16] = 0; uart_puts("DHCP: LEASED ! "); uart_puts(oled_msg); uart_puts("\r\n"); oled_pos(1, 0); oled_puts(oled_msg); spi_init(); pld_init(); //net_init(); /* Init HTTP content */ strcpy(httpcontent[0].name, "/pld"); httpcontent[0].wildcard = 0; httpcontent[0].cgi = cgi_ng_pld; httpcontent[0].next = &httpcontent[1]; /* Init HTTP content */ strcpy(httpcontent[1].name, "/spi"); httpcontent[1].wildcard = 0; httpcontent[1].cgi = cgi_spi; httpcontent[1].next = &httpcontent[2]; /* Init HTTP content */ strcpy(httpcontent[2].name, "/infos"); httpcontent[2].wildcard = 0; httpcontent[2].cgi = cgi_info; httpcontent[2].next = &httpcontent[3]; /* Init HTTP content */ strcpy(httpcontent[3].name, "/"); httpcontent[3].wildcard = 1; httpcontent[3].cgi = cgi_ng_page; httpcontent[3].next = 0; /* Init HTTP socket */ httpsock[0].id = 4; httpsock[0].state = 0; httpsock[0].server = &http; httpsock[0].next = &httpsock[1]; /* Init HTTP socket */ httpsock[1].id = 5; httpsock[1].state = 0; httpsock[1].server = &http; httpsock[1].next = &httpsock[2]; /* Init HTTP socket */ httpsock[2].id = 6; httpsock[2].state = 0; httpsock[2].server = &http; httpsock[2].next = &httpsock[3]; /* Init HTTP socket */ httpsock[3].id = 7; httpsock[3].state = 0; httpsock[3].server = &http; httpsock[3].next = 0; /* Init the new HTTP layer */ http.port = 80; http.err404 = 0; http.err403 = 0; http.keepalive = 10; http.socks = &httpsock[0]; http.contents = &httpcontent[0]; http_init(&http); while(1) { http_run(&http); } }
void a_dispatch_key_event( int layer_num, int key_num, int key_event ) { if ((key_lock) && (key_num != A_KEY_BUTTON_2)) return; if (key_num == A_KEY_BUTTON_APP_MANAGER) { if (key_event == A_KEY_PRESSED) { if (dvset_isedit()) { dvset_cursor(1); dvset_print(); return; } else if (dvset_isselected()) { a_set_button_text_pos(main_screen, "SELECT", 0); vd_clear_rect(help_layer, 0, 58, 24, 6); // button 1 vd_prints_xy(help_layer, 0, 58, VDISP_FONT_4x6, 0, main_screen->button_text[0]); a_set_button_text_pos(main_screen, "", 1); vd_clear_rect(help_layer, 34, 58, 24, 6); // button 2 vd_prints_xy(help_layer, 34, 58, VDISP_FONT_4x6, 0, main_screen->button_text[1]); a_set_button_text_pos(main_screen, "", 2); vd_clear_rect(help_layer, 66, 58, 24, 6); // button 3 vd_prints_xy(help_layer, 66, 58, VDISP_FONT_4x6, 0, main_screen->button_text[2]); a_set_button_text_pos(main_screen, "MENU", 3); vd_clear_rect(help_layer, 98, 58, 24, 6); // button 4 vd_prints_xy(help_layer, 98, 58, VDISP_FONT_4x6, 0, main_screen->button_text[3]); settings_init(); dvset_cancel(); dvset_print(); refresh_main_menu = true; return; } else if (r2cs_flag) { r2cs_flag = false; lcd_show_menu_layer(help_layer); help_layer_timer = 3; // approx 2 seconds a_set_button_text_pos(main_screen, "R>CS", 2); vd_clear_rect(help_layer, 66, 58, 24, 6); // button 3 vd_prints_xy(help_layer, 66, 58, VDISP_FONT_4x6, 0, main_screen->button_text[2]); return; } if (refresh_main_menu) { a_set_button_text_pos(main_screen, "PTT", 0); vd_clear_rect(help_layer, 0, 58, 24, 6); // button 1 vd_prints_xy(help_layer, 0, 58, VDISP_FONT_4x6, 0, main_screen->button_text[0]); a_set_button_text_pos(main_screen, "MUTE", 1); vd_clear_rect(help_layer, 34, 58, 24, 6); // button 2 vd_prints_xy(help_layer, 34, 58, VDISP_FONT_4x6, 0, main_screen->button_text[1]); a_set_button_text_pos(main_screen, "R>CS", 2); vd_clear_rect(help_layer, 66, 58, 24, 6); // button 3 vd_prints_xy(help_layer, 66, 58, VDISP_FONT_4x6, 0, main_screen->button_text[2]); a_set_button_text_pos(main_screen, "MENU", 3); vd_clear_rect(help_layer, 98, 58, 24, 6); // button 4 vd_prints_xy(help_layer, 98, 58, VDISP_FONT_4x6, 0, main_screen->button_text[3]); refresh_main_menu = false; } snmp_reset_cmnty = 0; software_ptt = 0; // prevent TXing forever... app_manager_select_next(); lcd_show_help_layer(help_layer); if ((current_app->screen_num == VDISP_REF_LAYER) || (current_app->screen_num == VDISP_DVSET_LAYER) || (current_app->screen_num == VDISP_MAIN_LAYER && r2csURCALL())) { help_layer_timer = 0; // show help forever.. } else if (current_app->screen_num == VDISP_RMUSET_LAYER) { help_layer_timer = 0; // show help forever.. rmuset_print(); } else { help_layer_timer = 5; // approx 2 seconds } } if (key_event == A_KEY_HOLD_5S) { if (SETTING_CHAR(C_DISABLE_UDP_BEACON) != 0) // toggle UDP beacon { SETTING_CHAR(C_DISABLE_UDP_BEACON) = 0; // beacon is now on dhcp_init(0); // switch on DHCP wm8510_beep(50, 1200, 100); snmp_reset_cmnty = 1; } else { SETTING_CHAR(C_DISABLE_UDP_BEACON) = 1; // // beacon is now off wm8510_beep(800, 300, 100); } } if (key_event == A_KEY_HOLD_10S) { if ((snmp_reset_cmnty == 2) && (SETTING_CHAR(C_DISABLE_UDP_BEACON) == 0)) { settings.s.snmp_cmnty[0] = 0; // erase first byte, new string will then // be generated automatically wm8510_beep(500, 1200, 100); snmp_reset_cmnty = 0; } } } else { if (snmp_reset_cmnty == 1) { if ((key_num == A_KEY_BUTTON_UP) && (key_event == A_KEY_HOLD_2S)) { snmp_reset_cmnty = 2; } } int res = 0; if (layer_num == VDISP_CURRENT_LAYER) { if (current_app->key_event_handler != NULL) { res = current_app->key_event_handler(current_app, key_num, key_event); } } else { app_context_t * tmp_app = app_list_head; while (tmp_app != NULL) { if ((tmp_app->screen_num == layer_num) && (tmp_app->key_event_handler != NULL)) { res = tmp_app->key_event_handler(tmp_app, key_num, key_event); break; } tmp_app = tmp_app->next; } } if (res == 0) // handler didn't use this event { if (((key_event == A_KEY_PRESSED) || (key_event == A_KEY_REPEAT)) && (!r2cs_flag)) { switch (key_num) { case A_KEY_BUTTON_UP: set_speaker_volume(1); break; case A_KEY_BUTTON_DOWN: set_speaker_volume(0); break; } } } } }
/*-----------------------------------------------------------------------------------*/ static void main_thread(void *arg) { struct ip_addr ipaddr, netmask, gw; sys_sem_t sem; #if PPP_SUPPORT sio_fd_t ppp_sio; #endif netif_init(); sem = sys_sem_new(0); tcpip_init(tcpip_init_done, &sem); sys_sem_wait(sem); sys_sem_free(sem); printf("TCP/IP initialized.\n"); #if PPP_SUPPORT pppInit(); #if PPP_PTY_TEST ppp_sio = sio_open(2); #else ppp_sio = sio_open(0); #endif if(!ppp_sio) { perror("Error opening device: "); exit(1); } #ifdef LWIP_PPP_CHAP_TEST pppSetAuth(PPPAUTHTYPE_CHAP, "lwip", "mysecret"); #endif pppOpen(ppp_sio, pppLinkStatusCallback, NULL); #endif /* PPP_SUPPORT */ #if LWIP_DHCP { IP4_ADDR(&gw, 0,0,0,0); IP4_ADDR(&ipaddr, 0,0,0,0); IP4_ADDR(&netmask, 0,0,0,0); netif_add(&netif, &ipaddr, &netmask, &gw, NULL, tapif_init, tcpip_input); netif_set_default(&netif); dhcp_init(); dhcp_start(&netif); } #else IP4_ADDR(&gw, 192,168,0,1); IP4_ADDR(&ipaddr, 192,168,0,2); IP4_ADDR(&netmask, 255,255,255,0); netif_set_default(netif_add(&netif,&ipaddr, &netmask, &gw, NULL, tapif_init, tcpip_input)); netif_set_up(&netif); #endif /* Only used for testing purposes: */ /* IP4_ADDR(&gw, 193,10,66,1); IP4_ADDR(&ipaddr, 193,10,66,107); IP4_ADDR(&netmask, 255,255,252,0); netif_add(&ipaddr, &netmask, &gw, NULL, pcapif_init, tcpip_input);*/ #if LWIP_HAVE_LOOPIF IP4_ADDR(&gw, 127,0,0,1); IP4_ADDR(&ipaddr, 127,0,0,1); IP4_ADDR(&netmask, 255,0,0,0); netif_set_default(netif_add(&loopif, &ipaddr, &netmask, &gw, NULL, loopif_init, tcpip_input)); #endif #if LWIP_TCP tcpecho_init(); shell_init(); httpd_init(); #endif #if LWIP_UDP udpecho_init(); #endif #if LWIP_RAW sys_thread_new(ping_thread, NULL, DEFAULT_THREAD_PRIO); #endif printf("Applications started.\n"); /* sys_timeout(5000, tcp_timeout, NULL);*/ #ifdef MEM_PERF mem_perf_init("/tmp/memstats.client"); #endif /* MEM_PERF */ #if 0 stats_display(); #endif /* Block for ever. */ sem = sys_sem_new(0); sys_sem_wait(sem); }
void netmain_init(void) { int e; int i; char * msg; #ifdef IP_V6 ip6_addr host; #endif printf("\n%s\n", name); printf("Copyright 1997-2006 by InterNiche Technologies. All rights reserved. \n"); #ifndef SUPERLOOP /* call this to do pre-task setup including intialization of port_prep */ msg = pre_task_setup(); if (msg) panic(msg); #endif #ifdef INCLUDE_NVPARMS /* system uses InterNiche NV system */ e = get_nv_params(); /* get flash parameters into data structs */ if (e) { printf("fatal error (%d) reading NV parameters.\n", e); panic("nv"); } /* set static iface IP info up from stored parameters. These may be overwritten from command line parms or DHCP later. */ for (i = 0; i < STATIC_NETS; i++) { netstatic[i].n_ipaddr = inet_nvparms.ifs[i].ipaddr; netstatic[i].snmask = inet_nvparms.ifs[i].subnet; netstatic[i].n_defgw = inet_nvparms.ifs[i].gateway; #ifdef IP_MULTICAST /* Create a dummy entry for the Ethernet interface mcastlist */ /* If this entry is set to NULL, multicast is not supported */ /* on this interface */ netstatic[i].n_mcastlist = mcastlist; #endif /* IP_MULTICAST */ #ifdef IP_V6 IP6CPY(&host, &inet_nvparms.ifs[i].ipv6addr); if ( (host.addr[0] == 0xFE) && (host.addr[1] == 0xC0)) { netstatic[i].v6addrs[IPA_SITE] = ip6_mkaddr(&netstatic[i], IPA_SITE, &host); } else if ( (host.addr[0] == 0xFE) && (host.addr[1] == 0x80) ) { printf ("[IPV6 init]error : bad IPV6 address\n"); } else if (host.addr[0] != 0) { netstatic[i].v6addrs[IPA_GLOBAL] = ip6_mkaddr(&netstatic[i], IPA_GLOBAL, &host ); } #endif } #ifdef DNS_CLIENT /* set DNS client's server list from nvparms information */ MEMCPY(dns_servers, inet_nvparms.dns_servers, sizeof(dns_servers)); #ifdef DNS_CLIENT_UPDT MEMCPY(soa_mname, inet_nvparms.dns_zone_name, sizeof(soa_mname)); #endif /* DNS_CLIENT_UPDT */ #endif /* DNS_CLIENT */ #ifdef USE_COMPORT comportcfg.comport = comport_nvparms.comport; comportcfg.LineProtocol = comport_nvparms.LineProtocol; #endif /* USE_COMPORT */ #endif /* INCLUDE_NVPARMS */ #ifndef INCLUDE_NVPARMS #ifdef USE_COMPORT comportcfg.comport = 0x01; comportcfg.LineProtocol = PPP; /* Default to PPP */ #endif /* USE_COMPORT */ #endif /* INCLUDE_NVPARMS */ msg = ip_startup(); if (msg) { printf("inet startup error: %s\n", msg); panic("IP"); } #if defined(MEMDEV_SIZE) && defined(VFS_FILES) init_memdev(); /* init the mem and null test devices */ #endif #ifdef IP_MULTICAST #ifdef INCLUDE_TCP /* call the IP multicast test program */ u_mctest_init(); #endif #endif /* clear debugging flags. Port can optionally turn them * back on in post_task_setup(); * NDEBUG = UPCTRACE | IPTRACE | TPTRACE ; */ NDEBUG = 0; /* print IP address of the first interface - for user's benefit */ printf("IP address of %s : %s\n" , ((NET)(netlist.q_head))->name, print_ipad(((NET)(netlist.q_head))->n_ipaddr)); #ifndef SUPERLOOP /* call this per-target routine after basic tasks & net are up */ msg = post_task_setup(); if (msg) panic(msg); #endif #ifdef PING_APP ping_init(); #endif /* PING_APP */ #ifdef RAWIPTEST raw_test_init(); #endif /* RAWIPTEST */ #if defined(TFTP_CLIENT) || defined(TFTP_SERVER) tftp_init(); #endif /* TFTP */ #ifdef TESTMENU install_menu(testmenu); #endif /* TESTMENU */ #ifdef USE_AUTOIP Upnp_init(); /* start Auto IP before DHCP client */ #endif /* USE_AUTOIP */ #ifdef DHCP_CLIENT if( POWERUP_CONFIG_DHCP_ENABLED ) dhc_setup(); /* kick off any DHCP clients */ #endif /* DHCP_CLIENT */ #ifdef DHCP_SERVER #ifdef INCLUDE_NVPARMS if(dhserve_nvparms.ServeDHCP) #endif { e = dhcp_init(); if(e) { dprintf("Error %d starting DHCP server.\n",e); } else { exit_hook(dhcpsrv_cleanup); dprintf("Started DHCP server\n"); } } #endif /* DHCP_SERVER */ #ifdef IN_MENUS printf(prompt); #endif #ifdef UDPSTEST e=udp_echo_init(); if ( e == SUCCESS ) { exit_hook(udp_echo_cleanup); } else dprintf("Error %d starting UDP Echo server.\n",e); #endif #ifdef RIP_SUPPORT e=rip_init(); if ( e == SUCCESS ) { exit_hook(rip_cleanup); } else dprintf("Error %d starting RIP server.\n",e); #endif #ifdef INICHE_SYSLOG e =syslog_init(); if (e == SUCCESS) exit_hook(closelog); else dprintf("Error %d initializing syslog client.\n",e); #endif #ifdef FTP_CLIENT fc_callback=ftpc_callback; #endif /* The following initializations take place when SUPERLOOP is enabled. * Otherwise they would be done in the respective task. */ #ifdef SUPERLOOP #ifdef INCLUDE_SNMP e = snmp_init(); if (e == SUCCESS) exit_hook(snmp_cleanup); else dprintf("Error %d initializing SNMP agent.\n",e); #endif /* INCLUDE_SNMP */ #ifdef WEBPORT e = http_init(); /* start up http server */ if (e) dprintf("Error %d starting HTTP server.\n",e); #endif /* WEBPORT */ #ifdef FTP_SERVER e = ftps_init(); if ( e == SUCCESS ) { exit_hook(ftps_cleanup); } else dprintf("Error %d starting FTP server.\n",e); #endif /* FTP_SERVER */ #ifdef TELNET_SVR e=tel_init(); if ( e == SUCCESS ) { exit_hook(tel_cleanup); } else dprintf("Error %d starting TELNET server.\n",e); #endif #ifdef TCP_ECHOTEST e=tcp_echo_init(); if ( e == SUCCESS ) { exit_hook(tcp_echo_cleanup); } else dprintf("Error %d starting TCP Echo server.\n",e); #endif #ifdef TCP_CIPHERTEST e=tcp_cipher_init(); if ( e == SUCCESS ) { exit_hook(tcp_cipher_cleanup); } else dprintf("Error %d starting TCP cipher server.\n",e); #endif #ifdef USE_CRYPTOENG e = ce_init(); if(e != 0) { dprintf("ce_init() failed\n"); panic("prep_modules"); } #endif #ifdef SMTP_ALERTS smtp_init (); #endif #endif /* SUPERLOOP */ USE_ARG(e); /* Avoid compiler warnings */ USE_ARG(i); } /* end of netmain_init() */
int main(void){ uint16_t plen; DDRC |= 1U << 3; /* DDRB|= (1<<DDB1); */ /* set output to Vcc, LED off */ PORTC |= 1U << 3; delay_ms(20); PORTC &= ~(1U << 3); delay_ms(20); // set the clock speed to 8MHz // set the clock prescaler. First write CLKPCE to enable setting of clock the // next four instructions. /* CLKPR=(1<<CLKPCE); */ /* CLKPR=0; // 8 MHZ */ /* enable PB0, reset as output */ DDRB|= (1<<DDB0); /* set output to gnd, reset the ethernet chip */ PORTB &= ~(1<<PB0); delay_ms(20); /* set output to Vcc, reset inactive */ PORTB|= (1<<PB0); delay_ms(100); PORTC |= 1U << 3; delay_ms(20); PORTC &= ~(1U << 3); delay_ms(20); // LED /* enable PB1, LED as output */ /*initialize enc28j60*/ enc28j60Init(mymac); /* Magjack leds configuration, see enc28j60 datasheet, page 11 */ // LEDA=greed LEDB=yellow // // 0x880 is PHLCON LEDB=on, LEDA=on // enc28j60PhyWrite(PHLCON,0b0000 1000 1000 00 00); enc28j60PhyWrite(PHLCON,0x880); delay_ms(500); // // 0x990 is PHLCON LEDB=off, LEDA=off // enc28j60PhyWrite(PHLCON,0b0000 1001 1001 00 00); enc28j60PhyWrite(PHLCON,0x990); delay_ms(500); // // 0x880 is PHLCON LEDB=on, LEDA=on // enc28j60PhyWrite(PHLCON,0b0000 1000 1000 00 00); enc28j60PhyWrite(PHLCON,0x880); delay_ms(500); // // 0x990 is PHLCON LEDB=off, LEDA=off // enc28j60PhyWrite(PHLCON,0b0000 1001 1001 00 00); enc28j60PhyWrite(PHLCON,0x990); delay_ms(500); // // 0x476 is PHLCON LEDA=links status, LEDB=receive/transmit // enc28j60PhyWrite(PHLCON,0b0000 0100 0111 01 10); enc28j60PhyWrite(PHLCON,0x476); delay_ms(100); PORTC &= ~(1<<PC3); delay_ms(1000); dhcp_init(); while(1){ // get the next new packet: if((plen = enc28j60PacketReceive(BUFFER_SIZE, buf))) { if(dhcp_process_packet(buf, plen)) continue; if(arp_process_packet(buf, plen)) continue; if(icmp_process_packet(buf, plen)) { if (PORTC & (1 << PC3)) PORTC &= ~(1 << PC3); else PORTC |= (1 << PC3); continue; } } else { //dhcp_tick_seconds(); } } return (0); }
/*-----------------------------------------------------------------------------------*/ static void main_thread(void *arg) { struct ip_addr ipaddr, netmask, gw; sys_sem_t sem; netif_init(); sem = sys_sem_new(0); tcpip_init(tcpip_init_done, &sem); sys_sem_wait(sem); sys_sem_free(sem); printf("TCP/IP initialized.\n"); #if LWIP_DHCP { struct netif *netif; IP4_ADDR(&gw, 0,0,0,0); IP4_ADDR(&ipaddr, 0,0,0,0); IP4_ADDR(&netmask, 0,0,0,0); netif = netif_add(&ipaddr, &netmask, &gw, tapif_init, tcpip_input); netif_set_default(netif); dhcp_init(); dhcp_start(netif); } #else IP4_ADDR(&gw, 192,168,0,1); IP4_ADDR(&ipaddr, 192,168,0,2); IP4_ADDR(&netmask, 255,255,255,0); /* netif_set_default(netif_add(&ipaddr, &netmask, &gw, tapif_init, tcpip_input));*/ netif_set_default(netif_add(&ipaddr, &netmask, &gw, tapif_init, tcpip_input)); #endif /* Only used for testing purposes: */ /* IP4_ADDR(&gw, 193,10,66,1); IP4_ADDR(&ipaddr, 193,10,66,107); IP4_ADDR(&netmask, 255,255,252,0); netif_add(&ipaddr, &netmask, &gw, pcapif_init, tcpip_input);*/ IP4_ADDR(&gw, 127,0,0,1); IP4_ADDR(&ipaddr, 127,0,0,1); IP4_ADDR(&netmask, 255,0,0,0); netif_add(&ipaddr, &netmask, &gw, loopif_init, tcpip_input); tcpecho_init(); shell_init(); httpd_init(); udpecho_init(); printf("Applications started.\n"); /* sys_timeout(5000, tcp_timeout, NULL);*/ #ifdef MEM_PERF mem_perf_init("/tmp/memstats.client"); #endif /* MEM_PERF */ /* Block for ever. */ sem = sys_sem_new(0); sys_sem_wait(sem); }