diff --git a/flight/modules/AltitudeHold/altitudehold.c b/flight/modules/AltitudeHold/altitudehold.c index dd0fc5bf5..ce7c556c8 100644 --- a/flight/modules/AltitudeHold/altitudehold.c +++ b/flight/modules/AltitudeHold/altitudehold.c @@ -86,7 +86,7 @@ int32_t AltitudeHoldStart() { // Start main task SettingsUpdatedCb(NULL); - DelayedCallbackDispatch(altitudeHoldCBInfo); + PIOS_CALLBACKSCHEDULER_Dispatch(altitudeHoldCBInfo); return 0; } @@ -103,7 +103,7 @@ int32_t AltitudeHoldInitialize() // Create object queue - altitudeHoldCBInfo = DelayedCallbackCreate(&altitudeHoldTask, CALLBACK_PRIORITY, CBTASK_PRIORITY, CALLBACKINFO_RUNNING_ALTITUDEHOLD, STACK_SIZE_BYTES); + altitudeHoldCBInfo = PIOS_CALLBACKSCHEDULER_Create(&altitudeHoldTask, CALLBACK_PRIORITY, CBTASK_PRIORITY, CALLBACKINFO_RUNNING_ALTITUDEHOLD, STACK_SIZE_BYTES); AltitudeHoldSettingsConnectCallback(&SettingsUpdatedCb); return 0; @@ -130,7 +130,7 @@ static void altitudeHoldTask(void) pid_zero(&pid0); pid_zero(&pid1); StabilizationDesiredThrottleGet(&startThrottle); - DelayedCallbackSchedule(altitudeHoldCBInfo, DESIRED_UPDATE_RATE_MS, CALLBACK_UPDATEMODE_SOONER); + PIOS_CALLBACKSCHEDULER_Schedule(altitudeHoldCBInfo, DESIRED_UPDATE_RATE_MS, CALLBACK_UPDATEMODE_SOONER); return; break; @@ -192,7 +192,7 @@ static void altitudeHoldTask(void) StabilizationDesiredSet(&stab); - DelayedCallbackSchedule(altitudeHoldCBInfo, DESIRED_UPDATE_RATE_MS, CALLBACK_UPDATEMODE_SOONER); + PIOS_CALLBACKSCHEDULER_Schedule(altitudeHoldCBInfo, DESIRED_UPDATE_RATE_MS, CALLBACK_UPDATEMODE_SOONER); } static void SettingsUpdatedCb(__attribute__((unused)) UAVObjEvent *ev) diff --git a/flight/modules/CallbackTest/callbacktest.c b/flight/modules/CallbackTest/callbacktest.c index 56d8243a2..d5be343de 100644 --- a/flight/modules/CallbackTest/callbacktest.c +++ b/flight/modules/CallbackTest/callbacktest.c @@ -65,13 +65,13 @@ int32_t CallbackTestInitialize() { mutex = xSemaphoreCreateRecursiveMutex(); - cbinfo[0] = DelayedCallbackCreate(&DelayedCb0, CALLBACK_PRIORITY_LOW, tskIDLE_PRIORITY + 2, -1, STACK_SIZE); - cbinfo[1] = DelayedCallbackCreate(&DelayedCb1, CALLBACK_PRIORITY_LOW, tskIDLE_PRIORITY + 2, -1, STACK_SIZE); - cbinfo[2] = DelayedCallbackCreate(&DelayedCb2, CALLBACK_PRIORITY_CRITICAL, tskIDLE_PRIORITY + 2, -1, STACK_SIZE); - cbinfo[3] = DelayedCallbackCreate(&DelayedCb3, CALLBACK_PRIORITY_CRITICAL, tskIDLE_PRIORITY + 2, -1, STACK_SIZE); - cbinfo[4] = DelayedCallbackCreate(&DelayedCb4, CALLBACK_PRIORITY_LOW, tskIDLE_PRIORITY + 2, -1, STACK_SIZE); - cbinfo[5] = DelayedCallbackCreate(&DelayedCb5, CALLBACK_PRIORITY_LOW, tskIDLE_PRIORITY + 2, -1, STACK_SIZE); - cbinfo[6] = DelayedCallbackCreate(&DelayedCb6, CALLBACK_PRIORITY_LOW, tskIDLE_PRIORITY + 20, -1, STACK_SIZE); + cbinfo[0] = PIOS_CALLBACKSCHEDULER_Create(&DelayedCb0, CALLBACK_PRIORITY_LOW, tskIDLE_PRIORITY + 2, -1, STACK_SIZE); + cbinfo[1] = PIOS_CALLBACKSCHEDULER_Create(&DelayedCb1, CALLBACK_PRIORITY_LOW, tskIDLE_PRIORITY + 2, -1, STACK_SIZE); + cbinfo[2] = PIOS_CALLBACKSCHEDULER_Create(&DelayedCb2, CALLBACK_PRIORITY_CRITICAL, tskIDLE_PRIORITY + 2, -1, STACK_SIZE); + cbinfo[3] = PIOS_CALLBACKSCHEDULER_Create(&DelayedCb3, CALLBACK_PRIORITY_CRITICAL, tskIDLE_PRIORITY + 2, -1, STACK_SIZE); + cbinfo[4] = PIOS_CALLBACKSCHEDULER_Create(&DelayedCb4, CALLBACK_PRIORITY_LOW, tskIDLE_PRIORITY + 2, -1, STACK_SIZE); + cbinfo[5] = PIOS_CALLBACKSCHEDULER_Create(&DelayedCb5, CALLBACK_PRIORITY_LOW, tskIDLE_PRIORITY + 2, -1, STACK_SIZE); + cbinfo[6] = PIOS_CALLBACKSCHEDULER_Create(&DelayedCb6, CALLBACK_PRIORITY_LOW, tskIDLE_PRIORITY + 20, -1, STACK_SIZE); return 0; @@ -79,22 +79,22 @@ int32_t CallbackTestInitialize() int32_t CallbackTestStart() { xSemaphoreTakeRecursive(mutex, portMAX_DELAY); - DelayedCallbackDispatch(cbinfo[3]); - DelayedCallbackDispatch(cbinfo[2]); - DelayedCallbackDispatch(cbinfo[1]); - DelayedCallbackDispatch(cbinfo[0]); + PIOS_CALLBACKSCHEDULER_Dispatch(cbinfo[3]); + PIOS_CALLBACKSCHEDULER_Dispatch(cbinfo[2]); + PIOS_CALLBACKSCHEDULER_Dispatch(cbinfo[1]); + PIOS_CALLBACKSCHEDULER_Dispatch(cbinfo[0]); // different callback priorities within a taskpriority - DelayedCallbackSchedule(cbinfo[4], 30000, CALLBACK_UPDATEMODE_NONE); - DelayedCallbackSchedule(cbinfo[4], 5000, CALLBACK_UPDATEMODE_OVERRIDE); - DelayedCallbackSchedule(cbinfo[4], 4000, CALLBACK_UPDATEMODE_SOONER); - DelayedCallbackSchedule(cbinfo[4], 10000, CALLBACK_UPDATEMODE_SOONER); - DelayedCallbackSchedule(cbinfo[4], 1000, CALLBACK_UPDATEMODE_LATER); - DelayedCallbackSchedule(cbinfo[4], 4800, CALLBACK_UPDATEMODE_LATER); - DelayedCallbackSchedule(cbinfo[4], 48000, CALLBACK_UPDATEMODE_NONE); + PIOS_CALLBACKSCHEDULER_Schedule(cbinfo[4], 30000, CALLBACK_UPDATEMODE_NONE); + PIOS_CALLBACKSCHEDULER_Schedule(cbinfo[4], 5000, CALLBACK_UPDATEMODE_OVERRIDE); + PIOS_CALLBACKSCHEDULER_Schedule(cbinfo[4], 4000, CALLBACK_UPDATEMODE_SOONER); + PIOS_CALLBACKSCHEDULER_Schedule(cbinfo[4], 10000, CALLBACK_UPDATEMODE_SOONER); + PIOS_CALLBACKSCHEDULER_Schedule(cbinfo[4], 1000, CALLBACK_UPDATEMODE_LATER); + PIOS_CALLBACKSCHEDULER_Schedule(cbinfo[4], 4800, CALLBACK_UPDATEMODE_LATER); + PIOS_CALLBACKSCHEDULER_Schedule(cbinfo[4], 48000, CALLBACK_UPDATEMODE_NONE); // should be at 4.8 seconds after this, allowing for exactly 9 prints of the following - DelayedCallbackSchedule(cbinfo[5], 500, CALLBACK_UPDATEMODE_NONE); + PIOS_CALLBACKSCHEDULER_Schedule(cbinfo[5], 500, CALLBACK_UPDATEMODE_NONE); // delayed counter with 500 ms - DelayedCallbackDispatch(cbinfo[6]); + PIOS_CALLBACKSCHEDULER_Dispatch(cbinfo[6]); // high task prio xSemaphoreGiveRecursive(mutex); return 0; @@ -104,28 +104,28 @@ static void DelayedCb0() { DEBUGPRINT("delayed counter low prio 0 updated: %i\n", counter[0]); if (++counter[0] < 10) { - DelayedCallbackDispatch(cbinfo[0]); + PIOS_CALLBACKSCHEDULER_Dispatch(cbinfo[0]); } } static void DelayedCb1() { DEBUGPRINT("delayed counter low prio 1 updated: %i\n", counter[1]); if (++counter[1] < 10) { - DelayedCallbackDispatch(cbinfo[1]); + PIOS_CALLBACKSCHEDULER_Dispatch(cbinfo[1]); } } static void DelayedCb2() { DEBUGPRINT("delayed counter high prio 2 updated: %i\n", counter[2]); if (++counter[2] < 10) { - DelayedCallbackDispatch(cbinfo[2]); + PIOS_CALLBACKSCHEDULER_Dispatch(cbinfo[2]); } } static void DelayedCb3() { DEBUGPRINT("delayed counter high prio 3 updated: %i\n", counter[3]); if (++counter[3] < 10) { - DelayedCallbackDispatch(cbinfo[3]); + PIOS_CALLBACKSCHEDULER_Dispatch(cbinfo[3]); } } static void DelayedCb4() @@ -137,7 +137,7 @@ static void DelayedCb5() { DEBUGPRINT("delayed scheduled counter 5 updated: %i\n", counter[5]); if (++counter[5] < 10) { - DelayedCallbackSchedule(cbinfo[5], 500, CALLBACK_UPDATEMODE_NONE); + PIOS_CALLBACKSCHEDULER_Schedule(cbinfo[5], 500, CALLBACK_UPDATEMODE_NONE); } // it will likely only reach 8 due to cb4 aborting the run } @@ -145,6 +145,6 @@ static void DelayedCb6() { DEBUGPRINT("delayed counter 6 (high task prio) updated: %i\n", counter[6]); if (++counter[6] < 10) { - DelayedCallbackDispatch(cbinfo[6]); + PIOS_CALLBACKSCHEDULER_Dispatch(cbinfo[6]); } } diff --git a/flight/modules/Example/examplemodcallback.c b/flight/modules/Example/examplemodcallback.c index 8bd052588..7c63475fc 100644 --- a/flight/modules/Example/examplemodcallback.c +++ b/flight/modules/Example/examplemodcallback.c @@ -72,7 +72,7 @@ int32_t ExampleModCallbackInitialize() // Listen for ExampleObject1 updates, connect a callback function ExampleObject1ConnectCallback(&ObjectUpdatedCb); - cbinfo = DelayedCallbackCreate(&DelayedCb, CALLBACK_PRIORITY, CBTASK_PRIORITY, CALLBACKINFO_RUNNING_EXAMPLE, STACK_SIZE); + cbinfo = PIOS_CALLBACKSCHEDULER_Create(&DelayedCb, CALLBACK_PRIORITY, CBTASK_PRIORITY, CALLBACKINFO_RUNNING_EXAMPLE, STACK_SIZE); return 0; } @@ -86,11 +86,11 @@ int32_t ExampleModCallbackInitialize() */ static void ObjectUpdatedCb(__attribute__((unused)) UAVObjEvent *ev) { - DelayedCallbackDispatch(cbinfo); + PIOS_CALLBACKSCHEDULER_Dispatch(cbinfo); } /** - * This function is called by the DelayedCallbackScheduler when its execution + * This function is called by the PIOS_CALLBACKSCHEDULER_Scheduler when its execution * has been requested. Callbacks scheduled for execution are executed in the * same thread in a round robin fashion. The Dispatch function to reschedule * execution can be called from within the Callback itself, in which case the @@ -136,5 +136,5 @@ ExampleObject2Set(&data2); // call the module again 10 seconds later, // even if the exampleobject has not been updated -DelayedCallbackSchedule(cbinfo, 10 * 1000, CALLBACK_UPDATEMODE_NONE); +PIOS_CALLBACKSCHEDULER_Schedule(cbinfo, 10 * 1000, CALLBACK_UPDATEMODE_NONE); } diff --git a/flight/modules/OPLink/oplinkmod.c b/flight/modules/OPLink/oplinkmod.c index 994e0d5d9..2ac5e6d74 100644 --- a/flight/modules/OPLink/oplinkmod.c +++ b/flight/modules/OPLink/oplinkmod.c @@ -119,7 +119,7 @@ static void systemTask(__attribute__((unused)) void *parameters) MODULE_TASKCREATE_ALL; /* start the delayed callback scheduler */ - CallbackSchedulerStart(); + PIOS_CALLBACKSCHEDULER_Start(); if (mallocFailed) { /* We failed to malloc during task creation, diff --git a/flight/modules/PathPlanner/pathplanner.c b/flight/modules/PathPlanner/pathplanner.c index 4e337e10d..632f4a8e9 100644 --- a/flight/modules/PathPlanner/pathplanner.c +++ b/flight/modules/PathPlanner/pathplanner.c @@ -96,7 +96,7 @@ int32_t PathPlannerStart() PathStatusConnectCallback(statusUpdated); // Start main task callback - DelayedCallbackDispatch(pathPlannerHandle); + PIOS_CALLBACKSCHEDULER_Dispatch(pathPlannerHandle); return 0; } @@ -116,8 +116,8 @@ int32_t PathPlannerInitialize() WaypointInitialize(); WaypointActiveInitialize(); - pathPlannerHandle = DelayedCallbackCreate(&pathPlannerTask, CALLBACK_PRIORITY_REGULAR, TASK_PRIORITY, CALLBACKINFO_RUNNING_PATHPLANNER0, STACK_SIZE_BYTES); - pathDesiredUpdaterHandle = DelayedCallbackCreate(&updatePathDesired, CALLBACK_PRIORITY_CRITICAL, TASK_PRIORITY, CALLBACKINFO_RUNNING_PATHPLANNER1, STACK_SIZE_BYTES); + pathPlannerHandle = PIOS_CALLBACKSCHEDULER_Create(&pathPlannerTask, CALLBACK_PRIORITY_REGULAR, TASK_PRIORITY, CALLBACKINFO_RUNNING_PATHPLANNER0, STACK_SIZE_BYTES); + pathDesiredUpdaterHandle = PIOS_CALLBACKSCHEDULER_Create(&updatePathDesired, CALLBACK_PRIORITY_CRITICAL, TASK_PRIORITY, CALLBACKINFO_RUNNING_PATHPLANNER1, STACK_SIZE_BYTES); return 0; } @@ -129,7 +129,7 @@ MODULE_INITCALL(PathPlannerInitialize, PathPlannerStart); */ static void pathPlannerTask() { - DelayedCallbackSchedule(pathPlannerHandle, PATH_PLANNER_UPDATE_RATE_MS, CALLBACK_UPDATEMODE_SOONER); + PIOS_CALLBACKSCHEDULER_Schedule(pathPlannerHandle, PATH_PLANNER_UPDATE_RATE_MS, CALLBACK_UPDATEMODE_SOONER); bool endCondition = false; @@ -333,13 +333,13 @@ static uint8_t checkPathPlan() // callback function when status changed, issue execution of state machine void commandUpdated(__attribute__((unused)) UAVObjEvent *ev) { - DelayedCallbackDispatch(pathDesiredUpdaterHandle); + PIOS_CALLBACKSCHEDULER_Dispatch(pathDesiredUpdaterHandle); } // callback function when waypoints changed in any way, update pathDesired void statusUpdated(__attribute__((unused)) UAVObjEvent *ev) { - DelayedCallbackDispatch(pathPlannerHandle); + PIOS_CALLBACKSCHEDULER_Dispatch(pathPlannerHandle); } diff --git a/flight/modules/StateEstimation/stateestimation.c b/flight/modules/StateEstimation/stateestimation.c index 587070547..bff326c87 100644 --- a/flight/modules/StateEstimation/stateestimation.c +++ b/flight/modules/StateEstimation/stateestimation.c @@ -268,7 +268,7 @@ int32_t StateEstimationInitialize(void) stack_required = maxint32_t(stack_required, filterEKF13iInitialize(&ekf13iFilter)); stack_required = maxint32_t(stack_required, filterEKF13Initialize(&ekf13Filter)); - stateEstimationCallback = DelayedCallbackCreate(&StateEstimationCb, CALLBACK_PRIORITY, TASK_PRIORITY, CALLBACKINFO_RUNNING_STATEESTIMATION, stack_required); + stateEstimationCallback = PIOS_CALLBACKSCHEDULER_Create(&StateEstimationCb, CALLBACK_PRIORITY, TASK_PRIORITY, CALLBACKINFO_RUNNING_STATEESTIMATION, stack_required); return 0; } @@ -307,7 +307,7 @@ static void StateEstimationCb(void) // after system startup, first few sensor readings might be messed up, delay until everything has settled if (bootDelay) { bootDelay--; - DelayedCallbackSchedule(stateEstimationCallback, TIMEOUT_MS, CALLBACK_UPDATEMODE_SOONER); + PIOS_CALLBACKSCHEDULER_Schedule(stateEstimationCallback, TIMEOUT_MS, CALLBACK_UPDATEMODE_SOONER); return; } @@ -390,7 +390,7 @@ static void StateEstimationCb(void) // we are not done, re-dispatch self execution runState = RUNSTATE_FILTER; - DelayedCallbackDispatch(stateEstimationCallback); + PIOS_CALLBACKSCHEDULER_Dispatch(stateEstimationCallback); break; case RUNSTATE_FILTER: @@ -407,7 +407,7 @@ static void StateEstimationCb(void) if (!current) { runState = RUNSTATE_SAVE; } - DelayedCallbackDispatch(stateEstimationCallback); + PIOS_CALLBACKSCHEDULER_Dispatch(stateEstimationCallback); break; case RUNSTATE_SAVE: @@ -460,9 +460,9 @@ static void StateEstimationCb(void) // we are done, re-schedule next self execution runState = RUNSTATE_LOAD; if (updatedSensors) { - DelayedCallbackDispatch(stateEstimationCallback); + PIOS_CALLBACKSCHEDULER_Dispatch(stateEstimationCallback); } else { - DelayedCallbackSchedule(stateEstimationCallback, TIMEOUT_MS, CALLBACK_UPDATEMODE_SOONER); + PIOS_CALLBACKSCHEDULER_Schedule(stateEstimationCallback, TIMEOUT_MS, CALLBACK_UPDATEMODE_SOONER); } break; } @@ -515,7 +515,7 @@ static void sensorUpdatedCb(UAVObjEvent *ev) updatedSensors |= SENSORUPDATES_airspeed; } - DelayedCallbackDispatch(stateEstimationCallback); + PIOS_CALLBACKSCHEDULER_Dispatch(stateEstimationCallback); } diff --git a/flight/modules/System/systemmod.c b/flight/modules/System/systemmod.c index 88b4fd1fe..010080d66 100644 --- a/flight/modules/System/systemmod.c +++ b/flight/modules/System/systemmod.c @@ -176,7 +176,7 @@ static void systemTask(__attribute__((unused)) void *parameters) MODULE_TASKCREATE_ALL; /* start the delayed callback scheduler */ - CallbackSchedulerStart(); + PIOS_CALLBACKSCHEDULER_Start(); if (mallocFailed) { /* We failed to malloc during task creation, diff --git a/flight/pios/common/pios_callbackscheduler.c b/flight/pios/common/pios_callbackscheduler.c index d31ec3202..21ccaff14 100644 --- a/flight/pios/common/pios_callbackscheduler.c +++ b/flight/pios/common/pios_callbackscheduler.c @@ -1,7 +1,7 @@ /** ****************************************************************************** * - * @file callbackscheduler.c + * @file pios_callbackscheduler.c * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2013. * @brief Scheduler to run callback functions from a shared context with given priorities. * @@ -24,8 +24,11 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include +#include +#ifdef PIOS_INCLUDE_CALLBACKSCHEDULER +#include +#include #include // Private constants @@ -74,7 +77,7 @@ static int32_t runNextCallback(struct DelayedCallbackTaskStruct *task, DelayedCa * must be called before any other functions are called * \return Success (0), failure (-1) */ -int32_t CallbackSchedulerInitialize() +int32_t PIOS_CALLBACKSCHEDULER_Initialize() { // Initialize variables schedulerTasks = NULL; @@ -100,7 +103,7 @@ int32_t CallbackSchedulerInitialize() * they can be marked for later execution by executing the dispatch function. * \return Success (0), failure (-1) */ -int32_t CallbackSchedulerStart() +int32_t PIOS_CALLBACKSCHEDULER_Start() { xSemaphoreTakeRecursive(mutex, portMAX_DELAY); @@ -144,7 +147,7 @@ int32_t CallbackSchedulerStart() * UPDATEMODE_OVERRIDE: The callback will be rescheduled in any case, effectively overriding any previous schedule. (sooner+later=override) * \return 0: not scheduled, previous schedule takes precedence, 1: new schedule, 2: previous schedule overridden */ -int32_t DelayedCallbackSchedule( +int32_t PIOS_CALLBACKSCHEDULER_Schedule( DelayedCallbackInfo *cbinfo, int32_t milliseconds, DelayedCallbackUpdateMode updatemode) @@ -192,7 +195,7 @@ int32_t DelayedCallbackSchedule( * \param[in] cbinfo the callback handle * \return Success (-1), failure (0) */ -int32_t DelayedCallbackDispatch(DelayedCallbackInfo *cbinfo) +int32_t PIOS_CALLBACKSCHEDULER_Dispatch(DelayedCallbackInfo *cbinfo) { PIOS_Assert(cbinfo); @@ -216,7 +219,7 @@ int32_t DelayedCallbackDispatch(DelayedCallbackInfo *cbinfo) * Check the demo task for your port to find the syntax required. * \return Success (-1), failure (0) */ -int32_t DelayedCallbackDispatchFromISR(DelayedCallbackInfo *cbinfo, long *pxHigherPriorityTaskWoken) +int32_t PIOS_CALLBACKSCHEDULER_DispatchFromISR(DelayedCallbackInfo *cbinfo, long *pxHigherPriorityTaskWoken) { PIOS_Assert(cbinfo); @@ -238,7 +241,7 @@ int32_t DelayedCallbackDispatchFromISR(DelayedCallbackInfo *cbinfo, long *pxHigh * \param[in] stacksize The stack requirements of the callback when called by the scheduler. * \return CallbackInfo Pointer on success, NULL if failed. */ -DelayedCallbackInfo *DelayedCallbackCreate( +DelayedCallbackInfo *PIOS_CALLBACKSCHEDULER_Create( DelayedCallback cb, DelayedCallbackPriority priority, DelayedCallbackPriorityTask priorityTask, @@ -287,7 +290,7 @@ DelayedCallbackInfo *DelayedCallbackCreate( // add to list of scheduler tasks LL_APPEND(schedulerTasks, task); - // Previously registered tasks are spawned when CallbackSchedulerStart() is called. + // Previously registered tasks are spawned when PIOS_CALLBACKSCHEDULER_Start() is called. // Tasks registered afterwards need to spawn upon creation. if (schedulerStarted) { xTaskCreate( @@ -414,3 +417,5 @@ static void CallbackSchedulerTask(void *task) } } } + +#endif // ifdef PIOS_INCLUDE_CALLBACKSCHEDULER diff --git a/flight/pios/inc/pios_callbackscheduler.h b/flight/pios/inc/pios_callbackscheduler.h index 3ec3fd648..b72d4d0a4 100644 --- a/flight/pios/inc/pios_callbackscheduler.h +++ b/flight/pios/inc/pios_callbackscheduler.h @@ -1,9 +1,9 @@ /** ****************************************************************************** * - * @file callbackscheduler.h - * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. - * @brief Include files of the uavobjectlist library + * @file pios_callbackscheduler.h + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2014. + * @brief Include files of the PIOS_CALLBACKSCHEDULER * @see The GNU Public License (GPL) Version 3 * *****************************************************************************/ @@ -23,8 +23,8 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#ifndef CALLBACKSCHEDULER_H -#define CALLBACKSCHEDULER_H +#ifndef PIOS_CALLBACKSCHEDULER_H +#define PIOS_CALLBACKSCHEDULER_H // Public types typedef enum { @@ -48,7 +48,7 @@ typedef enum { // ...ABcABdABxABcABdAByABcABdABxABcABdABy... // However if only the 3 callbacks, A, c and x want to execute, you will get: // ...AcAxAcAxAcAxAcAxAcAxAcAxAcAxAcAxAcAx... -// And if onlz A and y need execution it will be: +// And if only A and y need execution it will be: // ...AyAyAyAyAyAyAyAyAyAyAyAyAyAyAyAyAyAy... // despite their different priority they would get treated equally in this case. // @@ -113,7 +113,7 @@ typedef struct DelayedCallbackInfoStruct DelayedCallbackInfo; * must be called before any other functions are called * \return Success (0), failure (-1) */ -int32_t CallbackSchedulerInitialize(); +int32_t PIOS_CALLBACKSCHEDULER_Initialize(); /** * Start all scheduler tasks @@ -125,7 +125,7 @@ int32_t CallbackSchedulerInitialize(); * they can be marked for later execution by executing the dispatch function. * \return Success (0), failure (-1) */ -int32_t CallbackSchedulerStart(); +int32_t PIOS_CALLBACKSCHEDULER_Start(); /** * Register a new callback to be called by a delayed callback scheduler task. @@ -138,7 +138,7 @@ int32_t CallbackSchedulerStart(); * \param[in] callbackID - CallbackInfoRunningElem from CallbackInfo UAVObject, unique identified to collect stats for the callback, -1 to ignore! * \return CallbackInfo Pointer on success, NULL if failed. */ -DelayedCallbackInfo *DelayedCallbackCreate( +DelayedCallbackInfo *PIOS_CALLBACKSCHEDULER_Create( DelayedCallback cb, DelayedCallbackPriority priority, DelayedCallbackPriorityTask priorityTask, @@ -157,7 +157,7 @@ DelayedCallbackInfo *DelayedCallbackCreate( * UPDATEMODE_OVERRIDE: The callback will be rescheduled in any case, effectively overriding any previous schedule. (sooner+later=override) * \return 0: not scheduled, previous schedule takes precedence, 1: new schedule, 2: previous schedule overridden */ -int32_t DelayedCallbackSchedule( +int32_t PIOS_CALLBACKSCHEDULER_Schedule( DelayedCallbackInfo *cbinfo, int32_t milliseconds, DelayedCallbackUpdateMode updatemode); @@ -168,7 +168,7 @@ int32_t DelayedCallbackSchedule( * \param[in] *cbinfo the callback handle * \return Success (-1), failure (0) */ -int32_t DelayedCallbackDispatch(DelayedCallbackInfo *cbinfo); +int32_t PIOS_CALLBACKSCHEDULER_Dispatch(DelayedCallbackInfo *cbinfo); /** * Dispatch an event by invoking the supplied callback. The function @@ -184,6 +184,6 @@ int32_t DelayedCallbackDispatch(DelayedCallbackInfo *cbinfo); * Check the demo task for your port to find the syntax required. * \return Success (-1), failure (0) */ -int32_t DelayedCallbackDispatchFromISR(DelayedCallbackInfo *cbinfo, long *pxHigherPriorityTaskWoken); +int32_t PIOS_CALLBACKSCHEDULER_DispatchFromISR(DelayedCallbackInfo *cbinfo, long *pxHigherPriorityTaskWoken); -#endif // CALLBACKSCHEDULER_H +#endif // PIOS_CALLBACKSCHEDULER_H diff --git a/flight/targets/boards/coptercontrol/firmware/pios_board.c b/flight/targets/boards/coptercontrol/firmware/pios_board.c index 194387fdc..4026343ae 100644 --- a/flight/targets/boards/coptercontrol/firmware/pios_board.c +++ b/flight/targets/boards/coptercontrol/firmware/pios_board.c @@ -198,7 +198,7 @@ void PIOS_Board_Init(void) } /* Initialize the delayed callback library */ - CallbackSchedulerInitialize(); + PIOS_CALLBACKSCHEDULER_Initialize(); /* Initialize UAVObject libraries */ EventDispatcherInitialize(); diff --git a/flight/targets/boards/coptercontrol/firmware/pios_board_posix.c b/flight/targets/boards/coptercontrol/firmware/pios_board_posix.c index 7487a17aa..7fa958a38 100644 --- a/flight/targets/boards/coptercontrol/firmware/pios_board_posix.c +++ b/flight/targets/boards/coptercontrol/firmware/pios_board_posix.c @@ -39,7 +39,7 @@ void PIOS_Board_Init(void) PIOS_DELAY_Init(); /* Initialize the delayed callback library */ - CallbackSchedulerInitialize(); + PIOS_CALLBACKSCHEDULER_Initialize(); /* Initialize UAVObject libraries */ EventDispatcherInitialize(); diff --git a/flight/targets/boards/oplinkmini/firmware/pios_board.c b/flight/targets/boards/oplinkmini/firmware/pios_board.c index 85b3a9939..56adfb4f1 100644 --- a/flight/targets/boards/oplinkmini/firmware/pios_board.c +++ b/flight/targets/boards/oplinkmini/firmware/pios_board.c @@ -106,7 +106,7 @@ void PIOS_Board_Init(void) } /* Initialize the delayed callback library */ - CallbackSchedulerInitialize(); + PIOS_CALLBACKSCHEDULER_Initialize(); /* Initialize UAVObject libraries */ EventDispatcherInitialize(); diff --git a/flight/targets/boards/oplinkmini/firmware/pios_board_posix.c b/flight/targets/boards/oplinkmini/firmware/pios_board_posix.c index 7487a17aa..7fa958a38 100644 --- a/flight/targets/boards/oplinkmini/firmware/pios_board_posix.c +++ b/flight/targets/boards/oplinkmini/firmware/pios_board_posix.c @@ -39,7 +39,7 @@ void PIOS_Board_Init(void) PIOS_DELAY_Init(); /* Initialize the delayed callback library */ - CallbackSchedulerInitialize(); + PIOS_CALLBACKSCHEDULER_Initialize(); /* Initialize UAVObject libraries */ EventDispatcherInitialize(); diff --git a/flight/targets/boards/osd/firmware/pios_board.c b/flight/targets/boards/osd/firmware/pios_board.c index ffaa1dd36..0c45ddfdc 100644 --- a/flight/targets/boards/osd/firmware/pios_board.c +++ b/flight/targets/boards/osd/firmware/pios_board.c @@ -178,7 +178,7 @@ void PIOS_Board_Init(void) } /* Initialize the delayed callback library */ - CallbackSchedulerInitialize(); + PIOS_CALLBACKSCHEDULER_Initialize(); /* Initialize UAVObject libraries */ EventDispatcherInitialize(); diff --git a/flight/targets/boards/revolution/firmware/pios_board.c b/flight/targets/boards/revolution/firmware/pios_board.c index 15b667214..262fcf899 100644 --- a/flight/targets/boards/revolution/firmware/pios_board.c +++ b/flight/targets/boards/revolution/firmware/pios_board.c @@ -404,7 +404,7 @@ void PIOS_Board_Init(void) } /* Initialize the delayed callback library */ - CallbackSchedulerInitialize(); + PIOS_CALLBACKSCHEDULER_Initialize(); /* Initialize UAVObject libraries */ EventDispatcherInitialize(); diff --git a/flight/targets/boards/revolution/firmware/pios_board_sim.c b/flight/targets/boards/revolution/firmware/pios_board_sim.c index 4a9453efb..2171be22c 100644 --- a/flight/targets/boards/revolution/firmware/pios_board_sim.c +++ b/flight/targets/boards/revolution/firmware/pios_board_sim.c @@ -132,7 +132,7 @@ void PIOS_Board_Init(void) PIOS_DELAY_Init(); /* Initialize the delayed callback library */ - CallbackSchedulerInitialize(); + PIOS_CALLBACKSCHEDULER_Initialize(); /* Initialize UAVObject libraries */ EventDispatcherInitialize(); diff --git a/flight/targets/boards/revoproto/firmware/pios_board.c b/flight/targets/boards/revoproto/firmware/pios_board.c index ed142f951..9206a3f24 100644 --- a/flight/targets/boards/revoproto/firmware/pios_board.c +++ b/flight/targets/boards/revoproto/firmware/pios_board.c @@ -444,7 +444,7 @@ void PIOS_Board_Init(void) } /* Initialize the delayed callback library */ - CallbackSchedulerInitialize(); + PIOS_CALLBACKSCHEDULER_Initialize(); /* Initialize UAVObject libraries */ EventDispatcherInitialize(); diff --git a/flight/targets/boards/revoproto/firmware/pios_board_sim.c b/flight/targets/boards/revoproto/firmware/pios_board_sim.c index 401d4be57..a99f0b3e8 100644 --- a/flight/targets/boards/revoproto/firmware/pios_board_sim.c +++ b/flight/targets/boards/revoproto/firmware/pios_board_sim.c @@ -132,7 +132,7 @@ void PIOS_Board_Init(void) PIOS_DELAY_Init(); /* Initialize the delayed callback library */ - CallbackSchedulerInitialize(); + PIOS_CALLBACKSCHEDULER_Initialize(); /* Initialize UAVObject libraries */ EventDispatcherInitialize(); diff --git a/flight/targets/boards/simposix/firmware/pios_board.c b/flight/targets/boards/simposix/firmware/pios_board.c index d3dcc3f17..a11316893 100644 --- a/flight/targets/boards/simposix/firmware/pios_board.c +++ b/flight/targets/boards/simposix/firmware/pios_board.c @@ -132,7 +132,7 @@ void PIOS_Board_Init(void) } /* Initialize the delayed callback library */ - CallbackSchedulerInitialize(); + PIOS_CALLBACKSCHEDULER_Initialize(); /* Initialize UAVObject libraries */ EventDispatcherInitialize(); diff --git a/flight/uavobjects/eventdispatcher.c b/flight/uavobjects/eventdispatcher.c index 94564fc54..e33ac9e30 100644 --- a/flight/uavobjects/eventdispatcher.c +++ b/flight/uavobjects/eventdispatcher.c @@ -103,8 +103,8 @@ int32_t EventDispatcherInitialize() mQueue = xQueueCreate(MAX_QUEUE_SIZE, sizeof(EventCallbackInfo)); // Create callback - eventSchedulerCallback = DelayedCallbackCreate(&eventTask, CALLBACK_PRIORITY, TASK_PRIORITY, CALLBACKINFO_RUNNING_EVENTDISPATCHER, STACK_SIZE * 4); - DelayedCallbackDispatch(eventSchedulerCallback); + eventSchedulerCallback = PIOS_CALLBACKSCHEDULER_Create(&eventTask, CALLBACK_PRIORITY, TASK_PRIORITY, CALLBACKINFO_RUNNING_EVENTDISPATCHER, STACK_SIZE * 4); + PIOS_CALLBACKSCHEDULER_Dispatch(eventSchedulerCallback); // Done return 0; @@ -148,7 +148,7 @@ int32_t EventCallbackDispatch(UAVObjEvent *ev, UAVObjEventCallback cb) evInfo.queue = 0; // Push to queue int32_t result = xQueueSend(mQueue, &evInfo, 0); // will not block if queue is full - DelayedCallbackDispatch(eventSchedulerCallback); + PIOS_CALLBACKSCHEDULER_Dispatch(eventSchedulerCallback); return result; } @@ -306,7 +306,7 @@ static void eventTask() timeToNextUpdateMs = processPeriodicUpdates(); } - DelayedCallbackSchedule(eventSchedulerCallback, timeToNextUpdateMs - (xTaskGetTickCount() * portTICK_RATE_MS), CALLBACK_UPDATEMODE_SOONER); + PIOS_CALLBACKSCHEDULER_Schedule(eventSchedulerCallback, timeToNextUpdateMs - (xTaskGetTickCount() * portTICK_RATE_MS), CALLBACK_UPDATEMODE_SOONER); } /**