diff --git a/project.cmake b/project.cmake index a0c98ec..a7e7f3e 100644 --- a/project.cmake +++ b/project.cmake @@ -11,4 +11,6 @@ set(CLI_IFACE 0) set(PLATFORM rp2040) # BOARD - set the board being used (i.e. 'pico', 'pico_w', etc) -set(BOARD pico) +set(BOARD pico_w) + +set(WIFI_ENABLED 1) \ No newline at end of file diff --git a/rtos/rtos_utils.c b/rtos/rtos_utils.c index 047e3fe..7c7ecd1 100644 --- a/rtos/rtos_utils.c +++ b/rtos/rtos_utils.c @@ -38,4 +38,8 @@ void task_sched_update(uint32_t repeat, const TickType_t delay) { void task_delay_ms(uint32_t delay_ms) { TickType_t delay_ticks = (TickType_t)(delay_ms * configTICK_RATE_HZ / 1000); // convert millisecond delay to OS ticks vTaskDelay(delay_ticks); +} + +void task_self_terminate() { + vTaskDelete(NULL); } \ No newline at end of file diff --git a/rtos/rtos_utils.h b/rtos/rtos_utils.h index 3b096d5..6ede68b 100644 --- a/rtos/rtos_utils.h +++ b/rtos/rtos_utils.h @@ -35,8 +35,6 @@ */ void task_sched_update(uint32_t repeat, const TickType_t delay); -#endif - /** * @brief Delay a task by a specified number of milliseconds. * @@ -47,4 +45,15 @@ void task_sched_update(uint32_t repeat, const TickType_t delay); * * @return nothing */ -void task_delay_ms(uint32_t delay_ms); \ No newline at end of file +void task_delay_ms(uint32_t delay_ms); + +/** +* @brief Cause the currently running task to terminate +* +* Informs the OS that the currently running task should terminate. +* +* @return nothing +*/ +void task_self_terminate(); + +#endif \ No newline at end of file diff --git a/services/wifi_service.c b/services/wifi_service.c new file mode 100644 index 0000000..cb99881 --- /dev/null +++ b/services/wifi_service.c @@ -0,0 +1,64 @@ +/****************************************************************************** + * @file wifi_service.c + * + * @brief WiFi service implementation and FreeRTOS task creation. + * + * @author Alec Lanter + * + * @date 2024-06-25 + * + * @copyright Copyright (c) 2024 Alec Lanter + * Released under the MIT License + * + * SPDX-License-Identifier: MIT + ******************************************************************************/ + +#include "rtos_utils.h" +#include "services.h" +#include "service_queues.h" +#include "FreeRTOS.h" +#include "task.h" +#include "pico/cyw43_arch.h" + +#define SERVICE_NAME_WIFI wifi_init +#define PRIORITY_WIFI 2 +#define STACK_WIFI configMINIMAL_STACK_SIZE + +static void prvWifiTask(void *pvParameters); + +TaskHandle_t xWifiTask; + +BaseType_t wifi_service(void) { + if(cyw43_arch_init()) { + cli_print_raw("failed to initialize cyw43 architecture on pico_w"); + return pdFAIL; + } + + BaseType_t xReturn; + + xReturn = xTaskCreate( + prvWifiTask, + xstr(SERVICE_NAME_WIFI), + STACK_WIFI, + NULL, + PRIORITY_WIFI, + &xWifiTask + ); + + if (xReturn == pdPASS) { + cli_print_raw("wifi service started"); + } else { + cli_print_raw("Error starting wifi service"); + } + + return xReturn; +} + +static void prvWifiTask(void *pvParameters) { + cli_print_timestamped("wifi not implemented..."); + + // todo : on start, query flashfs for wifi configuration and, if exists, perform config + + // todo : wifi queue to handle reconfiguration on request from cli + task_self_terminate(); +} \ No newline at end of file diff --git a/wifi_optional.cmake b/wifi_optional.cmake index a9e6e2f..c2d432e 100644 --- a/wifi_optional.cmake +++ b/wifi_optional.cmake @@ -21,6 +21,8 @@ endif() add_library(WIFI_INTERFACE INTERFACE) target_include_directories(WIFI_INTERFACE INTERFACE ${WIFI_INCLUDE_PATH}) +target_sources(WIFI_INTERFACE INTERFACE + services/wifi_service.c) list(APPEND hardware_libs WIFI_INTERFACE) add_compile_definitions(WIFI_ENABLED) \ No newline at end of file