3
3
https://www.freertos.org/RTOS_Task_Notification_As_Binary_Semaphore.html
4
4
*/
5
5
6
- // Include Arduino FreeRTOS library
7
- #include < Arduino_FreeRTOS .h>
6
+ # include < Arduino.h >
7
+ #include < Adafruit_TinyUSB .h> // for Serial
8
8
9
9
/* *
10
10
Declaring a global TaskHandle for the led task.
@@ -13,8 +13,17 @@ TaskHandle_t taskNotificationHandler;
13
13
14
14
void setup () {
15
15
16
+ Serial.begin (115200 );
17
+
18
+ // Wait for a serial port connection to be established before continuing.
19
+ // Don't want to miss any debug messages.
20
+ while ( !Serial ) delay (10 ); // for nrf52840 with native usb
21
+
22
+ Serial.println (" STARTING THE APPLICATION." );
23
+
24
+
16
25
// Configure pin 2 as an input and enable the internal pull-up resistor.
17
- pinMode (2 , INPUT_PULLUP);
26
+ pinMode (4 , INPUT_PULLUP);
18
27
19
28
// Create task for FreeRTOS notification
20
29
xTaskCreate (TaskNotification, // Task function
@@ -27,6 +36,30 @@ void setup() {
27
36
28
37
void loop () {
29
38
39
+ static bool firstTime = true ;
40
+ static int previousDigitalReadValue = -1 ;
41
+
42
+ if ( firstTime ) {
43
+ Serial.println (" Starting loop...." );
44
+ delay (1000 );
45
+
46
+ firstTime = false ;
47
+ }
48
+
49
+ int digitalReadValue = digitalRead (4 );
50
+
51
+ if (digitalReadValue != previousDigitalReadValue) {
52
+ if (digitalReadValue == HIGH) {
53
+ Serial.println (" HIGH" );
54
+ }
55
+ else {
56
+ Serial.println (" LOW" );
57
+ }
58
+
59
+ previousDigitalReadValue = digitalReadValue;
60
+ }
61
+
62
+ delay (1000 );
30
63
}
31
64
32
65
/*
@@ -36,11 +69,17 @@ void TaskNotification(void *pvParameters)
36
69
{
37
70
(void ) pvParameters;
38
71
39
- int digitalPin = 2 ;
72
+ int digitalPin = 4 ;
73
+
74
+
75
+ int rv = attachInterrupt (digitalPinToInterrupt (digitalPin), digitalPinInterruptHandler, CHANGE);
40
76
41
- Serial.begin (9600 );
77
+ Serial.print (" Starting task " );
78
+ Serial.print (pcTaskGetName (NULL )); // Get task name
79
+ Serial.print (" with rv = " );
80
+ Serial.println (rv);
81
+ delay (1000 );
42
82
43
- attachInterrupt (digitalPinToInterrupt (digitalPin), digitalPinInterruptHandler, LOW);
44
83
45
84
for (;;) {
46
85
@@ -53,9 +92,11 @@ void TaskNotification(void *pvParameters)
53
92
54
93
55
94
void digitalPinInterruptHandler () {
95
+ Serial.println (" digitalPinInterruptHandler()" );
56
96
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
57
97
vTaskNotifyGiveFromISR (taskNotificationHandler, &xHigherPriorityTaskWoken);
58
98
if (xHigherPriorityTaskWoken) {
99
+ Serial.println (" Calling taskYIELD()" );
59
100
taskYIELD ();
60
101
}
61
102
}
0 commit comments