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

Merge branch 'schneider/work_queue' into 'master'

Basic work queue

See merge request !427
parents ff46b8ad 9974238a
No related branches found
No related tags found
1 merge request!427Basic work queue
Pipeline #4972 passed
......@@ -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 * 4,
NULL,
tskIDLE_PRIORITY + 1,
NULL) != pdPASS) {
panic("Failed to create %s task!", "Work Queue");
}
workqueue_init();
/*
* Initialize serial driver data structures.
*/
......
......@@ -38,17 +38,14 @@ uint16_t epic_light_sensor_read()
return last_value;
}
static void readAdcCallback()
static void workpoll(void *data)
{
if (hwlock_acquire_nonblock(HWLOCK_ADC) != 0) {
/* Can't do much about this here ... Retry next time */
return;
}
ADC_StartConvert(ADC_CH_7, 0, 0);
ADC_GetData(&last_value);
epic_light_sensor_read();
}
hwlock_release(HWLOCK_ADC);
static void poll(TimerHandle_t xTimer)
{
workqueue_schedule(workpoll, NULL);
}
int epic_light_sensor_run()
......@@ -65,7 +62,7 @@ int epic_light_sensor_run()
READ_FREQ,
pdTRUE,
NULL,
readAdcCallback,
poll,
&poll_timer_buffer
);
// since &poll_timer_buffer is not NULL, xTimerCreateStatic should allways succeed, so
......
......@@ -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.
Finish editing this message first!
Please register or to comment