SlideShare a Scribd company logo
J E A N L A B R O S S E | D I S T I N G U I S H E D E N G I N E E R
E M B E D D E D W O R L D : F E B R U A R Y 2 6 - 2 8 , 2 0 1 9
Everything You Need to Know about RTOSs in 30 Minutes
§ An RTOS is software that manages the time and resources of a CPU
§ Application is split into multiple tasks
§ The RTOS’s job is to run the most important task that is ready-to-run
§ On a single CPU, only one task executes at any given time
An RTOS Allows Multitasking
RTOS
(Code)
Task
(Code+Data+Stack)
Task
(Code+Data+Stack)
Task
(Code+Data+Stack)
Task
(Code+Data+Stack)
High
Priority
Low
Priority
Events
Signals/Messages
from Tasks or ISRs
CPU+FPU+MPU
(8, 16, 32 or 64-bit)
Select
Highest Priority Task
Tasks that are ready-to-run
silabs.com | @silabs
An RTOS Provides Services To Your Application
CPU + FPU (opt) + MPU (opt)
Tasks
OSTaskCreate(..)
OSTaskDel(..)
OSTaskSuspend(..)
OSTaskResume(..)
OSTaskChangePrio()
:
:
Semaphores
OSSemCreate(..)
OSSemDel(..)
OSSemPend(..)
OSSemPost(..)
:
:
OSFlagCreate(..)
OSFlagDel(..)
OSFlagPend(..)
OSFlagPost(..)
:
:
Event Flags Mutexes
OSMutexCreate(..)
OSMutexDel(..)
OSMutexPend(..)
OSMutexPost(..)
:
:
OSQCreate(..)
OSQDel(..)
OSQPend(..)
OSQPost(..)
:
:
Queues
OSTmrCreate(..)
OSTmrDel(..)
OSTmrStart(..)
OSTmrStop(..)
:
:
Timers Memory Blocks
OSMemCreate(..)
OSMemDel(..)
OSMemGet(..)
OSMemPut(..)
:
:
RTOS
Application
(Code + Data)
Optional Middleware
(Code + Data)
(TCP/IP, GUI, File System, USB Stacks, Bluetooth, Etc.)
Time
OSTimeDly(..)
OSTimeDlyHMSM(..)
OSTimeDlyResume(..)
OSTimeGet(..)
OSTimeSet(..)
:
:
silabs.com | @silabs
Benefits of Using an RTOS
§ Allows you to split and prioritize the application code
§ The RTOS always runs the highest priority task that is ready
§ Adding low-priority tasks don’t affect the responsiveness of
high priority tasks
§ Tasks wait for events
§ Avoids polling
§ RTOSs make it easy to add middleware components
§ TCP/IP stack
§ USB stacks
§ File System
§ Graphical User Interface (GUI)
§ Etc.
silabs.com | @silabs
Benefits of Using an RTOS
§ Creates a framework for developing applications
§ Facilitate teams of multiple developers
§ It’s possible to meet all the deadlines of an application
§ Rate Monotonic Analysis (RMA) could be used to determine schedulability
§ Most RTOSs have undergone thorough testing
§ Some are third-party certifiable, and even certified (DO-178B, IEC-61508, IEC-62304, etc.)
§ It’s unlikely that you will find bugs in RTOSs
§ RTOSs typically support many different CPU architectures
§ Very easy to add power management
silabs.com | @silabs
Drawbacks of Using an RTOS
§ The RTOS itself is code and thus requires more Flash
§ Typically between 6-20K bytes
§ An RTOS requires extra RAM
§ Each task requires its own stack
§ The size of each task depends on the application
§ Each task needs to be assigned a Task Control Block (TCB)
§ About 32 to 128 bytes of RAM
§ About 256 bytes for the RTOS variables
§ You have to assign task priorities
§ Deciding on what priority to give tasks is not always trivial
§ The services provided by the RTOS consume CPU time
§ Overhead is typically 2-10% of the CPU cycles
§ There is a learning curve associated with the RTOS you select
silabs.com | @silabs
§ For each task:
§ YOU assign a priority based on its importance
§ Requires its own Stack
§ Manages its own variables, arrays and structures
§ Is typically an infinite loop
§ Possibly manages I/O devices
§ Contains YOUR application code
Tasks
CPU_STK MyTaskStk[MY_TASK_STK_SIZE]; // Task Stack
void MyTask (void *p_arg) // Task Code
{
Local Variables;
Task initialization;
while (1) { // Infinite Loop (Typ.)
Wait for Event;
Perform task operation; // Do something useful
}
}
Task
(Priority)
Stack
(RAM) Variables
Arrays
Structures
(RAM)
I/O
Device(s)
(Optional)
silabs.com | @silabs
§ You must tell the RTOS about the existence of a task:
§ The RTOS provides a special API: OSTaskCreate() (or equivalent)
§ The RTOS assigns the task:
§ Its own set of CPU registers
§ A Task Control Block (TCB)
Creating a Task
Task
(Priority)
Stack
(RAM) Variables
Arrays
Structures
(RAM)
CPU
Registers
(CPU+FPU+MPU)
I/O
Device(s)
(Optional)
TCB
(RAM)
void OSTaskCreate (MyTask, // Address of code
&MyTaskStk[0], // Base of stack
MY_TASK_STK_SIZE,// Size of stack
MY_TASK_PRIO, // Task priority
:
:);
silabs.com | @silabs
RTOSs Are Event Driven
Task
Task
Task
Task
Task
High Priority
Low Priority
void EachTask (void)
{
Task initialization;
while (1) {
Setup to wait for event;
Wait for MY event to occur;
Perform task operation;
}
}
Event
Occurs
Wait For
Event
§ Only the highest-priority Ready task can execute
§ Other tasks will run when the current task decides to waits for its event
§ Ready tasks are placed in the RTOS’s Ready List
§ Tasks waiting for their event are placed in the Event Wait List …
Task
Task Task
silabs.com | @silabs
Tasks Waiting for Events Are Placed in a Wait List
Task waiting for
DMA to complete
DMA Completion
Semaphore
Printer Access
Mutex
Task waiting to
access printer
Task waiting to
access printer
Task waiting to
access printer
High Priority Low Priority
Tick List
(Delta List) Task waiting for
time to expire
Task waiting for
time to expire
Task waiting for
time to expire
Shortest Delay or Timeout Longest Delay or Timeout
silabs.com | @silabs
RTOSs Are Preemptive
High Priority Task
Low Priority Task Low Priority Task
Event
Occurs
Signal
Task
RTOS
Resumes
Task
RTOS
Resumes
Task
Wait For
Event
ISR
void Low_Prio_Task (void)
{
Task initialization;
while (1) {
Setup to wait for event;
Wait for event to occur;
Perform task operation;
}
}
void High_Prio_Task (void)
{
Task initialization;
while (1) {
Setup to wait for event;
Wait for event to occur;
Perform task operation;
}
}
void ISR (void)
{
Entering ISR;
Perform Work;
Signal or Send Message to Task;
Perform Work; // Optional
Leaving ISR;
}
Time
RTOS Overhead
silabs.com | @silabs
Interrupts Must Notify the RTOS
§ Oftentimes, interrupts are events that tasks are
wait for
§ Interrupts are more important than tasks
§ Assuming, of course, that interrupts are enabled
§ Kernel Aware (KA) ISRs:
§ Need to notify the RTOS of ISR entry and exit
§ Allows for nesting ISRs and avoid multiple scheduling
§ ISRs can be written directly in C on Cortex-M CPUs
void MyISR (void)
{
Entering ISR;
:
Signal or send a message to a MyTask;
:
Leaving ISR;
}
Task
Task
Event
Occurs
ISR Level 3
RTOS resumes which task?
Signal
OR?
Task
ISR Level 2
ISR Level 1
Exit
Enter
Event
Occurs
Event
Occurs
No scheduling
No scheduling
Scheduling
silabs.com | @silabs
A Context Switch Occurs When the RTOS Decides to Run Another Task
Example using Cortex-M4
CPU
FPU
Task Stack
(RAM)
Task Stack
(RAM)
CPU Registers
+
FPU Registers
Context
Switch
Save
Restore
1
2
Task
Control
Block
(TCB)
Task
Control
Block
(TCB)
silabs.com | @silabs
Most RTOSs Have a Periodic Time Source
§ Most RTOS have a time-based interrupt
§ Called the System Tick or Clock Tick
§ Requires a hardware timer
§ The System Tick is used to provide coarse:
§ Delay (or sleep)
§ Timeouts on Wait for Event RTOS APIs
§ A System Tick is not mandatory!
§ If you don’t need time delays or timeouts you can
remove it
§ Typically interrupts at regular intervals
§ Not power-efficient
§ Dynamic tick (a.k.a. tick suppression) is more efficient
§ Requires reconfiguring the tick timer at each interrupt
Typical RTOS Tick
Dynamic RTOS Tick
5 ms 17 ms 5 ms
3 ms
Typ. 1 ms
silabs.com | @silabs
RTOS Services – Time Delays (i.e. Sleep)
§ A task can put itself to sleep by calling RTOS APIs:
§ OSTimeDly() // Delay for N ticks
§ OSTimeDlyHMSM() // Delay for Hours, Minutes, Seconds, Milliseconds
§ Can be used to wake up a task at regular intervals
§ Control loops
§ Updating a display
§ Scanning a keyboard
§ Letting other tasks a chance to run
§ Etc.
Task
void Task (void)
{
Task initialization;
while (1) {
Sleep for ‘N’ ticks;
Do work;
}
}
N Ticks
silabs.com | @silabs
RTOS Services – Sharing a Resource Using a Mutex
§ What is a resource?
§ Shared memory, variables, arrays, structures
§ I/O devices
§ RTOSs typically provide resource sharing APIs
§ Mutex have built-in priority inheritance
§ Eliminates unbounded priority inversions
§ There could be multiple mutexes in a system
§ Each protecting access to a different resource
Task
Task
Task
Shared
Resource
(Memory or I/O)
Mutex
Acquire
Relinquish
1
2
Access
3
void EachTask (void)
{
Task initialization;
while (1) {
:
:
Acquire Mutex;
Access the resource;
Relinquish the Mutex;
:
}
}
Timeout
OSMutexPost()
OSMutexPend()
silabs.com | @silabs
RTOS Services – Signaling a Task Using a Semaphore
§ Semaphores can be used to signal a task
§ Called from ISR or Task
§ Does not contain data
ISR Task
Semaphore
Signal Wait
void TaskEventISR (void)
{
Clear interrupt;
Signal Semaphore;
}
Timeout
void Task (void)
{
Task Initialization;
while (1) {
Wait on Semaphore;
Perform work;
}
}
OSSemPost() OSSemPend()
silabs.com | @silabs
RTOS Services – Signaling Task(s) Using Event Flags
§ Event Flags are a grouping of bits used to signal the
occurrence of more than one events
§ Signals from ISRs or Tasks
§ Only tasks can wait for events
Task
Event
Flag
Group
Set/Clear
Flag(s)
Timeout
void Task (void)
{
Task Initialization;
while (1) {
Wait on Event Flag Group;
Perform work;
}
}
Task
Timeout
Wait for ‘ANY’ of
the desired flags
Wait for ‘ALL’ of
the desired flags
ISR
Set/Clear
Flag(s)
void TaskEventISR (void)
{
Clear interrupt;
Signal Event Flag Group;
}
Task
‘N’
Flag(s)
‘M’
Flag(s)
OSFlagPend()
OSFlagPend()
OSFlagPost()
OSFlagPost()
silabs.com | @silabs
RTOS Services – Sending Messages to Task(s)
§ Messages can be sent from an ISR or a task to other task(s)
§ Messages are typically pointers to data
§ The data sent depends on the application
§ The data must remain in scope until no longer referenced
Task
Task
Task
Send
void ReceiverTask (void)
{
Task initialization;
while (1) {
Wait for Message;
Process data;
}
}
Receive
Producers
void SenderTask (void)
{
Task initialization;
while (1) {
Produce data;
Send to task;
}
}
ISR
Timeout
OSQPost() OSQPend()
Data
Send
Send
Consumer(s)
silabs.com | @silabs
Debugging RTOS-Based Systems – µC/Probe, Graphical Live Watch®
§ Seeing inside an embedded system
§ Non-intrusive
§ Display or change ANY values numerically
or graphically
§ A universal tool that interfaces to any
target:
§ 8-, 16-, 32-, 64-bit and DSPs
§ No CPU intervention with Cortex-M
§ Requires target resident code if not using the
debug port:
§ RS232C
§ TCP/IP
§ USB
§ For bare metal or RTOS-Based applications
§ Micrium’s RTOS and TCP/IP awareness
Your
Code
RTOS
(Optional)
Libraries
Compiler
Assembler
Linker
Debugger
Cortex-M
Target
.ELF
IDE
µC/Probe
.ELF
CDF (I/Os)
CSF (Custom Symbols)
On-the-Fly
Memory & I/O
Access
silabs.com | @silabs
Debugging RTOS-Based Systems – µC/Probe, Graphical Live Watch®
§ RTOS awareness
§ Task state stack usage
§ CPU usage
§ Run counters
§ Interrupt disable time
§ Kernel objects
§ Etc.
§ Built-in 8 channel oscilloscope
§ Display live data in Microsoft Excel
§ Scripting
§ Joystick Interface
§ Multimedia support
§ Etc.
Micrium’s µC/ProbeTM
silabs.com | @silabs
Debugging RTOS-Based Systems – Segger’s SystemView
§ Displays the execution profile of RTOS-
based systems
§ Displayed live
§ Trigger on any task or ISR
§ Visualizing the execution profile of an
application
§ Helps confirm the expected behavior of your
system
§ Measures CPU usage on a per-task basis
§ Min/Max/Avg task run time
§ Counts the number of task executions
§ Display the occurrence of ‘events’ in your
code
§ Traces can be saved for post-analysis or
record keeping
silabs.com | @silabs
Do You Need an RTOS?
§ Do you have some real-time requirements?
§ Do you have independent tasks?
§ User interface, control loops, communications, etc.
§ Do you have tasks that could starve other tasks?
§ e.g. updating a graphics display, receiving an Ethernet frame, encryption, etc.
§ Do you have multiple programmers working on different portions of your project?
§ Is portability and reuse important?
§ Does your product need additional middleware components?
§ TCP/IP stack, USB stack, GUI, File System, Bluetooth, etc.
§ Do you have enough RAM to support multiple tasks?
§ Flash memory is rarely a concern because most embedded systems have more Flash than RAM
§ Are you using a 32-bit CPU?
§ You should consider using an RTOS
silabs.com | @silabs
§ Silicon Labs Integrated Development Environment (FREE):
§ https://www.silabs.com/products/development-tools/software/simplicity-studio
§ Silicon Labs Development Boards:
§ https://www.silabs.com/products/development-tools/mcu
§ Silicon Labs / Micrium OS Kernel (FREE when using Silicon Labs chips):
§ https://www.silabs.com/products/development-tools/software/micrium-os
§ Micrium’s µC/Probe, Graphical Live Watch® (FREE Educational Version):
§ https://www.micrium.com/ucprobe/trial/
§ Segger’s SystemView (FREE Evaluation Version):
§ https://www.segger.com/downloads/free-utilities/
§ Micrium Books (FREE PDF downloads):
§ https://www.micrium.com/books/ucosiii/
Development Tools and Books
silabs.com | @silabs
S I L A B S . C O M
Thank you!

