//LWIP查询 void LWIP_Polling(void){ // if(timer_expired(&input_time,5)) //接收包,周期处理函数 // { ethernetif_input(&enc28j60_netif); // } if(timer_expired(&last_tcp_time,TCP_TMR_INTERVAL/CLOCKTICKS_PER_MS))//TCP处理定时器处理函数 { tcp_tmr(); } if(timer_expired(&last_arp_time,ARP_TMR_INTERVAL/CLOCKTICKS_PER_MS))//ARP处理定时器 { etharp_tmr(); } if(timer_expired(&last_ipreass_time,IP_TMR_INTERVAL/CLOCKTICKS_PER_MS)){ //IP重新组装定时器 ip_reass_tmr(); } #if LWIP_DHCP>0 if(timer_expired(&last_dhcp_fine_time,DHCP_FINE_TIMER_MSECS/CLOCKTICKS_PER_MS)) { dhcp_fine_tmr(); } if(timer_expired(&last_dhcp_coarse_time,DHCP_COARSE_TIMER_MSECS/CLOCKTICKS_PER_MS)) { dhcp_coarse_tmr(); } #endif }
CAMLprim value caml_timer_ip_reass(value v_unit) { CAMLparam1(v_unit); ip_reass_tmr(); CAMLreturn(Val_unit); }
/** * Timer callback function that calls ip_reass_tmr() and reschedules itself. * * @param arg unused argument */ static void ip_reass_timer(void *arg) { LWIP_UNUSED_ARG(arg); LWIP_DEBUGF(TIMERS_DEBUG, ("tcpip: ip_reass_tmr()\n")); ip_reass_tmr(); sys_timeout(IP_TMR_INTERVAL, ip_reass_timer, NULL); }
static void ip_timer(void *data) { LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip: ip_reass_tmr()\n")); ip_reass_tmr(); sys_timeout(1000, ip_timer, NULL); }
void poll_networking(void) { uint64_t now; if (!netif) return; /* poll interface */ netfrontif_poll(netif, LWIP_NETIF_MAX_RXBURST_LEN); /* process lwIP timers */ now = NSEC_TO_MSEC(NOW()); TIMED(now, ts_etharp, ARP_TMR_INTERVAL, etharp_tmr()); TIMED(now, ts_ipreass, IP_TMR_INTERVAL, ip_reass_tmr()); TIMED(now, ts_tcp, TCP_TMR_INTERVAL, tcp_tmr()); TIMED(now, ts_dns, DNS_TMR_INTERVAL, dns_tmr()); }
static void lwIPServiceTimers(void) { // // Service the MDIX timer. // if((EthernetPHYRead(ETH_BASE, PHY_MR1) & PHY_MR1_LINK) == 0) { // // See if there has not been a link for 2 seconds. // if((g_ulLocalTimer - g_ulMDIXTimer) >= 2000) { // // There has not been a link for 2 seconds, so flip the MDI/MDIX // switch. This is handled automatically by Fury rev A2, but is // harmless. // HWREG(ETH_BASE + MAC_O_MDIX) ^= MAC_MDIX_EN; // // Reset the MDIX timer. // g_ulMDIXTimer = g_ulLocalTimer; } } else { // // There is a link, so reset the MDIX timer. // g_ulMDIXTimer = g_ulLocalTimer; } // // Service the host timer. // #if HOST_TMR_INTERVAL if((g_ulLocalTimer - g_ulHostTimer) >= HOST_TMR_INTERVAL) { g_ulHostTimer = g_ulLocalTimer; lwIPHostTimerHandler(); } #endif // // Service the ARP timer. // #if LWIP_ARP if((g_ulLocalTimer - g_ulARPTimer) >= ARP_TMR_INTERVAL) { g_ulARPTimer = g_ulLocalTimer; etharp_tmr(); } #endif // // Service the TCP timer. // #if LWIP_TCP if((g_ulLocalTimer - g_ulTCPTimer) >= TCP_TMR_INTERVAL) { g_ulTCPTimer = g_ulLocalTimer; tcp_tmr(); } #endif // // Service the AutoIP timer. // #if LWIP_AUTOIP if((g_ulLocalTimer - g_ulAutoIPTimer) >= AUTOIP_TMR_INTERVAL) { g_ulAutoIPTimer = g_ulLocalTimer; autoip_tmr(); } #endif // // Service the DCHP Coarse Timer. // #if LWIP_DHCP if((g_ulLocalTimer - g_ulDHCPCoarseTimer) >= DHCP_COARSE_TIMER_MSECS) { g_ulDHCPCoarseTimer = g_ulLocalTimer; dhcp_coarse_tmr(); } #endif // // Service the DCHP Fine Timer. // #if LWIP_DHCP if((g_ulLocalTimer - g_ulDHCPFineTimer) >= DHCP_FINE_TIMER_MSECS) { g_ulDHCPFineTimer = g_ulLocalTimer; dhcp_fine_tmr(); } #endif // // Service the IP Reassembly Timer // #if IP_REASSEMBLY if((g_ulLocalTimer - g_ulIPReassemblyTimer) >= IP_TMR_INTERVAL) { g_ulIPReassemblyTimer = g_ulLocalTimer; ip_reass_tmr(); } #endif // // Service the IGMP Timer // #if LWIP_IGMP if((g_ulLocalTimer - g_ulIGMPTimer) >= IGMP_TMR_INTERVAL) { g_ulIGMPTimer = g_ulLocalTimer; igmp_tmr(); } #endif // // Service the DNS Timer // #if LWIP_DNS if((g_ulLocalTimer - g_ulDNSTimer) >= DNS_TMR_INTERVAL) { g_ulDNSTimer = g_ulLocalTimer; dns_tmr(); } #endif }
int main(int argc, char **argv) { struct netif netif; sigset_t mask, oldmask, empty; int ch; char ip_str[16] = {0}, nm_str[16] = {0}, gw_str[16] = {0}; /* startup defaults (may be overridden by one or more opts) */ IP4_ADDR(&gw, 192,168,0,1); IP4_ADDR(&ipaddr, 192,168,0,2); IP4_ADDR(&netmask, 255,255,255,0); trap_flag = 0; /* use debug flags defined by debug.h */ debug_flags = LWIP_DBG_OFF; while ((ch = getopt_long(argc, argv, "dhg:i:m:t:", longopts, NULL)) != -1) { switch (ch) { case 'd': debug_flags |= (LWIP_DBG_ON|LWIP_DBG_TRACE|LWIP_DBG_STATE|LWIP_DBG_FRESH|LWIP_DBG_HALT); break; case 'h': usage(); exit(0); break; case 'g': ipaddr_aton(optarg, &gw); break; case 'i': ipaddr_aton(optarg, &ipaddr); break; case 'm': ipaddr_aton(optarg, &netmask); break; case 't': trap_flag = !0; /* @todo: remove this authentraps tweak when we have proper SET & non-volatile mem */ snmpauthentraps_set = 1; ipaddr_aton(optarg, &trap_addr); strncpy(ip_str, ipaddr_ntoa(&trap_addr),sizeof(ip_str)); printf("SNMP trap destination %s\n", ip_str); break; default: usage(); break; } } argc -= optind; argv += optind; strncpy(ip_str, ipaddr_ntoa(&ipaddr), sizeof(ip_str)); strncpy(nm_str, ipaddr_ntoa(&netmask), sizeof(nm_str)); strncpy(gw_str, ipaddr_ntoa(&gw), sizeof(gw_str)); printf("Host at %s mask %s gateway %s\n", ip_str, nm_str, gw_str); #ifdef PERF perf_init("/tmp/minimal.perf"); #endif /* PERF */ lwip_init(); printf("TCP/IP initialized.\n"); netif_add(&netif, &ipaddr, &netmask, &gw, NULL, mintapif_init, ethernet_input); netif_set_default(&netif); netif_set_up(&netif); #if SNMP_PRIVATE_MIB != 0 /* initialize our private example MIB */ lwip_privmib_init(); #endif snmp_trap_dst_ip_set(0,&trap_addr); snmp_trap_dst_enable(0,trap_flag); snmp_set_syscontact(syscontact_str,&syscontact_len); snmp_set_syslocation(syslocation_str,&syslocation_len); snmp_set_snmpenableauthentraps(&snmpauthentraps_set); snmp_init(); echo_init(); timer_init(); timer_set_interval(TIMER_EVT_ETHARPTMR, ARP_TMR_INTERVAL / 10); timer_set_interval(TIMER_EVT_TCPTMR, TCP_TMR_INTERVAL / 10); #if IP_REASSEMBLY timer_set_interval(TIMER_EVT_IPREASSTMR, IP_TMR_INTERVAL / 10); #endif printf("Applications started.\n"); while (1) { /* poll for input packet and ensure select() or read() arn't interrupted */ sigemptyset(&mask); sigaddset(&mask, SIGALRM); sigprocmask(SIG_BLOCK, &mask, &oldmask); /* start of critical section, poll netif, pass packet to lwIP */ if (mintapif_select(&netif) > 0) { /* work, immediatly end critical section hoping lwIP ended quickly ... */ sigprocmask(SIG_SETMASK, &oldmask, NULL); } else { /* no work, wait a little (10 msec) for SIGALRM */ sigemptyset(&empty); sigsuspend(&empty); /* ... end critical section */ sigprocmask(SIG_SETMASK, &oldmask, NULL); } if(timer_testclr_evt(TIMER_EVT_TCPTMR)) { tcp_tmr(); } #if IP_REASSEMBLY if(timer_testclr_evt(TIMER_EVT_IPREASSTMR)) { ip_reass_tmr(); } #endif if(timer_testclr_evt(TIMER_EVT_ETHARPTMR)) { etharp_tmr(); } } return 0; }
static void lwIPServiceTimers(void) { // // Service the host timer. // #if HOST_TMR_INTERVAL if((g_ui32LocalTimer - g_ui32HostTimer) >= HOST_TMR_INTERVAL) { g_ui32HostTimer = g_ui32LocalTimer; lwIPHostTimerHandler(); } #endif // // Service the ARP timer. // #if LWIP_ARP if((g_ui32LocalTimer - g_ui32ARPTimer) >= ARP_TMR_INTERVAL) { g_ui32ARPTimer = g_ui32LocalTimer; etharp_tmr(); } #endif // // Service the TCP timer. // #if LWIP_TCP if((g_ui32LocalTimer - g_ui32TCPTimer) >= TCP_TMR_INTERVAL) { g_ui32TCPTimer = g_ui32LocalTimer; tcp_tmr(); } #endif // // Service the AutoIP timer. // #if LWIP_AUTOIP if((g_ui32LocalTimer - g_ui32AutoIPTimer) >= AUTOIP_TMR_INTERVAL) { g_ui32AutoIPTimer = g_ui32LocalTimer; autoip_tmr(); } #endif // // Service the DCHP Coarse Timer. // #if LWIP_DHCP if((g_ui32LocalTimer - g_ui32DHCPCoarseTimer) >= DHCP_COARSE_TIMER_MSECS) { g_ui32DHCPCoarseTimer = g_ui32LocalTimer; dhcp_coarse_tmr(); } #endif // // Service the DCHP Fine Timer. // #if LWIP_DHCP if((g_ui32LocalTimer - g_ui32DHCPFineTimer) >= DHCP_FINE_TIMER_MSECS) { g_ui32DHCPFineTimer = g_ui32LocalTimer; dhcp_fine_tmr(); } #endif // // Service the IP Reassembly Timer // #if IP_REASSEMBLY if((g_ui32LocalTimer - g_ui32IPReassemblyTimer) >= IP_TMR_INTERVAL) { g_ui32IPReassemblyTimer = g_ui32LocalTimer; ip_reass_tmr(); } #endif // // Service the IGMP Timer // #if LWIP_IGMP if((g_ui32LocalTimer - g_ui32IGMPTimer) >= IGMP_TMR_INTERVAL) { g_ui32IGMPTimer = g_ui32LocalTimer; igmp_tmr(); } #endif // // Service the DNS Timer // #if LWIP_DNS if((g_ui32LocalTimer - g_ui32DNSTimer) >= DNS_TMR_INTERVAL) { g_ui32DNSTimer = g_ui32LocalTimer; dns_tmr(); } #endif // // Service the link timer. // #if LWIP_AUTOIP || LWIP_DHCP if((g_ui32LocalTimer - g_ui32LinkTimer) >= LINK_TMR_INTERVAL) { g_ui32LinkTimer = g_ui32LocalTimer; lwIPLinkDetect(); } #endif }
static void ip_tmr_cb(void *ctx) { ip_reass_tmr(); }