File tree Expand file tree Collapse file tree 1 file changed +61
-0
lines changed
Expand file tree Collapse file tree 1 file changed +61
-0
lines changed Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments