changes for timers
This commit is contained in:
parent
70f3933db1
commit
d90f8c06c2
|
@ -66,6 +66,13 @@ sys_thread_t g_lwip_task = NULL;
|
||||||
sys_mutex_t lock_tcpip_core;
|
sys_mutex_t lock_tcpip_core;
|
||||||
#endif /* LWIP_TCPIP_CORE_LOCKING */
|
#endif /* LWIP_TCPIP_CORE_LOCKING */
|
||||||
|
|
||||||
|
#if LWIP_TIMERS
|
||||||
|
/* wait for a message, timeouts are processed while waiting */
|
||||||
|
#define TCPIP_MBOX_FETCH(mbox, msg) sys_timeouts_mbox_fetch(mbox, msg)
|
||||||
|
#else /* LWIP_TIMERS */
|
||||||
|
/* wait for a message with timers disabled (e.g. pass a timer-check trigger into tcpip_thread) */
|
||||||
|
#define TCPIP_MBOX_FETCH(mbox, msg) sys_mbox_fetch(mbox, msg)
|
||||||
|
#endif /* LWIP_TIMERS */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The main lwIP thread. This thread has exclusive access to lwIP core functions
|
* The main lwIP thread. This thread has exclusive access to lwIP core functions
|
||||||
|
@ -99,7 +106,7 @@ tcpip_thread(void *arg)
|
||||||
UNLOCK_TCPIP_CORE();
|
UNLOCK_TCPIP_CORE();
|
||||||
LWIP_TCPIP_THREAD_ALIVE();
|
LWIP_TCPIP_THREAD_ALIVE();
|
||||||
/* wait for a message, timeouts are processed while waiting */
|
/* wait for a message, timeouts are processed while waiting */
|
||||||
sys_timeouts_mbox_fetch(&mbox, (void **)&msg);
|
TCPIP_MBOX_FETCH(&mbox, (void **)&msg);
|
||||||
LOCK_TCPIP_CORE();
|
LOCK_TCPIP_CORE();
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -44,8 +44,6 @@
|
||||||
#include "lwip/timers.h"
|
#include "lwip/timers.h"
|
||||||
#include "lwip/priv/tcp_priv.h"
|
#include "lwip/priv/tcp_priv.h"
|
||||||
|
|
||||||
#if LWIP_TIMERS
|
|
||||||
|
|
||||||
#include "lwip/def.h"
|
#include "lwip/def.h"
|
||||||
#include "lwip/memp.h"
|
#include "lwip/memp.h"
|
||||||
#include "lwip/priv/tcpip_priv.h"
|
#include "lwip/priv/tcpip_priv.h"
|
||||||
|
@ -62,11 +60,64 @@
|
||||||
#include "lwip/sys.h"
|
#include "lwip/sys.h"
|
||||||
#include "lwip/pbuf.h"
|
#include "lwip/pbuf.h"
|
||||||
|
|
||||||
|
#if LWIP_DEBUG_TIMERNAMES
|
||||||
|
#define HANDLER(x) x, #x
|
||||||
|
#else /* LWIP_DEBUG_TIMERNAMES */
|
||||||
|
#define HANDLER(x) x
|
||||||
|
#endif /* LWIP_DEBUG_TIMERNAMES */
|
||||||
|
|
||||||
|
#if ESP_DHCP
|
||||||
|
extern void dhcps_coarse_tmr(void);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/** This array contains all stack-internal cyclic timers. To get the number of
|
||||||
|
* timers, use LWIP_ARRAYSIZE() */
|
||||||
|
const struct lwip_cyclic_timer lwip_cyclic_timers[] = {
|
||||||
|
#if LWIP_TCP
|
||||||
|
/* The TCP timer is a special case: it does not have to run always and
|
||||||
|
* is triggered to start from TCP using tcp_timer_needed() */
|
||||||
|
{TCP_TMR_INTERVAL, HANDLER(tcp_tmr)},
|
||||||
|
#endif /* LWIP_TCP */
|
||||||
|
#if LWIP_IPV4
|
||||||
|
#if IP_REASSEMBLY
|
||||||
|
{IP_TMR_INTERVAL, HANDLER(ip_reass_tmr)},
|
||||||
|
#endif /* IP_REASSEMBLY */
|
||||||
|
#if LWIP_ARP
|
||||||
|
{ARP_TMR_INTERVAL, HANDLER(etharp_tmr)},
|
||||||
|
#endif /* LWIP_ARP */
|
||||||
|
#if LWIP_DHCP
|
||||||
|
{DHCP_COARSE_TIMER_MSECS, HANDLER(dhcp_coarse_tmr)},
|
||||||
|
{DHCP_FINE_TIMER_MSECS, HANDLER(dhcp_fine_tmr)},
|
||||||
|
#if ESP_DHCP
|
||||||
|
{DHCP_COARSE_TIMER_MSECS, HANDLER(dhcps_coarse_tmr)},
|
||||||
|
#endif
|
||||||
|
#endif /* LWIP_DHCP */
|
||||||
|
#if LWIP_AUTOIP
|
||||||
|
{AUTOIP_TMR_INTERVAL, HANDLER(autoip_tmr)},
|
||||||
|
#endif /* LWIP_AUTOIP */
|
||||||
|
#if LWIP_IGMP
|
||||||
|
{IGMP_TMR_INTERVAL, HANDLER(igmp_tmr)},
|
||||||
|
#endif /* LWIP_IGMP */
|
||||||
|
#endif /* LWIP_IPV4 */
|
||||||
|
#if LWIP_DNS
|
||||||
|
{DNS_TMR_INTERVAL, HANDLER(dns_tmr)},
|
||||||
|
#endif /* LWIP_DNS */
|
||||||
|
#if LWIP_IPV6
|
||||||
|
{ND6_TMR_INTERVAL, HANDLER(nd6_tmr)},
|
||||||
|
#if LWIP_IPV6_REASS
|
||||||
|
{IP6_REASS_TMR_INTERVAL, HANDLER(ip6_reass_tmr)},
|
||||||
|
#endif /* LWIP_IPV6_REASS */
|
||||||
|
#if LWIP_IPV6_MLD
|
||||||
|
{MLD6_TMR_INTERVAL, HANDLER(mld6_tmr)},
|
||||||
|
#endif /* LWIP_IPV6_MLD */
|
||||||
|
#endif /* LWIP_IPV6 */
|
||||||
|
};
|
||||||
|
|
||||||
|
#if LWIP_TIMERS && !LWIP_TIMERS_CUSTOM
|
||||||
|
|
||||||
/** The one and only timeout list */
|
/** The one and only timeout list */
|
||||||
static struct sys_timeo *next_timeout;
|
static struct sys_timeo *next_timeout;
|
||||||
#if NO_SYS
|
|
||||||
static u32_t timeouts_last_time;
|
static u32_t timeouts_last_time;
|
||||||
#endif /* NO_SYS */
|
|
||||||
|
|
||||||
#if LWIP_TCP
|
#if LWIP_TCP
|
||||||
/** global variable that shows if the tcp timer is currently scheduled or not */
|
/** global variable that shows if the tcp timer is currently scheduled or not */
|
||||||
|
@ -111,213 +162,35 @@ tcp_timer_needed(void)
|
||||||
}
|
}
|
||||||
#endif /* LWIP_TCP */
|
#endif /* LWIP_TCP */
|
||||||
|
|
||||||
#if LWIP_IPV4
|
|
||||||
#if IP_REASSEMBLY
|
|
||||||
/**
|
|
||||||
* Timer callback function that calls ip_reass_tmr() and reschedules itself.
|
|
||||||
*
|
|
||||||
* @param arg unused argument
|
|
||||||
*/
|
|
||||||
static void
|
|
||||||
ip_reass_timer(void *arg)
|
|
||||||
{
|
|
||||||
LWIP_UNUSED_ARG(arg);
|
|
||||||
LWIP_DEBUGF(TIMERS_DEBUG, ("tcpip: ip_reass_tmr()\n"));
|
|
||||||
ip_reass_tmr();
|
|
||||||
sys_timeout(IP_TMR_INTERVAL, ip_reass_timer, NULL);
|
|
||||||
}
|
|
||||||
#endif /* IP_REASSEMBLY */
|
|
||||||
|
|
||||||
#if LWIP_ARP
|
|
||||||
/**
|
|
||||||
* 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);
|
|
||||||
}
|
|
||||||
#endif /* LWIP_ARP */
|
|
||||||
|
|
||||||
#if LWIP_DHCP
|
|
||||||
/**
|
|
||||||
* Timer callback function that calls dhcp_coarse_tmr() and reschedules itself.
|
|
||||||
*
|
|
||||||
* @param arg unused argument
|
|
||||||
*/
|
|
||||||
static void
|
|
||||||
dhcp_timer_coarse(void *arg)
|
|
||||||
{
|
|
||||||
LWIP_UNUSED_ARG(arg);
|
|
||||||
LWIP_DEBUGF(TIMERS_DEBUG, ("tcpip: dhcp_coarse_tmr()\n"));
|
|
||||||
dhcp_coarse_tmr();
|
|
||||||
|
|
||||||
#if ESP_DHCP
|
|
||||||
extern void dhcps_coarse_tmr(void);
|
|
||||||
dhcps_coarse_tmr();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
sys_timeout(DHCP_COARSE_TIMER_MSECS, dhcp_timer_coarse, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Timer callback function that calls dhcp_fine_tmr() and reschedules itself.
|
|
||||||
*
|
|
||||||
* @param arg unused argument
|
|
||||||
*/
|
|
||||||
static void
|
|
||||||
dhcp_timer_fine(void *arg)
|
|
||||||
{
|
|
||||||
LWIP_UNUSED_ARG(arg);
|
|
||||||
LWIP_DEBUGF(TIMERS_DEBUG, ("tcpip: dhcp_fine_tmr()\n"));
|
|
||||||
dhcp_fine_tmr();
|
|
||||||
sys_timeout(DHCP_FINE_TIMER_MSECS, dhcp_timer_fine, NULL);
|
|
||||||
}
|
|
||||||
#endif /* LWIP_DHCP */
|
|
||||||
|
|
||||||
#if LWIP_AUTOIP
|
|
||||||
/**
|
|
||||||
* Timer callback function that calls autoip_tmr() and reschedules itself.
|
|
||||||
*
|
|
||||||
* @param arg unused argument
|
|
||||||
*/
|
|
||||||
static void
|
|
||||||
autoip_timer(void *arg)
|
|
||||||
{
|
|
||||||
LWIP_UNUSED_ARG(arg);
|
|
||||||
LWIP_DEBUGF(TIMERS_DEBUG, ("tcpip: autoip_tmr()\n"));
|
|
||||||
autoip_tmr();
|
|
||||||
sys_timeout(AUTOIP_TMR_INTERVAL, autoip_timer, NULL);
|
|
||||||
}
|
|
||||||
#endif /* LWIP_AUTOIP */
|
|
||||||
|
|
||||||
#if LWIP_IGMP
|
|
||||||
/**
|
|
||||||
* Timer callback function that calls igmp_tmr() and reschedules itself.
|
|
||||||
*
|
|
||||||
* @param arg unused argument
|
|
||||||
*/
|
|
||||||
static void
|
|
||||||
igmp_timer(void *arg)
|
|
||||||
{
|
|
||||||
LWIP_UNUSED_ARG(arg);
|
|
||||||
LWIP_DEBUGF(TIMERS_DEBUG, ("tcpip: igmp_tmr()\n"));
|
|
||||||
igmp_tmr();
|
|
||||||
sys_timeout(IGMP_TMR_INTERVAL, igmp_timer, NULL);
|
|
||||||
}
|
|
||||||
#endif /* LWIP_IGMP */
|
|
||||||
#endif /* LWIP_IPV4 */
|
|
||||||
|
|
||||||
#if LWIP_DNS
|
|
||||||
/**
|
|
||||||
* Timer callback function that calls dns_tmr() and reschedules itself.
|
|
||||||
*
|
|
||||||
* @param arg unused argument
|
|
||||||
*/
|
|
||||||
static void
|
|
||||||
dns_timer(void *arg)
|
|
||||||
{
|
|
||||||
LWIP_UNUSED_ARG(arg);
|
|
||||||
LWIP_DEBUGF(TIMERS_DEBUG, ("tcpip: dns_tmr()\n"));
|
|
||||||
dns_tmr();
|
|
||||||
sys_timeout(DNS_TMR_INTERVAL, dns_timer, NULL);
|
|
||||||
}
|
|
||||||
#endif /* LWIP_DNS */
|
|
||||||
|
|
||||||
#if LWIP_IPV6
|
|
||||||
/**
|
|
||||||
* Timer callback function that calls nd6_tmr() and reschedules itself.
|
|
||||||
*
|
|
||||||
* @param arg unused argument
|
|
||||||
*/
|
|
||||||
static void
|
|
||||||
nd6_timer(void *arg)
|
|
||||||
{
|
|
||||||
LWIP_UNUSED_ARG(arg);
|
|
||||||
LWIP_DEBUGF(TIMERS_DEBUG, ("tcpip: nd6_tmr()\n"));
|
|
||||||
nd6_tmr();
|
|
||||||
sys_timeout(ND6_TMR_INTERVAL, nd6_timer, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
#if LWIP_IPV6_REASS
|
|
||||||
/**
|
|
||||||
* Timer callback function that calls ip6_reass_tmr() and reschedules itself.
|
|
||||||
*
|
|
||||||
* @param arg unused argument
|
|
||||||
*/
|
|
||||||
static void
|
|
||||||
ip6_reass_timer(void *arg)
|
|
||||||
{
|
|
||||||
LWIP_UNUSED_ARG(arg);
|
|
||||||
LWIP_DEBUGF(TIMERS_DEBUG, ("tcpip: ip6_reass_tmr()\n"));
|
|
||||||
ip6_reass_tmr();
|
|
||||||
sys_timeout(IP6_REASS_TMR_INTERVAL, ip6_reass_timer, NULL);
|
|
||||||
}
|
|
||||||
#endif /* LWIP_IPV6_REASS */
|
|
||||||
|
|
||||||
#if LWIP_IPV6_MLD
|
|
||||||
/**
|
/**
|
||||||
* Timer callback function that calls mld6_tmr() and reschedules itself.
|
* Timer callback function that calls mld6_tmr() and reschedules itself.
|
||||||
*
|
*
|
||||||
* @param arg unused argument
|
* @param arg unused argument
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
mld6_timer(void *arg)
|
cyclic_timer(void *arg)
|
||||||
{
|
{
|
||||||
LWIP_UNUSED_ARG(arg);
|
const struct lwip_cyclic_timer* cyclic = (const struct lwip_cyclic_timer*)arg;
|
||||||
LWIP_DEBUGF(TIMERS_DEBUG, ("tcpip: mld6_tmr()\n"));
|
#if LWIP_DEBUG_TIMERNAMES
|
||||||
mld6_tmr();
|
LWIP_DEBUGF(TIMERS_DEBUG, ("tcpip: %s()\n", cyclic->handler_name));
|
||||||
sys_timeout(MLD6_TMR_INTERVAL, mld6_timer, NULL);
|
#endif
|
||||||
|
cyclic->handler();
|
||||||
|
sys_timeout(cyclic->interval_ms, cyclic_timer, arg);
|
||||||
}
|
}
|
||||||
#endif /* LWIP_IPV6_MLD */
|
|
||||||
#endif /* LWIP_IPV6 */
|
|
||||||
|
|
||||||
/** Initialize this module */
|
/** Initialize this module */
|
||||||
void sys_timeouts_init(void)
|
void sys_timeouts_init(void)
|
||||||
{
|
{
|
||||||
#if LWIP_IPV4
|
size_t i;
|
||||||
#if IP_REASSEMBLY
|
/* tcp_tmr() at index 0 is started on demand */
|
||||||
sys_timeout(IP_TMR_INTERVAL, ip_reass_timer, NULL);
|
for (i = (LWIP_TCP ? 1 : 0); i < LWIP_ARRAYSIZE(lwip_cyclic_timers); i++) {
|
||||||
#endif /* IP_REASSEMBLY */
|
/* we have to cast via size_t to get rid of const warning
|
||||||
#if LWIP_ARP
|
* (this is OK as cyclic_timer() casts back to const* */
|
||||||
sys_timeout(ARP_TMR_INTERVAL, arp_timer, NULL);
|
sys_timeout(lwip_cyclic_timers[i].interval_ms, cyclic_timer, LWIP_CONST_CAST(void*, &lwip_cyclic_timers[i]));
|
||||||
#endif /* LWIP_ARP */
|
}
|
||||||
#if LWIP_DHCP
|
|
||||||
|
|
||||||
sys_timeout(DHCP_COARSE_TIMER_MSECS, dhcp_timer_coarse, NULL);
|
|
||||||
sys_timeout(DHCP_FINE_TIMER_MSECS, dhcp_timer_fine, NULL);
|
|
||||||
#endif /* LWIP_DHCP */
|
|
||||||
#if LWIP_AUTOIP
|
|
||||||
sys_timeout(AUTOIP_TMR_INTERVAL, autoip_timer, NULL);
|
|
||||||
#endif /* LWIP_AUTOIP */
|
|
||||||
#if LWIP_IGMP
|
|
||||||
sys_timeout(IGMP_TMR_INTERVAL, igmp_timer, NULL);
|
|
||||||
#endif /* LWIP_IGMP */
|
|
||||||
#endif /* LWIP_IPV4 */
|
|
||||||
|
|
||||||
#if LWIP_DNS
|
|
||||||
sys_timeout(DNS_TMR_INTERVAL, dns_timer, NULL);
|
|
||||||
#endif /* LWIP_DNS */
|
|
||||||
|
|
||||||
#if LWIP_IPV6
|
|
||||||
sys_timeout(ND6_TMR_INTERVAL, nd6_timer, NULL);
|
|
||||||
#if LWIP_IPV6_REASS
|
|
||||||
sys_timeout(IP6_REASS_TMR_INTERVAL, ip6_reass_timer, NULL);
|
|
||||||
#endif /* LWIP_IPV6_REASS */
|
|
||||||
#if LWIP_IPV6_MLD
|
|
||||||
sys_timeout(MLD6_TMR_INTERVAL, mld6_timer, NULL);
|
|
||||||
#endif /* LWIP_IPV6_MLD */
|
|
||||||
#endif /* LWIP_IPV6 */
|
|
||||||
|
|
||||||
#if NO_SYS
|
|
||||||
/* Initialise timestamp for sys_check_timeouts */
|
/* Initialise timestamp for sys_check_timeouts */
|
||||||
timeouts_last_time = sys_now();
|
timeouts_last_time = sys_now();
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -334,19 +207,12 @@ void sys_timeouts_init(void)
|
||||||
void
|
void
|
||||||
sys_timeout_debug(u32_t msecs, sys_timeout_handler handler, void *arg, const char* handler_name)
|
sys_timeout_debug(u32_t msecs, sys_timeout_handler handler, void *arg, const char* handler_name)
|
||||||
#else /* LWIP_DEBUG_TIMERNAMES */
|
#else /* LWIP_DEBUG_TIMERNAMES */
|
||||||
|
|
||||||
#if ESP_LIGHT_SLEEP
|
|
||||||
u32_t LwipTimOutLim = 0; // For light sleep. time out. limit is 3000ms
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void
|
void
|
||||||
sys_timeout(u32_t msecs, sys_timeout_handler handler, void *arg)
|
sys_timeout(u32_t msecs, sys_timeout_handler handler, void *arg)
|
||||||
#endif /* LWIP_DEBUG_TIMERNAMES */
|
#endif /* LWIP_DEBUG_TIMERNAMES */
|
||||||
{
|
{
|
||||||
struct sys_timeo *timeout, *t;
|
struct sys_timeo *timeout, *t;
|
||||||
#if NO_SYS
|
|
||||||
u32_t now, diff;
|
u32_t now, diff;
|
||||||
#endif
|
|
||||||
|
|
||||||
timeout = (struct sys_timeo *)memp_malloc(MEMP_SYS_TIMEOUT);
|
timeout = (struct sys_timeo *)memp_malloc(MEMP_SYS_TIMEOUT);
|
||||||
if (timeout == NULL) {
|
if (timeout == NULL) {
|
||||||
|
@ -354,7 +220,6 @@ sys_timeout(u32_t msecs, sys_timeout_handler handler, void *arg)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if NO_SYS
|
|
||||||
now = sys_now();
|
now = sys_now();
|
||||||
if (next_timeout == NULL) {
|
if (next_timeout == NULL) {
|
||||||
diff = 0;
|
diff = 0;
|
||||||
|
@ -362,22 +227,11 @@ sys_timeout(u32_t msecs, sys_timeout_handler handler, void *arg)
|
||||||
} else {
|
} else {
|
||||||
diff = now - timeouts_last_time;
|
diff = now - timeouts_last_time;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
timeout->next = NULL;
|
timeout->next = NULL;
|
||||||
timeout->h = handler;
|
timeout->h = handler;
|
||||||
timeout->arg = arg;
|
timeout->arg = arg;
|
||||||
|
|
||||||
#if ESP_LIGHT_SLEEP
|
|
||||||
if(msecs < LwipTimOutLim)
|
|
||||||
msecs = LwipTimOutLim;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if NO_SYS
|
|
||||||
timeout->time = msecs + diff;
|
timeout->time = msecs + diff;
|
||||||
#else
|
|
||||||
timeout->time = msecs;
|
|
||||||
#endif
|
|
||||||
#if LWIP_DEBUG_TIMERNAMES
|
#if LWIP_DEBUG_TIMERNAMES
|
||||||
timeout->handler_name = handler_name;
|
timeout->handler_name = handler_name;
|
||||||
LWIP_DEBUGF(TIMERS_DEBUG, ("sys_timeout: %p msecs=%"U32_F" handler=%s arg=%p\n",
|
LWIP_DEBUGF(TIMERS_DEBUG, ("sys_timeout: %p msecs=%"U32_F" handler=%s arg=%p\n",
|
||||||
|
@ -399,6 +253,12 @@ sys_timeout(u32_t msecs, sys_timeout_handler handler, void *arg)
|
||||||
if (t->next == NULL || t->next->time > timeout->time) {
|
if (t->next == NULL || t->next->time > timeout->time) {
|
||||||
if (t->next != NULL) {
|
if (t->next != NULL) {
|
||||||
t->next->time -= timeout->time;
|
t->next->time -= timeout->time;
|
||||||
|
} else if (timeout->time > msecs) {
|
||||||
|
/* If this is the case, 'timeouts_last_time' and 'now' differs too much.
|
||||||
|
* This can be due to sys_check_timeouts() not being called at the right
|
||||||
|
* times, but also when stopping in a breakpoint. Anyway, let's assume
|
||||||
|
* this is not wanted, so add the first timer's time instead of 'diff' */
|
||||||
|
timeout->time = msecs + next_timeout->time;
|
||||||
}
|
}
|
||||||
timeout->next = t->next;
|
timeout->next = t->next;
|
||||||
t->next = timeout;
|
t->next = timeout;
|
||||||
|
@ -445,14 +305,17 @@ sys_untimeout(sys_timeout_handler handler, void *arg)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if NO_SYS
|
/**
|
||||||
|
* @ingroup lwip_nosys
|
||||||
/** Handle timeouts for NO_SYS==1 (i.e. without using
|
* Handle timeouts for NO_SYS==1 (i.e. without using
|
||||||
* tcpip_thread/sys_timeouts_mbox_fetch(). Uses sys_now() to call timeout
|
* tcpip_thread/sys_timeouts_mbox_fetch(). Uses sys_now() to call timeout
|
||||||
* handler functions when timeouts expire.
|
* handler functions when timeouts expire.
|
||||||
*
|
*
|
||||||
* Must be called periodically from your main loop.
|
* Must be called periodically from your main loop.
|
||||||
*/
|
*/
|
||||||
|
#if !NO_SYS && !defined __DOXYGEN__
|
||||||
|
static
|
||||||
|
#endif /* !NO_SYS */
|
||||||
void
|
void
|
||||||
sys_check_timeouts(void)
|
sys_check_timeouts(void)
|
||||||
{
|
{
|
||||||
|
@ -468,9 +331,7 @@ sys_check_timeouts(void)
|
||||||
/* this cares for wraparounds */
|
/* this cares for wraparounds */
|
||||||
diff = now - timeouts_last_time;
|
diff = now - timeouts_last_time;
|
||||||
do {
|
do {
|
||||||
#if PBUF_POOL_FREE_OOSEQ
|
|
||||||
PBUF_CHECK_FREE_OOSEQ();
|
PBUF_CHECK_FREE_OOSEQ();
|
||||||
#endif /* PBUF_POOL_FREE_OOSEQ */
|
|
||||||
had_one = 0;
|
had_one = 0;
|
||||||
tmptimeout = next_timeout;
|
tmptimeout = next_timeout;
|
||||||
if (tmptimeout && (tmptimeout->time <= diff)) {
|
if (tmptimeout && (tmptimeout->time <= diff)) {
|
||||||
|
@ -483,14 +344,22 @@ sys_check_timeouts(void)
|
||||||
arg = tmptimeout->arg;
|
arg = tmptimeout->arg;
|
||||||
#if LWIP_DEBUG_TIMERNAMES
|
#if LWIP_DEBUG_TIMERNAMES
|
||||||
if (handler != NULL) {
|
if (handler != NULL) {
|
||||||
LWIP_DEBUGF(TIMERS_DEBUG, ("sct calling h=%s arg=%p\n",
|
LWIP_DEBUGF(TIMERS_DEBUG, ("sct calling h=%s arg=%p\n",tmptimeout->handler_name, arg));
|
||||||
tmptimeout->handler_name, arg));
|
|
||||||
}
|
}
|
||||||
#endif /* LWIP_DEBUG_TIMERNAMES */
|
#endif /* LWIP_DEBUG_TIMERNAMES */
|
||||||
memp_free(MEMP_SYS_TIMEOUT, tmptimeout);
|
memp_free(MEMP_SYS_TIMEOUT, tmptimeout);
|
||||||
if (handler != NULL) {
|
if (handler != NULL) {
|
||||||
|
#if !NO_SYS
|
||||||
|
/* For LWIP_TCPIP_CORE_LOCKING, lock the core before calling the
|
||||||
|
* timeout handler function. */
|
||||||
|
LOCK_TCPIP_CORE();
|
||||||
|
#endif /* !NO_SYS */
|
||||||
handler(arg);
|
handler(arg);
|
||||||
|
#if !NO_SYS
|
||||||
|
UNLOCK_TCPIP_CORE();
|
||||||
|
#endif /* !NO_SYS */
|
||||||
}
|
}
|
||||||
|
LWIP_TCPIP_THREAD_ALIVE();
|
||||||
}
|
}
|
||||||
/* repeat until all expired timers have been called */
|
/* repeat until all expired timers have been called */
|
||||||
} while (had_one);
|
} while (had_one);
|
||||||
|
@ -511,6 +380,9 @@ sys_restart_timeouts(void)
|
||||||
/** Return the time left before the next timeout is due. If no timeouts are
|
/** Return the time left before the next timeout is due. If no timeouts are
|
||||||
* enqueued, returns 0xffffffff
|
* enqueued, returns 0xffffffff
|
||||||
*/
|
*/
|
||||||
|
#if !NO_SYS
|
||||||
|
static
|
||||||
|
#endif /* !NO_SYS */
|
||||||
u32_t
|
u32_t
|
||||||
sys_timeouts_sleeptime(void)
|
sys_timeouts_sleeptime(void)
|
||||||
{
|
{
|
||||||
|
@ -526,7 +398,7 @@ sys_timeouts_sleeptime(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#else /* NO_SYS */
|
#if !NO_SYS
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wait (forever) for a message to arrive in an mbox.
|
* Wait (forever) for a message to arrive in an mbox.
|
||||||
|
@ -538,66 +410,30 @@ sys_timeouts_sleeptime(void)
|
||||||
void ESP_IRAM_ATTR
|
void ESP_IRAM_ATTR
|
||||||
sys_timeouts_mbox_fetch(sys_mbox_t *mbox, void **msg)
|
sys_timeouts_mbox_fetch(sys_mbox_t *mbox, void **msg)
|
||||||
{
|
{
|
||||||
u32_t time_needed;
|
u32_t sleeptime;
|
||||||
struct sys_timeo *tmptimeout;
|
|
||||||
sys_timeout_handler handler;
|
|
||||||
void *arg;
|
|
||||||
|
|
||||||
again:
|
again:
|
||||||
if (!next_timeout) {
|
if (!next_timeout) {
|
||||||
time_needed = sys_arch_mbox_fetch(mbox, msg, 0);
|
sys_arch_mbox_fetch(mbox, msg, 0);
|
||||||
} else {
|
return;
|
||||||
if (next_timeout->time > 0) {
|
|
||||||
time_needed = sys_arch_mbox_fetch(mbox, msg, next_timeout->time);
|
|
||||||
} else {
|
|
||||||
time_needed = SYS_ARCH_TIMEOUT;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (time_needed == SYS_ARCH_TIMEOUT) {
|
sleeptime = sys_timeouts_sleeptime();
|
||||||
/* If time == SYS_ARCH_TIMEOUT, a timeout occurred before a message
|
if (sleeptime == 0 || sys_arch_mbox_fetch(mbox, msg, sleeptime) == SYS_ARCH_TIMEOUT) {
|
||||||
could be fetched. We should now call the timeout handler and
|
/* If a SYS_ARCH_TIMEOUT value is returned, a timeout occurred
|
||||||
deallocate the memory allocated for the timeout. */
|
* before a message could be fetched. */
|
||||||
tmptimeout = next_timeout;
|
sys_check_timeouts();
|
||||||
next_timeout = tmptimeout->next;
|
|
||||||
handler = tmptimeout->h;
|
|
||||||
arg = tmptimeout->arg;
|
|
||||||
#if LWIP_DEBUG_TIMERNAMES
|
|
||||||
if (handler != NULL) {
|
|
||||||
LWIP_DEBUGF(TIMERS_DEBUG, ("stmf calling h=%s arg=%p\n",
|
|
||||||
tmptimeout->handler_name, arg));
|
|
||||||
}
|
|
||||||
#endif /* LWIP_DEBUG_TIMERNAMES */
|
|
||||||
memp_free(MEMP_SYS_TIMEOUT, tmptimeout);
|
|
||||||
if (handler != NULL) {
|
|
||||||
/* For LWIP_TCPIP_CORE_LOCKING, lock the core before calling the
|
|
||||||
timeout handler function. */
|
|
||||||
LOCK_TCPIP_CORE();
|
|
||||||
handler(arg);
|
|
||||||
UNLOCK_TCPIP_CORE();
|
|
||||||
}
|
|
||||||
LWIP_TCPIP_THREAD_ALIVE();
|
|
||||||
|
|
||||||
/* We try again to fetch a message from the mbox. */
|
/* We try again to fetch a message from the mbox. */
|
||||||
goto again;
|
goto again;
|
||||||
} else {
|
|
||||||
/* If time != SYS_ARCH_TIMEOUT, a message was received before the timeout
|
|
||||||
occured. The time variable is set to the number of
|
|
||||||
milliseconds we waited for the message. */
|
|
||||||
if (time_needed < next_timeout->time) {
|
|
||||||
next_timeout->time -= time_needed;
|
|
||||||
} else {
|
|
||||||
next_timeout->time = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* NO_SYS */
|
#endif /* NO_SYS */
|
||||||
|
|
||||||
#else /* LWIP_TIMERS */
|
#else /* LWIP_TIMERS && !LWIP_TIMERS_CUSTOM */
|
||||||
/* Satisfy the TCP code which calls this function */
|
/* Satisfy the TCP code which calls this function */
|
||||||
void
|
void
|
||||||
tcp_timer_needed(void)
|
tcp_timer_needed(void)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
#endif /* LWIP_TIMERS */
|
#endif /* LWIP_TIMERS && !LWIP_TIMERS_CUSTOM */
|
||||||
|
|
||||||
|
|
|
@ -52,6 +52,11 @@
|
||||||
#define X8_F "02x"
|
#define X8_F "02x"
|
||||||
#endif /* X8_F */
|
#endif /* X8_F */
|
||||||
|
|
||||||
|
/** C++ const_cast<target_type>(val) equivalent to remove constness from a value (GCC -Wcast-qual) */
|
||||||
|
#ifndef LWIP_CONST_CAST
|
||||||
|
#define LWIP_CONST_CAST(target_type, val) ((target_type)((ptrdiff_t)val))
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -69,11 +69,16 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* NO_SYS_NO_TIMERS==1: Drop support for sys_timeout when NO_SYS==1
|
* LWIP_TIMERS==0: Drop support for sys_timeout and lwip-internal cyclic timers.
|
||||||
* Mainly for compatibility to old versions.
|
* (the array of lwip-internal cyclic timers is still provided)
|
||||||
|
* (check NO_SYS_NO_TIMERS for compatibility to old versions)
|
||||||
*/
|
*/
|
||||||
#ifndef NO_SYS_NO_TIMERS
|
#if !defined LWIP_TIMERS || defined __DOXYGEN__
|
||||||
#define NO_SYS_NO_TIMERS 0
|
#ifdef NO_SYS_NO_TIMERS
|
||||||
|
#define LWIP_TIMERS (!NO_SYS || (NO_SYS && !NO_SYS_NO_TIMERS))
|
||||||
|
#else
|
||||||
|
#define LWIP_TIMERS 1
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -169,12 +169,12 @@ struct pbuf_custom {
|
||||||
};
|
};
|
||||||
#endif /* LWIP_SUPPORT_CUSTOM_PBUF */
|
#endif /* LWIP_SUPPORT_CUSTOM_PBUF */
|
||||||
|
|
||||||
#if LWIP_TCP && TCP_QUEUE_OOSEQ
|
|
||||||
/** Define this to 0 to prevent freeing ooseq pbufs when the PBUF_POOL is empty */
|
/** Define this to 0 to prevent freeing ooseq pbufs when the PBUF_POOL is empty */
|
||||||
#ifndef PBUF_POOL_FREE_OOSEQ
|
#ifndef PBUF_POOL_FREE_OOSEQ
|
||||||
#define PBUF_POOL_FREE_OOSEQ 1
|
#define PBUF_POOL_FREE_OOSEQ 1
|
||||||
#endif /* PBUF_POOL_FREE_OOSEQ */
|
#endif /* PBUF_POOL_FREE_OOSEQ */
|
||||||
#if NO_SYS && PBUF_POOL_FREE_OOSEQ
|
#if LWIP_TCP && TCP_QUEUE_OOSEQ && NO_SYS && PBUF_POOL_FREE_OOSEQ
|
||||||
extern volatile u8_t pbuf_free_ooseq_pending;
|
extern volatile u8_t pbuf_free_ooseq_pending;
|
||||||
void pbuf_free_ooseq(void);
|
void pbuf_free_ooseq(void);
|
||||||
/** When not using sys_check_timeouts(), call PBUF_CHECK_FREE_OOSEQ()
|
/** When not using sys_check_timeouts(), call PBUF_CHECK_FREE_OOSEQ()
|
||||||
|
@ -184,8 +184,10 @@ void pbuf_free_ooseq(void);
|
||||||
/* pbuf_alloc() reported PBUF_POOL to be empty -> try to free some \
|
/* pbuf_alloc() reported PBUF_POOL to be empty -> try to free some \
|
||||||
ooseq queued pbufs now */ \
|
ooseq queued pbufs now */ \
|
||||||
pbuf_free_ooseq(); }}while(0)
|
pbuf_free_ooseq(); }}while(0)
|
||||||
#endif /* NO_SYS && PBUF_POOL_FREE_OOSEQ*/
|
#else /* LWIP_TCP && TCP_QUEUE_OOSEQ && NO_SYS && PBUF_POOL_FREE_OOSEQ */
|
||||||
#endif /* LWIP_TCP && TCP_QUEUE_OOSEQ */
|
/* Otherwise declare an empty PBUF_CHECK_FREE_OOSEQ */
|
||||||
|
#define PBUF_CHECK_FREE_OOSEQ()
|
||||||
|
#endif /* LWIP_TCP && TCP_QUEUE_OOSEQ && NO_SYS && PBUF_POOL_FREE_OOSEQ*/
|
||||||
|
|
||||||
/* Initializes the pbuf module. This call is empty for now, but may not be in future. */
|
/* Initializes the pbuf module. This call is empty for now, but may not be in future. */
|
||||||
#define pbuf_init()
|
#define pbuf_init()
|
||||||
|
|
|
@ -34,12 +34,6 @@
|
||||||
#define LWIP_HDR_TIMERS_H
|
#define LWIP_HDR_TIMERS_H
|
||||||
|
|
||||||
#include "lwip/opt.h"
|
#include "lwip/opt.h"
|
||||||
|
|
||||||
/* Timers are not supported when NO_SYS==1 and NO_SYS_NO_TIMERS==1 */
|
|
||||||
#define LWIP_TIMERS (!NO_SYS || (NO_SYS && !NO_SYS_NO_TIMERS))
|
|
||||||
|
|
||||||
#if LWIP_TIMERS
|
|
||||||
|
|
||||||
#include "lwip/err.h"
|
#include "lwip/err.h"
|
||||||
#if !NO_SYS
|
#if !NO_SYS
|
||||||
#include "lwip/sys.h"
|
#include "lwip/sys.h"
|
||||||
|
@ -57,6 +51,26 @@ extern "C" {
|
||||||
#endif /* LWIP_DEBUG*/
|
#endif /* LWIP_DEBUG*/
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/** Function prototype for a stack-internal timer function that has to be
|
||||||
|
* called at a defined interval */
|
||||||
|
typedef void (* lwip_cyclic_timer_handler)(void);
|
||||||
|
|
||||||
|
/** This struct contains information about a stack-internal timer function
|
||||||
|
* that has to be called at a defined interval */
|
||||||
|
struct lwip_cyclic_timer {
|
||||||
|
u32_t interval_ms;
|
||||||
|
lwip_cyclic_timer_handler handler;
|
||||||
|
#if LWIP_DEBUG_TIMERNAMES
|
||||||
|
const char* handler_name;
|
||||||
|
#endif /* LWIP_DEBUG_TIMERNAMES */
|
||||||
|
};
|
||||||
|
|
||||||
|
/** This array contains all stack-internal cyclic timers. To get the number of
|
||||||
|
* timers, use LWIP_ARRAYSIZE() */
|
||||||
|
extern const struct lwip_cyclic_timer lwip_cyclic_timers[];
|
||||||
|
|
||||||
|
#if LWIP_TIMERS
|
||||||
|
|
||||||
/** Function prototype for a timeout callback function. Register such a function
|
/** Function prototype for a timeout callback function. Register such a function
|
||||||
* using sys_timeout().
|
* using sys_timeout().
|
||||||
*
|
*
|
||||||
|
@ -84,18 +98,20 @@ void sys_timeout(u32_t msecs, sys_timeout_handler handler, void *arg);
|
||||||
#endif /* LWIP_DEBUG_TIMERNAMES */
|
#endif /* LWIP_DEBUG_TIMERNAMES */
|
||||||
|
|
||||||
void sys_untimeout(sys_timeout_handler handler, void *arg);
|
void sys_untimeout(sys_timeout_handler handler, void *arg);
|
||||||
|
void sys_restart_timeouts(void);
|
||||||
#if NO_SYS
|
#if NO_SYS
|
||||||
void sys_check_timeouts(void);
|
void sys_check_timeouts(void);
|
||||||
void sys_restart_timeouts(void);
|
|
||||||
u32_t sys_timeouts_sleeptime(void);
|
u32_t sys_timeouts_sleeptime(void);
|
||||||
#else /* NO_SYS */
|
#else /* NO_SYS */
|
||||||
void sys_timeouts_mbox_fetch(sys_mbox_t *mbox, void **msg);
|
void sys_timeouts_mbox_fetch(sys_mbox_t *mbox, void **msg);
|
||||||
#endif /* NO_SYS */
|
#endif /* NO_SYS */
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* LWIP_TIMERS */
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* LWIP_TIMERS */
|
|
||||||
#endif /* LWIP_HDR_TIMERS_H */
|
#endif /* LWIP_HDR_TIMERS_H */
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue