Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf02fa2e

Browse files
committed
rp2: Disable the LWIP tick timer when not needed.
Prevents lightsleep being woken up every 64ms to service LWIP timers, when:1. No netif is up, and2. No TCP sockets are activeThe TCP socket check may not be strictly necessary, but without ticking thetcp timer they won't ever time out by themselves.This work was funded through GitHub Sponsors.Signed-off-by: Angus Gratton <angus@redyak.com.au>
1 parentd01a981 commitf02fa2e

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

‎ports/rp2/mpnetworkport.c

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#ifMICROPY_PY_LWIP
3232

3333
#include"shared/runtime/softtimer.h"
34+
#include"lwip/netif.h"
3435
#include"lwip/timeouts.h"
3536

3637
// Poll lwIP every 64ms by default
@@ -39,6 +40,9 @@
3940
// Soft timer for running lwIP in the background.
4041
staticsoft_timer_entry_tmp_network_soft_timer;
4142

43+
// Callback for change of netif state
44+
NETIF_DECLARE_EXT_CALLBACK(netif_callback)
45+
4246
#ifMICROPY_PY_NETWORK_CYW43
4347
#include"lib/cyw43-driver/src/cyw43.h"
4448
#include"lib/cyw43-driver/src/cyw43_stats.h"
@@ -137,8 +141,27 @@ static void mp_network_soft_timer_callback(soft_timer_entry_t *self) {
137141
#ifMICROPY_PY_NETWORK_WIZNET5K
138142
wiznet5k_poll();
139143
#endif
144+
145+
// Only keep the timer running if any TCP sockets are active, or any netif is up
146+
structnetif*netif;
147+
externvoid*tcp_active_pcbs;
148+
boolkeep_running= (tcp_active_pcbs!=NULL);
149+
if (!keep_running) {
150+
NETIF_FOREACH(netif) {
151+
if (netif->flags&NETIF_FLAG_LINK_UP) {
152+
keep_running= true;
153+
break;
154+
}
155+
}
156+
}
157+
158+
// Periodic timer will re-queue as soon as this handler exits,
159+
// one shot timer will not
160+
mp_network_soft_timer.mode=keep_running ?SOFT_TIMER_MODE_PERIODIC :SOFT_TIMER_MODE_ONE_SHOT;
140161
}
141162

163+
staticvoidmp_network_netif_status_cb(structnetif*netif,netif_nsc_reason_treason,constnetif_ext_callback_args_t*args);
164+
142165
voidmod_network_lwip_init(void) {
143166
soft_timer_static_init(
144167
&mp_network_soft_timer,
@@ -147,7 +170,16 @@ void mod_network_lwip_init(void) {
147170
mp_network_soft_timer_callback
148171
);
149172

150-
soft_timer_reinsert(&mp_network_soft_timer,LWIP_TICK_RATE_MS);
173+
if (netif_callback.callback_fn==NULL) {
174+
netif_add_ext_callback(&netif_callback,mp_network_netif_status_cb);
175+
}
176+
}
177+
178+
staticvoidmp_network_netif_status_cb(structnetif*netif,netif_nsc_reason_treason,constnetif_ext_callback_args_t*args) {
179+
// Start the network soft timer any time an interface comes up
180+
if (reason==LWIP_NSC_LINK_CHANGED&&args->link_changed.state) {
181+
soft_timer_reinsert(&mp_network_soft_timer,LWIP_TICK_RATE_MS);
182+
}
151183
}
152184

153185
#endif// MICROPY_PY_LWIP

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp