IOT 6
IOT 6
RTOS II
Associated Prof. Wafaa
Shalash
Lect. 6
Class Rules
• Be in class on time,
• Listen to instructions and
explanations.
• Talk to your classmates only when
there is an activity.
• Use appropriate and professional
language.
• Keep your mobile silent.
Sensors & Protocols
Lecture Topics
• RTOS kernelKey
• Functions of the RTOS
Kernel
• What is RTOS task?
Scheduler
• The Heart of RTOS
• Preemptive vs Non-
Preemptive Scheduling
RTOS kernel
1. Task Priority
•Determines the order in which tasks are executed.
•Higher-priority tasks preempt lower-priority ones (in preemptive scheduling).
•Example: In FreeRTOS, priority ranges from 0 (lowest) to configMAX_PRIORITIES-1
(highest).
2. Task State
•A task can be in one of these states:
•Ready – Waiting to be executed (eligible for CPU time).
•Running – Currently executing on the CPU.
•Blocked/Waiting – Waiting for an event (e.g., delay, semaphore, message).
•Suspended – Manually paused (not scheduled until resumed).
Key RTOS Task Properties (cont.)
Property Description
Priority Determines execution order (higher = runs first)
State Ready, Running, Blocked, Suspended
Stack Size Memory reserved for task execution
Entry Function The function where the task starts
TCB OS-managed metadata for task control
Scheduling Preemptive, Round Robin, or Cooperative
Parameters Input data passed at task creation
Delay/Timeout Pausing or waiting for events
Sync Mechanisms Semaphores, Mutexes, Queues, Events
Deletion Dynamically removing a task
More On Priorie
Why Are Task Properties Important?
• Predictability – Ensures real-time deadlines are met.
• Resource Management – Prevents stack overflows and deadlocks.
• Efficiency – Optimizes CPU usage and task switching.
Example of an RTOS Task (FreeRTOS):
Fixed Priority Scheduling Priorities are set manually Simple and predictable
Needs careful
Resource handling Safer and simpler
management
osPriorityAboveNormal osPriorityAboveHigh
1. Preemptive Scheduling Example (Default in FreeRTOS)
Configuration:
#define configUSE_PREEMPTION 1 // Enables preemptive scheduling
Behavior:
•Task B starts running.
•When Task A becomes ready, it preempts
Task B.
•Task A runs first every time it's ready.
2. Non-Preemptive Scheduling Example
• Configuration:
#define configUSE_PREEMPTION 0 // Disables preemptive scheduling
Behavior:
Tasks only switch when they call vTaskDelay or
yield.
Even if Task A is higher priority, it must wait for
Task B to yield.
Task switching is cooperative.
Summary:
Responsiveness High (good for real-time) Low (task must give up CPU)