dispatcher.c 665 Bytes
Newer Older
1
#include "modules/log.h"
2
#include "modules/mutex.h"
3 4 5 6 7 8 9 10

#include "api/dispatcher.h"

#include "FreeRTOS.h"
#include "task.h"

#define TIMEOUT pdMS_TO_TICKS(2000)

11 12
TaskHandle_t dispatcher_task_id;

13
struct mutex api_mutex = { 0 };
14

15 16
void dispatcher_mutex_init(void)
{
17
	mutex_create(&api_mutex);
18 19
}

20 21 22 23 24 25 26 27 28
/*
 * 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()) {
29
			mutex_lock(&api_mutex);
30
			api_dispatcher_exec();
31
			mutex_unlock(&api_mutex);
32 33 34 35
		}
		ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
	}
}