diff --git a/UAV-ControlSystem/inc/Scheduler/scheduler.h b/UAV-ControlSystem/inc/Scheduler/scheduler.h index db8c95e..92cab4c 100644 --- a/UAV-ControlSystem/inc/Scheduler/scheduler.h +++ b/UAV-ControlSystem/inc/Scheduler/scheduler.h @@ -13,18 +13,18 @@ #include #include - +#include "stm32f4xx_revo.h" /* Enum containing all the possible task priorities */ typedef enum { - IDLE = 0, - LOW, - MEDIUM, - HIGH, - REALTIME, - MAX_PRIORITY = 255 + PRIORITY_IDLE = 0, + PRIORITY_LOW, + PRIORITY_MEDIUM, + PRIORITY_HIGH, + PRIORITY_REALTIME, + PRIORITY_MAX_PRIORITY = 255 } taskPriority_t; diff --git a/UAV-ControlSystem/inc/Scheduler/tasks.h b/UAV-ControlSystem/inc/Scheduler/tasks.h index e7635db..c6d33b2 100644 --- a/UAV-ControlSystem/inc/Scheduler/tasks.h +++ b/UAV-ControlSystem/inc/Scheduler/tasks.h @@ -11,12 +11,15 @@ #ifndef SCHEDULER_TASKS_H_ #define SCHEDULER_TASKS_H_ +#include + //All the task functions in the system, one for each task void systemTaskSystem(void); void systemTaskGyroPid(void); void systemTaskAccelerometer(void); void systemTaskAttitude(void); void systemTaskRx(void); +bool systemTaskRxCheck(uint32_t currentDeltaTime); void systemTaskSerial(void); void systemTaskBattery(void); void systemTaskBaro(void); diff --git a/UAV-ControlSystem/inc/stm32f4xx_revo.h b/UAV-ControlSystem/inc/stm32f4xx_revo.h index fa46876..21a1758 100644 --- a/UAV-ControlSystem/inc/stm32f4xx_revo.h +++ b/UAV-ControlSystem/inc/stm32f4xx_revo.h @@ -92,12 +92,24 @@ /* Baro */ +//#define BARO /* Compass */ +//#define COMPASS /* GPS */ +//#define GPS + + + /* Sonar */ +//#define SONAR + + + /* Beeper */ +//#define BEEPER + /* Define all the moter of the system, servos + extra */ diff --git a/UAV-ControlSystem/src/Scheduler/scheduler.c b/UAV-ControlSystem/src/Scheduler/scheduler.c index 8b4b86d..b6e19d5 100644 --- a/UAV-ControlSystem/src/Scheduler/scheduler.c +++ b/UAV-ControlSystem/src/Scheduler/scheduler.c @@ -8,8 +8,9 @@ * -------- ---- ----------- * ***************************************************************************/ -#include "Scheduler/scheduler.h" #include "stm32f4xx_revo.h" +#include "Scheduler/scheduler.h" +#include "Scheduler/tasks.h" //Todo: change for several instances where 0 is used as null to the define value NULL @@ -252,7 +253,7 @@ void scheduler(void) bool changeTask = false; //flag used to check if the task should be updated /* If a realtime task is found the bool isRealTime will be set to true * meaning no other tasks than realtime will be able to enter the function */ - if (taskToRun->staticPriority == REALTIME) //if it is a realtime task + if (taskToRun->staticPriority == PRIORITY_REALTIME) //if it is a realtime task { isRealTime = true; //toggle this flag so that no non realtime task can be selected this cycle diff --git a/UAV-ControlSystem/src/Scheduler/tasks.c b/UAV-ControlSystem/src/Scheduler/tasks.c index 17ec7a3..bff30e2 100644 --- a/UAV-ControlSystem/src/Scheduler/tasks.c +++ b/UAV-ControlSystem/src/Scheduler/tasks.c @@ -11,86 +11,129 @@ #include "Scheduler/tasks.h" #include "Scheduler/scheduler.h" +#define GetUpdateRateHz(x) (1000000 / x) //x is the desired hz value given in micro seconds //initiate the values for all the tasks //This information needs to be changed when functionality and setting for the tasks needs to be changed +// - Note: desiredPeriod is given in micro seconds, writing for example (1000000 / 10) means 10 hz rate task_t SystemTasks[TASK_COUNT] = { [TASK_SYSTEM] = { - + .taskName = "SYSTEM", + .taskFunction = systemTaskSystem, + .desiredPeriod = GetUpdateRateHz(10), //10 hz update rate (100 ms) + .staticPriority = PRIORITY_HIGH, }, [TASK_GYROPID] = { - + .taskName = "PID", + .subTaskName = "GYRO", + .taskFunction = systemTaskGyroPid, + .desiredPeriod = GetUpdateRateHz(1000), //1000 hz update rate (1 ms) + .staticPriority = PRIORITY_REALTIME, }, [TASK_ACCELEROMETER] = { - + .taskName = "ACCELEROMTER", + .taskFunction = systemTaskAccelerometer, + .desiredPeriod = GetUpdateRateHz(1000), //1000 hz update rate (1 ms) + .staticPriority = PRIORITY_MEDIUM, }, [TASK_ATTITUDE] = { - + .taskName = "ATTITUDE", + .taskFunction = systemTaskAttitude, + .desiredPeriod = GetUpdateRateHz(100), //100 hz update rate (10 ms) + .staticPriority = PRIORITY_MEDIUM, }, [TASK_RX] = { - + .taskName = "RX", + .taskFunction = systemTaskRx, //Event handler function, will check if a message is obtainable + .checkEventTriggered = systemTaskRxCheck, + .desiredPeriod = GetUpdateRateHz(50), //Standard scheduling should not be used if event based, used as fail safe + .staticPriority = PRIORITY_HIGH, }, [TASK_SERIAL] = { - + .taskName = "SERIAL", + .taskFunction = systemTaskSerial, + .desiredPeriod = GetUpdateRateHz(100), //100 hz update rate (10 ms) + .staticPriority = PRIORITY_LOW, }, [TASK_BATTERY] = { - + .taskName = "BATTERY", + .taskFunction = systemTaskBattery, + .desiredPeriod = GetUpdateRateHz(50), + .staticPriority = PRIORITY_MEDIUM, }, #ifdef BARO [TASK_BARO] = { - + .taskName = "BAROMETER", + .taskFunction = systemTaskBaro, + .desiredPeriod = GetUpdateRateHz(20), + .staticPriority = PRIORITY_LOW, }, #endif #ifdef COMPASS [TASK_COMPASS] = { - + .taskName = "COMPASS", + .taskFunction = systemTaskCompass, + .desiredPeriod = GetUpdateRateHz(10), + .staticPriority = PRIORITY_LOW, }, #endif #ifdef GPS - [TASK_GPS] = - { - - }, + [TASK_GPS] = + { + .taskName = "GPS", + .taskFunction = systemTaskGps, + .desiredPeriod = GetUpdateRateHz(10), + .staticPriority = PRIORITY_MEDIUM, + }, #endif #ifdef SONAR - [TASK_SONAR] = - { - - }, + [TASK_SONAR] = + { + .taskName = "SONAR", + .taskFunction = systemTaskSonar, + .desiredPeriod = GetUpdateRateHz(20), + .staticPriority = PRIORITY_LOW, + }, #endif #if defined(BARO) || defined(SONAR) - [TASK_ALTITUDE] = - { - - }, + [TASK_ALTITUDE] = + { + .taskName = "ALTITUDE", + .taskFunction = systemTaskAltitude, + .desiredPeriod = GetUpdateRateHz(40), + .staticPriority = PRIORITY_LOW, + }, #endif #if BEEPER - [TASK_BEEPER] = - { - - }, + [TASK_BEEPER] = + { + .taskName = "BEEPER", + .taskFunction = systemTaskBeeper, + .desiredPeriod = GetUpdateRateHz(100), + .staticPriority = PRIORITY_LOW, + }, #endif