自己在做項目時,需求與LWIP協議棧中的DHCP實現不太一樣,發現如果修改起來沒有想象的那麼容易,跟大家分享一下修改過程。
一、時間變量
- u32_t offered_t0_lease; /* lease period (in seconds) */
- u32_t offered_t1_renew; /* recommended renew time (usually 50% of lease period) */
- u32_t offered_t2_rebind; /* recommended rebind time (usually 66% of lease period) */
- u16_t request_timeout; /* #ticks with period DHCP_FINE_TIMER_SECS for request timeout */
- u16_t t1_timeout; /* #ticks with period DHCP_COARSE_TIMER_SECS for renewal time */
- u16_t t2_timeout; /* #ticks with period DHCP_COARSE_TIMER_SECS for rebind time */
1.在dhcp的代碼中,沒有定時器,這個時間是如何與系統時間所匹配呢?
- for(idxtimer=0;
- idxtimer < (sizeof(timers_table)/sizeof(timers_info));
- idxtimer ++)
- {
- ptmr_inf = &timers_table[idxtimer];
- ptmr_inf->timer += time_diff;
- if (ptmr_inf->timer > ptmr_inf->timer_interval)
- {
- if (ptmr_inf->timer_func)
- ptmr_inf->timer_func();
- ptmr_inf->timer -= ptmr_inf->timer_interval;
- }
- }
- static timers_info timers_table[] = {
- /* LWIP_TCP */
- { 0, TCP_FAST_INTERVAL, tcp_fasttmr},
- { 0, TCP_SLOW_INTERVAL, tcp_slowtmr},
- /* LWIP_ARP */
- { 0, ARP_TMR_INTERVAL, etharp_tmr},
- /* LWIP_DHCP */
- #if LWIP_DHCP
- { 0, DHCP_COARSE_TIMER_SECS, dhcp_coarse_tmr},
- { 0, DHCP_FINE_TIMER_MSECS, dhcp_fine_tmr},
- #endif
- };
- timeout = (dhcp->offered_t1_renew + DHCP_COARSE_TIMER_SECS / 2) / DHCP_COARSE_TIMER_SECS;
- dhcp->t1_timeout = (u16_t)timeout;