Optimizing LwIP Timers#
Introduction#
LwIP timer optimization is a power-saving feature that reduces CPU wake-ups by running protocol timers only when needed. Instead of periodic, fixed-interval timers that wake the CPU constantly, these optimizations implement on-demand and dynamic timers that activate only during actual protocol activity.
This feature is designed for battery-powered and low-power wireless devices where minimizing CPU wake-ups is critical for extending battery life.
Optimized Timer Types#
On-Demand Timers#
On-demand timers optimize power by waking up only when protocol events occur:
Run at standard lwIP intervals during active protocol operations
Calculate and wake up at exact protocol events to avoid unnecessary periodic wakeups
Stop completely when no protocol activity exists
Key characteristic: Event-driven wakeups with zero periodic overhead.
Dynamic Timers#
Dynamic timers switch between two modes based on protocol activity:
Active Mode: Timers run at standard lwIP intervals. Enters on user/network/protocol activity.
Eco Mode: Timers run at extended periodic intervals to save battery. Applies when device is idle, all sessions are healthy, and no protocol deadline is near.
Key characteristic: Wake up periodically even in ECO mode.
How to Enable#
Timer optimizations are disabled by default. You can enable them in two ways:
Option 1: Enable All Optimizations (Recommended)#
Add the following to your lwipopts.h to enable all timer optimizations at once:
#define SL_LWIP_ADAPTIVE_TIMERS 1This global enable switch activates all timer optimizations.
Option 2: Selective Enable#
Keep the global switch disabled and selectively enable individual timers based on your needs:
/* Keep global switch off */
#define SL_LWIP_ADAPTIVE_TIMERS 0
/* Enable only specific timers */
#define SL_LWIP_DHCP_ONDEMAND_TIMER 1
#define SL_LWIP_DNS_ONDEMAND_TIMER 1
#define SL_LWIP_TCP_DYNAMIC_TIMER 1Timer Configuration#
Each individual timer macro defaults to the value of SL_LWIP_ADAPTIVE_TIMERS. All timer optimizations are independent and can be enabled/disabled individually without affecting other timers.
DHCP On-Demand Timer#
#define SL_LWIP_DHCP_ONDEMAND_TIMER 1The DHCP On-Demand Timer uses per-interface timers that dynamically activate based on DHCP transaction state:
Runs only during DHCP negotiation (DORA sequence) and lease renewal operations
Auto-starts when DHCP negotiation begins and auto-stops when idle
Stops completely when interface acquires a valid IP lease
DNS On-Demand Timer#
#define SL_LWIP_DNS_ONDEMAND_TIMER 1The DNS On-Demand Timer dynamically schedules DNS timeouts based on DNS table activity:
Runs at DNS_TMR_INTERVAL when queries are active
Switches to minimum-TTL intervals when only cached entries exist
Stops completely when the DNS table is empty
ARP On-Demand Timer#
#define SL_LWIP_ETHARP_ONDEMAND_TIMER 1The ARP On-Demand Timer dynamically schedules ARP timeouts based on ARP table activity:
Runs at ARP_TMR_INTERVAL when entries need precise state handling
Switches to longer calculated intervals for stable entries
Stops completely when the ARP table is empty
ACD On-Demand Timer#
#define SL_LWIP_ACD_ONDEMAND_TIMER 1The ACD On-Demand Timer dynamically schedules ACD timeouts based on ACD instance activity:
Runs at ACD_TMR_INTERVAL when instances are in active states or during conflict defense windows
Stops completely when all instances are stable with no conflicts
MLD6 On-Demand Timer#
#define SL_LWIP_MLD6_ONDEMAND_TIMER 1The MLD6 On-Demand Timer dynamically schedules MLD timeouts based on multicast group activity:
Runs during active multicast group membership operations
Stops completely when no MLD operations are in progress
ND6 Dynamic Timer#
#define SL_LWIP_ND6_DYNAMIC_TIMER 1The ND6 Dynamic Timer adaptively adjusts IPv6 Neighbor Discovery timer intervals based on neighbor cache activity:
ACTIVE mode: Runs at ND6_TMR_ACTIVE_INTERVAL when neighbors are in active discovery states or during Duplicate Address Detection
ECO mode: Extends intervals up to ND6_TMR_ECO_INTERVAL when all neighbors are in stable states
TCP Dynamic Timer#
#define SL_LWIP_TCP_DYNAMIC_TIMER 1The TCP Dynamic Timer adaptively adjusts TCP timer intervals based on connection activity:
ACTIVE mode: Runs at TCP_TMR_INTERVAL when connections have recent activity or are in active states (pending data, retransmissions, keep-alive, etc.)
ECO mode: Extends intervals up to TCP_TMR_MAX_ECO_INTERVAL when all connections are idle beyond the threshold (TCP_ECO_THRESHOLD_TIME)
Configuration Parameters#
TCP Dynamic Timer#
The TCP dynamic timer provides two user-configurable parameters (both specified in milliseconds):
Note: Configure these values as multiples of TCP_TMR_INTERVAL.
TCP_TMR_MAX_ECO_INTERVAL#
Maximum sleep duration in ECO mode.
Minimum: TCP_ECO_THRESHOLD_TIME
Maximum: 30000ms (30 seconds)
TCP_ECO_THRESHOLD_TIME#
Idle time threshold before entering ECO mode from ACTIVE mode.
Default: 2000 ms (2 seconds) recommended
Minimum: TCP_TMR_INTERVAL
Maximum: TCP_TMR_MAX_ECO_INTERVAL
Tuning Guide:
Lower values = more aggressive power savings (may cause frequent mode switches)
Higher values = stays in ACTIVE mode longer (more responsive, higher power consumption)
ND6 Dynamic Timer#
Note: Configure this value as a multiple of ND6_TMR_ACTIVE_INTERVAL.
ND6_TMR_ECO_INTERVAL#
Maximum: 30000 ms (30 seconds)
Minimum: ND6_TMR_INTERVAL