63 #if LWIP_DEBUG_TIMERNAMES
64 #define HANDLER(x) x, #x
75 {TCP_TMR_INTERVAL,
HANDLER(tcp_tmr)},
79 {IP_TMR_INTERVAL,
HANDLER(ip_reass_tmr)},
82 {ARP_TMR_INTERVAL,
HANDLER(etharp_tmr)},
85 {DHCP_COARSE_TIMER_MSECS,
HANDLER(dhcp_coarse_tmr)},
86 {DHCP_FINE_TIMER_MSECS,
HANDLER(dhcp_fine_tmr)},
89 {AUTOIP_TMR_INTERVAL,
HANDLER(autoip_tmr)},
92 {IGMP_TMR_INTERVAL,
HANDLER(igmp_tmr)},
96 {DNS_TMR_INTERVAL,
HANDLER(dns_tmr)},
99 {ND6_TMR_INTERVAL,
HANDLER(nd6_tmr)},
101 {IP6_REASS_TMR_INTERVAL,
HANDLER(ip6_reass_tmr)},
104 {MLD6_TMR_INTERVAL,
HANDLER(mld6_tmr)},
109 #if LWIP_TIMERS && !LWIP_TIMERS_CUSTOM
112 static struct sys_timeo *next_timeout;
113 static u32_t timeouts_last_time;
117 static int tcpip_tcp_timer_active;
125 tcpip_tcp_timer(
void *arg)
132 if (tcp_active_pcbs || tcp_tw_pcbs) {
134 sys_timeout(TCP_TMR_INTERVAL, tcpip_tcp_timer,
NULL);
137 tcpip_tcp_timer_active = 0;
150 if (!tcpip_tcp_timer_active && (tcp_active_pcbs || tcp_tw_pcbs)) {
152 tcpip_tcp_timer_active = 1;
153 sys_timeout(TCP_TMR_INTERVAL, tcpip_tcp_timer,
NULL);
164 cyclic_timer(
void *arg)
167 #if LWIP_DEBUG_TIMERNAMES
171 sys_timeout(cyclic->
interval_ms, cyclic_timer, arg);
175 void sys_timeouts_init(
void)
186 timeouts_last_time =
sys_now();
199 #if LWIP_DEBUG_TIMERNAMES
201 sys_timeout_debug(
u32_t msecs, sys_timeout_handler
handler,
void *arg,
const char* handler_name)
204 sys_timeout(
u32_t msecs, sys_timeout_handler
handler,
void *arg)
207 struct sys_timeo *timeout, *t;
210 timeout = (
struct sys_timeo *)
memp_malloc(MEMP_SYS_TIMEOUT);
211 if (timeout ==
NULL) {
212 LWIP_ASSERT(
"sys_timeout: timeout != NULL, pool MEMP_SYS_TIMEOUT is empty", timeout !=
NULL);
217 if (next_timeout ==
NULL) {
219 timeouts_last_time = now;
221 diff = now - timeouts_last_time;
224 timeout->next =
NULL;
225 timeout->h = handler;
227 timeout->time = msecs + diff;
228 #if LWIP_DEBUG_TIMERNAMES
229 timeout->handler_name = handler_name;
231 (
void *)timeout, msecs, handler_name, (
void *)arg));
234 if (next_timeout ==
NULL) {
235 next_timeout = timeout;
239 if (next_timeout->time > msecs) {
240 next_timeout->time -= msecs;
241 timeout->next = next_timeout;
242 next_timeout = timeout;
244 for (t = next_timeout; t !=
NULL; t = t->next) {
245 timeout->time -= t->time;
246 if (t->next ==
NULL || t->next->time > timeout->time) {
247 if (t->next !=
NULL) {
248 t->next->time -= timeout->time;
249 }
else if (timeout->time > msecs) {
254 timeout->time = msecs + next_timeout->time;
256 timeout->next = t->next;
273 sys_untimeout(sys_timeout_handler handler,
void *arg)
275 struct sys_timeo *prev_t, *t;
277 if (next_timeout ==
NULL) {
281 for (t = next_timeout, prev_t =
NULL; t !=
NULL; prev_t = t, t = t->next) {
282 if ((t->h == handler) && (t->arg == arg)) {
285 if (prev_t ==
NULL) {
286 next_timeout = t->next;
288 prev_t->next = t->next;
291 if (t->next !=
NULL) {
292 t->next->time += t->time;
309 #if !NO_SYS && !defined __DOXYGEN__
313 sys_check_timeouts(
void)
316 struct sys_timeo *tmptimeout;
318 sys_timeout_handler handler;
325 diff = now - timeouts_last_time;
329 tmptimeout = next_timeout;
330 if (tmptimeout && (tmptimeout->time <= diff)) {
333 timeouts_last_time += tmptimeout->time;
334 diff -= tmptimeout->time;
335 next_timeout = tmptimeout->next;
336 handler = tmptimeout->h;
337 arg = tmptimeout->arg;
338 #if LWIP_DEBUG_TIMERNAMES
339 if (handler !=
NULL) {
341 tmptimeout->handler_name, arg));
345 if (handler !=
NULL) {
369 sys_restart_timeouts(
void)
371 timeouts_last_time =
sys_now();
381 sys_timeouts_sleeptime(
void)
384 if (next_timeout ==
NULL) {
387 diff =
sys_now() - timeouts_last_time;
388 if (diff > next_timeout->time) {
391 return next_timeout->time - diff;
405 sys_timeouts_mbox_fetch(
sys_mbox_t *mbox,
void **msg)
415 sleeptime = sys_timeouts_sleeptime();
419 sys_check_timeouts();