-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added 05-07 demos, challenges, and solutions. Updated README.
- Loading branch information
1 parent
4281e22
commit baf86d2
Showing
5 changed files
with
97 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
...p32-freertos-06-challenge-task-parameters/esp32-freertos-06-challenge-task-parameters.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/** | ||
* FreeRTOS Mutex Challenge | ||
* | ||
* Pass a parameter to a task using a mutex. | ||
* | ||
* Date: January 20, 2021 | ||
* Author: Shawn Hymel | ||
* License: 0BSD | ||
*/ | ||
|
||
// You'll likely need this on vanilla FreeRTOS | ||
//#include semphr.h | ||
|
||
// Use only core 1 for demo purposes | ||
#if CONFIG_FREERTOS_UNICORE | ||
static const BaseType_t app_cpu = 0; | ||
#else | ||
static const BaseType_t app_cpu = 1; | ||
#endif | ||
|
||
// Pins (change this if your Arduino board does not have LED_BUILTIN defined) | ||
static const int led_pin = LED_BUILTIN; | ||
|
||
//***************************************************************************** | ||
// Tasks | ||
|
||
// Blink LED based on rate passed by parameter | ||
void blinkLED(void *parameters) { | ||
|
||
// Copy the parameter into a local variable | ||
int num = *(int *)parameters; | ||
|
||
// Print the parameter | ||
Serial.print("Received: "); | ||
Serial.println(num); | ||
|
||
// Configure the LED pin | ||
pinMode(led_pin, OUTPUT); | ||
|
||
// Blink forever and ever | ||
while (1) { | ||
digitalWrite(led_pin, HIGH); | ||
vTaskDelay(num / portTICK_PERIOD_MS); | ||
digitalWrite(led_pin, LOW); | ||
vTaskDelay(num / portTICK_PERIOD_MS); | ||
} | ||
} | ||
|
||
//***************************************************************************** | ||
// Main (runs as its own task with priority 1 on core 1) | ||
|
||
void setup() { | ||
|
||
long int delay_arg; | ||
|
||
// Configure Serial | ||
Serial.begin(115200); | ||
|
||
// Wait a moment to start (so we don't miss Serial output) | ||
vTaskDelay(1000 / portTICK_PERIOD_MS); | ||
Serial.println(); | ||
Serial.println("---FreeRTOS Mutex Challenge---"); | ||
Serial.println("Enter a number for delay (milliseconds)"); | ||
|
||
// Wait for input from Serial | ||
while (Serial.available() <= 0); | ||
|
||
// Read integer value | ||
delay_arg = Serial.parseInt(); | ||
Serial.print("Sending: "); | ||
Serial.println(delay_arg); | ||
|
||
// Start task 1 | ||
xTaskCreatePinnedToCore(blinkLED, | ||
"Blink LED", | ||
1024, | ||
(void *)&delay_arg, | ||
1, | ||
NULL, | ||
app_cpu); | ||
|
||
// Show that we accomplished our task of passing the stack-based argument | ||
Serial.println("Done!"); | ||
} | ||
|
||
void loop() { | ||
|
||
// Do nothing but allow yielding to lower-priority tasks | ||
vTaskDelay(1000 / portTICK_PERIOD_MS); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters