diff options
author | lonkaars <loek@pipeframe.xyz> | 2024-05-09 15:18:51 +0200 |
---|---|---|
committer | lonkaars <loek@pipeframe.xyz> | 2024-05-09 15:18:51 +0200 |
commit | 21bfc93676c56e2265f330170d319da2c480987d (patch) | |
tree | 78caa1526cf0c570118d893e52df3301eb9e02a8 /main/init.cpp | |
parent | efc9870fb1ddd286954fc056b79dddf39f68353a (diff) |
working FreeRTOS + lwIP blink/wifi connect example again
Diffstat (limited to 'main/init.cpp')
-rw-r--r-- | main/init.cpp | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/main/init.cpp b/main/init.cpp index 425f591..48f3774 100644 --- a/main/init.cpp +++ b/main/init.cpp @@ -1,9 +1,15 @@ #include "config.h" #include "init.h" +#include <FreeRTOS.h> +#include <task.h> +#include <event_groups.h> + #include <pico/stdio.h> #include <pico/cyw43_arch.h> +EventGroupHandle_t init_complete; + static void init_stdio() { stdio_init_all(); } @@ -20,13 +26,29 @@ static void init_wifi() { if (cyw43_arch_wifi_connect_timeout_ms(CONF_NET_SSID, CONF_NET_PASS, CYW43_AUTH_WPA2_AES_PSK, CONF_NET_CONN_TIMEOUT)) panic("cyw43_arch_wifi_connect failed\n"); - // TODO: announce hostname + // TODO: announce hostname(?) } void init() { + init_complete = xEventGroupCreate(); + + // used for debug `printf` and `panic` on errors init_stdio(); - init_cyw34(); - init_wifi(); - // TODO: initialize i2c + + // defer other initialization until the task scheduler is running (important) + xTaskCreate((TaskFunction_t) [](void*) { + init_cyw34(); + init_wifi(); + // TODO: initialize i2c + + xEventGroupSetBits(init_complete, 1); + + // delete self + vTaskDelete(NULL); + }, "init", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 4, NULL); +} + +void await_init() { + xEventGroupWaitBits(init_complete, 1, pdFALSE, pdFALSE, portMAX_DELAY); } |