Task creating - FreeRTOS

Thread Starter

Pushkar1

Joined Apr 5, 2021
416
I want to port free rtos on ESP32. I have installed Arduino IDE on Windows 10 system. I don't find current version of free rtos for ESP32. Can anyone tell me where to get current version of free rtos for ESP32 on freertos website?
 

Thread Starter

Pushkar1

Joined Apr 5, 2021
416
I think the activity known as porting has already be done. It is just a matter of using google to find the pieces that you need.
I thought i had to download the free rtos file. because i saw that for avr and other microcontrollers we have to download free rtos files. But I just understood that when we install library for ESP32 , the free rtos library gets installed by default
 

Ya’akov

Joined Jan 27, 2019
9,152
Hello @Pushkar1. Just a clarification about porting. Why something is ported the code is modified to run properly on a different target system. This can include processor architecture, operating system, and programming language.

Just using something isn't porting. Not a big deal but it's a very specific term and if you use it to mean something random you are likely to confuse people.
 

Thread Starter

Pushkar1

Joined Apr 5, 2021
416
I wrote code for two LED's after spending few time on internet. My main objective was to flash two LED's using FreeRTOS

C:
/* Include FreeRTOS APIs and defines */
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/timers.h"

const int LED_1 = 22; //Pin of the LED_1
const int LED_2 = 25; //Pin of the LED_2

void setup()
{
   Serial.begin(115200);
   pinMode(LED_1, OUTPUT);
   pinMode(LED_2, OUTPUT);

/*For creating Task, xTaskCreate() API is called in setup function with certain parameters/arguments.*/
  xTaskCreate(
    Task1,          /*Task1 function */
    "Task1",        /*Task name - Task1*/
    1000,           /* Task stack, allocated from heap */
    NULL,           /* No param passed to task function */
    1,              /* Priority 1*/
    NULL);          /* Task handle */

  xTaskCreate(
    Task2,         /* Task2 function */
    "Task2",       /*Task name - Task2*/
    1000,          /*Task stack, allocated from heap */
    NULL,          /* No param passed to task function */
    2,              /* Priority 2*/             
    NULL);         /* Task handle */
}

void Task1( void * parameter )
{
  Serial.print("Task1 is running on core ");

  for(;;)
  {
    digitalWrite(LED_1, HIGH);
    delay(500);
    digitalWrite(LED_1, LOW);
    delay(500);
  }
}

void Task2( void * parameter )
{
  for(;;)
  {
    digitalWrite(LED_2, HIGH); // Make LED 2 Pin High
    delay(500);
    digitalWrite(LED_2, LOW); //Make LED 2 Pin Low
    delay(500);
  }
}
void loop() {}
 
Last edited:

Ya’akov

Joined Jan 27, 2019
9,152
The point of an RTOS is to have access to the CPU even when there are other things are running. You should try to make something interactive that accepts, say, a button press, while still executing something which needs a lot of CPU. Maybe something that changes the blinking of the LEDs.
 

Thread Starter

Pushkar1

Joined Apr 5, 2021
416
The point of an RTOS is to have access to the CPU even when there are other things are running. You should try to make something interactive that accepts, say, a button press, while still executing something which needs a lot of CPU. Maybe something that changes the blinking of the LEDs.
@Yaakov Thank you! I didn't understand clearly, need more explanation. single core cpu can execute only one task at a time. Task 1 and Task 2 run on the CPU for the amount of time given to them.
 

Thread Starter

Pushkar1

Joined Apr 5, 2021
416
The preemptive scheduler is part of the OS. It's not that more than one task executers, it's how the OS manages access to the CPU.

https://www.freertos.org/implementation/a00005.html
After much thought, I have come to the conclusion that I should first learn how to schedule a task.

For Example : system tick 1 ms

T1 runs once for 8ms in every 40ms with Priority 2
T2 runs twice for 5ms in every 40ms with Priority1
T3 runs three times for 10ms in every 40ms with Priority3

C:
TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT.
22222111111113333333222223333333333333
I don't understand how to write coding for this example
 
Top