void task_lwip(void) { if(HWREGBITW(&g_ulFlags, FLAG_SYSTICK) == 1) { HWREGBITW(&g_ulFlags, FLAG_SYSTICK) = 0; if( (g_ulTickCounter - last_arp_time) * TICK_MS >= ARP_TMR_INTERVAL) { etharp_tmr(); last_arp_time = g_ulTickCounter; } if( (g_ulTickCounter - last_tcp_time) * TICK_MS >= TCP_TMR_INTERVAL) { tcp_tmr(); last_tcp_time = g_ulTickCounter; } if( (g_ulTickCounter - last_dhcp_coarse_time) * TICK_MS >= DHCP_COARSE_TIMER_MSECS) { dhcp_coarse_tmr(); last_dhcp_coarse_time = g_ulTickCounter; } if( (g_ulTickCounter - last_dhcp_fine_time) * TICK_MS >= DHCP_FINE_TIMER_MSECS) { dhcp_fine_tmr(); last_dhcp_fine_time = g_ulTickCounter; } } }
static void arp_timer( void *arg ) { ( void ) arg; etharp_tmr(); sys_timeout( ARP_TMR_INTERVAL, arp_timer, NULL ); }
static void TimerThread(void* pvArg) { while (1) { //TCP timer. tcp_tmr(); //ARP timer. iTimerARP+=TCP_TMR_INTERVAL; if (iTimerARP>=ARP_TMR_INTERVAL) { iTimerARP-=ARP_TMR_INTERVAL; etharp_tmr(); } #if defined(PS2IP_DHCP) //DHCP timer. iTimerDHCP+=TCP_TMR_INTERVAL; if ((iTimerDHCP-TCP_TMR_INTERVAL)/DHCP_FINE_TIMER_MSECS!=iTimerDHCP/DHCP_FINE_TIMER_MSECS) { dhcp_fine_tmr(); } if (iTimerDHCP>=DHCP_COARSE_TIMER_SECS*1000) { iTimerDHCP-=DHCP_COARSE_TIMER_SECS*1000; dhcp_coarse_tmr(); } #endif DelayThread(TCP_TMR_INTERVAL*250); /* Note: The IOP's DelayThread() function isn't accurate, and the actual timming accuracy is about 25% of the specified value. */ } }
/* This function is similar to the 'tcpip_thread' function defined in the tcpip.c module */ void lwip_process_timers (void) { unsigned int CurrentTickCnt; #if LWIP_TCP static unsigned int lwip_tcp_timer = 0; #endif #if LWIP_ARP static unsigned int lwip_arp_timer = 0; #endif CurrentTickCnt = TickGet (); #if LWIP_DHCP static unsigned int lwip_DHCP_fine_timer = 0; static unsigned int lwip_DHCP_coarce_timer = 0; #endif #if LWIP_AUTOIP static unsigned int lwip_autoip_timer = 0; #endif #if LWIP_ARP /* Process the ARP timer */ if(TickGetDiff (CurrentTickCnt, lwip_arp_timer) >= TICKS_IN_MS(ARP_TMR_INTERVAL)) { lwip_arp_timer = CurrentTickCnt; etharp_tmr(); } #endif #if LWIP_TCP /* Process the TCP timer */ if (TickGetDiff (CurrentTickCnt, lwip_tcp_timer) >= TICKS_IN_MS(TCP_TMR_INTERVAL)) { lwip_tcp_timer = CurrentTickCnt; /* Increment fast (incremented every 250ms) and slow (incremented every 500ms) tcp timers */ tcp_tmr (); } #endif #if LWIP_DHCP /* Process the DHCP Coarce timer */ if (TickGetDiff (CurrentTickCnt, lwip_DHCP_coarce_timer) >= TICKS_IN_MS(DHCP_COARSE_TIMER_MSECS)) { lwip_DHCP_coarce_timer = CurrentTickCnt; dhcp_coarse_tmr (); } /* Process the DHCP Fine timer */ if (TickGetDiff (CurrentTickCnt, lwip_DHCP_fine_timer) >= TICKS_IN_MS(DHCP_FINE_TIMER_MSECS)) { lwip_DHCP_fine_timer = CurrentTickCnt; dhcp_fine_tmr (); } #endif #if LWIP_AUTOIP /* Process the DHCP Fine timer */ if (TickGetDiff (CurrentTickCnt, lwip_autoip_timer) >= TICKS_IN_MS(AUTOIP_TMR_INTERVAL)) { lwip_autoip_timer = CurrentTickCnt; autoip_tmr (); } #endif }
//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 }
static void Timer(void* pvArg) { //TCP timer. tcp_tmr(); //ARP timer. iTimerARP+=TCP_TMR_INTERVAL; if (iTimerARP>=ARP_TMR_INTERVAL) { iTimerARP-=ARP_TMR_INTERVAL; etharp_tmr(); } #if defined(PS2IP_DHCP) //DHCP timer. iTimerDHCP+=TCP_TMR_INTERVAL; if ((iTimerDHCP-TCP_TMR_INTERVAL)/DHCP_FINE_TIMER_MSECS!=iTimerDHCP/DHCP_FINE_TIMER_MSECS) { dhcp_fine_tmr(); } if (iTimerDHCP>=DHCP_COARSE_TIMER_SECS*1000) { iTimerDHCP-=DHCP_COARSE_TIMER_SECS*1000; dhcp_coarse_tmr(); } #endif }
/** * Timer callback function that calls etharp_tmr() and reschedules itself. * * @param arg unused argument */ static void arp_timer(void *arg) { LWIP_UNUSED_ARG(arg); LWIP_DEBUGF(TIMERS_DEBUG, ("tcpip: etharp_tmr()\n")); etharp_tmr(); sys_timeout(ARP_TMR_INTERVAL, arp_timer, NULL); }
/** \brief Polling the timer event flags */ void Ifx_Lwip_pollTimerFlags(void) { Ifx_Lwip *lwip = &Ifx_g_Lwip; uint32 timerFlags = __swap(&lwip->timerFlags, 0); if (timerFlags & IFX_LWIP_FLAG_DHCP_COARSE) { dhcp_coarse_tmr(); } if (timerFlags & IFX_LWIP_FLAG_DHCP_FINE) { dhcp_fine_tmr(); } if (timerFlags & IFX_LWIP_FLAG_TCP_FAST) { tcp_fasttmr(); } if (timerFlags & IFX_LWIP_FLAG_TCP_SLOW) { tcp_slowtmr(); } if (timerFlags & IFX_LWIP_FLAG_ARP) { etharp_tmr(); } if (timerFlags & IFX_LWIP_FLAG_LINK) {} }
/** * @brief LwIP periodic tasks * @param localtime the current LocalTime value * @retval None */ void LwIP_Periodic_Handle(__IO uint32_t localtime) { /* TCP periodic process every 250 ms */ if (localtime - TCPTimer >= TCP_TMR_INTERVAL) { TCPTimer = localtime; tcp_tmr(); } /* ARP periodic process every 5s */ if (localtime - ARPTimer >= ARP_TMR_INTERVAL) { ARPTimer = localtime; etharp_tmr(); } #if LWIP_DHCP /* Fine DHCP periodic process every 500ms */ if (localtime - DHCPfineTimer >= DHCP_FINE_TIMER_MSECS) { DHCPfineTimer = localtime; dhcp_fine_tmr(); } /* DHCP Coarse periodic process every 60s */ if (localtime - DHCPcoarseTimer >= DHCP_COARSE_TIMER_MSECS) { DHCPcoarseTimer = localtime; dhcp_coarse_tmr(); } #endif }
CAMLprim value caml_timer_etharp(value v_unit) { CAMLparam1(v_unit); etharp_tmr(); CAMLreturn(Val_unit); }
/** * @brief LwIP periodic tasks * @param localtime the current LocalTime value * @retval None */ void LwIP_Periodic_Handle(__IO uint32_t localtime) { #if LWIP_TCP /* TCP periodic process every 250 ms */ if (localtime - TCPTimer >= TCP_TMR_INTERVAL) { TCPTimer = localtime; tcp_tmr(); } #endif /* ARP periodic process every 5s */ if ((localtime - ARPTimer) >= ARP_TMR_INTERVAL) { ARPTimer = localtime; etharp_tmr(); } #ifdef USE_DHCP /* Fine DHCP periodic process every 500ms */ if (localtime - DHCPfineTimer >= DHCP_FINE_TIMER_MSECS) { DHCPfineTimer = localtime; dhcp_fine_tmr(); if ((DHCP_state != DHCP_ADDRESS_ASSIGNED)&&(DHCP_state != DHCP_TIMEOUT)) { /* process DHCP state machine */ LwIP_DHCP_Process_Handle(); } } /* DHCP Coarse periodic process every 60s */ if (localtime - DHCPcoarseTimer >= DHCP_COARSE_TIMER_MSECS) { DHCPcoarseTimer = localtime; dhcp_coarse_tmr(); } #endif }
/* Helper functions */ static void etharp_remove_all(void) { int i; /* call etharp_tmr often enough to have all entries cleaned */ for(i = 0; i < 0xff; i++) { etharp_tmr(); } }
/**************************************************************************//** * @brief SysTick_Handler * Interrupt Service Routine for system tick counter. *****************************************************************************/ void SysTick_Handler(void) { ++g_ulLocalTimer; ++tick_count; /*Service the host timer.*/ #if HOST_TMR_INTERVAL if ((g_ulLocalTimer - g_ulHostTimer) >= HOST_TMR_INTERVAL) { g_ulHostTimer = g_ulLocalTimer; } #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 ((g_ulLocalTimer - g_ulTCPTimer) >= TCP_TMR_INTERVAL) { g_ulTCPTimer = g_ulLocalTimer; tcp_tmr(); } /* 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 }
/* * 函数名:LwIP_Periodic_Handle * 描述 :lwip协议栈要求周期调用一些函数 tcp_tmr etharp_tmr dhcp_fine_tmr dhcp_coarse_tmr * 输入 :无 * 输出 : 无 * 调用 :外部调用 */ void LwIP_Periodic_Handle(__IO uint32_t localtime) { //err_t err; if(localtime - INPUT_Timer >= INPUT_TMR_INTERVAL) { /* Read a received packet from the Ethernet buffers and send it to the lwIP for handling */ ethernetif_input(&enc28j60); //轮询是否接收到数据 // err = ethernetif_input(&enc28j60); //轮询是否接收到数据 // if (err !=ERR_OK ) // { // // // } } /* TCP periodic process every 250 ms */ if (localtime - TCPTimer >= TCP_TMR_INTERVAL) { TCPTimer = localtime; tcp_tmr(); //每250ms调用一次 } /* ARP periodic process every 5s */ if (localtime - ARPTimer >= ARP_TMR_INTERVAL) { ARPTimer = localtime; etharp_tmr(); //每5s调用一次 } #if LWIP_DHCP /* Fine DHCP periodic process every 500ms */ if (localtime - DHCPfineTimer >= DHCP_FINE_TIMER_MSECS) { DHCPfineTimer = localtime; dhcp_fine_tmr(); } /* DHCP Coarse periodic process every 60s */ if (localtime - DHCPcoarseTimer >= DHCP_COARSE_TIMER_MSECS) { DHCPcoarseTimer = localtime; dhcp_coarse_tmr(); } #endif }
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 s_ipal_sys_timers_tick(void) { #ifdef IPAL_USE_TCP /* TCP periodic process every 250 ms */ if (ipal_sys_localtime - s_ipal_sys_timerstamps.tcp_tmr.value >= s_ipal_sys_timerstamps.tcp_tmr.numofticks) //TCP_TMR_INTERVAL is expressed in millisec { s_ipal_sys_timerstamps.tcp_tmr.value = ipal_sys_localtime; tcp_tmr(); } #endif /* ARP periodic process every 5s */ if ((ipal_sys_localtime - s_ipal_sys_timerstamps.arp_tmr.value) >= s_ipal_sys_timerstamps.arp_tmr.numofticks) // ARP_TMR_INTERVAL is expressed in millisec { s_ipal_sys_timerstamps.arp_tmr.value = ipal_sys_localtime; etharp_tmr(); } }
void net_poll(void) { u64 now = gettb(); gelicif_input(ð); if ((now - last_arp_time) >= (ARP_TMR_INTERVAL*TICKS_PER_MS)) { etharp_tmr(); last_arp_time = now; } #if LWIP_TCP if ((now - last_tcp_time) >= (TCP_TMR_INTERVAL*TICKS_PER_MS)) { tcp_tmr(); last_tcp_time = now; } #endif if ((now - last_dhcp_coarse_time) >= (DHCP_COARSE_TIMER_SECS*TICKS_PER_SEC)) { dhcp_coarse_tmr(); last_dhcp_coarse_time = now; } if ((now - last_dhcp_fine_time) >= (DHCP_FINE_TIMER_MSECS*TICKS_PER_MS)) { dhcp_fine_tmr(); last_dhcp_fine_time = now; } }
static void etharp_tmr_cb(void *ctx) { etharp_tmr(); }
void ethProcess() { static uint32_t lastCheck = 0; if (ticks - lastCheck >= 1000) { lastCheck = ticks; TByteBuffer b; if (ethPrepareBuffer(&b, 2)) { uint16_t type = 0x0000; BYTEBUFFER_APPEND(&b, type); ethSendPacket(&b); ethFreeBuffer(&b); } if (dodump) enc28j60Dump(); } static uint32_t lastARPTime = 0; if (ticks - lastARPTime >= ARP_TMR_INTERVAL) { lastARPTime = ticks; etharp_tmr(); } static uint32_t lastDHCPTime1 = 0; if (ticks - lastDHCPTime1 >= DHCP_COARSE_TIMER_MSECS) { lastDHCPTime1 = ticks; dhcp_coarse_tmr(); } static uint32_t lastDHCPTime2 = 0; if (ticks - lastDHCPTime2 >= DHCP_FINE_TIMER_MSECS) { lastDHCPTime2 = ticks; dhcp_fine_tmr(); } if (IO_IS_LOW(INT_ETH)) { uint8_t eir = enc28j60ReadControl(EIR); myprintf("eir 0x%02x\r\n", eir); if (eir & EIR_LINKIF) { uint16_t phir = enc28j60ReadPhyWord(PHIR); if (phir & PHIR_PLNKIF) { uint16_t stat = enc28j60ReadPhyWord(PHSTAT2); if (stat & PHSTAT2_LSTAT) // link is up { myprintf("LINK UP\r\n"); netif_set_up(ð_netif); dhcp_start(ð_netif); } else // link is down or was for a period { myprintf("LINK DOWN\r\n"); dhcp_stop(ð_netif); netif_set_down(ð_netif); } } myprintf("phir: 0x%04x\r\n", phir); } enc28j60_if_input(ð_netif); } }
void lwIPServiceTimers(void) { // // 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((g_ulLocalTimer - g_ulTCPTimer) >= TCP_TMR_INTERVAL) { g_ulTCPTimer = g_ulLocalTimer; tcp_tmr(); } // // 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 }
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 }
//***************************************************************************** // //! Service the lwIP timers. //! //! This function services all of the lwIP periodic timers, including TCP and //! Host timers. This should be called from the lwIP context, which may be //! the Ethernet interrupt (in the case of a non-RTOS system) or the lwIP //! thread, in the event that an RTOS is used. //! //! \return None. // //***************************************************************************** static void lwIPServiceTimers(struct netif *netif) { LWIP_DRIVER_DATA* drv_data = (LWIP_DRIVER_DATA*)netif; MAC_Type* mac = (MAC_Type*)netif->state; // // Service the MDIX timer. // if(drv_data->timer_main > drv_data->timer_mdix) { // // See if there has not been a link for 2 seconds. // if((EthernetPHYRead(mac, PHY_MR1) & PHY_MR1_LINK) == 0) { // 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. // mac->MDIX ^= MAC_MDIX_EN; if (netif->flags & NETIF_FLAG_LINK_UP) { #if LWIP_DHCP autoip_stop(netif); dhcp_start(netif); #endif netif_set_link_down(netif); } } else netif_set_link_up(netif); // // Reset the MDIX timer. // drv_data->timer_mdix = drv_data->timer_main + 2048; } // // Service the host timer. // #if HOST_TMR_INTERVAL if(drv_data->timer_main > drv_data->timer_host ) { drv_data->timer_host = drv_data->timer_main + HOST_TMR_INTERVAL; lwIPHostTimerHandler(); } #endif // // Service the ARP timer. // #if LWIP_ARP if(drv_data->timer_main > drv_data->timer_arp) { drv_data->timer_arp = drv_data->timer_main + ARP_TMR_INTERVAL; etharp_tmr(); } #endif // // Service the TCP timer. // #if LWIP_TCP if(drv_data->timer_main > drv_data->timer_tcp) { drv_data->timer_tcp = drv_data->timer_main + TCP_TMR_INTERVAL; tcp_tmr(); } #endif // // Service the AutoIP timer. // #if LWIP_AUTOIP if(drv_data->timer_main - drv_data->timer_autoIP) { drv_data->timer_autoIP = drv_data->timer_main + AUTOIP_TMR_INTERVAL; autoip_tmr(); } #endif // // Service the DCHP Coarse Timer. // #if LWIP_DHCP if(drv_data->timer_main > drv_data->timer_DHCPCoarse) { drv_data->timer_DHCPCoarse = drv_data->timer_main + DHCP_COARSE_TIMER_MSECS; dhcp_coarse_tmr(); } #endif // // Service the DCHP Fine Timer. // #if LWIP_DHCP if(drv_data->timer_main > drv_data->timer_DHCPFine) { drv_data->timer_DHCPFine = drv_data->timer_main + DHCP_FINE_TIMER_MSECS; dhcp_fine_tmr(); } #endif }
/* ** Main function. The application starts here. */ int main(void) { unsigned char rxByte; unsigned int value = (unsigned int)E_FAIL; #ifdef __TMS470__ /* Relocate the required section to internal RAM */ memcpy((void *)(&relocstart), (const void *)(&iram_start), (unsigned int)(&iram_size)); #elif defined(__IAR_SYSTEMS_ICC__) #pragma section = "CodeRelocOverlay" #pragma section = "DataRelocOverlay" #pragma section = "DataOverlayBlk" #pragma section = "CodeOverlayBlk" char* srcAddr = (__section_begin("CodeRelocOverlay")); char* endAddr = (__section_end("DataRelocOverlay")); memcpy((void *)(__section_begin("CodeRelocOverlay")), (const void *)(__section_begin("CodeOverlayBlk")), endAddr - srcAddr); #else memcpy((void *)&(relocstart), (const void *)&(iram_start), (unsigned int)(((&(relocend)) - (&(relocstart))) * (sizeof(unsigned int)))); #endif MMUConfigAndEnable(); /* Enable Instruction Cache */ CacheEnable(CACHE_ALL); PeripheralsSetUp(); /* Initialize the ARM Interrupt Controller */ IntAINTCInit(); /* Register the ISRs */ Timer2IntRegister(); Timer4IntRegister(); EnetIntRegister(); RtcIntRegister(); CM3IntRegister(); HSMMCSDIntRegister(); IntRegister(127, dummyIsr); IntMasterIRQEnable(); pageIndex = 0; prevAction = 0; /* Enable system interrupts */ IntSystemEnable(SYS_INT_RTCINT); IntPrioritySet(SYS_INT_RTCINT, 0, AINTC_HOSTINT_ROUTE_IRQ); IntSystemEnable(SYS_INT_3PGSWTXINT0); IntPrioritySet(SYS_INT_3PGSWTXINT0, 0, AINTC_HOSTINT_ROUTE_IRQ); IntSystemEnable(SYS_INT_3PGSWRXINT0); IntPrioritySet(SYS_INT_3PGSWRXINT0, 0, AINTC_HOSTINT_ROUTE_IRQ); IntSystemEnable(SYS_INT_TINT2); IntPrioritySet(SYS_INT_TINT2, 0, AINTC_HOSTINT_ROUTE_IRQ); IntSystemEnable(SYS_INT_TINT4); IntPrioritySet(SYS_INT_TINT4, 0, AINTC_HOSTINT_ROUTE_IRQ); IntSystemEnable(SYS_INT_MMCSD0INT); IntPrioritySet(SYS_INT_MMCSD0INT, 0, AINTC_HOSTINT_ROUTE_IRQ); IntSystemEnable(SYS_INT_EDMACOMPINT); IntPrioritySet(SYS_INT_EDMACOMPINT, 0, AINTC_HOSTINT_ROUTE_IRQ); IntPrioritySet(SYS_INT_M3_TXEV, 0, AINTC_HOSTINT_ROUTE_IRQ ); IntSystemEnable(SYS_INT_M3_TXEV); IntSystemEnable(127); IntPrioritySet(127, 0, AINTC_HOSTINT_ROUTE_IRQ); IntSystemEnable(SYS_INT_UART0INT); IntPrioritySet(SYS_INT_UART0INT, 0, AINTC_HOSTINT_ROUTE_IRQ); IntRegister(SYS_INT_UART0INT, uartIsr); /* GPIO interrupts */ IntSystemEnable(SYS_INT_GPIOINT0A); IntPrioritySet(SYS_INT_GPIOINT0A, 0, AINTC_HOSTINT_ROUTE_IRQ); IntRegister(SYS_INT_GPIOINT0A, gpioIsr); IntSystemEnable(SYS_INT_GPIOINT0B); IntPrioritySet(SYS_INT_GPIOINT0B, 0, AINTC_HOSTINT_ROUTE_IRQ); IntRegister(SYS_INT_GPIOINT0B, gpioIsr); BoardInfoInit(); deviceVersion = DeviceVersionGet(); CM3EventsClear(); CM3LoadAndRun(); waitForM3Txevent(); /* Initialize console for communication with the Host Machine */ ConsoleUtilsInit(); /* ** Select the console type based on compile time check ** Note: This example is not fully complaint to semihosting. It is ** recommended to use Uart console interface only. */ ConsoleUtilsSetType(CONSOLE_UART); /* Print Board and SoC information on console */ ConsoleUtilsPrintf("\n\r Board Name : %s", BoardNameGet()); ConsoleUtilsPrintf("\n\r Board Version : %s", BoardVersionGet()); ConsoleUtilsPrintf("\n\r SoC Version : %d", deviceVersion); /* On CM3 init firmware version is loaded onto the IPC Message Reg */ ConsoleUtilsPrintf("\n CM3 Firmware Version: %d", readCM3FWVersion()); I2CIntRegister(I2C_0); IntPrioritySet(SYS_INT_I2C0INT, 0, AINTC_HOSTINT_ROUTE_IRQ); IntSystemEnable(SYS_INT_I2C0INT); I2CInit(I2C_0); IntSystemEnable(SYS_INT_TINT1_1MS); IntPrioritySet(SYS_INT_TINT1_1MS, 0, AINTC_HOSTINT_ROUTE_IRQ); IntRegister(SYS_INT_TINT1_1MS,clearTimerInt); configVddOpVoltage(); RtcInit(); HSMMCSDContolInit(); DelayTimerSetup(); initializeTimer1(); ConsoleUtilsPrintf("\r\n After intializing timer"); Timer2Config(); Timer4Config(); LedIfConfig(); MailBoxInit(); Timer2IntEnable(); Timer4IntEnable(); RtcSecIntEnable(); Timer4Start(); while(FALSE == tmr4Flag); tmr4Flag = FALSE; Timer4Stop(); ConsoleUtilsPrintf("\n\r Configuring for maximum OPP"); mpuOpp = ConfigMaximumOPP(); mpuFreq = FrequencyGet(mpuOpp); mpuVdd1 = VddVoltageGet(mpuOpp); PrintConfigDVFS(); /* Create menu page */ pageIndex = MENU_IDX_MAIN; ActionEnetInit(); /* ** Loop for ever. Necessary actions shall be taken ** after detecting the click. */ while(1) { /* ** Check for any any activity on Uart Console and process it. */ if (true == UARTCharsAvail(SOC_UART_0_REGS)) { /* Receiving bytes from the host machine through serial console. */ rxByte = UARTGetc(); /* ** Checking if the entered character is a carriage return. ** Pressing the 'Enter' key on the keyboard executes a ** carriage return on the serial console. */ if('\r' == rxByte) { ConsoleUtilsPrintf("\n"); UartAction(value); value = (unsigned int)E_FAIL; rxByte = 0; } /* ** Checking if the character entered is one among the decimal ** number set 0,1,2,3,....9 */ if(('0' <= rxByte) && (rxByte <= '9')) { ConsoleUtilsPrintf("%c", rxByte); if((unsigned int)E_FAIL == value) { value = 0; } value = value*10 + (rxByte - 0x30); } } /* ** Check if click is detected */ if(clickIdx != 0) { /* ** Take the Action for click */ ClickAction(); clickIdx = 0; } /* ** Check if the Timer Expired */ if(TRUE == tmrFlag) { /* Toggle the LED state */ LedToggle(); tmrFlag = FALSE; } /* ** Check if RTC Time is set */ if(TRUE == rtcSetFlag) { if(TRUE == rtcSecUpdate) { rtcSecUpdate = FALSE; RtcTimeCalDisplay(); ConsoleUtilsPrintf(" --- Selected: "); } } if(TRUE == tmr4Flag) { tmr4Flag = FALSE; /* Make sure that interrupts are disabled and no lwIP functions are executed while calling an lwIP exported API */ IntMasterIRQDisable(); etharp_tmr(); IntMasterIRQEnable(); } } }
static void arp_watchdog(__unused minix_timer_t *tp) { etharp_tmr(); set_timer(&arp_tmr, arp_ticks, arp_watchdog, 0); }
void ethProcess() { static uint32_t lastCheck = 0; if (ticks - lastCheck >= 1000) { lastCheck = ticks; // TProvHeader header; // provPrepareHeader(&header); // header.type = PROVIDER_TYPE_CONTROL; // header.cmd = 0; // provSendPacket(&header, sizeof(header)); if (dodump) enc28j60Dump(); } static uint32_t lastARPTime = 0; if (ticks - lastARPTime >= ARP_TMR_INTERVAL) { lastARPTime = ticks; etharp_tmr(); } static uint32_t lastDHCPTime1 = 0; if (ticks - lastDHCPTime1 >= DHCP_COARSE_TIMER_MSECS) { lastDHCPTime1 = ticks; dhcp_coarse_tmr(); } static uint32_t lastDHCPTime2 = 0; if (ticks - lastDHCPTime2 >= DHCP_FINE_TIMER_MSECS) { lastDHCPTime2 = ticks; dhcp_fine_tmr(); } if (IO_IS_LOW(INT_ETH)) { uint8_t eir = enc28j60ReadControl(EIR); myprintf("eir 0x%02x\r\n", eir); if (eir & EIR_LINKIF) { uint16_t phir = enc28j60ReadPhyWord(PHIR); if (phir & PHIR_PLNKIF) { uint16_t stat = enc28j60ReadPhyWord(PHSTAT2); if (stat & PHSTAT2_LSTAT) // link is up { myprintf("LINK UP\r\n"); netif_set_up(ð_netif); dhcp_start(ð_netif); } else // link is down or was for a period { myprintf("LINK DOWN\r\n"); dhcp_stop(ð_netif); netif_set_down(ð_netif); } } myprintf("phir: 0x%04x\r\n", phir); } enc28j60_if_input(ð_netif); } }
/*..........................................................................*/ QState LwIPMgr_running(LwIPMgr *me, QEvt const *e) { switch (e->sig) { case Q_ENTRY_SIG: { #if (LWIP_DHCP != 0) dhcp_start(me->netif); /* start DHCP if configured */ /* NOTE: If LWIP_AUTOIP is configured in lwipopts.h and * LWIP_DHCP_AUTOIP_COOP is set as well, the DHCP process will * start AutoIP after DHCP fails for 59 seconds. */ #elif (LWIP_AUTOIP != 0) autoip_start(me->netif); /* start AutoIP if configured */ #endif QTimeEvt_postEvery(&me->te_LWIP_SLOW_TICK, (QActive *)me, (LWIP_SLOW_TICK_MS * BSP_TICKS_PER_SEC) / 1000U); return Q_HANDLED(); } case Q_EXIT_SIG: { QTimeEvt_disarm(&me->te_LWIP_SLOW_TICK); return Q_HANDLED(); } case SEND_UDP_SIG: { if (me->upcb->remote_port != 0U) { struct pbuf *p = pbuf_new((u8_t *)((TextEvt const *)e)->text, strlen(((TextEvt const *)e)->text) + 1U); if (p != (struct pbuf *)0) { udp_send(me->upcb, p); pbuf_free(p); /* don't leak the pbuf! */ } } return Q_HANDLED(); } case LWIP_RX_READY_SIG: { eth_driver_read(); return Q_HANDLED(); } case LWIP_TX_READY_SIG: { eth_driver_write(); return Q_HANDLED(); } case LWIP_SLOW_TICK_SIG: { /* has IP address changed? */ if (me->ip_addr != me->netif->ip_addr.addr) { me->ip_addr = me->netif->ip_addr.addr; /* save the IP addr. */ BSP_displyIP(ntohl(me->ip_addr)); } #if LWIP_TCP me->tcp_tmr += LWIP_SLOW_TICK_MS; if (me->tcp_tmr >= TCP_TMR_INTERVAL) { me->tcp_tmr = 0; tcp_tmr(); } #endif #if LWIP_ARP me->arp_tmr += LWIP_SLOW_TICK_MS; if (me->arp_tmr >= ARP_TMR_INTERVAL) { me->arp_tmr = 0; etharp_tmr(); } #endif #if LWIP_DHCP me->dhcp_fine_tmr += LWIP_SLOW_TICK_MS; if (me->dhcp_fine_tmr >= DHCP_FINE_TIMER_MSECS) { me->dhcp_fine_tmr = 0; dhcp_fine_tmr(); } me->dhcp_coarse_tmr += LWIP_SLOW_TICK_MS; if (me->dhcp_coarse_tmr >= DHCP_COARSE_TIMER_MSECS) { me->dhcp_coarse_tmr = 0; dhcp_coarse_tmr(); } #endif #if LWIP_AUTOIP me->auto_ip_tmr += LWIP_SLOW_TICK_MS; if (me->auto_ip_tmr >= AUTOIP_TMR_INTERVAL) { me->auto_ip_tmr = 0; autoip_tmr(); } #endif return Q_HANDLED(); } case LWIP_RX_OVERRUN_SIG: { LINK_STATS_INC(link.err); return Q_HANDLED(); } } return Q_SUPER(&QHsm_top); }
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 arp_timer(void *arg) { etharp_tmr(); sys_timeout(ARP_TMR_INTERVAL, (sys_timeout_handler)arp_timer, NULL); }
/*..........................................................................*/ QState LwIPMgr_running(LwIPMgr *me, QEvent const *e) { switch (e->sig) { case Q_ENTRY_SIG: { QTimeEvt_postEvery(&me->te_LWIP_SLOW_TICK, (QActive *)me, (LWIP_SLOW_TICK_MS * BSP_TICKS_PER_SEC) / 1000); return Q_HANDLED(); } case Q_EXIT_SIG: { QTimeEvt_disarm(&me->te_LWIP_SLOW_TICK); return Q_HANDLED(); } case SEND_UDP_SIG: { if (me->upcb->remote_port != (uint16_t)0) { struct pbuf *p = pbuf_new((u8_t *)((TextEvt const *)e)->text, strlen(((TextEvt const *)e)->text) + 1); if (p != (struct pbuf *)0) { udp_send(me->upcb, p); printf("Sent: %s\n", ((TextEvt const *)e)->text); pbuf_free(p); /* don't leak the pbuf! */ } } return Q_HANDLED(); } case LWIP_RX_READY_SIG: { eth_driver_read(); return Q_HANDLED(); } case LWIP_TX_READY_SIG: { eth_driver_write(); return Q_HANDLED(); } case LWIP_SLOW_TICK_SIG: { /* has IP address changed? */ if (me->ip_addr != me->netif->ip_addr.addr) { TextEvt *te; uint32_t ip_net; /* IP address in the network byte order */ me->ip_addr = me->netif->ip_addr.addr; /* save the IP addr. */ ip_net = ntohl(me->ip_addr); /* publish the text event to display the new IP address */ te = Q_NEW(TextEvt, DISPLAY_IPADDR_SIG); snprintf(te->text, Q_DIM(te->text), "%d.%d.%d.%d", ((ip_net) >> 24) & 0xFF, ((ip_net) >> 16) & 0xFF, ((ip_net) >> 8) & 0xFF, ip_net & 0xFF); QF_PUBLISH((QEvent *)te, me); } #if LWIP_TCP me->tcp_tmr += LWIP_SLOW_TICK_MS; if (me->tcp_tmr >= TCP_TMR_INTERVAL) { me->tcp_tmr = 0; tcp_tmr(); } #endif #if LWIP_ARP me->arp_tmr += LWIP_SLOW_TICK_MS; if (me->arp_tmr >= ARP_TMR_INTERVAL) { me->arp_tmr = 0; etharp_tmr(); } #endif #if LWIP_DHCP me->dhcp_fine_tmr += LWIP_SLOW_TICK_MS; if (me->dhcp_fine_tmr >= DHCP_FINE_TIMER_MSECS) { me->dhcp_fine_tmr = 0; dhcp_fine_tmr(); } me->dhcp_coarse_tmr += LWIP_SLOW_TICK_MS; if (me->dhcp_coarse_tmr >= DHCP_COARSE_TIMER_MSECS) { me->dhcp_coarse_tmr = 0; dhcp_coarse_tmr(); } #endif #if LWIP_AUTOIP me->auto_ip_tmr += LWIP_SLOW_TICK_MS; if (me->auto_ip_tmr >= AUTOIP_TMR_INTERVAL) { me->auto_ip_tmr = 0; autoip_tmr(); } #endif return Q_HANDLED(); } case LWIP_RX_OVERRUN_SIG: { LINK_STATS_INC(link.err); return Q_HANDLED(); } }
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; }