More Related Content

PPTX
FreeRTOS basics (Real time Operating System)
PPTX
REAL TIME OPERATING SYSTEM
PDF
PPT
1230 Rtf Final
PPTX
PART-2 : Mastering RTOS FreeRTOS and STM32Fx with Debugging
PPTX
RTOS _Timer , Event, Memory, Device, File & IO Systems Management_10-07-25.pptx
PDF
The Free RTOS kernel By Khaled AMIRAT
FreeRTOS basics (Real time Operating System)
REAL TIME OPERATING SYSTEM
1230 Rtf Final
PART-2 : Mastering RTOS FreeRTOS and STM32Fx with Debugging
RTOS _Timer , Event, Memory, Device, File & IO Systems Management_10-07-25.pptx
The Free RTOS kernel By Khaled AMIRAT

Similar to Intro To RTOS by Silicon labs covering fundamentals (20)

PPTX
Embedded os
PDF
RTOS implementation
PPTX
ERTOS_Spectrum_Unit01_PresentationP.pptx
PDF
FreeRTOS Slides annotations.pdf
PPTX
Real time operating systems (rtos) concepts 9
PPTX
RTOS_Keywords_with basic Definitions.pptx
PPTX
Real Time Operating Systems Basic Definitions
PPTX
Introduction to RTOS
PPTX
Real time operating systems (rtos) concepts 4
PPTX
Real Time OS For Embedded Systems
PPTX
Real Time Operating Systems, Dynamic Precision: Exploring the Realm of Real-...
PPTX
Real time Operating System
PPT
Real Time Operating Systems
PPTX
OVERVIEW OF RTOS
PPT
Real-Time Operating Systems Real-Time Operating Systems RTOS .ppt
PDF
freertos-proj.pdf
PPTX
Entreprenuership notes module 3 notes.pptx
PPTX
tasks (mutenga) (1).pptx
PPTX
PPT
21-Classification of Real time system-12-02-2025.ppt
Embedded os
RTOS implementation
ERTOS_Spectrum_Unit01_PresentationP.pptx
FreeRTOS Slides annotations.pdf
Real time operating systems (rtos) concepts 9
RTOS_Keywords_with basic Definitions.pptx
Real Time Operating Systems Basic Definitions
Introduction to RTOS
Real time operating systems (rtos) concepts 4
Real Time OS For Embedded Systems
Real Time Operating Systems, Dynamic Precision: Exploring the Realm of Real-...
Real time Operating System
Real Time Operating Systems
OVERVIEW OF RTOS
Real-Time Operating Systems Real-Time Operating Systems RTOS .ppt
freertos-proj.pdf
Entreprenuership notes module 3 notes.pptx
tasks (mutenga) (1).pptx
21-Classification of Real time system-12-02-2025.ppt
Ad

