Skip to content

Commit 75051b1

Browse files
Only make an EtherPoll task if we need to poll (#3098)
Save the minimal CPU overhead and ~1K of heap.
1 parent 4eb1c7d commit 75051b1

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

libraries/lwIP_Ethernet/src/LwipEthernet.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
#include "task.h"
3434
#include "semphr.h"
3535
static SemaphoreHandle_t _lwip_ethernet_mutex;
36+
static TaskHandle_t _ethernetTask = nullptr;
37+
static void ethernetTask(void *param);
3638
#else
3739
#include <pico/async_context_threadsafe_background.h>
3840
static async_context_threadsafe_background_t lwip_ethernet_async_context;
@@ -91,6 +93,12 @@ void ethernet_arch_lwip_end() {
9193

9294
int __addEthernetPacketHandler(std::function<void(void)> _packetHandler) {
9395
static int id = 0xdead;
96+
#ifdef __FREERTOS
97+
// Only create the task if we need to poll
98+
if (!_ethernetTask) {
99+
xTaskCreate(ethernetTask, "EthPoll", 256, nullptr, 1, &_ethernetTask);
100+
}
101+
#endif
94102
ethernet_arch_lwip_begin();
95103
_handlePacketList.insert({id, _packetHandler});
96104
ethernet_arch_lwip_end();
@@ -204,7 +212,6 @@ static uint32_t _pollingPeriod = 20;
204212
// We have a background pump which calls sys_check_timeouts on a periodic basis
205213
// and polls all Ethernet interfaces
206214
#ifdef __FREERTOS
207-
static TaskHandle_t _ethernetTask;;
208215

209216
static void stage2(void *cbData) {
210217
(void) cbData;
@@ -257,7 +264,6 @@ void __startEthernetContext() {
257264
}
258265
#ifdef __FREERTOS
259266
_lwip_ethernet_mutex = xSemaphoreCreateMutex();
260-
xTaskCreate(ethernetTask, "EthPoll", 256, nullptr, 1, &_ethernetTask);
261267
#else
262268
#if defined(PICO_CYW43_SUPPORTED)
263269
if (rp2040.isPicoW()) {

0 commit comments

Comments
 (0)