/*
Example of a FreeRTOS mutex
https://www.freertos.org/Real-time-embedded-RTOS-mutexes.html
*/
// Include Arduino FreeRTOS library
#include <Arduino_FreeRTOS.h>
// Include mutex support
#include <semphr.h>
/*
Declaring a global variable of type SemaphoreHandle_t
*/
SemaphoreHandle_t mutex;
int globalCount = 0;
void setup() {
Serial.begin(9600);
/**
Create a mutex.
https://www.freertos.org/CreateMutex.html
*/
mutex = xSemaphoreCreateMutex();
if (mutex != NULL) {
Serial.println("Mutex created");
}
/**
Create tasks
*/
xTaskCreate(TaskMutex, // Task function
"Task1", // Task name for humans
128,
2000, // Task parameter
1, // Task priority
NULL);
xTaskCreate(TaskMutex,
"Task2",
128,
2000,
1,
NULL);
}
void loop() {}