From ec7d3c260b202c1369385d8fce1c1e40324d5bac Mon Sep 17 00:00:00 2001 From: Muhammad Lutfi Santoso Date: Sat, 17 Nov 2018 07:04:31 +0700 Subject: [PATCH 1/4] Add FreeRTOS exsample --- libraries/FreeRTOS/FreeRTOS.ino | 114 ++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 libraries/FreeRTOS/FreeRTOS.ino diff --git a/libraries/FreeRTOS/FreeRTOS.ino b/libraries/FreeRTOS/FreeRTOS.ino new file mode 100644 index 00000000000..7a699f91ccd --- /dev/null +++ b/libraries/FreeRTOS/FreeRTOS.ino @@ -0,0 +1,114 @@ +#if CONFIG_FREERTOS_UNICORE +#define ARDUINO_RUNNING_CORE 0 +#else +#define ARDUINO_RUNNING_CORE 1 +#endif + +// define two tasks for Blink & AnalogRead +void TaskAnalogReadA0( void *pvParameters ); +void TaskAnalogReadA3( void *pvParameters ); + +// the setup function runs once when you press reset or power the board +void setup() { + + // initialize serial communication at 9600 bits per second: + Serial.begin(115200); + + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB, on LEONARDO, MICRO, YUN, and other 32u4 based boards. + } + + // Now set up two tasks to run independently. + xTaskCreatePinnedToCore( + TaskAnalogReadA0 + , "AnalogReadA0" // A name just for humans + , 128 // This stack size can be checked & adjusted by reading the Stack Highwater + , NULL + , 2 // Priority, with 3 (configMAX_PRIORITIES - 1) being the highest, and 0 being the lowest. + , NULL + , ARDUINO_RUNNING_CORE); + + xTaskCreatePinnedToCore( + TaskAnalogReadA3 + , "AnalogReadA3" + , 128 // Stack size + , NULL + , 1 // Priority + , NULL + , ARDUINO_RUNNING_CORE); + + // Now the task scheduler, which takes over control of scheduling individual tasks, is automatically started. +} + +void loop() +{ + for(;;);// Empty. Things are done in Tasks. +} + +/*--------------------------------------------------*/ +/*---------------------- Tasks ---------------------*/ +/*--------------------------------------------------*/ + +void TaskAnalogReadA0(void *pvParameters) // This is a task. +{ + (void) pvParameters; + +/* + Blink + Turns on an LED on for one second, then off for one second, repeatedly. + + Most Arduinos have an on-board LED you can control. On the UNO, LEONARDO, MEGA, and ZERO + it is attached to digital pin 13, on MKR1000 on pin 6. LED_BUILTIN takes care + of use the correct LED pin whatever is the board used. + + The MICRO does not have a LED_BUILTIN available. For the MICRO board please substitute + the LED_BUILTIN definition with either LED_BUILTIN_RX or LED_BUILTIN_TX. + e.g. pinMode(LED_BUILTIN_RX, OUTPUT); etc. + + If you want to know what pin the on-board LED is connected to on your Arduino model, check + the Technical Specs of your board at https://www.arduino.cc/en/Main/Products + + This example code is in the public domain. + + modified 8 May 2014 + by Scott Fitzgerald + + modified 2 Sep 2016 + by Arturo Guadalupi +*/ + + // initialize digital LED_BUILTIN on pin 13 as an output. + //pinMode(LED_BUILTIN, OUTPUT); + + for (;;) // A Task shall never return or exit. + { + // read the input on analog pin 0: + int sensorValueA0 = analogRead(A0); + // print out the value you read: + Serial.println(sensorValueA0); + vTaskDelay(100); // one tick delay (15ms) in between reads for stability + } +} + +void TaskAnalogReadA3(void *pvParameters) // This is a task. +{ + (void) pvParameters; + +/* + AnalogReadSerial + Reads an analog input on pin 0, prints the result to the serial monitor. + Graphical representation is available using serial plotter (Tools > Serial Plotter menu) + Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground. + + This example code is in the public domain. +*/ + + for (;;) + { + // read the input on analog pin 0: + int sensorValueA3 = analogRead(A3); + // print out the value you read: + Serial.println(sensorValueA3); + vTaskDelay(10); // one tick delay (15ms) in between reads for stability + } +} From e39f0ae5840e7e720afb2aa19c903c8c79089137 Mon Sep 17 00:00:00 2001 From: Muhammad Lutfi Santoso Date: Sun, 18 Nov 2018 23:40:53 +0700 Subject: [PATCH 2/4] Update Code --- libraries/FreeRTOS/FreeRTOS.ino | 209 +++++++++++++++----------------- 1 file changed, 96 insertions(+), 113 deletions(-) diff --git a/libraries/FreeRTOS/FreeRTOS.ino b/libraries/FreeRTOS/FreeRTOS.ino index 7a699f91ccd..abed7975566 100644 --- a/libraries/FreeRTOS/FreeRTOS.ino +++ b/libraries/FreeRTOS/FreeRTOS.ino @@ -1,114 +1,97 @@ -#if CONFIG_FREERTOS_UNICORE -#define ARDUINO_RUNNING_CORE 0 -#else -#define ARDUINO_RUNNING_CORE 1 -#endif - -// define two tasks for Blink & AnalogRead -void TaskAnalogReadA0( void *pvParameters ); -void TaskAnalogReadA3( void *pvParameters ); - -// the setup function runs once when you press reset or power the board -void setup() { - - // initialize serial communication at 9600 bits per second: - Serial.begin(115200); - - while (!Serial) { - ; // wait for serial port to connect. Needed for native USB, on LEONARDO, MICRO, YUN, and other 32u4 based boards. - } - - // Now set up two tasks to run independently. - xTaskCreatePinnedToCore( - TaskAnalogReadA0 - , "AnalogReadA0" // A name just for humans - , 128 // This stack size can be checked & adjusted by reading the Stack Highwater - , NULL - , 2 // Priority, with 3 (configMAX_PRIORITIES - 1) being the highest, and 0 being the lowest. - , NULL - , ARDUINO_RUNNING_CORE); - - xTaskCreatePinnedToCore( - TaskAnalogReadA3 - , "AnalogReadA3" - , 128 // Stack size - , NULL - , 1 // Priority - , NULL - , ARDUINO_RUNNING_CORE); - - // Now the task scheduler, which takes over control of scheduling individual tasks, is automatically started. -} - -void loop() -{ - for(;;);// Empty. Things are done in Tasks. -} - -/*--------------------------------------------------*/ -/*---------------------- Tasks ---------------------*/ -/*--------------------------------------------------*/ - -void TaskAnalogReadA0(void *pvParameters) // This is a task. -{ - (void) pvParameters; - -/* - Blink - Turns on an LED on for one second, then off for one second, repeatedly. - - Most Arduinos have an on-board LED you can control. On the UNO, LEONARDO, MEGA, and ZERO - it is attached to digital pin 13, on MKR1000 on pin 6. LED_BUILTIN takes care - of use the correct LED pin whatever is the board used. - - The MICRO does not have a LED_BUILTIN available. For the MICRO board please substitute - the LED_BUILTIN definition with either LED_BUILTIN_RX or LED_BUILTIN_TX. - e.g. pinMode(LED_BUILTIN_RX, OUTPUT); etc. - - If you want to know what pin the on-board LED is connected to on your Arduino model, check - the Technical Specs of your board at https://www.arduino.cc/en/Main/Products - - This example code is in the public domain. - - modified 8 May 2014 - by Scott Fitzgerald - - modified 2 Sep 2016 - by Arturo Guadalupi -*/ - - // initialize digital LED_BUILTIN on pin 13 as an output. - //pinMode(LED_BUILTIN, OUTPUT); - - for (;;) // A Task shall never return or exit. - { - // read the input on analog pin 0: - int sensorValueA0 = analogRead(A0); - // print out the value you read: - Serial.println(sensorValueA0); - vTaskDelay(100); // one tick delay (15ms) in between reads for stability - } -} - -void TaskAnalogReadA3(void *pvParameters) // This is a task. -{ - (void) pvParameters; - -/* - AnalogReadSerial - Reads an analog input on pin 0, prints the result to the serial monitor. - Graphical representation is available using serial plotter (Tools > Serial Plotter menu) - Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground. - - This example code is in the public domain. -*/ - - for (;;) - { - // read the input on analog pin 0: - int sensorValueA3 = analogRead(A3); - // print out the value you read: - Serial.println(sensorValueA3); - vTaskDelay(10); // one tick delay (15ms) in between reads for stability - } +#if CONFIG_FREERTOS_UNICORE +#define ARDUINO_RUNNING_CORE 0 +#else +#define ARDUINO_RUNNING_CORE 1 +#endif + +// define two tasks for Blink & AnalogRead +void TaskBlink( void *pvParameters ); +void TaskAnalogReadA3( void *pvParameters ); + +// the setup function runs once when you press reset or power the board +void setup() { + + // initialize serial communication at 115200 bits per second: + Serial.begin(115200); + + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB, on LEONARDO, MICRO, YUN, and other 32u4 based boards. + } + + // Now set up two tasks to run independently. + xTaskCreatePinnedToCore( + TaskBlink + , "TaskBlink" // A name just for humans + , 128 // This stack size can be checked & adjusted by reading the Stack Highwater + , NULL + , 2 // Priority, with 3 (configMAX_PRIORITIES - 1) being the highest, and 0 being the lowest. + , NULL + , ARDUINO_RUNNING_CORE); + + xTaskCreatePinnedToCore( + TaskAnalogReadA3 + , "AnalogReadA3" + , 128 // Stack size + , NULL + , 1 // Priority + , NULL + , ARDUINO_RUNNING_CORE); + + // Now the task scheduler, which takes over control of scheduling individual tasks, is automatically started. +} + +void loop() +{ + for(;;);// Empty. Things are done in Tasks. +} + +/*--------------------------------------------------*/ +/*---------------------- Tasks ---------------------*/ +/*--------------------------------------------------*/ + +void TaskBlink(void *pvParameters) // This is a task. +{ + (void) pvParameters; + +/* + Blink + Turns on an LED on for one second, then off for one second, repeatedly. + + If you want to know what pin the on-board LED is connected to on your ESP32 model, check + the Technical Specs of your board. +*/ + + // initialize digital LED_BUILTIN on pin 13 as an output. + pinMode(LED_BUILTIN, OUTPUT); + + for (;;) // A Task shall never return or exit. + { + digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level) + vTaskDelay(100); // one tick delay (15ms) in between reads for stability + digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW + vTaskDelay(100); // one tick delay (15ms) in between reads for stability + } +} + +void TaskAnalogReadA3(void *pvParameters) // This is a task. +{ + (void) pvParameters; + +/* + AnalogReadSerial + Reads an analog input on pin A3, prints the result to the serial monitor. + Graphical representation is available using serial plotter (Tools > Serial Plotter menu) + Attach the center pin of a potentiometer to pin A#, and the outside pins to +5V and ground. + + This example code is in the public domain. +*/ + + for (;;) + { + // read the input on analog pin A3: + int sensorValueA3 = analogRead(A3); + // print out the value you read: + Serial.println(sensorValueA3); + vTaskDelay(10); // one tick delay (15ms) in between reads for stability + } } From 43779b54bbbd54dc073a62bd4dad33cce1fc98b3 Mon Sep 17 00:00:00 2001 From: Muhammad Lutfi Santoso Date: Mon, 19 Nov 2018 00:08:13 +0700 Subject: [PATCH 3/4] Change stack size --- libraries/FreeRTOS/FreeRTOS.ino | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libraries/FreeRTOS/FreeRTOS.ino b/libraries/FreeRTOS/FreeRTOS.ino index abed7975566..a9222d16059 100644 --- a/libraries/FreeRTOS/FreeRTOS.ino +++ b/libraries/FreeRTOS/FreeRTOS.ino @@ -22,7 +22,7 @@ void setup() { xTaskCreatePinnedToCore( TaskBlink , "TaskBlink" // A name just for humans - , 128 // This stack size can be checked & adjusted by reading the Stack Highwater + , 1024 // This stack size can be checked & adjusted by reading the Stack Highwater , NULL , 2 // Priority, with 3 (configMAX_PRIORITIES - 1) being the highest, and 0 being the lowest. , NULL @@ -31,7 +31,7 @@ void setup() { xTaskCreatePinnedToCore( TaskAnalogReadA3 , "AnalogReadA3" - , 128 // Stack size + , 1024 // Stack size , NULL , 1 // Priority , NULL @@ -81,7 +81,7 @@ void TaskAnalogReadA3(void *pvParameters) // This is a task. AnalogReadSerial Reads an analog input on pin A3, prints the result to the serial monitor. Graphical representation is available using serial plotter (Tools > Serial Plotter menu) - Attach the center pin of a potentiometer to pin A#, and the outside pins to +5V and ground. + Attach the center pin of a potentiometer to pin A3, and the outside pins to +5V and ground. This example code is in the public domain. */ From 2a18a1cad0acf0151a5877e24c1bded42fa7e096 Mon Sep 17 00:00:00 2001 From: Me No Dev Date: Sun, 16 Dec 2018 17:26:40 +0100 Subject: [PATCH 4/4] Fix LED_BUILTIN not defined Fix LED_BUILTIN not defined --- libraries/FreeRTOS/FreeRTOS.ino | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/libraries/FreeRTOS/FreeRTOS.ino b/libraries/FreeRTOS/FreeRTOS.ino index a9222d16059..b120f29268a 100644 --- a/libraries/FreeRTOS/FreeRTOS.ino +++ b/libraries/FreeRTOS/FreeRTOS.ino @@ -4,6 +4,10 @@ #define ARDUINO_RUNNING_CORE 1 #endif +#ifndef LED_BUILTIN +#define LED_BUILTIN 13 +#endif + // define two tasks for Blink & AnalogRead void TaskBlink( void *pvParameters ); void TaskAnalogReadA3( void *pvParameters ); @@ -14,10 +18,6 @@ void setup() { // initialize serial communication at 115200 bits per second: Serial.begin(115200); - while (!Serial) { - ; // wait for serial port to connect. Needed for native USB, on LEONARDO, MICRO, YUN, and other 32u4 based boards. - } - // Now set up two tasks to run independently. xTaskCreatePinnedToCore( TaskBlink @@ -42,7 +42,7 @@ void setup() { void loop() { - for(;;);// Empty. Things are done in Tasks. + // Empty. Things are done in Tasks. } /*--------------------------------------------------*/