Skip to content
Snippets Groups Projects
Verified Commit 5f794074 authored by rahix's avatar rahix
Browse files

chore(epicardium): Move dispatcher into own module


Also add a mutex around API calls in preparation for future changes.

Signed-off-by: default avatarRahix <rahix@rahix.de>
parent 3b9393fe
No related branches found
No related tags found
No related merge requests found
......@@ -31,21 +31,6 @@ TaskHandle_t dispatcher_task_id;
void vBleTask(void *pvParameters);
/*
* API dispatcher task. This task will sleep until an API call is issued and
* then wake up to dispatch it.
*/
void vApiDispatcher(void *pvParameters)
{
LOG_DEBUG("dispatcher", "Ready.");
while (1) {
if (api_dispatcher_poll()) {
api_dispatcher_exec();
}
ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
}
}
int main(void)
{
LOG_INFO("startup", "Epicardium startup ...");
......
#include "modules/log.h"
#include "api/dispatcher.h"
#include "FreeRTOS.h"
#include "task.h"
#include "semphr.h"
#define TIMEOUT pdMS_TO_TICKS(2000)
static StaticSemaphore_t api_mutex_data;
SemaphoreHandle_t api_mutex = NULL;
/*
* API dispatcher task. This task will sleep until an API call is issued and
* then wake up to dispatch it.
*/
void vApiDispatcher(void *pvParameters)
{
api_mutex = xSemaphoreCreateMutexStatic(&api_mutex_data);
LOG_DEBUG("dispatcher", "Ready.");
while (1) {
if (api_dispatcher_poll()) {
if (xSemaphoreTake(api_mutex, TIMEOUT) != pdTRUE) {
LOG_ERR("dispatcher", "API mutex blocked");
continue;
}
api_dispatcher_exec();
xSemaphoreGive(api_mutex);
}
ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
}
}
module_sources = files(
'dispatcher.c',
'display.c',
'fileops.c',
'leds.c',
......
#ifndef MODULES_H
#define MODULES_H
#include "FreeRTOS.h"
#include "semphr.h"
#include <stdint.h>
/* ---------- Dispatcher --------------------------------------------------- */
void vApiDispatcher(void *pvParameters);
extern SemaphoreHandle_t api_mutex;
extern TaskHandle_t dispatcher_task_id;
/* ---------- Serial ------------------------------------------------------- */
#define SERIAL_READ_BUFFER_SIZE 128
void vSerialTask(void *pvParameters);
void serial_enqueue_char(char chr);
/* ---------- PMIC --------------------------------------------------------- */
......
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