#include <Arduino_FreeRTOS.h>
#include <semphr.h> // Include FreeRTOS mutex support
// Mutex handle
SemaphoreHandle_t Mutex_Com;
//--------------------------------------- Blink_LED--------------------------------------------
void Blink_LED(const uint8_t Led, int Delay)
{
digitalWrite(Led, HIGH);
delay(Delay);
//vTaskDelay((Delay * configTICK_RATE_HZ) / 1000L);
digitalWrite(Led, LOW);
}
//------------------------------------- Tache 1 ---------------------------------------------
void Tache_1(void * pvParameters )
{
while (1)
{
Blink_LED(7, 100);
xSemaphoreTake( Mutex_Com ,portMAX_DELAY ) ;
Serial.println("Task1");
xSemaphoreGive(Mutex_Com);
vTaskDelay(120);
}
}
//--------------------------------------- Tache 2 ---------------------------------------------
void Tache_2(void * pvParameters )
{
while (1)
{
Blink_LED(6, 200);
xSemaphoreTake( Mutex_Com ,portMAX_DELAY ) ;
Serial.println("Task2");
xSemaphoreGive(Mutex_Com);
vTaskDelay(400);
}
}
//--------------------------------------- Tache 3 ---------------------------------------------
void Tache_3(void * pvParameters )
{
while (1)
{
Blink_LED(5, 200);
xSemaphoreTake( Mutex_Com ,portMAX_DELAY ) ;
Serial.println("Task3");
xSemaphoreGive(Mutex_Com);
vTaskDelay(200);
}
}
//--------------------------------------- Setup -----------------------------------------------
void setup()
{
pinMode(7, OUTPUT); // configuration de pin 7 en sortie
pinMode(5, OUTPUT); // configuration de pin 5 en sortie
pinMode(6, OUTPUT); // configuration de pin 6 en sortie
Serial.begin(9600);
// création du sémaphore mutex
Mutex_Com=xSemaphoreCreateMutex() ;
//************ Création de trois taches périodiques *****
xTaskCreate(Tache_1, NULL, configMINIMAL_STACK_SIZE, NULL, 1, NULL);
xTaskCreate(Tache_2, NULL, configMINIMAL_STACK_SIZE, NULL, 1, NULL);
xTaskCreate(Tache_3, NULL, configMINIMAL_STACK_SIZE, NULL, 1, NULL);
//*********** Lancement du Scheduler ********************
vTaskStartScheduler();
while(1);
}
//------------------------------------------------------------------------------
void loop()
{
}