/**********************************************************************************************************************
* FILE DESCRIPTION
* -------------------------------------------------------------------------------------------------------------------
* File: Scheduler.c
* Date: Mar 31, 2020
* Version: //00.01
* Author: Echipa 1
*
* Description: <from GitLab Issue>
*
*
*********************************************************************************************************************/
/**********************************************************************************************************************
* DO NOT CHANGE THIS COMMENT! << INCLUDES >> DO NOT CHANGE THIS COMMENT!
*********************************************************************************************************************/
#include<stdio.h>
#include "SchedulerLib.h"
#include "Sensors_and_Actuators.h"
/**********************************************************************************************************************
* DO NOT CHANGE THIS COMMENT! << LOCAL DEFINES >> DO NOT CHANGE THIS COMMENT!
*********************************************************************************************************************/
/**********************************************************************************************************************
* DO NOT CHANGE THIS COMMENT! << GLOBAL VARIABLE DEFINITION >> DO NOT CHANGE THIS COMMENT!
*********************************************************************************************************************/
uint32_t TimerFlag;
uint32_t TimerCounter;
bool DTC_Distance;
bool flag_distance;
bool flag_read;
int distance_a;
/**********************************************************************************************************************
* DO NOT CHANGE THIS COMMENT! << STATIC VARIABLE DECLARATION >> DO NOT CHANGE THIS COMMENT!
*********************************************************************************************************************/
/*Task configuration table. Holds the task interval, last time executed, and
* the function to be executed. A continuous task is defined as a task with
* an interval of 0. Last time executed is set to 0.
*/
static TaskType Tasks[] =
{
{0 , 0 , BackgroundTask}, //This is background task
{INTERVAL_10MS , 0 , Task10MilliSecond},
{INTERVAL_50MS , 0 , Task50MilliSecond},
{INTERVAL_100MS , 0 , Task100MilliSecond},
};
/**********************************************************************************************************************
* DO NOT CHANGE THIS COMMENT! << STATIC FUNCTIONS DECLARATION >> DO NOT CHANGE THIS COMMENT!
*********************************************************************************************************************/
/**********************************************************************************************************************
* DO NOT CHANGE THIS COMMENT! << STATIC FUNCTIONS DEFINITIONS >> DO NOT CHANGE THIS COMMENT!
*********************************************************************************************************************/
/**********************************************************************************************************************
* DO NOT CHANGE THIS COMMENT! << GLOBAL FUNCTIONS DEFINITION >> DO NOT CHANGE THIS COMMENT!
*********************************************************************************************************************/
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
//pinMode(RGB_Temperature, OUTPUT);
pinMode(Echo, INPUT);
pinMode(Trig, OUTPUT);
}
//Timer interrupt
void TimerISR(void)
{
if (TimerFlag)
{
Serial.println("Timer ticked before task processing done. \n");
// printf("Timer ticked before task processing done.\n");
}
else
{
TimerFlag = 1;
}
return;
}
//This a simulation of a timer because we don't have a real timer to configure
void Timer(void)
{
uint32_t index;
for (index = 0; index < 100000000; index++)
{
}
TimerCounter++;
}
//Initialization of variable for Scheduler
void SchedulerInit(void)
{
TimerCounter = 0;
TimerFlag = 0;
}
void Scheduler(void)
{
unsigned long currentTime=millis();
uint32_t index;
Timer();
TimerISR();
if(TimerFlag == 1)
{
for(index = 1; index <= NUMBER_OF_TASK; index++)
{
if(currentTime - Tasks[index].LastTick >= Tasks[index].Interval)
{
Tasks[index].Func();
Tasks[index].LastTick = currentTime;
}
}
//After cyclic tasks are excuted , TimerFlag is down and background task is called
TimerFlag = 0;
while(!TimerFlag)
{
//Call background task
Tasks[0].Func();
//Simulate the interrupt
TimerISR();
}
}
}
void BackgroundTask(void) //Background Task will run when not cyclic task is running
{
// Serial.println("Idle");
}
void Task10MilliSecond(void) //this task will trigger every 10 milliseconds
{
//Distance_Measurement();
// Oil_Pressure_Measurement();
}
void Task50MilliSecond(void) //this task will trigger every 50 milliseconds
{
}
void Task100MilliSecond(void) //this task will trigger every 100 milliseconds //
{
Serial.println("salut");
}
void loop()
{
Serial_Read();
//SchedulerInit();
//Scheduler();
}