Skip to content

Commit c5484f6

Browse files
committed
2 parents a28b479 + feec156 commit c5484f6

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/**
2+
Example of a Arduino interruption and RTOS Task Notification.
3+
https://www.freertos.org/RTOS_Task_Notification_As_Binary_Semaphore.html
4+
*/
5+
6+
// Include Arduino FreeRTOS library
7+
#include <Arduino_FreeRTOS.h>
8+
9+
/**
10+
Declaring a global TaskHandle for the led task.
11+
*/
12+
TaskHandle_t taskNotificationHandler;
13+
14+
void setup() {
15+
16+
// Configure pin 2 as an input and enable the internal pull-up resistor.
17+
pinMode(2, INPUT_PULLUP);
18+
19+
// Create task for FreeRTOS notification
20+
xTaskCreate(TaskNotification, // Task function
21+
"Notification", // Task name
22+
128, // Stack size
23+
NULL,
24+
3, // Priority
25+
&taskNotificationHandler ); // TaskHandle
26+
}
27+
28+
void loop() {
29+
30+
}
31+
32+
/*
33+
Notification task.
34+
*/
35+
void TaskNotification(void *pvParameters)
36+
{
37+
(void) pvParameters;
38+
39+
int digitalPin = 2;
40+
41+
Serial.begin(115200);
42+
43+
attachInterrupt(digitalPinToInterrupt(digitalPin), digitalPinInterruptHandler, LOW);
44+
45+
for (;;) {
46+
47+
if (ulTaskNotifyTake(pdTRUE, portMAX_DELAY)) {
48+
Serial.println("Notification received");
49+
}
50+
51+
}
52+
}
53+
54+
55+
void digitalPinInterruptHandler() {
56+
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
57+
vTaskNotifyGiveFromISR(taskNotificationHandler, &xHigherPriorityTaskWoken);
58+
if (xHigherPriorityTaskWoken) {
59+
taskYIELD();
60+
}
61+
}

0 commit comments

Comments
 (0)