64#if LWIP_DEBUG_TIMERNAMES
65#define HANDLER(x) x, #x
70#define LWIP_MAX_TIMEOUT 0x7fffffff
73#define TIME_LESS_THAN(t, compare_to) ( (((u32_t)((t)-(compare_to))) > LWIP_MAX_TIMEOUT) ? 1 : 0 )
81 {TCP_TMR_INTERVAL, HANDLER(tcp_tmr)},
85 {IP_TMR_INTERVAL, HANDLER(ip_reass_tmr)},
88 {ARP_TMR_INTERVAL, HANDLER(etharp_tmr)},
91 {DHCP_COARSE_TIMER_MSECS, HANDLER(dhcp_coarse_tmr)},
92 {DHCP_FINE_TIMER_MSECS, HANDLER(dhcp_fine_tmr)},
95 {ACD_TMR_INTERVAL, HANDLER(acd_tmr)},
98 {IGMP_TMR_INTERVAL, HANDLER(igmp_tmr)},
105 {ND6_TMR_INTERVAL, HANDLER(nd6_tmr)},
107 {IP6_REASS_TMR_INTERVAL, HANDLER(ip6_reass_tmr)},
110 {MLD6_TMR_INTERVAL, HANDLER(mld6_tmr)},
113 {DHCP6_TIMER_MSECS, HANDLER(dhcp6_tmr)},
119#if LWIP_TIMERS && !LWIP_TIMERS_CUSTOM
122static struct sys_timeo *next_timeout;
124static u32_t current_timeout_due_time;
128sys_timeouts_get_next_timeout(
void)
130 return &next_timeout;
136static int tcpip_tcp_timer_active;
144tcpip_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;
166tcp_timer_needed(
void)
171 if (!tcpip_tcp_timer_active && (tcp_active_pcbs || tcp_tw_pcbs)) {
173 tcpip_tcp_timer_active = 1;
174 sys_timeout(TCP_TMR_INTERVAL, tcpip_tcp_timer, NULL);
180#if LWIP_DEBUG_TIMERNAMES
181sys_timeout_abs(u32_t abs_time, sys_timeout_handler handler,
void *arg,
const char *handler_name)
183sys_timeout_abs(u32_t abs_time, sys_timeout_handler handler,
void *arg)
186 struct sys_timeo *timeout, *t;
188 timeout = (
struct sys_timeo *)
memp_malloc(MEMP_SYS_TIMEOUT);
189 if (timeout == NULL) {
190 LWIP_ASSERT(
"sys_timeout: timeout != NULL, pool MEMP_SYS_TIMEOUT is empty", timeout != NULL);
194 timeout->next = NULL;
195 timeout->h = handler;
197 timeout->time = abs_time;
199#if LWIP_DEBUG_TIMERNAMES
200 timeout->handler_name = handler_name;
201 LWIP_DEBUGF(
TIMERS_DEBUG, (
"sys_timeout: %p abs_time=%"U32_F
" handler=%s arg=%p\n",
202 (
void *)timeout, abs_time, handler_name, (
void *)arg));
205 if (next_timeout == NULL) {
206 next_timeout = timeout;
209 if (TIME_LESS_THAN(timeout->time, next_timeout->time)) {
210 timeout->next = next_timeout;
211 next_timeout = timeout;
213 for (t = next_timeout; t != NULL; t = t->next) {
214 if ((t->next == NULL) || TIME_LESS_THAN(timeout->time, t->next->time)) {
215 timeout->next = t->next;
235 u32_t next_timeout_time;
238#if LWIP_DEBUG_TIMERNAMES
239 LWIP_DEBUGF(
TIMERS_DEBUG, (
"tcpip: %s()\n", cyclic->handler_name));
244 next_timeout_time = (u32_t)(current_timeout_due_time + cyclic->interval_ms);
245 if (TIME_LESS_THAN(next_timeout_time, now)) {
247#if LWIP_DEBUG_TIMERNAMES
248 sys_timeout_abs((u32_t)(now + cyclic->interval_ms),
lwip_cyclic_timer, arg, cyclic->handler_name);
255#if LWIP_DEBUG_TIMERNAMES
256 sys_timeout_abs(next_timeout_time,
lwip_cyclic_timer, arg, cyclic->handler_name);
264void sys_timeouts_init(
void)
285#if LWIP_DEBUG_TIMERNAMES
287sys_timeout_debug(u32_t msecs, sys_timeout_handler handler,
void *arg,
const char *handler_name)
290sys_timeout(u32_t msecs, sys_timeout_handler handler,
void *arg)
293 u32_t next_timeout_time;
297 LWIP_ASSERT(
"Timeout time too long, max is LWIP_UINT32_MAX/4 msecs", msecs <= (LWIP_UINT32_MAX / 4));
299 next_timeout_time = (u32_t)(
sys_now() + msecs);
301#if LWIP_DEBUG_TIMERNAMES
302 sys_timeout_abs(next_timeout_time, handler, arg, handler_name);
304 sys_timeout_abs(next_timeout_time, handler, arg);
317sys_untimeout(sys_timeout_handler handler,
void *arg)
319 struct sys_timeo *prev_t, *t;
323 if (next_timeout == NULL) {
327 for (t = next_timeout, prev_t = NULL; t != NULL; prev_t = t, t = t->next) {
328 if ((t->h == handler) && (t->arg == arg)) {
331 if (prev_t == NULL) {
332 next_timeout = t->next;
334 prev_t->next = t->next;
352sys_check_timeouts(
void)
362 struct sys_timeo *tmptimeout;
363 sys_timeout_handler handler;
366 PBUF_CHECK_FREE_OOSEQ();
368 tmptimeout = next_timeout;
369 if (tmptimeout == NULL) {
373 if (TIME_LESS_THAN(now, tmptimeout->time)) {
378 next_timeout = tmptimeout->next;
379 handler = tmptimeout->h;
380 arg = tmptimeout->arg;
381 current_timeout_due_time = tmptimeout->time;
382#if LWIP_DEBUG_TIMERNAMES
383 if (handler != NULL) {
384 LWIP_DEBUGF(
TIMERS_DEBUG, (
"sct calling h=%s t=%"U32_F
" arg=%p\n",
385 tmptimeout->handler_name,
sys_now() - tmptimeout->time, arg));
389 if (handler != NULL) {
404sys_restart_timeouts(
void)
410 if (next_timeout == NULL) {
415 base = next_timeout->time;
417 for (t = next_timeout; t != NULL; t = t->next) {
418 t->time = (t->time - base) + now;
426sys_timeouts_sleeptime(
void)
432 if (next_timeout == NULL) {
436 if (TIME_LESS_THAN(next_timeout->time, now)) {
439 u32_t ret = (u32_t)(next_timeout->time - now);
440 LWIP_ASSERT(
"invalid sleeptime", ret <= LWIP_MAX_TIMEOUT);
448tcp_timer_needed(
void)
#define LWIP_UNUSED_ARG(x)
#define LWIP_CONST_CAST(target_type, val)
#define LWIP_ASSERT_CORE_LOCKED()
#define LWIP_TCPIP_THREAD_ALIVE()
void * memp_malloc(memp_t type)
void memp_free(memp_t type, void *mem)
const int lwip_num_cyclic_timers
#define SYS_TIMEOUTS_SLEEPTIME_INFINITE
const struct lwip_cyclic_timer lwip_cyclic_timers[]