Recently uploaded (20)

PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PPTX
L1 - Introduction to python Backend.pptx
PPTX
Operating system designcfffgfgggggggvggggggggg
PPTX
Odoo POS Development Services by CandidRoot Solutions
PDF
AI in Product Development-omnex systems
PPTX
Essential Infomation Tech presentation.pptx
PDF
System and Network Administration Chapter 2
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PPTX
Reimagine Home Health with the Power of Agentic AI​
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
Understanding Forklifts - TECH EHS Solution
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PDF
System and Network Administraation Chapter 3
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
L1 - Introduction to python Backend.pptx
Operating system designcfffgfgggggggvggggggggg
Odoo POS Development Services by CandidRoot Solutions
AI in Product Development-omnex systems
Essential Infomation Tech presentation.pptx
System and Network Administration Chapter 2
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
How to Choose the Right IT Partner for Your Business in Malaysia
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
wealthsignaloriginal-com-DS-text-... (1).pdf
Wondershare Filmora 15 Crack With Activation Key [2025
Reimagine Home Health with the Power of Agentic AI​
Internet Downloader Manager (IDM) Crack 6.42 Build 41
Understanding Forklifts - TECH EHS Solution
2025 Textile ERP Trends: SAP, Odoo & Oracle
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
System and Network Administraation Chapter 3
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Ad

Intro To RTOS by Silicon labs covering fundamentals

  • 1. J E A N L A B R O S S E | D I S T I N G U I S H E D E N G I N E E R E M B E D D E D W O R L D : F E B R U A R Y 2 6 - 2 8 , 2 0 1 9 Everything You Need to Know about RTOSs in 30 Minutes
  • 2. § An RTOS is software that manages the time and resources of a CPU § Application is split into multiple tasks § The RTOS’s job is to run the most important task that is ready-to-run § On a single CPU, only one task executes at any given time An RTOS Allows Multitasking RTOS (Code) Task (Code+Data+Stack) Task (Code+Data+Stack) Task (Code+Data+Stack) Task (Code+Data+Stack) High Priority Low Priority Events Signals/Messages from Tasks or ISRs CPU+FPU+MPU (8, 16, 32 or 64-bit) Select Highest Priority Task Tasks that are ready-to-run silabs.com | @silabs
  • 3. An RTOS Provides Services To Your Application CPU + FPU (opt) + MPU (opt) Tasks OSTaskCreate(..) OSTaskDel(..) OSTaskSuspend(..) OSTaskResume(..) OSTaskChangePrio() : : Semaphores OSSemCreate(..) OSSemDel(..) OSSemPend(..) OSSemPost(..) : : OSFlagCreate(..) OSFlagDel(..) OSFlagPend(..) OSFlagPost(..) : : Event Flags Mutexes OSMutexCreate(..) OSMutexDel(..) OSMutexPend(..) OSMutexPost(..) : : OSQCreate(..) OSQDel(..) OSQPend(..) OSQPost(..) : : Queues OSTmrCreate(..) OSTmrDel(..) OSTmrStart(..) OSTmrStop(..) : : Timers Memory Blocks OSMemCreate(..) OSMemDel(..) OSMemGet(..) OSMemPut(..) : : RTOS Application (Code + Data) Optional Middleware (Code + Data) (TCP/IP, GUI, File System, USB Stacks, Bluetooth, Etc.) Time OSTimeDly(..) OSTimeDlyHMSM(..) OSTimeDlyResume(..) OSTimeGet(..) OSTimeSet(..) : : silabs.com | @silabs
  • 4. Benefits of Using an RTOS § Allows you to split and prioritize the application code § The RTOS always runs the highest priority task that is ready § Adding low-priority tasks don’t affect the responsiveness of high priority tasks § Tasks wait for events § Avoids polling § RTOSs make it easy to add middleware components § TCP/IP stack § USB stacks § File System § Graphical User Interface (GUI) § Etc. silabs.com | @silabs
  • 5. Benefits of Using an RTOS § Creates a framework for developing applications § Facilitate teams of multiple developers § It’s possible to meet all the deadlines of an application § Rate Monotonic Analysis (RMA) could be used to determine schedulability § Most RTOSs have undergone thorough testing § Some are third-party certifiable, and even certified (DO-178B, IEC-61508, IEC-62304, etc.) § It’s unlikely that you will find bugs in RTOSs § RTOSs typically support many different CPU architectures § Very easy to add power management silabs.com | @silabs
  • 6. Drawbacks of Using an RTOS § The RTOS itself is code and thus requires more Flash § Typically between 6-20K bytes § An RTOS requires extra RAM § Each task requires its own stack § The size of each task depends on the application § Each task needs to be assigned a Task Control Block (TCB) § About 32 to 128 bytes of RAM § About 256 bytes for the RTOS variables § You have to assign task priorities § Deciding on what priority to give tasks is not always trivial § The services provided by the RTOS consume CPU time § Overhead is typically 2-10% of the CPU cycles § There is a learning curve associated with the RTOS you select silabs.com | @silabs
  • 7. § For each task: § YOU assign a priority based on its importance § Requires its own Stack § Manages its own variables, arrays and structures § Is typically an infinite loop § Possibly manages I/O devices § Contains YOUR application code Tasks CPU_STK MyTaskStk[MY_TASK_STK_SIZE]; // Task Stack void MyTask (void *p_arg) // Task Code { Local Variables; Task initialization; while (1) { // Infinite Loop (Typ.) Wait for Event; Perform task operation; // Do something useful } } Task (Priority) Stack (RAM) Variables Arrays Structures (RAM) I/O Device(s) (Optional) silabs.com | @silabs
  • 8. § You must tell the RTOS about the existence of a task: § The RTOS provides a special API: OSTaskCreate() (or equivalent) § The RTOS assigns the task: § Its own set of CPU registers § A Task Control Block (TCB) Creating a Task Task (Priority) Stack (RAM) Variables Arrays Structures (RAM) CPU Registers (CPU+FPU+MPU) I/O Device(s) (Optional) TCB (RAM) void OSTaskCreate (MyTask, // Address of code &MyTaskStk[0], // Base of stack MY_TASK_STK_SIZE,// Size of stack MY_TASK_PRIO, // Task priority : :); silabs.com | @silabs
  • 9. RTOSs Are Event Driven Task Task Task Task Task High Priority Low Priority void EachTask (void) { Task initialization; while (1) { Setup to wait for event; Wait for MY event to occur; Perform task operation; } } Event Occurs Wait For Event § Only the highest-priority Ready task can execute § Other tasks will run when the current task decides to waits for its event § Ready tasks are placed in the RTOS’s Ready List § Tasks waiting for their event are placed in the Event Wait List … Task Task Task silabs.com | @silabs
  • 10. Tasks Waiting for Events Are Placed in a Wait List Task waiting for DMA to complete DMA Completion Semaphore Printer Access Mutex Task waiting to access printer Task waiting to access printer Task waiting to access printer High Priority Low Priority Tick List (Delta List) Task waiting for time to expire Task waiting for time to expire Task waiting for time to expire Shortest Delay or Timeout Longest Delay or Timeout silabs.com | @silabs
  • 11. RTOSs Are Preemptive High Priority Task Low Priority Task Low Priority Task Event Occurs Signal Task RTOS Resumes Task RTOS Resumes Task Wait For Event ISR void Low_Prio_Task (void) { Task initialization; while (1) { Setup to wait for event; Wait for event to occur; Perform task operation; } } void High_Prio_Task (void) { Task initialization; while (1) { Setup to wait for event; Wait for event to occur; Perform task operation; } } void ISR (void) { Entering ISR; Perform Work; Signal or Send Message to Task; Perform Work; // Optional Leaving ISR; } Time RTOS Overhead silabs.com | @silabs
  • 12. Interrupts Must Notify the RTOS § Oftentimes, interrupts are events that tasks are wait for § Interrupts are more important than tasks § Assuming, of course, that interrupts are enabled § Kernel Aware (KA) ISRs: § Need to notify the RTOS of ISR entry and exit § Allows for nesting ISRs and avoid multiple scheduling § ISRs can be written directly in C on Cortex-M CPUs void MyISR (void) { Entering ISR; : Signal or send a message to a MyTask; : Leaving ISR; } Task Task Event Occurs ISR Level 3 RTOS resumes which task? Signal OR? Task ISR Level 2 ISR Level 1 Exit Enter Event Occurs Event Occurs No scheduling No scheduling Scheduling silabs.com | @silabs
  • 13. A Context Switch Occurs When the RTOS Decides to Run Another Task Example using Cortex-M4 CPU FPU Task Stack (RAM) Task Stack (RAM) CPU Registers + FPU Registers Context Switch Save Restore 1 2 Task Control Block (TCB) Task Control Block (TCB) silabs.com | @silabs
  • 14. Most RTOSs Have a Periodic Time Source § Most RTOS have a time-based interrupt § Called the System Tick or Clock Tick § Requires a hardware timer § The System Tick is used to provide coarse: § Delay (or sleep) § Timeouts on Wait for Event RTOS APIs § A System Tick is not mandatory! § If you don’t need time delays or timeouts you can remove it § Typically interrupts at regular intervals § Not power-efficient § Dynamic tick (a.k.a. tick suppression) is more efficient § Requires reconfiguring the tick timer at each interrupt Typical RTOS Tick Dynamic RTOS Tick 5 ms 17 ms 5 ms 3 ms Typ. 1 ms silabs.com | @silabs
  • 15. RTOS Services – Time Delays (i.e. Sleep) § A task can put itself to sleep by calling RTOS APIs: § OSTimeDly() // Delay for N ticks § OSTimeDlyHMSM() // Delay for Hours, Minutes, Seconds, Milliseconds § Can be used to wake up a task at regular intervals § Control loops § Updating a display § Scanning a keyboard § Letting other tasks a chance to run § Etc. Task void Task (void) { Task initialization; while (1) { Sleep for ‘N’ ticks; Do work; } } N Ticks silabs.com | @silabs
  • 16. RTOS Services – Sharing a Resource Using a Mutex § What is a resource? § Shared memory, variables, arrays, structures § I/O devices § RTOSs typically provide resource sharing APIs § Mutex have built-in priority inheritance § Eliminates unbounded priority inversions § There could be multiple mutexes in a system § Each protecting access to a different resource Task Task Task Shared Resource (Memory or I/O) Mutex Acquire Relinquish 1 2 Access 3 void EachTask (void) { Task initialization; while (1) { : : Acquire Mutex; Access the resource; Relinquish the Mutex; : } } Timeout OSMutexPost() OSMutexPend() silabs.com | @silabs
  • 17. RTOS Services – Signaling a Task Using a Semaphore § Semaphores can be used to signal a task § Called from ISR or Task § Does not contain data ISR Task Semaphore Signal Wait void TaskEventISR (void) { Clear interrupt; Signal Semaphore; } Timeout void Task (void) { Task Initialization; while (1) { Wait on Semaphore; Perform work; } } OSSemPost() OSSemPend() silabs.com | @silabs
  • 18. RTOS Services – Signaling Task(s) Using Event Flags § Event Flags are a grouping of bits used to signal the occurrence of more than one events § Signals from ISRs or Tasks § Only tasks can wait for events Task Event Flag Group Set/Clear Flag(s) Timeout void Task (void) { Task Initialization; while (1) { Wait on Event Flag Group; Perform work; } } Task Timeout Wait for ‘ANY’ of the desired flags Wait for ‘ALL’ of the desired flags ISR Set/Clear Flag(s) void TaskEventISR (void) { Clear interrupt; Signal Event Flag Group; } Task ‘N’ Flag(s) ‘M’ Flag(s) OSFlagPend() OSFlagPend() OSFlagPost() OSFlagPost() silabs.com | @silabs
  • 19. RTOS Services – Sending Messages to Task(s) § Messages can be sent from an ISR or a task to other task(s) § Messages are typically pointers to data § The data sent depends on the application § The data must remain in scope until no longer referenced Task Task Task Send void ReceiverTask (void) { Task initialization; while (1) { Wait for Message; Process data; } } Receive Producers void SenderTask (void) { Task initialization; while (1) { Produce data; Send to task; } } ISR Timeout OSQPost() OSQPend() Data Send Send Consumer(s) silabs.com | @silabs
  • 20. Debugging RTOS-Based Systems – µC/Probe, Graphical Live Watch® § Seeing inside an embedded system § Non-intrusive § Display or change ANY values numerically or graphically § A universal tool that interfaces to any target: § 8-, 16-, 32-, 64-bit and DSPs § No CPU intervention with Cortex-M § Requires target resident code if not using the debug port: § RS232C § TCP/IP § USB § For bare metal or RTOS-Based applications § Micrium’s RTOS and TCP/IP awareness Your Code RTOS (Optional) Libraries Compiler Assembler Linker Debugger Cortex-M Target .ELF IDE µC/Probe .ELF CDF (I/Os) CSF (Custom Symbols) On-the-Fly Memory & I/O Access silabs.com | @silabs
  • 21. Debugging RTOS-Based Systems – µC/Probe, Graphical Live Watch® § RTOS awareness § Task state stack usage § CPU usage § Run counters § Interrupt disable time § Kernel objects § Etc. § Built-in 8 channel oscilloscope § Display live data in Microsoft Excel § Scripting § Joystick Interface § Multimedia support § Etc. Micrium’s µC/ProbeTM silabs.com | @silabs
  • 22. Debugging RTOS-Based Systems – Segger’s SystemView § Displays the execution profile of RTOS- based systems § Displayed live § Trigger on any task or ISR § Visualizing the execution profile of an application § Helps confirm the expected behavior of your system § Measures CPU usage on a per-task basis § Min/Max/Avg task run time § Counts the number of task executions § Display the occurrence of ‘events’ in your code § Traces can be saved for post-analysis or record keeping silabs.com | @silabs
  • 23. Do You Need an RTOS? § Do you have some real-time requirements? § Do you have independent tasks? § User interface, control loops, communications, etc. § Do you have tasks that could starve other tasks? § e.g. updating a graphics display, receiving an Ethernet frame, encryption, etc. § Do you have multiple programmers working on different portions of your project? § Is portability and reuse important? § Does your product need additional middleware components? § TCP/IP stack, USB stack, GUI, File System, Bluetooth, etc. § Do you have enough RAM to support multiple tasks? § Flash memory is rarely a concern because most embedded systems have more Flash than RAM § Are you using a 32-bit CPU? § You should consider using an RTOS silabs.com | @silabs
  • 24. § Silicon Labs Integrated Development Environment (FREE): § https://www.silabs.com/products/development-tools/software/simplicity-studio § Silicon Labs Development Boards: § https://www.silabs.com/products/development-tools/mcu § Silicon Labs / Micrium OS Kernel (FREE when using Silicon Labs chips): § https://www.silabs.com/products/development-tools/software/micrium-os § Micrium’s µC/Probe, Graphical Live Watch® (FREE Educational Version): § https://www.micrium.com/ucprobe/trial/ § Segger’s SystemView (FREE Evaluation Version): § https://www.segger.com/downloads/free-utilities/ § Micrium Books (FREE PDF downloads): § https://www.micrium.com/books/ucosiii/ Development Tools and Books silabs.com | @silabs
  • 25. S I L A B S . C O M Thank you!