#include <Arduino_FreeRTOS.h>
#include "semphr.h"
//Mutex handler
SemaphoreHandle_t xMutex;
void setup()
{
// Setting buad rate in arduino board
Serial.begin(9600);
//API for creating mutex & Initializing with mutex handler
xMutex = xSemaphoreCreateMutex();
// Creating two task with equal priority
xTaskCreate(Ram_Turn,"RAM_IS_PLAYING",100,NULL,2,NULL);
xTaskCreate(Ram_Turn,"LAXMAN_IS_PLAYING",100,NULL,3,NULL);
}
// Ram task
void Ram_Turn(void *pvParameters)
{
while (1)
{
xSemaphoreTake(xMutex, portMAX_DELAY);
Serial.println("RAM's Turn to play ");
taskYIELD();
Serial.println("playing mario \r\n");
xSemaphoreGive(xMutex);
taskYIELD();
}
}
//Laxman task
void Laxman_Turn(void *pvParameters)
{
while (1)
{
xSemaphoreTake(xMutex, portMAX_DELAY);
Serial.println("And now Laxman turn to play ");
taskYIELD();
Serial.println("playing modern combat\r\n");
xSemaphoreGive(xMutex);
taskYIELD();
}
}
void loop() {
// put your main code here, to run repeatedly:
}