Skip to content

Commit

Permalink
feat(mcknly#20): WIP - first pass at basic wifi service concepts
Browse files Browse the repository at this point in the history
  • Loading branch information
Kintar committed Jun 26, 2024
1 parent 98cf0e4 commit 0fc515f
Show file tree
Hide file tree
Showing 6 changed files with 149 additions and 4 deletions.
64 changes: 64 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion project.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
4 changes: 4 additions & 0 deletions rtos/rtos_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
15 changes: 12 additions & 3 deletions rtos/rtos_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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);
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
64 changes: 64 additions & 0 deletions services/wifi_service.c
Original file line number Diff line number Diff line change
@@ -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();
}
2 changes: 2 additions & 0 deletions wifi_optional.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 0fc515f

Please sign in to comment.