1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-17 02:52:12 +01:00

made event dispatcher a callback

This commit is contained in:
Corvus Corax 2013-06-27 12:25:39 +02:00
parent 0c43346292
commit cd2cc821d6
11 changed files with 52 additions and 60 deletions

View File

@ -197,6 +197,9 @@ void PIOS_Board_Init(void)
PIOS_Assert(0);
}
/* Initialize the delayed callback library */
CallbackSchedulerInitialize();
/* Initialize UAVObject libraries */
EventDispatcherInitialize();
UAVObjInitialize();
@ -237,9 +240,6 @@ void PIOS_Board_Init(void)
AlarmsSet(SYSTEMALARMS_ALARM_BOOTFAULT, SYSTEMALARMS_ALARM_CRITICAL);
}
/* Initialize the delayed callback library */
CallbackSchedulerInitialize();
/* Set up pulse timers */
PIOS_TIM_InitClock(&tim_1_cfg);
PIOS_TIM_InitClock(&tim_2_cfg);

View File

@ -38,6 +38,9 @@ void PIOS_Board_Init(void)
/* Delay system */
PIOS_DELAY_Init();
/* Initialize the delayed callback library */
CallbackSchedulerInitialize();
/* Initialize UAVObject libraries */
EventDispatcherInitialize();
UAVObjInitialize();
@ -50,9 +53,6 @@ void PIOS_Board_Init(void)
PIOS_Assert(0);
}
/* Initialize the delayed callback library */
CallbackSchedulerInitialize();
/* Initialize the PiOS library */
PIOS_COM_Init();
}

View File

@ -95,6 +95,9 @@ void PIOS_Board_Init(void)
if (PIOS_TASK_MONITOR_Initialize(TASKINFO_RUNNING_NUMELEM)) {
PIOS_Assert(0);
}
/* Initialize the delayed callback library */
CallbackSchedulerInitialize();
/* Initialize UAVObject libraries */
EventDispatcherInitialize();
@ -143,9 +146,6 @@ void PIOS_Board_Init(void)
}
OPLinkSettingsGet(&oplinkSettings);
/* Initialize the delayed callback library */
CallbackSchedulerInitialize();
#if defined(PIOS_INCLUDE_TIM)
/* Set up pulse timers */
PIOS_TIM_InitClock(&tim_1_cfg);

View File

@ -38,6 +38,9 @@ void PIOS_Board_Init(void)
/* Delay system */
PIOS_DELAY_Init();
/* Initialize the delayed callback library */
CallbackSchedulerInitialize();
/* Initialize UAVObject libraries */
EventDispatcherInitialize();
UAVObjInitialize();
@ -50,9 +53,6 @@ void PIOS_Board_Init(void)
PIOS_Assert(0);
}
/* Initialize the delayed callback library */
CallbackSchedulerInitialize();
/* Initialize the PiOS library */
PIOS_COM_Init();
}

View File

@ -177,6 +177,9 @@ void PIOS_Board_Init(void)
PIOS_Assert(0);
}
/* Initialize the delayed callback library */
CallbackSchedulerInitialize();
/* Initialize UAVObject libraries */
EventDispatcherInitialize();
UAVObjInitialize();
@ -191,9 +194,6 @@ void PIOS_Board_Init(void)
/* Initialize the alarms library */
AlarmsInitialize();
/* Initialize the delayed callback library */
CallbackSchedulerInitialize();
/* IAP System Setup */
PIOS_IAP_Init();
uint16_t boot_count = PIOS_IAP_ReadBootCount();

View File

@ -388,6 +388,9 @@ void PIOS_Board_Init(void)
PIOS_Assert(0);
}
/* Initialize the delayed callback library */
CallbackSchedulerInitialize();
/* Initialize UAVObject libraries */
EventDispatcherInitialize();
UAVObjInitialize();
@ -396,9 +399,6 @@ void PIOS_Board_Init(void)
/* Initialize the alarms library */
AlarmsInitialize();
/* Initialize the delayed callback library */
CallbackSchedulerInitialize();
/* Set up pulse timers */
PIOS_TIM_InitClock(&tim_1_cfg);
PIOS_TIM_InitClock(&tim_3_cfg);

View File

@ -131,6 +131,9 @@ void PIOS_Board_Init(void)
/* Delay system */
PIOS_DELAY_Init();
/* Initialize the delayed callback library */
CallbackSchedulerInitialize();
/* Initialize UAVObject libraries */
EventDispatcherInitialize();
UAVObjInitialize();
@ -150,9 +153,6 @@ void PIOS_Board_Init(void)
PIOS_Assert(0);
}
/* Initialize the delayed callback library */
CallbackSchedulerInitialize();
#if defined(PIOS_INCLUDE_COM)
#if defined(PIOS_INCLUDE_TELEMETRY_RF) && 1
{

View File

@ -443,6 +443,9 @@ void PIOS_Board_Init(void)
PIOS_Assert(0);
}
/* Initialize the delayed callback library */
CallbackSchedulerInitialize();
/* Initialize UAVObject libraries */
EventDispatcherInitialize();
UAVObjInitialize();
@ -452,9 +455,6 @@ void PIOS_Board_Init(void)
/* Initialize the alarms library */
AlarmsInitialize();
/* Initialize the delayed callback library */
CallbackSchedulerInitialize();
/* Set up pulse timers */
PIOS_TIM_InitClock(&tim_1_cfg);
PIOS_TIM_InitClock(&tim_2_cfg);

