Standard FreeRTOS uses C based API. However I prefer to have some lean C++ abstractions. That’s when I discovered the freertos-addons project from Michael Becker.

I have converted it to an Arduino Library, so that it can be used e.g. on an ESP32. I also added a new Task class (which is a subclass of Thread) that allows to pass a function pointer in the constructor. For the ESP32 we support the xTaskCreatePinnedToCore() method by indicating the core in the Start method.

Here is the link that shows all supported classes!

Example

Here is a simple example that creates a task from a lambda function, starts it on core 0 and uses a queue to pass the information back to the Arduino task:

#include "freertos-all.h"

Queue queue(100, sizeof(size_t));
Task task("name",1000,10, [](){ static size_t count=0; queue.Enqueue(&(++count));});

void setup() {
  Serial.begin(115200);
  task.Start(0);
}

void loop() {
  size_t result;
  queue.Dequeue(&result);
  Serial.println(result);
}

Further Information

Further information can be found on Github!

Categories: Arduino

2 Comments

Hardy · 26. August 2023 at 3:43

Hi Phil. I think you’ll find that if you use the Ardunio implementation for ESP32 that FreeRTOS is already in the libraries.

    pschatzmann · 26. August 2023 at 3:46

    The C API is part of Arduino. This is about a proper C++ API!

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *