diff --git a/UAV-ControlSystem/inc/Scheduler/scheduler.h b/UAV-ControlSystem/inc/Scheduler/scheduler.h index 5b7a665..c3d71eb 100644 --- a/UAV-ControlSystem/inc/Scheduler/scheduler.h +++ b/UAV-ControlSystem/inc/Scheduler/scheduler.h @@ -11,8 +11,11 @@ #ifndef SCHEDULER_H_ #define SCHEDULER_H_ +#include #include + + /* Enum containing all the possible task priorities */ typedef enum { @@ -24,12 +27,110 @@ typedef enum MAX_PRIORITY = 255 } taskPriority_t; + +/* Struct used to contain the information for each task */ typedef struct { - const char * taskName; /* Name of the task */ - const char * subTaskName; /*Needed?*/ + /* Basic task information */ + const char * taskName; /* Name of the task */ + const char * subTaskName; /*Needed?*/ + bool (*checkEventTriggered)(uint32_t currentDeltaTime); /* Function pointer to event trigger check, if used no standard scheduling */ + void (*taskFunction)(void); /* Pointer to the function that should be called to run the task */ + uint32_t desiredPeriod; /* The period the task wants to run in */ + const uint8_t staticPriority; /* Value used to increment the dynamic priority */ + + /* Scheduling variables */ + uint16_t dynamicPriority; /* Priority increases the longer the task have been idle, increased by staticPriority value */ + uint16_t taskAgeCycle; /* Helps to keep track of the "periods" for the task */ + uint32_t lastExecutedAt; /* last time of invocation */ + uint32_t lastSignaledAt; /* time of invocation event for event-driven tasks */ + + /* ToDo: potential statistic values of the task */ }task_t; +/* Task counter, ToDo: If more tasks are needed add them here first, defines are used to make sure the task is somewhere in the system */ +/* Important: If a new define for a task is added here it MUST be added in the tasks.c */ +typedef enum +{ + /* All the tasks that will be in the system, some are separated by IfDef */ + TASK_SYSTEM = 0, + TASK_GYROPID, + TASK_ACCELEROMETER, + TASK_ATTITUDE, + TASK_RX, + TASK_SERIAL, + TASK_BATTERY, +#ifdef BARO + TASK_BARO, +#endif +#ifdef COMPASS + TASK_COMPASS, +#endif +#ifdef GPS + TASK_GPS, +#endif +#ifdef SONAR + TASK_SONAR, +#endif +#if defined(BARO) || defined(SONAR) + TASK_ALTITUDE, +#endif +#if BEEPER + TASK_BEEPER +#endif + + /* Need to be the value directly after the tasks id. Keeps track of the count of the tasks */ + TASK_COUNT, + + /* Service task IDs */ + TASK_NONE = TASK_COUNT, + TASK_SELF +}taskId_t; + +/* Variables --------------------------------------------------------------------------------- */ + + + +/* Functions that operate can operate on the tasks ------------------------------------------- */ + +/************************************************************************** +* BRIEF: Enables or disables a specific task in the system * +* INFORMATION: Takes the id of the task(task_t) along with a true or * +* false value. If true the task will be added to the task queue, if false * +* it will be removed. * +**************************************************************************/ +void enableTask(taskId_t taskId, bool enabled); + +/************************************************************************** +* BRIEF: * +* INFORMATION: * +**************************************************************************/ +uint32_t getTaskDeltaTime(taskId_t taskId); + +/************************************************************************** +* BRIEF: * +* INFORMATION: * +**************************************************************************/ +void rescheduleTask(taskId_t taskId, uint32_t newPeriodMicros); + + +/* Functions that handle the scheduler ------------------------------------------------------- */ + +/************************************************************************** +* BRIEF: * +* INFORMATION: * +**************************************************************************/ +void scheduler(void); + +/************************************************************************** +* BRIEF: * +* INFORMATION: * +**************************************************************************/ +void initScheduler(void); + + + + #endif /* SCHEDULER_H_ */ diff --git a/UAV-ControlSystem/inc/Scheduler/tasks.h b/UAV-ControlSystem/inc/Scheduler/tasks.h index bc6dacc..e82df8e 100644 --- a/UAV-ControlSystem/inc/Scheduler/tasks.h +++ b/UAV-ControlSystem/inc/Scheduler/tasks.h @@ -1,9 +1,12 @@ -/* - * tasks.h - * - * Created on: 12 sep. 2016 - * Author: holmis - */ +/************************************************************************** +* NAME: tasks.h * +* PURPOSE: Defining the the scheduler to be used in the system to organize* +* the runtime for the tasks in the system based on priority. * +* INFORMATION: * +* GLOBAL VARIABLES: * +* Variable Type Description * +* -------- ---- ----------- * +***************************************************************************/ #ifndef SCHEDULER_TASKS_H_ #define SCHEDULER_TASKS_H_ diff --git a/UAV-ControlSystem/src/Scheduler/scheduler.c b/UAV-ControlSystem/src/Scheduler/scheduler.c index fb63ebf..1d24e13 100644 --- a/UAV-ControlSystem/src/Scheduler/scheduler.c +++ b/UAV-ControlSystem/src/Scheduler/scheduler.c @@ -1,8 +1,128 @@ -/* - * scheduler.c - * - * Created on: 12 sep. 2016 - * Author: holmis - */ +/************************************************************************** +* NAME: Scheduler.c * +* PURPOSE: Defining the the scheduler to be used in the system to organize* +* the runtime for the tasks in the system based on priority. * +* INFORMATION: * +* GLOBAL VARIABLES: * +* Variable Type Description * +* -------- ---- ----------- * +***************************************************************************/ + +#include "Scheduler/scheduler.h" + +static uint32_t tasksReadyToRun; + +uint32_t currentTime = 0; +uint16_t averageSystmeLoad = 0; + +static int taskQueuePos = 0; +static int taskQueueSize = 0; + +static task_t * taskReadyQueue[TASK_COUNT + 1]; /* Array holding all the tasks that are ready to run in the system */ + + +/* Functions to operate on the task queue ------------------------------------------------------- */ + +/************************************************************************** +* BRIEF: * +* INFORMATION: * +**************************************************************************/ +void taskReadyQueueClear(void) +{ + +} + +/************************************************************************** +* BRIEF: * +* INFORMATION: * +**************************************************************************/ +bool taskReadyQueueContains(task_t *task) +{ + //Go through the taskReadyQueue to see if the current task is contained + for (int i = 0; i < taskQueueSize; i++) + { + if (taskReadyQueue[i] == task) + { + return true; + } + } + + return false; +} + +/************************************************************************** +* BRIEF: * +* INFORMATION: * +**************************************************************************/ +bool taskReadyQueueAdd(task_t *task) +{ + +} + +/************************************************************************** +* BRIEF: * +* INFORMATION: * +**************************************************************************/ +bool taskReadyQueueRemove(task_t *task) +{ + +} + + +/************************************************************************** +* BRIEF: Enables or disables a specific task in the system * +* INFORMATION: Takes the id of the task(task_t) along with a true or * +* false value. If true the task will be added to the task queue, if false * +* it will be removed. * +**************************************************************************/ +void enableTask(taskId_t taskId, bool enabled) +{ + +} + +/************************************************************************** +* BRIEF: * +* INFORMATION: * +**************************************************************************/ +uint32_t getTaskDeltaTime(taskId_t taskId) +{ + +} + +/************************************************************************** +* BRIEF: * +* INFORMATION: * +**************************************************************************/ +void rescheduleTask(taskId_t taskId, uint32_t newPeriodMicros) +{ + +} + +/************************************************************************** +* BRIEF: * +* INFORMATION: * +**************************************************************************/ +void initScheduler(void) +{ + +} + +/************************************************************************** +* BRIEF: * +* INFORMATION: * +**************************************************************************/ +void scheduler(void) +{ + +} + + + + + + + + + diff --git a/UAV-ControlSystem/src/Scheduler/tasks.c b/UAV-ControlSystem/src/Scheduler/tasks.c index 03a9d74..f2ca5a8 100644 --- a/UAV-ControlSystem/src/Scheduler/tasks.c +++ b/UAV-ControlSystem/src/Scheduler/tasks.c @@ -1,8 +1,11 @@ -/* - * tasks.c - * - * Created on: 12 sep. 2016 - * Author: holmis - */ - +/************************************************************************** +* NAME: tasks.c * +* PURPOSE: Defining the the scheduler to be used in the system to organize* +* the runtime for the tasks in the system based on priority. * +* INFORMATION: * +* GLOBAL VARIABLES: * +* Variable Type Description * +* -------- ---- ----------- * +***************************************************************************/ +#include "Scheduler/tasks.h" diff --git a/UAV-ControlSystem/src/main.c b/UAV-ControlSystem/src/main.c index e4f449e..560e48e 100644 --- a/UAV-ControlSystem/src/main.c +++ b/UAV-ControlSystem/src/main.c @@ -10,6 +10,7 @@ #include "stm32f4xx.h" +#include "stm32f4xx_revo.h" /* Private function prototypes -----------------------------------------------*/ static void SystemClock_Config(void); @@ -21,6 +22,7 @@ int main(void) int i = 1; + TIM_Base_InitTypeDef t; /* Configure the system clock to 100 MHz */ SystemClock_Config(); @@ -35,6 +37,7 @@ int main(void) gpinit.Pull = GPIO_PULLUP; gpinit.Speed = GPIO_SPEED_FAST; + /*##-2- Configure PA05 IO in output push-pull mode to drive external LED ###*/ //GPIO_InitStruct.Pin = GPIO_PIN_5 | GPIO_PIN_6; //GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;