View File

@ -131,6 +131,9 @@ void PIOS_Board_Init(void)
/* Delay system */
PIOS_DELAY_Init();
/* Initialize the delayed callback library */
CallbackSchedulerInitialize();
/* Initialize UAVObject libraries */
EventDispatcherInitialize();
UAVObjInitialize();
@ -151,9 +154,6 @@ void PIOS_Board_Init(void)
PIOS_Assert(0);
}
/* Initialize the delayed callback library */
CallbackSchedulerInitialize();
#if defined(PIOS_INCLUDE_COM)
#if defined(PIOS_INCLUDE_TELEMETRY_RF) && 1
{

View File

@ -123,6 +123,9 @@ void PIOS_Board_Init(void)
PIOS_Assert(0);
}
/* Initialize the delayed callback library */
CallbackSchedulerInitialize();
/* Initialize UAVObject libraries */
EventDispatcherInitialize();
UAVObjInitialize();
@ -134,9 +137,6 @@ void PIOS_Board_Init(void)
/* Initialize the alarms library */
AlarmsInitialize();
/* Initialize the delayed callback library */
CallbackSchedulerInitialize();
/* Configure IO ports */
/* Configure Telemetry port */

View File

@ -41,7 +41,8 @@
#define STACK_SIZE configMINIMAL_STACK_SIZE
#endif /* PIOS_EVENTDISPATCHER_STACK_SIZE */
#define TASK_PRIORITY (tskIDLE_PRIORITY + 3)
#define CALLBACK_PRIORITY CALLBACK_PRIORITY_CRITICAL
#define TASK_PRIORITY CALLBACK_TASK_FLIGHTCONTROL
#define MAX_UPDATE_PERIOD_MS 1000
// Private types
@ -70,7 +71,7 @@ typedef struct PeriodicObjectListStruct PeriodicObjectList;
// Private variables
static PeriodicObjectList *mObjList;
static xQueueHandle mQueue;
static xTaskHandle mEventTaskHandle;
static DelayedCallbackInfo *eventSchedulerCallback;
static xSemaphoreHandle mMutex;
static EventStats mStats;
@ -101,8 +102,8 @@ int32_t EventDispatcherInitialize()
// Create event queue
mQueue = xQueueCreate(MAX_QUEUE_SIZE, sizeof(EventCallbackInfo));
// Create task
xTaskCreate(eventTask, (signed char *)"Event", STACK_SIZE, NULL, TASK_PRIORITY, &mEventTaskHandle);
// Create callback
eventSchedulerCallback = DelayedCallbackCreate(&eventTask, CALLBACK_PRIORITY, TASK_PRIORITY, STACK_SIZE * 4);
// Done
return 0;
@ -145,7 +146,9 @@ int32_t EventCallbackDispatch(UAVObjEvent *ev, UAVObjEventCallback cb)
evInfo.cb = cb;
evInfo.queue = 0;
// Push to queue
return xQueueSend(mQueue, &evInfo, 0); // will not block if queue is full
int32_t result = xQueueSend(mQueue, &evInfo, 0); // will not block if queue is full
DelayedCallbackDispatch(eventSchedulerCallback);
return result;
}
/**
@ -276,38 +279,27 @@ static int32_t eventPeriodicUpdate(UAVObjEvent *ev, UAVObjEventCallback cb, xQue
}
/**
* Event task, responsible of invoking callbacks.
* Delayed event callback, responsible of invoking (event) callbacks.
*/
static void eventTask()
{
uint32_t timeToNextUpdateMs;
uint32_t delayMs;
static uint32_t timeToNextUpdateMs = 0;
EventCallbackInfo evInfo;
/* Must do this in task context to ensure that TaskMonitor has already finished its init */
PIOS_TASK_MONITOR_RegisterTask(TASKINFO_RUNNING_EVENTDISPATCHER, mEventTaskHandle);
// Initialize time
timeToNextUpdateMs = xTaskGetTickCount() * portTICK_RATE_MS;
// Loop forever
while (1) {
// Calculate delay time
delayMs = timeToNextUpdateMs - (xTaskGetTickCount() * portTICK_RATE_MS);
// Wait for queue message
if (xQueueReceive(mQueue, &evInfo, delayMs / portTICK_RATE_MS) == pdTRUE) {
// Invoke callback, if one
if (evInfo.cb != 0) {
evInfo.cb(&evInfo.ev); // the function is expected to copy the event information
}
}
// Process periodic updates
if ((xTaskGetTickCount() * portTICK_RATE_MS) >= timeToNextUpdateMs) {
timeToNextUpdateMs = processPeriodicUpdates();
// Wait for queue message
while (xQueueReceive(mQueue, &evInfo, 0) == pdTRUE) {
// Invoke callback, if one
if (evInfo.cb != 0) {
evInfo.cb(&evInfo.ev); // the function is expected to copy the event information
}
}
// Process periodic updates
if ((xTaskGetTickCount() * portTICK_RATE_MS) >= timeToNextUpdateMs) {
timeToNextUpdateMs = processPeriodicUpdates();
}
DelayedCallbackSchedule(eventSchedulerCallback, timeToNextUpdateMs, CALLBACK_UPDATEMODE_SOONER);
}
/**