|
33 | 33 | #include "task.h"
|
34 | 34 | #include "semphr.h"
|
35 | 35 | static SemaphoreHandle_t _lwip_ethernet_mutex;
|
| 36 | +static TaskHandle_t _ethernetTask = nullptr; |
| 37 | +static void ethernetTask(void *param); |
36 | 38 | #else
|
37 | 39 | #include <pico/async_context_threadsafe_background.h>
|
38 | 40 | static async_context_threadsafe_background_t lwip_ethernet_async_context;
|
@@ -91,6 +93,12 @@ void ethernet_arch_lwip_end() {
|
91 | 93 |
|
92 | 94 | int __addEthernetPacketHandler(std::function<void(void)> _packetHandler) {
|
93 | 95 | 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 |
94 | 102 | ethernet_arch_lwip_begin();
|
95 | 103 | _handlePacketList.insert({id, _packetHandler});
|
96 | 104 | ethernet_arch_lwip_end();
|
@@ -204,7 +212,6 @@ static uint32_t _pollingPeriod = 20;
|
204 | 212 | // We have a background pump which calls sys_check_timeouts on a periodic basis
|
205 | 213 | // and polls all Ethernet interfaces
|
206 | 214 | #ifdef __FREERTOS
|
207 |
| -static TaskHandle_t _ethernetTask;; |
208 | 215 |
|
209 | 216 | static void stage2(void *cbData) {
|
210 | 217 | (void) cbData;
|
@@ -257,7 +264,6 @@ void __startEthernetContext() {
|
257 | 264 | }
|
258 | 265 | #ifdef __FREERTOS
|
259 | 266 | _lwip_ethernet_mutex = xSemaphoreCreateMutex();
|
260 |
| - xTaskCreate(ethernetTask, "EthPoll", 256, nullptr, 1, &_ethernetTask); |
261 | 267 | #else
|
262 | 268 | #if defined(PICO_CYW43_SUPPORTED)
|
263 | 269 | if (rp2040.isPicoW()) {
|
|
0 commit comments