#include <Arduino_FreeRTOS.h>
#include "semphr.h"
SemaphoreHandle_t serial_mutex;
void setup() {
Serial.begin(9600);
//how to call a mutex, just ensure to do the include and its
//handle
serial_mutex = xSemaphoreCreateMutex();
xTaskCreate(task1, "print task", 128, NULL, 2, NULL);
xTaskCreate(task2, "print task", 128, NULL, 2, NULL);
}
void loop() {
//this code is empty
}
void task1(void *pvParameters){
while(1){
if(xSemaphoreTake(serial_mutex, portMAX_DELAY) == pdTRUE){
Serial.println("Hello from task1");
xSemaphoreGive(serial_mutex);
vTaskDelay(1000/portTICK_PERIOD_MS);
}
}
}
void task2(void *pvParameters){
while(1){
if(xSemaphoreTake(serial_mutex, portMAX_DELAY) == pdTRUE){
Serial.println("Hello from task2");
xSemaphoreGive(serial_mutex);
vTaskDelay(1000/portTICK_PERIOD_MS);
}
}
}