#include <Arduino_FreeRTOS.h>
#include "semphr.h"
SemaphoreHandle_t xSemaphore;
void setup() {
Serial.begin(9600);
pinMode(2, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(2), my_isr, FALLING);
xTaskCreate(isr_task, "process event", 128, NULL, 3, NULL);
xTaskCreate(my_print, "print task", 128, NULL, 2, NULL);
xSemaphore = xSemaphoreCreateBinary();
}
void loop() {
//this code is empty
}
void my_print(void *pvParameters){
while(1){
Serial.println("Hello from Task 1");
vTaskDelay( 1000 / portTICK_PERIOD_MS );
}
}
void isr_task(void *pvParameters){
while(1){
xSemaphoreTake(xSemaphore, portMAX_DELAY);
Serial.println("Push Button Pressed, Process Event");
}
}
void my_isr(){
//xSemaphoreGiveFromISR(xSemaphore, NULL);
BaseType_t high_priority_waiting = pdFALSE;
xSemaphoreGiveFromISR(xSemaphore, &high_priority_waiting);
if(high_priority_waiting == true){
Serial.println("Require context switch");
}
else{
Serial.println("no context switching");
}
}