@@ -30,7 +30,6 @@ typedef struct TCP_SERVER_T_ {
30
30
struct tcp_pcb * server_pcb ;
31
31
bool complete ;
32
32
ip_addr_t gw ;
33
- async_context_t * context ;
34
33
} TCP_SERVER_T ;
35
34
36
35
typedef struct TCP_CONNECT_STATE_T_ {
@@ -269,24 +268,15 @@ static bool tcp_server_open(void *arg, const char *ap_name) {
269
268
return true;
270
269
}
271
270
272
- // This "worker" function is called to safely perform work when instructed by key_pressed_func
273
- void key_pressed_worker_func (async_context_t * context , async_when_pending_worker_t * worker ) {
274
- assert (worker -> user_data );
275
- printf ("Disabling wifi\n" );
276
- cyw43_arch_disable_ap_mode ();
277
- ((TCP_SERVER_T * )(worker -> user_data ))-> complete = true;
278
- }
279
-
280
- static async_when_pending_worker_t key_pressed_worker = {
281
- .do_work = key_pressed_worker_func
282
- };
283
-
284
271
void key_pressed_func (void * param ) {
285
272
assert (param );
273
+ TCP_SERVER_T * state = (TCP_SERVER_T * )param ;
286
274
int key = getchar_timeout_us (0 ); // get any pending key press but don't wait
287
275
if (key == 'd' || key == 'D' ) {
288
- // We are probably in irq context so call wifi in a "worker"
289
- async_context_set_work_pending (((TCP_SERVER_T * )param )-> context , & key_pressed_worker );
276
+ cyw43_arch_lwip_begin ();
277
+ cyw43_arch_disable_ap_mode ();
278
+ cyw43_arch_lwip_end ();
279
+ state -> complete = true;
290
280
}
291
281
}
292
282
@@ -305,9 +295,6 @@ int main() {
305
295
}
306
296
307
297
// Get notified if the user presses a key
308
- state -> context = cyw43_arch_async_context ();
309
- key_pressed_worker .user_data = state ;
310
- async_context_add_when_pending_worker (cyw43_arch_async_context (), & key_pressed_worker );
311
298
stdio_set_chars_available_callback (key_pressed_func , state );
312
299
313
300
const char * ap_name = "picow_test" ;
@@ -358,5 +345,6 @@ int main() {
358
345
dns_server_deinit (& dns_server );
359
346
dhcp_server_deinit (& dhcp_server );
360
347
cyw43_arch_deinit ();
348
+ printf ("Test complete\n" );
361
349
return 0 ;
362
350
}
0 commit comments