RTOS learning

Status
Not open for further replies.

Kittu20

Member level 2
Joined
Oct 18, 2022
Messages
52
Helped
1
Reputation
2
Reaction score
0
Trophy points
6
Activity points
427
Hello everyone

I've been immersing myself in the fascinating realm of Real-Time Operating Systems (RTOS) with a focus on FreeRTOS. The concepts of task scheduling, synchronization, and multitasking have got me intrigued, but now I'm on the hunt for exciting project ideas to put theory into practice.

Please keep in mind that I'm looking for projects that are within my reach and not too advanced, so projects like radar systems, air traffic control, and satellites are a bit beyond my current capabilities.

Do you have any project suggestions that would be a perfect fit for a RTOS? I’d really appreciate it!


[MODERATOR ACTION]​
Removed request for help to a specific member.​
Questions are not expected to be addressed to the whole comunity.​
 
Last edited by a moderator:

The Arduino platform was built on an RTOS, the freeRTOS, and it even inherits many of the RTOS resources in its framework so you can explore the various examples and tutorials available on the Web. In my particular case, I use it with the ESP32 core. BTW, Arduino works with a C++ compiling toolset, GCC if I'm not mistaken.
 
Hi,

I don´t use freeRTOS.

But you may use RTOS with almost any application.
Let´s say you have two simple tasks:
* blinking a LED with software (not hardware PWM, just as an example)
* and polling the UART to get the commands for for different blinking frequencies.

The - simple - solutionf for a LED blinking with 1Hz is:
* LED ON
* delay 500 ms
* LED ON
* delay 500 ms
.. and all this in a loop.

But this leaves no room for a fast enough UART poll not to lose UART data.

So you may use RTOS for this.
Just as an example. There are many other solutions to solve this problem.

Klaus
 
Let´s say you have two simple tasks:
* blinking a LED with software (not hardware PWM, just as an example)
* and pollin

This is what I understand from your description:

LED Control Task:
  • Purpose: Control LEDs based on received commands.
  • Inputs: Commands.
  • Outputs: LED control signals.
  • Sequence of Operations:
    1. Monitor received commands.
    2. Determine LED control based on received commands.
    3. Control LEDs accordingly.
  • Timing Constraints: LED updates can be less frequent than command reception.
  • Priority Level: Lowest priority
UART Communication Task:
  • Purpose: Transmit data to a system using UART communication.
  • Inputs: Data stored in a buffer.
  • Outputs: UART transmission.
  • Sequence of Operations:
    1. Read data from the buffer.
    2. Transmit data via UART to the central system.
  • Timing Constraints: UART transmission can occur at regular intervals or based on sufficient data.
  • Priority Level: Highest priority
 

I've put my best effort into crafting a scenario that requires efficient multitasking and real-time response, two key features of an RTOS.
However, I'm eager to hear your thoughts and insights.

Are there any adjustments or considerations that you would recommend?


Your feedback will be greatly appreciated and will contribute to enhancing my knowledge in this domain.

Thank you all in advance for your valuable input!
@KlausST
 

There are numerous approaches with RTOS'es that could meet that, so even if at a glance the above scenario seems ok, only by putting the hands-on, coding, looking and feeling you will indeed understand what resources are needed or missed; so the next step is to make a sketch and select what to use ( e.g. queue, mailbox, mutex, etc... ).
 
Hey everyone,

I wanted to provide an update on my project. I followed the suggestions you all gave, and I'm glad to report that things are working as expected! The UART communication and LED control tasks are functioning properly.

I noticed that the program seems to work fine even without the use of a mutex for synchronizing the access to the shared variables (receivedChar and commandReceived).

C:
//ESP32 and Arduino IDE C langauge 

#include "freertos/FreeRTOS.h"
#include "freertos/task.h"

#define LED_PIN 2
#define BAUD_RATE 115200

TaskHandle_t uartTaskHandle = NULL;
TaskHandle_t ledTaskHandle = NULL;

volatile char receivedChar = 0;
volatile bool commandReceived = false;

void setup()
{
  Serial.begin(BAUD_RATE);
  pinMode(LED_PIN, OUTPUT);

  xTaskCreate(
    uartTask,
    "UART Task",
    1000,
    NULL,
    1,
    &uartTaskHandle
  );

  xTaskCreate(
    ledTask,
    "LED Task",
    1000,
    NULL,
    1,
    &ledTaskHandle
  );

  Serial.println("Setup completed.");
}

void loop()
{
}

void uartTask(void * parameter)
{
  while (1)
  {
    if (Serial.available())
    {
      receivedChar = Serial.read();
      Serial.print("UART Task: Received character: ");
      Serial.println(receivedChar);
      commandReceived = true;
    }
    vTaskDelay(pdMS_TO_TICKS(10));
  }
}

void ledTask(void * parameter)
{
  while (1)
  {
    if (commandReceived)
    {
      if (receivedChar == '1')
      {
        digitalWrite(LED_PIN, HIGH);
        vTaskDelay(pdMS_TO_TICKS(500));  // LED on for 500 ms
        digitalWrite(LED_PIN, LOW);
        vTaskDelay(pdMS_TO_TICKS(500));  // LED off for 500 ms
      }
      else if (receivedChar == '2')
      {
        digitalWrite(LED_PIN, HIGH);
        vTaskDelay(pdMS_TO_TICKS(100));  // LED on for 100 ms
        digitalWrite(LED_PIN, LOW);
        vTaskDelay(pdMS_TO_TICKS(100));  // LED off for 100 ms
      }
    }
    else
    {
      digitalWrite(LED_PIN, LOW);  // Turn off LED if no command received
    }
    vTaskDelay(pdMS_TO_TICKS(10));
  }
}
 

I noticed that the program seems to work fine even without the use of a mutex for synchronizing the access to the shared variables (receivedChar and commandReceived).

As you are checking the status of the receive buffer, and as you are sharing the sending and receiving of the UART with only one Task in each, in fact, there is no need for more elaborate RTOS resources for this purpose.
 
Thank you for providing the practical use case to understand RTOS better. It helped me to understand task priority, multitasking, scheduling, and mutex. Now, I'm looking to grasp semaphore and queue applications. If you have any ideas or examples to share, I would greatly appreciate it!
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…