aboutsummaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-06-09 10:23:15 +0200
committerLoek Le Blansch <loek@pipeframe.xyz>2024-06-09 10:23:15 +0200
commitf6ac5839b6b54713126d430d8a037138d6619dce (patch)
tree4ff12033575cdf17787f4ccd91e93222df93b20f /main
parent228f50b8cb0e2bbd579cc8ae4f0a08e6d34af66e (diff)
clean up init functions
Diffstat (limited to 'main')
-rw-r--r--main/CMakeLists.txt2
-rw-r--r--main/blink.c16
-rw-r--r--main/blink.h4
-rw-r--r--main/i2c.c12
-rw-r--r--main/i2c.h6
-rw-r--r--main/init.c19
-rw-r--r--main/init.h29
-rw-r--r--main/main.c24
-rw-r--r--main/sock.c2
-rw-r--r--main/sock.h2
-rw-r--r--main/tasks.c17
-rw-r--r--main/tasks.h4
12 files changed, 56 insertions, 81 deletions
diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt
index 04e612d..7a0b136 100644
--- a/main/CMakeLists.txt
+++ b/main/CMakeLists.txt
@@ -21,6 +21,8 @@ add_executable(main
sock.c
i2c.c
mod.c
+ tasks.c
+ blink.c
)
pico_enable_stdio_usb(main 1)
diff --git a/main/blink.c b/main/blink.c
new file mode 100644
index 0000000..956e910
--- /dev/null
+++ b/main/blink.c
@@ -0,0 +1,16 @@
+#include <FreeRTOS.h>
+#include <task.h>
+#include <pico/cyw43_arch.h>
+
+#include "blink.h"
+#include "config.h"
+
+void blink_task() {
+ while (true) {
+ cyw43_arch_gpio_put(CFG_LED_PIN, 1);
+ vTaskDelay(50 / portTICK_PERIOD_MS);
+ cyw43_arch_gpio_put(CFG_LED_PIN, 0);
+ vTaskDelay(1000 / portTICK_PERIOD_MS);
+ }
+}
+
diff --git a/main/blink.h b/main/blink.h
new file mode 100644
index 0000000..51c5f32
--- /dev/null
+++ b/main/blink.h
@@ -0,0 +1,4 @@
+#pragma once
+
+void blink_task();
+
diff --git a/main/i2c.c b/main/i2c.c
index 43d17bf..5db5b61 100644
--- a/main/i2c.c
+++ b/main/i2c.c
@@ -1,14 +1,14 @@
-#include "i2c.h"
-#include "init.h"
-
-#include "pb-mod.h"
-
+#include <FreeRTOS.h>
+#include <task.h>
#include <stdio.h>
#include <stddef.h>
#include <stdint.h>
#include <pico/stdlib.h>
#include <hardware/i2c.h>
+#include "i2c.h"
+#include "pb-mod.h"
+
uint8_t* scan_bus(uint8_t *array) {
int ret;
int i = 0;
@@ -33,8 +33,6 @@ uint8_t* scan_bus(uint8_t *array) {
void bus_task() {
// scan bus for slaves
// send updates at regular intervals
- await_init();
-
vTaskDelay(1000 / portTICK_PERIOD_MS);
// int i = 0;
diff --git a/main/i2c.h b/main/i2c.h
index e873fae..dcc3997 100644
--- a/main/i2c.h
+++ b/main/i2c.h
@@ -1,12 +1,8 @@
#pragma once
// https://github.com/raspberrypi/pico-examples/tree/master/i2c
-#include <stddef.h>
-#include <stdint.h>
-#include <hardware/i2c.h>
-
#define MAX_SLAVES 10
-/** \brief looking for slave addresses and requesting updates */
+//! looking for slave addresses and requesting updates
void bus_task();
diff --git a/main/init.c b/main/init.c
index 9297093..1cfec9a 100644
--- a/main/init.c
+++ b/main/init.c
@@ -1,15 +1,13 @@
-#include "config.h"
-#include "init.h"
-#include "drv/rp2040/mod.h"
-
#include <FreeRTOS.h>
#include <task.h>
-#include <event_groups.h>
#include <pico/stdio.h>
#include <pico/cyw43_arch.h>
-EventGroupHandle_t init_complete;
+#include "config.h"
+#include "init.h"
+#include "tasks.h"
+#include "drv/rp2040/mod.h"
static void init_stdio() {
stdio_init_all();
@@ -46,16 +44,13 @@ static void async_init() {
#ifndef CFG_NET_DISABLE
init_wifi();
#endif
-
- xEventGroupSetBits(init_complete, 1);
+ init_tasks();
// delete self
vTaskDelete(NULL);
}
void init() {
- init_complete = xEventGroupCreate();
-
// used for debug `printf` and `panic` on errors
init_stdio();
@@ -63,7 +58,3 @@ void init() {
xTaskCreate((TaskFunction_t) async_init, "init", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 4, NULL);
}
-void await_init() {
- xEventGroupWaitBits(init_complete, 1, pdFALSE, pdFALSE, portMAX_DELAY);
-}
-
diff --git a/main/init.h b/main/init.h
index de9023c..73d2773 100644
--- a/main/init.h
+++ b/main/init.h
@@ -1,38 +1,11 @@
#pragma once
-#include <FreeRTOS.h>
-#include <event_groups.h>
-
-/**
- * \brief init function complete event group handle
- *
- * This is required to make sure the main task waits until initialization is
- * complete. Due to the combination of FreeRTOS + lwIP, the initialization
- * should be done while the task scheduler is running. Specifically the
- * cyw43_arch_init functions make the pico hang indefinitely when used while
- * the task scheduler is not running.
- *
- * \note `init_complete` only utilizes LSB, so `uxBitsToWaitFor` should always
- * be set to *1*
- */
-extern EventGroupHandle_t init_complete;
-
/**
- * \brief initialize all peripherals on the pico
+ * \brief initialize the main controller
*
* This function only synchronously initializes the standard input/output (used
* for `printf` and `panic`), and queues all other types of initialization in
* the `init` task using FreeRTOS.
- *
- * \note Tasks dependent on the wifi being initialized should use the
- * `init_complete` event group to wait for initialization to complete!
*/
void init();
-/**
- * \brief block task until all initialization is complete
- *
- * utility function, see above comments
- */
-void await_init();
-
diff --git a/main/main.c b/main/main.c
index 5d2abd1..1c615fc 100644
--- a/main/main.c
+++ b/main/main.c
@@ -1,34 +1,10 @@
#include <FreeRTOS.h>
#include <task.h>
-#include <pico/stdlib.h>
-#include <pico/time.h>
-
-#include "config.h"
#include "init.h"
-#include "sock.h"
-#include "i2c.h"
-
-void blink_task() {
- await_init(); // `blink_task` uses GPIO
-
- while (true) {
- cyw43_arch_gpio_put(CFG_LED_PIN, 1);
- vTaskDelay(50 / portTICK_PERIOD_MS);
- cyw43_arch_gpio_put(CFG_LED_PIN, 0);
- vTaskDelay(1000 / portTICK_PERIOD_MS);
- }
-}
int main() {
init();
-
- xTaskCreate((TaskFunction_t) blink_task, "blink", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 2, NULL);
-#ifndef CFG_SRV_DISABLE
- xTaskCreate((TaskFunction_t) serve_task, "serve", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 2, NULL);
-#endif
- xTaskCreate((TaskFunction_t) bus_task, "bus", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 2, NULL);
-
vTaskStartScheduler();
}
diff --git a/main/sock.c b/main/sock.c
index dc3d7ea..6a5ff72 100644
--- a/main/sock.c
+++ b/main/sock.c
@@ -79,8 +79,6 @@ void accept_handler(struct netconn* conn) {
}
void serve_task() {
- await_init();
-
printf("starting server...\n");
struct netconn* conn = netconn_new(NETCONN_TCP);
netconn_bind(conn, IP_ADDR_ANY, CFG_SRV_PORT);
diff --git a/main/sock.h b/main/sock.h
index f2db35d..61828fb 100644
--- a/main/sock.h
+++ b/main/sock.h
@@ -3,7 +3,7 @@
#include <stdint.h>
#include <stddef.h>
-/** \brief start listening for TCP socket requests */
+//! start listening for TCP socket requests
void serve_task();
void i2c_send(uint16_t addr, const char * data, size_t data_size);
diff --git a/main/tasks.c b/main/tasks.c
new file mode 100644
index 0000000..253c47b
--- /dev/null
+++ b/main/tasks.c
@@ -0,0 +1,17 @@
+#include <FreeRTOS.h>
+#include <task.h>
+
+#include "config.h"
+#include "tasks.h"
+
+#include "blink.h"
+#include "i2c.h"
+#include "sock.h"
+
+void init_tasks() {
+ xTaskCreate((TaskFunction_t) blink_task, "blink", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 2, NULL);
+#ifndef CFG_SRV_DISABLE
+ xTaskCreate((TaskFunction_t) serve_task, "serve", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 2, NULL);
+#endif
+ xTaskCreate((TaskFunction_t) bus_task, "bus", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 2, NULL);
+}
diff --git a/main/tasks.h b/main/tasks.h
new file mode 100644
index 0000000..002f830
--- /dev/null
+++ b/main/tasks.h
@@ -0,0 +1,4 @@
+#pragma once
+
+void init_tasks();
+