This repository has been archived on 2020-06-14. You can view files and clone it, but cannot push or open issues or pull requests.
Jonas Holmberg a70c874cca Added all the files for scheduler and some code
Some code and structure for the scheduler.
2016-09-13 13:57:33 +02:00

137 lines
4.9 KiB
C

/**************************************************************************
* NAME: scheduler.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_H_
#define SCHEDULER_H_
#include <stdint.h>
#include <stdbool.h>
/* Enum containing all the possible task priorities */
typedef enum
{
IDLE = 0,
LOW,
MEDIUM,
HIGH,
REALTIME,
MAX_PRIORITY = 255
} taskPriority_t;
/* Struct used to contain the information for each task */
typedef struct
{
/* 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_ */