@@ -30,7 +30,6 @@ typedef struct TCP_SERVER_T_ {
3030 struct tcp_pcb * server_pcb ;
3131 bool complete ;
3232 ip_addr_t gw ;
33- async_context_t * context ;
3433} TCP_SERVER_T ;
3534
3635typedef struct TCP_CONNECT_STATE_T_ {
@@ -269,24 +268,15 @@ static bool tcp_server_open(void *arg, const char *ap_name) {
269268 return true;
270269}
271270
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-
284271void key_pressed_func (void * param ) {
285272 assert (param );
273+ TCP_SERVER_T * state = (TCP_SERVER_T * )param ;
286274 int key = getchar_timeout_us (0 ); // get any pending key press but don't wait
287275 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;
290280 }
291281}
292282
@@ -305,9 +295,6 @@ int main() {
305295 }
306296
307297 // 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 );
311298 stdio_set_chars_available_callback (key_pressed_func , state );
312299
313300 const char * ap_name = "picow_test" ;
@@ -358,5 +345,6 @@ int main() {
358345 dns_server_deinit (& dns_server );
359346 dhcp_server_deinit (& dhcp_server );
360347 cyw43_arch_deinit ();
348+ printf ("Test complete\n" );
361349 return 0 ;
362350}
0 commit comments