#if CONFIG_FREERTOS_UNICORE
static const BaseType_t app_cpu = 0;
#else
static const BaseType_t app_cpu = 1;
#endif
// Global Variables -
static int shared_var = 0;
static SemaphoreHandle_t mutex;
// ------------------------------------------------- Task1
void incTask(void *parameters)
{
int local_var;
// Loop
while(1)
{
// Take mutex prior to critical section
if(xSemaphoreTake(mutex,0)==pdTRUE)
{
shared_var++;
Serial.println(shared_var);
vTaskDelay(1000/portTICK_PERIOD_MS);
xSemaphoreGive(mutex);
}
else{
}
}
}
// ------------------------------------------------------
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("------------FreeRTOS Mutex demo---------");
// Create mutex before starting the tasks
mutex = xSemaphoreCreateMutex();
// Start CLI task
xTaskCreatePinnedToCore(incTask,
"CLI",
1024,
NULL,
1,
NULL,
app_cpu);
xTaskCreatePinnedToCore(incTask,
"CLI2",
1024,
NULL,
1,
NULL,
app_cpu);
// Delete "setup and loop" task
vTaskDelete(NULL);
}
void loop() {
// put your main code here, to run repeatedly:
delay(10); // this speeds up the simulation
}