RTOS: Difference between revisions
Created page with "=Introduction= Thought I would do a page on RTOS so I have the terminology right. May do the same for Zephyr and Embassy to see how they compare. =RTOS Platforms= For me I have come across the different platforms *Zephyr running on my Nordic boards *FreeRTOS no used but the course drove me to this *IDF RTOS running on my ESP32 (not sure the difference) =Arduino= I guess most people of familiar with the Arduino approach to software with sketches. I dislike the ecosystem..." |
|||
Line 28: | Line 28: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
=Using Arduino with RTOS= | |||
The purpose of this page we will use only one processor, whereas the ESP32 I am using has two. To disable this we will use the following code. It will be omitted from code examples to save space. | |||
<syntaxhighlight lang="c"> | |||
// Use only core 1 for demo purposes | |||
#if CONFIG_FREERTOS_UNICORE | |||
static const BaseType_t app_cpu = 0; | |||
#else | |||
static const BaseType_t app_cpu = 1; | |||
#endif | |||
</syntaxhighlight> | |||
=Tasks= | |||
In RTOS a task is a unit of work. It have these states<br> | |||
[[File:RTOS States.png|300px]]<br> | |||
To create a task we use the following code. | |||
<syntaxhighlight lang="c"> | |||
// Task to run forever | |||
xTaskCreatePinnedToCore( // Use xTaskCreate() in vanilla FreeRTOS | |||
toggleLED_1, // Function to be called | |||
"Toggle 1", // Name of task | |||
1024, // Stack size (bytes in ESP32, words in FreeRTOS) | |||
NULL, // Parameter to pass to function | |||
1, // Task priority (0 to configMAX_PRIORITIES - 1) | |||
NULL, // Task handle | |||
app_cpu); // Run on one core for demo purposes (ESP32 only) | |||
</syntaxhighlight> | |||
I guess this is mainly self explanatory. There are other APIs to create a task. I have used xTaskCreate, but I think we are using this to ensure only on CPU is useda task |
Revision as of 22:22, 28 December 2024
Introduction
Thought I would do a page on RTOS so I have the terminology right. May do the same for Zephyr and Embassy to see how they compare.
RTOS Platforms
For me I have come across the different platforms
- Zephyr running on my Nordic boards
- FreeRTOS no used but the course drove me to this
- IDF RTOS running on my ESP32 (not sure the difference)
Arduino
I guess most people of familiar with the Arduino approach to software with sketches. I dislike the ecosystem and try to avoid it but this is what the course used.
void foo1() {
// Do some function
}
void foo2() {
// Do some function
}
void setup() {
// Do some setup
}
void loop() {
// Do something forever
foo1();
foo2();
}
Using Arduino with RTOS
The purpose of this page we will use only one processor, whereas the ESP32 I am using has two. To disable this we will use the following code. It will be omitted from code examples to save space.
// Use only core 1 for demo purposes
#if CONFIG_FREERTOS_UNICORE
static const BaseType_t app_cpu = 0;
#else
static const BaseType_t app_cpu = 1;
#endif
Tasks
In RTOS a task is a unit of work. It have these states
To create a task we use the following code.
// Task to run forever
xTaskCreatePinnedToCore( // Use xTaskCreate() in vanilla FreeRTOS
toggleLED_1, // Function to be called
"Toggle 1", // Name of task
1024, // Stack size (bytes in ESP32, words in FreeRTOS)
NULL, // Parameter to pass to function
1, // Task priority (0 to configMAX_PRIORITIES - 1)
NULL, // Task handle
app_cpu); // Run on one core for demo purposes (ESP32 only)
I guess this is mainly self explanatory. There are other APIs to create a task. I have used xTaskCreate, but I think we are using this to ensure only on CPU is useda task