82 #if LWIP_DEBUG_TIMERNAMES 83 #define HANDLER(x) x, #x 94 {TCP_TMR_INTERVAL, HANDLER(tcp_tmr)},
98 {IP_TMR_INTERVAL, HANDLER(ip_reass_tmr)},
101 {ARP_TMR_INTERVAL, HANDLER(etharp_tmr)},
104 {DHCP_COARSE_TIMER_MSECS, HANDLER(dhcp_coarse_tmr)},
105 {DHCP_FINE_TIMER_MSECS, HANDLER(dhcp_fine_tmr)},
108 {AUTOIP_TMR_INTERVAL, HANDLER(autoip_tmr)},
111 {IGMP_TMR_INTERVAL, HANDLER(igmp_tmr)},
115 {DNS_TMR_INTERVAL, HANDLER(dns_tmr)},
118 {ND6_TMR_INTERVAL, HANDLER(nd6_tmr)},
120 {IP6_REASS_TMR_INTERVAL, HANDLER(ip6_reass_tmr)},
123 {MLD6_TMR_INTERVAL, HANDLER(mld6_tmr)},
128 #if LWIP_TIMERS && !LWIP_TIMERS_CUSTOM 131 static struct sys_timeo *next_timeout;
132 static u32_t timeouts_last_time;
136 static int tcpip_tcp_timer_active;
144 tcpip_tcp_timer(
void *arg)
151 if (tcp_active_pcbs || tcp_tw_pcbs) {
153 sys_timeout(TCP_TMR_INTERVAL, tcpip_tcp_timer, NULL);
156 tcpip_tcp_timer_active = 0;
166 tcp_timer_needed(
void)
169 if (!tcpip_tcp_timer_active && (tcp_active_pcbs || tcp_tw_pcbs)) {
171 tcpip_tcp_timer_active = 1;
172 sys_timeout(TCP_TMR_INTERVAL, tcpip_tcp_timer, NULL);
183 cyclic_timer(
void *arg)
186 #if LWIP_DEBUG_TIMERNAMES 190 sys_timeout(cyclic->interval_ms, cyclic_timer, arg);
194 void sys_timeouts_init(
void)
198 for (i = 1; i < LWIP_ARRAYSIZE(lwip_cyclic_timers); i++) {
201 sys_timeout(lwip_cyclic_timers[i].interval_ms, cyclic_timer,
LWIP_CONST_CAST(
void*, &lwip_cyclic_timers[i]));
205 timeouts_last_time =
sys_now();
218 #if LWIP_DEBUG_TIMERNAMES 220 sys_timeout_debug(u32_t msecs, sys_timeout_handler handler,
void *arg,
const char* handler_name)
223 sys_timeout(u32_t msecs, sys_timeout_handler handler,
void *arg)
226 struct sys_timeo *timeout, *t;
229 timeout = (
struct sys_timeo *)
memp_malloc(MEMP_SYS_TIMEOUT);
230 if (timeout == NULL) {
231 LWIP_ASSERT(
"sys_timeout: timeout != NULL, pool MEMP_SYS_TIMEOUT is empty", timeout != NULL);
236 if (next_timeout == NULL) {
238 timeouts_last_time = now;
240 diff = now - timeouts_last_time;
243 timeout->next = NULL;
244 timeout->h = handler;
246 timeout->time = msecs + diff;
247 #if LWIP_DEBUG_TIMERNAMES 248 timeout->handler_name = handler_name;
250 (
void *)timeout, msecs, handler_name, (
void *)arg));
253 if (next_timeout == NULL) {
254 next_timeout = timeout;
258 if (next_timeout->time > msecs) {
259 next_timeout->time -= msecs;
260 timeout->next = next_timeout;
261 next_timeout = timeout;
263 for (t = next_timeout; t != NULL; t = t->next) {
264 timeout->time -= t->time;
265 if (t->next == NULL || t->next->time > timeout->time) {
266 if (t->next != NULL) {
267 t->next->time -= timeout->time;
268 }
else if (timeout->time > msecs) {
273 timeout->time = msecs + next_timeout->time;
275 timeout->next = t->next;
292 sys_untimeout(sys_timeout_handler handler,
void *arg)
294 struct sys_timeo *prev_t, *t;
296 if (next_timeout == NULL) {
300 for (t = next_timeout, prev_t = NULL; t != NULL; prev_t = t, t = t->next) {
301 if ((t->h == handler) && (t->arg == arg)) {
304 if (prev_t == NULL) {
305 next_timeout = t->next;
307 prev_t->next = t->next;
310 if (t->next != NULL) {
311 t->next->time += t->time;
328 #if !NO_SYS && !defined __DOXYGEN__ 332 sys_check_timeouts(
void)
335 struct sys_timeo *tmptimeout;
337 sys_timeout_handler handler;
344 diff = now - timeouts_last_time;
346 PBUF_CHECK_FREE_OOSEQ();
348 tmptimeout = next_timeout;
349 if (tmptimeout && (tmptimeout->time <= diff)) {
352 timeouts_last_time += tmptimeout->time;
353 diff -= tmptimeout->time;
354 next_timeout = tmptimeout->next;
355 handler = tmptimeout->h;
356 arg = tmptimeout->arg;
357 #if LWIP_DEBUG_TIMERNAMES 358 if (handler != NULL) {
360 tmptimeout->handler_name, arg));
364 if (handler != NULL) {
388 sys_restart_timeouts(
void)
390 timeouts_last_time =
sys_now();
400 sys_timeouts_sleeptime(
void)
403 if (next_timeout == NULL) {
406 diff =
sys_now() - timeouts_last_time;
407 if (diff > next_timeout->time) {
410 return next_timeout->time - diff;
424 sys_timeouts_mbox_fetch(
sys_mbox_t *mbox,
void **msg)
434 sleeptime = sys_timeouts_sleeptime();
438 sys_check_timeouts();
449 tcp_timer_needed(
void)
u32_t sys_arch_mbox_fetch(sys_mbox_t *mbox, void **msg, u32_t timeout)
void memp_free(memp_t type, void *mem)
const struct lwip_cyclic_timer lwip_cyclic_timers[]
#define LWIP_TCPIP_THREAD_ALIVE()
#define LWIP_DEBUGF(debug, message)
#define LWIP_UNUSED_ARG(x)
#define LWIP_CONST_CAST(target_type, val)
void * memp_malloc(memp_t type)