2525#if defined(PICO_CYW43_SUPPORTED)
2626#include < pico/cyw43_arch.h>
2727#endif
28+
2829#if defined(__FREERTOS)
2930#include < pico/async_context_freertos.h>
30- static async_context_freertos_t lwip_ethernet_async_context_threadsafe_background;
31+ #include " FreeRTOS.h"
32+ #include " task.h"
33+ static async_context_freertos_t lwip_ethernet_async_context;
3134static StackType_t lwip_ethernet_async_context_freertos_task_stack[CYW43_TASK_STACK_SIZE];
3235
3336static async_context_t *lwip_ethernet_init_default_async_context (void ) {
3437 async_context_freertos_config_t config = async_context_freertos_default_config ();
3538#if configSUPPORT_STATIC_ALLOCATION && !CYW43_NO_DEFAULT_TASK_STACK
3639 config.task_stack = lwip_ethernet_async_context_freertos_task_stack;
3740#endif
38- if (async_context_freertos_init (&lwip_ethernet_async_context_threadsafe_background , &config)) {
39- return &lwip_ethernet_async_context_threadsafe_background .core ;
41+ if (async_context_freertos_init (&lwip_ethernet_async_context , &config)) {
42+ return &lwip_ethernet_async_context .core ;
4043 }
4144 return NULL ;
4245}
4346
4447#else
4548#include < pico/async_context_threadsafe_background.h>
46- static async_context_threadsafe_background_t lwip_ethernet_async_context_threadsafe_background ;
49+ static async_context_threadsafe_background_t lwip_ethernet_async_context ;
4750
4851static async_context_t *lwip_ethernet_init_default_async_context (void ) {
4952 async_context_threadsafe_background_config_t config = async_context_threadsafe_background_default_config ();
50- if (async_context_threadsafe_background_init (&lwip_ethernet_async_context_threadsafe_background , &config)) {
51- return &lwip_ethernet_async_context_threadsafe_background .core ;
53+ if (async_context_threadsafe_background_init (&lwip_ethernet_async_context , &config)) {
54+ return &lwip_ethernet_async_context .core ;
5255 }
5356 return NULL ;
5457}
@@ -63,7 +66,7 @@ bool __ethernetContextInitted = false;
6366// Async context that pumps the ethernet controllers
6467static async_when_pending_worker_t always_pending_update_timeout_worker;
6568static async_at_time_worker_t ethernet_timeout_worker;
66- // static async_context_t *_context = nullptr;
69+ static async_context_t *_context = nullptr ;
6770
6871// Theoretically support multiple interfaces
6972static std::map<int , std::function<void (void )>> _handlePacketList;
@@ -75,7 +78,7 @@ void ethernet_arch_lwip_begin() {
7578// return;
7679// }
7780// #endif
78- __startEthernetContext ();
81+ // __startEthernetContext();
7982// async_context_acquire_lock_blocking(_context);
8083}
8184
@@ -224,11 +227,26 @@ static void update_next_timeout(async_context_t *context, async_when_pending_wor
224227 async_context_add_at_time_worker_in_ms (context, ðernet_timeout_worker, _pollingPeriod);
225228}
226229
230+ TaskHandle_t sctTask;
231+
232+ void sct (void *param) {
233+ (void ) param;
234+ while (true ) {
235+ vTaskDelay (100 );
236+ ethernet_arch_lwip_gpio_mask (); // Ensure non-polled devices won't interrupt us
237+ for (auto handlePacket : _handlePacketList) {
238+ handlePacket.second ();
239+ }
240+ sys_check_timeouts ();
241+ ethernet_arch_lwip_gpio_unmask ();
242+ }
243+ }
227244void __startEthernetContext () {
228245 if (__ethernetContextInitted) {
229246 return ;
230247 }
231- #if 0
248+ // xTaskCreate(sct, "SCT", 256, nullptr, 1, &sctTask);
249+ #if 1
232250// #if defined(PICO_CYW43_SUPPORTED)
233251// if (rp2040.isPicoW()) {
234252// _context = cyw43_arch_async_context();
0 commit comments