strategy to learn FreeRTOS [CLOSED]

Thread Starter

Pushkar1

Joined Apr 5, 2021
416
I want to learn FreeRTOS coding for ESP32 dev board. For this I have installed arduino IDE in my laptop. I have downloaded User Manual API document and sample code for PC from Freertos website. First I tried running the sample code in Visual Studio. I got off to a good start but it had some sample code. Then I moved from the PC to the ESP32.

After this I write some code for ESP32 in which I was checking what happens when the task priority is same, What happens when task priority is different, What happens when task is in block state.

I do not understand how to prepare the next strategy to learn FreeRTOS. What are the easy tasks that I should do first and then move on to the harder ones to learn?

if you want to learn FreeRTOS then how would you plan to learn. What are the 10 tasks for which you would like to check the result by writing code? Will you test each API in code or write code for a specific task?
 

DickCappels

Joined Aug 21, 2008
10,152
I would think of something I would like to accomplish with the tool (FreeRTOS) and then make a project out of it. Along the way, I would learn a lot about FreeRTOS. It has worked foro me on many different projects involving microcontrollers and their development environments in the past.
 

Irving

Joined Jan 30, 2016
3,843
My thoughts exactly. Find a real-world problem and code for that. My first foray into FreeRTOS on ESP32 a couple of years back was reading data from an external CANBus adaptor on one core into a ring buffer, synchronising that with further processing on the 2nd core and passing the result back via a second ring buffer to the internal CANBus controller on the first core, while the 2nd core reports aynchronously back to the host over a tcp/ip socket monitoring and state data... thats actually 4 tasks, 2 ring buffers, various semaphores, socket/wifi programming and at least 2 interrupt routines... Timing was critical and it took a few days to get it up and running reliably.
 

Thread Starter

Pushkar1

Joined Apr 5, 2021
416
My thoughts exactly. Find a real-world problem and code for that.
I want to learn FreeRTOS because now it is in high demand in the job market. Right now no such project is coming in my mind in which I need to write code for critical time. There are many projects available on the internet for FreeRTOS but for them I have to buy additional hardware like sensors and more. I was searching for some examples on the internet in which i can use what i have now available in my hand.

The number of times push button opens and closes by pressing and releasing the push button, Counting many times does button open and close a during debounce period is critical time task for me.

What do you think @Irving @DickCappels Is this a real world problem ?
 
Last edited:

Thread Starter

Pushkar1

Joined Apr 5, 2021
416
are you sure that a RTOS is appropriate for this task?
We use RTOS only when we need guaranteed response time, we cannot miss the deadline.

We can use interrupt to count the number of times the button opens and closes during the debounce period. RTOS is not necessary for this task.

Edit : But here's my point that I want to learn FreeRTOS that's why I can use it. counting task is time critical task because we want accurate count we don't want to miss any count.
 

Irving

Joined Jan 30, 2016
3,843
We use RTOS only when we need guaranteed response time, we cannot miss the deadline.

We can use interrupt to count the number of times the button opens and closes during the debounce period. RTOS is not necessary for this task.

Edit : But here's my point that I want to learn FreeRTOS that's why I can use it. counting task is time critical task because we want accurate count we don't want to miss any count.
It's a bit simplistic and interrupt programming isn't really a FreeRTOS issue; lm not sure how much 'rtos' experience you'll get from it, but give it a try.

But FreeRTOS isn't just about real time, it's also about handling multiple parallel co-operating or even competing tasks and resources.

You don't need a whole load of hardware to experiment. A few LED and push buttons is all that's needed if any. One of the examples my students use is 6 led and 4 pushbuttons and simulating the traffic lights at a crossroads. We first do it as a single state machine and then as 4 independent tasks each running their own state machines, with an overall master timer interrupt.

Another 'no hardware' example is implementing the classic producer-consumer pattern. Producer tasks create messages at random intervals with various priorities into one or more ring buffers. Consumer tasks remove them and process in order of priority. To make things even more 'interesting' high priority messages are sent back to the host via wifi while lower priority go via serial. There are many ways to implement this; discussion & decisions about how consumer tasks handle priorities on a single ring buffer can get quite heated!
 

Thread Starter

Pushkar1

Joined Apr 5, 2021
416
You don't need a whole load of hardware to experiment. A few LED and push buttons is all that's needed if any. One of the examples my students use is 6 led and 4 pushbuttons and simulating the traffic lights at a crossroads. We first do it as a single state machine and then as 4 independent tasks each running their own state machines, with an overall master timer interrupt.
I don't know how your student developed traffic light system in RTOS way. If you can share more information it would be helpful for me.

It is facts that traffic rules are not strictly followed in my country India. The fixed time traffic light system controller works for the vehicle in the city I live in. If you are driving car and you get green signal then you can go towards east north and south direction. One direction is active for one minute and on three directions the driver has to wait for one minute.

When the signal is green, the countdown timer starts at 60 seconds, so the driver can go in three directions. The yellow light turns on when the timer reaches 10 seconds. The red light turns on when the timer reaches 0 seconds. Driver has to stop when he sees a red light. It is a busy traffic system with long stops. In some places, automatic as well as manual traffic light system is operated.

@Irving
 

Irving

Joined Jan 30, 2016
3,843
In the UK drivers generally observe the traffic lights. This exercise models a main road with a cross street. Generally the main road has priority and a green light. In-road sensors (emulated here by a single push-button) detect when more than a few cars are waiting to cross and stop the main traffic for approx 60-90sec to allow cross traffic. Another set of in-road sensors detect build up on the main road and adjust the 'green' time on the side road to avoid too much delay on the main road. Finally another pair of push buttons represent pedestrian requests to cross both main and cross roads, which result in stopping both main and cross roads for variable periods of time depending on traffic volumes, plus managing both wait & cross-now signs and the countdown timers (represented by LEDs).

In the UK the lights sequence is Red (stop) , Red & Yellow (get ready, approx 4 - 5 sec), Green (go), Yellow (prepare to stop, 5 - 10sec), Red. Pedestrian lights are Red, Red/wait, Green/walk (15 - 20sec), flashing green/walk + countdown (typically 10sec), Red.

We typically use 1 task for the main road, 1 for the cross road, 1 for the pedestrian lights and one monitoring the traffic flows, plus inter-task communication via flags and semaphores.
 

Thread Starter

Pushkar1

Joined Apr 5, 2021
416
Thanks for the detailed information but still i don't understand how traffic light works with 6 led and 4 buttons. I think this confusion can be overcome by making a logic table. Right now my main objective is to create a logic table to understand the working of traffic light system. I need your help to make the logic table. I assume in the logic table I have four inputs buttons and six outputs led.

Do I have to specify the direction in the table and may also have to show columns for this direction? Do I have to make a separate column for Pedestrian as well?

@Irving
 
Top