Skip to content

Commit cbb5d61

Browse files
Simplify example of stdio_set_chars_available_callback (#495)
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
1 parent 69e63cc commit cbb5d61

File tree

1 file changed

+4
-13
lines changed

1 file changed

+4
-13
lines changed

pico_w/wifi/iperf/picow_iperf.c

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,12 @@ static void iperf_report(void *arg, enum lwiperf_report_type report_type,
3636
#endif
3737
}
3838

39-
// This "worker" function is called to safely perform work when instructed by key_pressed_func
40-
void key_pressed_worker_func(async_context_t *context, async_when_pending_worker_t *worker) {
41-
printf("Disabling wifi\n");
42-
cyw43_arch_disable_sta_mode();
43-
}
44-
45-
static async_when_pending_worker_t key_pressed_worker = {
46-
.do_work = key_pressed_worker_func
47-
};
48-
4939
void key_pressed_func(void *param) {
5040
int key = getchar_timeout_us(0); // get any pending key press but don't wait
5141
if (key == 'd' || key == 'D') {
52-
// We are probably in irq context so call wifi in a "worker"
53-
async_context_set_work_pending((async_context_t*)param, &key_pressed_worker);
42+
cyw43_arch_lwip_begin();
43+
cyw43_arch_disable_sta_mode();
44+
cyw43_arch_lwip_end();
5445
}
5546
}
5647

@@ -63,7 +54,6 @@ int main() {
6354
}
6455

6556
// Get notified if the user presses a key
66-
async_context_add_when_pending_worker(cyw43_arch_async_context(), &key_pressed_worker);
6757
stdio_set_chars_available_callback(key_pressed_func, cyw43_arch_async_context());
6858

6959
cyw43_arch_enable_sta_mode();
@@ -122,5 +112,6 @@ int main() {
122112
}
123113

124114
cyw43_arch_deinit();
115+
printf("Test complete\n");
125116
return 0;
126117
}

0 commit comments

Comments
 (0)