Skip to content
Snippets Groups Projects
Commit fe1356cb authored by schneider's avatar schneider
Browse files

feat(epicardium): Basic work queue

parent ae8f6b1c
No related branches found
No related tags found
No related merge requests found
......@@ -179,6 +179,18 @@ int main(void)
panic("Failed to create %s task!", "Lifecycle");
}
/* Work Queue */
if (xTaskCreate(
vWorkQueueTask,
(const char *)"Work Queue",
configMINIMAL_STACK_SIZE,
NULL,
tskIDLE_PRIORITY + 1,
NULL) != pdPASS) {
panic("Failed to create %s task!", "Work Queue");
}
workqueue_init();
/*
* Initialize serial driver data structures.
*/
......
......@@ -28,5 +28,6 @@ module_sources = files(
'usb.c',
'vibra.c',
'watchdog.c',
'work_queue.c',
'ws2812.c'
)
......@@ -138,6 +138,13 @@ extern gpio_cfg_t gpio_configs[];
void sleep_deepsleep(void);
/* ---------- RNG ---------------------------------------------------------- */
void rng_init(void);
/* ---------- Work Queue --------------------------------------------------- */
#define WORK_QUEUE_SIZE 20
void workqueue_init(void);
int workqueue_schedule(void (*func)(void *data), void *data);
void vWorkQueueTask(void *pvParameters);
#endif /* MODULES_H */
#include "epicardium.h"
#include "modules/log.h"
#include "modules.h"
#include "FreeRTOS.h"
#include "queue.h"
struct work {
void (*func)(void *data);
void *data;
};
static QueueHandle_t work_queue;
static uint8_t buffer[sizeof(struct work) * WORK_QUEUE_SIZE];
static StaticQueue_t work_queue_data;
void workqueue_init(void)
{
work_queue = xQueueCreateStatic(
WORK_QUEUE_SIZE, sizeof(struct work), buffer, &work_queue_data
);
}
int workqueue_schedule(void (*func)(void *data), void *data)
{
struct work work = { func, data };
if (xQueueSend(work_queue, &work, 0) != pdTRUE) {
/* Likely full */
LOG_WARN("workqueue", "could not schedule %p(%p)", func, data);
return -EAGAIN;
}
return 0;
}
void vWorkQueueTask(void *pvParameters)
{
struct work work;
workqueue_init();
while (1) {
if (xQueueReceive(work_queue, &work, portMAX_DELAY) == pdTRUE) {
if (work.func) {
work.func(work.data);
}
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment