From e583fd54dfba74591661b188f7ed7647031f7982 Mon Sep 17 00:00:00 2001 From: Peter Harper Date: Wed, 1 May 2024 18:16:22 +0100 Subject: [PATCH] Simplify example of stdio_set_chars_available_callback The example in here uses an async callback to avoid a race when using stdio_usb. But there's a fix available for this issue so simplify the example. To test pass -DPICO_STDIO_USB=1 on the cmake command line. Fixes #461 --- pico_w/wifi/iperf/picow_iperf.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/pico_w/wifi/iperf/picow_iperf.c b/pico_w/wifi/iperf/picow_iperf.c index c99671f13..927e5c7b2 100644 --- a/pico_w/wifi/iperf/picow_iperf.c +++ b/pico_w/wifi/iperf/picow_iperf.c @@ -36,21 +36,12 @@ static void iperf_report(void *arg, enum lwiperf_report_type report_type, #endif } -// This "worker" function is called to safely perform work when instructed by key_pressed_func -void key_pressed_worker_func(async_context_t *context, async_when_pending_worker_t *worker) { - printf("Disabling wifi\n"); - cyw43_arch_disable_sta_mode(); -} - -static async_when_pending_worker_t key_pressed_worker = { - .do_work = key_pressed_worker_func -}; - void key_pressed_func(void *param) { int key = getchar_timeout_us(0); // get any pending key press but don't wait if (key == 'd' || key == 'D') { - // We are probably in irq context so call wifi in a "worker" - async_context_set_work_pending((async_context_t*)param, &key_pressed_worker); + cyw43_arch_lwip_begin(); + cyw43_arch_disable_sta_mode(); + cyw43_arch_lwip_end(); } } @@ -63,7 +54,6 @@ int main() { } // Get notified if the user presses a key - async_context_add_when_pending_worker(cyw43_arch_async_context(), &key_pressed_worker); stdio_set_chars_available_callback(key_pressed_func, cyw43_arch_async_context()); cyw43_arch_enable_sta_mode(); @@ -122,5 +112,6 @@ int main() { } cyw43_arch_deinit(); + printf("Test complete\n"); return 0; }