0% found this document useful (0 votes)
5 views

Module-3.1 - Embedded Systems Based on SoC and RTOS

The document outlines a course on Embedded Systems and IoT, focusing on embedded systems based on System-on-a-Chip (SoC) and Real-Time Operating Systems (RTOS). It discusses the transition from microcontrollers to SoCs, detailing their architecture, examples, and the integration of various components. Additionally, it covers the role of operating systems in managing resources and providing an abstraction layer for application programs.

Uploaded by

arvin.lajani3
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Module-3.1 - Embedded Systems Based on SoC and RTOS

The document outlines a course on Embedded Systems and IoT, focusing on embedded systems based on System-on-a-Chip (SoC) and Real-Time Operating Systems (RTOS). It discusses the transition from microcontrollers to SoCs, detailing their architecture, examples, and the integration of various components. Additionally, it covers the role of operating systems in managing resources and providing an abstraction layer for application programs.

Uploaded by

arvin.lajani3
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 75

v1.0.

0-20241119

Embedded Systems and IoT


Ingegneria e Scienze Informatiche - UNIBO
a.a 2024/2025
Lecturer: Prof. Alessandro Ricci

[module-3.1]
EMBEDDED SYSTEMS
BASED ON SOC AND RTOS
ESIOT ISI-LT - UNIBO EMBEDDED SYSTEMS BASED ON SOC AND RTOS 1
MODULE OUTLINE
• Introduction to embedded systems based on SoCs
(System-On-a-Chip)
• Introduction to Real-Time OS
– Operating Systems — some recall
– RTOS

ESIOT ISI-LT - UNIBO EMBEDDED SYSTEMS BASED ON SOC AND RTOS 2


FROM MICROCONTROLLERS TO
SoC
• So far we focused on embedded systems based on
microcontrollers
– no operating systems
• Now we move from microcontrollers to system-on-a-
chip systems
– chips for embedded systems featuring a CPU
architecture and enough memory to host an OS,
typically a Real-Time OS

ESIOT ISI-LT - UNIBO EMBEDDED SYSTEMS BASED ON SOC AND RTOS 3


SoC AND SINGLE-BOARD CPU
• SOC = System-on-a-Chip
– an integrated circuit (a chip) that integrates all or most
components of a computer or other electronic system
• CPU, memory, I/O controllers, network interfaces, etc
• Examples:
– BROADCOM BCM2837 64bit ARMv8 Cortex A53 Quad
Core (1.2Ghz)
• used in Raspberry Pi 3
– ARM Sitara AM335x SoC - including ARM Cortex-A8
processor
• used in BeagleBone, Arduino Tre
– Texas Instruments OMAP3530
– …

ESIOT ISI-LT - UNIBO EMBEDDED SYSTEMS BASED ON SOC AND RTOS 4


SoC AS AN INTEGRATED SYSTEM
• A SoC integrates:
– one or multiple processors/cores
• including microcontrollers, microprocessors, DSP
– a memory module containing one or multiple blocks of
different types:ROM, RAM, EEPROM, FLASH
– a clock, timers
– connectors for standard interfaces, such
as USB, Ethernet, USART, I2C, SPI
– radio/network interfaces
– DAC and ADC
– …

ESIOT ISI-LT - UNIBO EMBEDDED SYSTEMS BASED ON SOC AND RTOS 5


SoC

ESIOT ISI-LT - UNIBO EMBEDDED SYSTEMS BASED ON SOC AND RTOS 6


An IOT TINY SOC: ESP 8266
• SoC designed for IoT
• Hardware
– Processor: L106 32-bit RISC microprocessor core 80 MHz*
– 64 KiB of instruction RAM, 96 KiB of data RAM
– 16 GPIO pins
• SPI, I²C, I²S + UART
• 10-bit ADC
– IEEE 802.11 b/g/n Wi-Fi
• Various SDKs and firmwares
– GCC toolchain, Wiring / Arduino, NodeMCU Lua-based,
MicroPython Python based, ESP-Open-RTOS Open source
FreeRTOS-based…

ESIOT ISI-LT - UNIBO EMBEDDED SYSTEMS BASED ON SOC AND RTOS 7


A MORE RECENT VERSION: ESP32
• ESP32 is a series of low-cost, low-power system on a chip microcontrollers
with integrated Wi-Fi and dual-mode Bluetooth.
– successor to the ESP8266 SoC, created and developed by Espressif
Systems
• Hardware
– CPU: Xtensa dual-core (or single-core) 32-bit LX6 microprocessor,
operating at 160 or 240 MHz + Ultra low power (ULP) co-processor
– Memory: 320 KiB RAM, 448 KiB ROM
– Wireless connectivity: Wi-Fi: 802.11 b/g/n + Bluetooth: v4.2 BR/EDR and
BLE (shares the radio with Wi-Fi)
• Peripheral interfaces:
– 34 × programmable GPIOs, 12-bit SAR ADC up to 18 channels, 2 × 8-bit
DACs
– 4 × SPI, 2 × I²S interfaces, 2 × I²C interfaces
– 3 × UART

ESIOT ISI-LT - UNIBO EMBEDDED SYSTEMS BASED ON SOC AND RTOS 8


ESP32 ARCHITECTURE

ESIOT ISI-LT - UNIBO EMBEDDED SYSTEMS BASED ON SOC AND RTOS 9


RASPBERRY PI 5
2.4GHz quad-core, 64-bit Arm Cortex-A76
GPU: 800MHz VideoCore VII GPU
RAM: LPDDR4X-4267 SDRAM (4GB or 8GB)

ESIOT ISI-LT - UNIBO EMBEDDED SYSTEMS BASED ON SOC AND RTOS 10


EMBEDDED OS AND REAL-TIME OS
• Embedded systems based on SoC have enough resources (in
terms of computational power and memory) to host a full-
fledged operating system (OS)
• Embedded and Real-Time OS (RTOS)
– operating systems designed to be used in embedded
systems

ESIOT ISI-LT - UNIBO EMBEDDED SYSTEMS BASED ON SOC AND RTOS 11


OPERATING SYSTEMS:
SOME RECALL

ESIOT ISI-LT - UNIBO EMBEDDED SYSTEMS BASED ON SOC AND RTOS 12


MODERN COMPUTING SYSTEMS: A
BIRD’S EYE VIEW
• Computing System
– software + hardware
• highest levels: high-level programming languages,
applications, complex software systems
• lowest levels: electronic circuits, logical ports, binary logics
– design and construction complexity
• Organisation based on hierarchical levels (layers)
– decomposition in modules
• each module encapsulates some set of functionalities
• define an abstraction level
– a module provides an interface to exploit functionalities
– hide/abstract from implementation details
– hierarchical organisation (levels or layers)
• each module corresponds to a layer (level)

ESIOT ISI-LT - UNIBO EMBEDDED SYSTEMS BASED ON SOC AND RTOS 13


LAYERS/LEVELS
• Highest-level view

High-leveldi
Linguaggi Languages
alto livello/ /Applications
Applicazioni

Sistema Operativo
Operating System

Hardware

ESIOT ISI-LT - UNIBO EMBEDDED SYSTEMS BASED ON SOC AND RTOS 14


LANGUAGE/APPLICATION LEVEL
ZOOM
Applications
Applicazioni

High-level
Linguaggio
High-level
Linguaggio Languages
di alto livello
Languages
di alto livello
Compilers
Compilatore

Virtual
Macchina
Interpreters/compilers
Inteprete / Compilatore
Machines
Virtuale

Sistema Operativo
Operating System

Hardware

ESIOT ISI-LT - UNIBO EMBEDDED SYSTEMS BASED ON SOC AND RTOS 15


HARDWARE LEVEL ZOOM
High-level
LinguaggiLanguages/Applications
di alto livello / Applicazioni

Operating Systems
Sistema Operativo

Assembler

Linguaggio
Machine Macchina
Language (or Code)

Computer Architecture
Architettura dell'elaboratore

ALU Memoria
Memory

Combinatory &
Boolean Arithmetic/
Aritmetica booleana Sequential
Reti logichelogic
sequenziali
algebra
circuits

Boolean
Logica Logics
booleana

ESIOT ISI-LT - UNIBO EMBEDDED SYSTEMS BASED ON SOC AND RTOS 16


VIRTUALISATION LEVEL ZOOM

High-level Languages
Linguaggi di alto livello/ Applications
/ Applicazioni

Sistema Operativo
Operating System

Compilatore di Sistema
System Compiler

SystemVirtuale
Macchina Virtual Machine
di Sistema

Hardware

ESIOT ISI-LT - UNIBO EMBEDDED SYSTEMS BASED ON SOC AND RTOS 17


OVERALL
Applicazioni

Linguaggio
Linguaggio di alto livello
di alto livello
Compilatore

Macchina
Inteprete / Compilatore
Virtuale

Sistema Operativo

SOFTWARE
GERARCHIA
Compilatore di Sistema
LEVELS
LIVELLI
HIERARCHY
SOFTWARE

Macchina Virtuale di Sistema

Assembler

Linguaggio Macchina

Architettura dell'elaboratore HARDWARE


GERARCHIA
LEVELS
LIVELLI
HIERARCHY
HARDWARE
ALU Memoria

Aritmetica booleana Reti logiche sequenziali

Logica booleana

ESIOT ISI-LT - UNIBO EMBEDDED SYSTEMS BASED ON SOC AND RTOS 18


LEVELS AND INTERFACES
1
MAIN INTERFACES APPLICATION PROGRAMS
2
ISA LIBRARIES
- System ISA: 8 3
- User ISA: 7 + 8
3 Software
OPERATING SYSTEM
Application Binary 4 5 6
Interface (ABI): 7+3
Drivers Memory Scheduler
Manager
System Call
Interface: 3 8 8 8 8 7 7
ISA

Application EXECUTION HARDWARE


Programming Interface 9
(API) for High-Level Memory
Languages (HLL) (es: 10 10 Translation Hardware
C, Java,...): 2 System Interconnect (BUS)

11 11 12
Controllers Controllers
13 14
I/O Device and Main Memory
Networking

ESIOT ISI-LT - UNIBO EMBEDDED SYSTEMS BASED ON SOC AND RTOS 19


ISA, ABI AND SYSTEM CALL INTERFACE
• Instruction Set Architecture (ISA)
– interface separating HW and SW levels
– user ISA
• all instructions, aspects, parts that are visible and accessible from
a user programs
• interface 7
– system ISA
• all instructions, aspects, parts that can be accessed and used only
by the OS (es: privileged instructions)
• interface 8
• Application Binary Interface (ABI)
– interface provided by programs to access to HW resources and system
services
– two main components: user ISA + System Call Interface
• System Call interface
– set of operations that the OS provides to program as fundamental
services
• transferring control to the OS kernel, changing the privilege level
ESIOT ISI-LT - UNIBO EMBEDDED SYSTEMS BASED ON SOC AND RTOS 20
MACHINE INTERFACE: ISA
APPLICATION SOFTWARE

OPERATING SYSTEM

System ISA User ISA


ISA
EXECUTION HARDWARE

PHYSICAL Memory
MACHINE
System Interconnect (BUS)
Traslation

Controllers Controllers

I/O Device and Main Memory


Networking

ESIOT ISI-LT - UNIBO EMBEDDED SYSTEMS BASED ON SOC AND RTOS 21


MACHINE INTERFACE: ABI
APPLICATION SOFTWARE
System Call Interface

OPERATING SYSTEM

Drivers Memory Scheduler


User
Manager ISA
ABI
EXECUTION HARDWARE
ABSTRACT / VIRTUAL
Memory
MACHINE Traslation
System Interconnect (BUS)

Controllers Controllers

I/O Device and Main Memory


Networking

ESIOT ISI-LT - UNIBO EMBEDDED SYSTEMS BASED ON SOC AND RTOS 22


OPERATING SYSTEM: OVERALL
VIEW
• The Operating System (OS) is that software part of a
computing system that orchestrates the execution of
application programs and functions as intermediary for
them to access to the HW
Banking
System
Videogame Web
browser } Application programs
}
Compiler Editors Command
Interpreter
System programs
Operating System

}
Machine language
Hardware
Microarchitecture
Physical device

ESIOT ISI-LT - UNIBO EMBEDDED SYSTEMS BASED ON SOC AND RTOS 23


OS: MAIN OBJECTIVES
• Executing user programs and controlling their execution,
in particular their access to the resources of the
underlying executing machine/
– OS as an extended / virtual machine
– functions: abstraction, control, protection
• Making the access and use of computer resources
effective and efficient
– OS as a resource manager
– function: optimisation
• Enabling and coordinating the interactions among
applications, users and resources
– concurrent applications
– multi-user systems

ESIOT ISI-LT - UNIBO EMBEDDED SYSTEMS BASED ON SOC AND RTOS 24


LEVELS AGAIN
User
utenteX
X UserY Y
utente

Web
server videgioco
Shell Application
Livello delle
Application
Programmatore Word comandi Web Level
Applicazioni
di applicazioni processor browser
programmer

API - chiamate di sistema (system calls)

System
amministratore Livello del
administrator
di sistema OS level
Sistema Operativo
Driver Driver

Programmatore
System
di sistema
CPU Video Tastiera Mouse
Livello
programmer HW level
Hardware
Interfaccia
Memoria Dischi
di rete

ESIOT ISI-LT - UNIBO EMBEDDED SYSTEMS BASED ON SOC AND RTOS 25


MEDIATION ROLE
• The OS mediates the interaction between the application
level and the HW level controlling and coordinating the
access and use of the HW level as requested by the
application, and making the application and HW levels as
much as independent as possible
– common functionalities required by applications are
factorised into services provided by the OS
• Fundamental role of the API (Application Programming
Interface)
– programming interface for programs
– set of functions or OS level primitives referred as
system calls

ESIOT ISI-LT - UNIBO EMBEDDED SYSTEMS BASED ON SOC AND RTOS 26


OS AS A VIRTUAL MACHINE
• The OS hides the structure of the physical machine to
application programs, so that applications see a virtual
or abstract machine
– it is a simpler machine than the physical one,
providing a higher level of abstraction than the
physical layer
– accessible by means of the system calls
• they are the interface of the virtual machine
– top-down view

ESIOT ISI-LT - UNIBO EMBEDDED SYSTEMS BASED ON SOC AND RTOS 27


OS AS A VIRTUAL MACHINE
User
utente X
X User
utente YY

Web
server videgioco
Shell
comandi
Application
Livello delle
Word Web Applicazioni
Application
Programmatore
di applicazioni processor browser Level
programmer

API - chiamate di sistema (system calls)

Systemamministratore
di sistema
administrator Driver Driver

OS asOperativo
Sistema
come
Virtual Machine
Macchina Virtuale
Programmatore
System
di sistema
CPU Video Tastiera Mouse

programmer Interfaccia
Memoria Dischi
di rete

ESIOT ISI-LT - UNIBO EMBEDDED SYSTEMS BASED ON SOC AND RTOS 28


OS AS A VIRTUAL MACHINE -
BENEFITS
• To ease the design and development of applications
– programmers should not necessarily know details
about the physical machine to interact with HW
resources and can focus on program
functionalities
• To ease porting of programs
– the same program can be executed by different
virtual machines exploring the same interface,
running on different physical machines
– simplifying porting of a program from an OS to
another OS

ESIOT ISI-LT - UNIBO EMBEDDED SYSTEMS BASED ON SOC AND RTOS 29


OS AS A RESOURCE MANAGER
• Resource management
– resources are shared and used by multiple programs in
execution
• possibly concurrently
– possibly belonging to different users
• multi-user systems
• Functions
– access optimisation
• scheduling algorithms
– security and protection
• a program in execution must not create problems to the
system or to other programs in execution
• user data protection and security
• This is the bottom-up view
– from resources (bottom) up to application programs

ESIOT ISI-LT - UNIBO EMBEDDED SYSTEMS BASED ON SOC AND RTOS 30


OS AS A RESOURCE MANAGER
APPLICATIONS
APPLICAZIONI

OS

VIDEO CARDS
SCHEDA VIDEO
CENTRAL
MEMORIA
MEMORY
CENTRALE CONTROLLERS

BUS INTERFACCE
NETWORK
DI RETE
INTERFACES
CPU
STORAGE
MEMORIE
DISPOSITIVI
DI MASSA I/O DEVICESI/O
USB
MOUSE
DISKS
DISCHI TASTIERA
KEYBOARDS
...

ESIOT ISI-LT - UNIBO EMBEDDED SYSTEMS BASED ON SOC AND RTOS 31


RESOURCE VIRTUALISATION
• Virtual memory
– a program in execution sees the whole memory as a linear
memory space, virtually unlimited
– transparent access (for application programs in execution) to
secondary memory/storage as an extension of the primary
one
• Virtual File system
– to access and change a file in the file system in spite of the
specific type of file systems and their location (local or
remote)

ESIOT ISI-LT - UNIBO EMBEDDED SYSTEMS BASED ON SOC AND RTOS 32


PROGRAM EXECUTION
• Multi-programming
– capability of loading in central memory multiple programs at the
same time and of executing them to optimise CPU usage
– if a program in execution is busy in executing an I/O operation and
do not need a CPU, the CPU is allocated to another program in
execution
– it allows a first form of multi-tasking, i.e. the concurrent execution of
multiple programs
• Time-sharing
– extension of multi-programming towards the execution of programs
that involve the interaction with the user
– capability of executing multiple programs concurrently (in spite of I/O
operations), sharing the CPU among programs in execution
according to specific scheduling algorithms
– full realisation of multi-tasking

ESIOT ISI-LT - UNIBO EMBEDDED SYSTEMS BASED ON SOC AND RTOS 33


OS/KERNEL FUNCTIONING
• Interrupt-driven functioning
– the execution of the kernel of the OS is triggered by hardware
interrupt and software trap
• hardware interrupt
– physical signals sent by devices (es: keyboard, timer,
disks,...)
– asynchronous
• SW trap / interrupt:
– application programs requests to execute OS services
(system calls)
– or exceptions, generated by errors in programs
– synchronous
• Exploiting two distinct execution modalities of CPU
– user-mode
• when executing user programs
– kernel-mode (super-visor mode, privileged mode, system mode)
• when executing parts of the kernel

ESIOT ISI-LT - UNIBO EMBEDDED SYSTEMS BASED ON SOC AND RTOS 34


OS MAIN ACTIVITIES
• Process management
• Memory management
• Storage management
– File System management
– Disk management
– caching
• I/O management
• Network management
• Protection & security management
• Users management

ESIOT ISI-LT - UNIBO EMBEDDED SYSTEMS BASED ON SOC AND RTOS 35


EMBEDDED AND
REAL-TIME OS

ESIOT ISI-LT - UNIBO EMBEDDED SYSTEMS BASED ON SOC AND RTOS 36


EMBEDDED AND REAL-TIME OS
• Embedded e Real-Time Operating Systems (RTOS)
– operating systems designed to be used in embedded
systems
• General features
– compactness
– efficiency
– reliability
– determinism & predictability
• explained later
• Differently from desktop OS, typically a RTOS is designed to
run one application at a time
– the application is typically multi-task/multi-threaded

ESIOT ISI-LT - UNIBO EMBEDDED SYSTEMS BASED ON SOC AND RTOS 37


EXAMPLES
• Open-source
– FreeRTOS, eCos
– RT Linux, Linux Embedded
• Commerciali
– VxWorks, LynxOS, Micrium µC/OS-III
– QNX Neutrino
– Windows CE
• Una lista
– https://en.wikipedia.org/wiki/Comparison_of_real-
time_operating_systems

ESIOT ISI-LT - UNIBO EMBEDDED SYSTEMS BASED ON SOC AND RTOS 38


EXAMPLE:
µC/OS
FAMILY
(1) The port developer is responsible for providing the
µC/OS-III CPU Specific portion. A µC/OS-III port
consists of writing or changing the contents of four
kernel-specific files: os_cpu.h, os_cpu_a.asm,
os_cpu_a.inc and os_cpu_c.c.

(2) A port also involves writing or changing the


contents of two CPU specific files: cpu.h and
cpu_a.asm. cpu_core.c is generally generic and
should not require modifications.

(3) A Board Support Package (BSP) is generally


necessary to interface µC/OS-III to a timer (which is
used for the clock tick) and an interrupt controller.

(4) Some semiconductor manufacturers provide


source and header files to access on-chip peripherals.
These are contained in CPU/MCU specific files. You
generally don’t need to modify any of these and thus,
you can use them as-is.

https://doc.micrium.com/
ESIOT ISI-LT - UNIBO EMBEDDED SYSTEMS BASED ON SOC AND RTOS 39
EXAMPLE:
µC/OS
FAMILY

ESIOT ISI-LT - UNIBO EMBEDDED SYSTEMS BASED ON SOC AND RTOS 40


EXAMPLE: FreeRTOS

https://www.freertos.org/

ESIOT ISI-LT - UNIBO EMBEDDED SYSTEMS BASED ON SOC AND RTOS 41


EXAMPLE: QNX REAL-TIME OS

ESIOT ISI-LT - UNIBO EMBEDDED SYSTEMS BASED ON SOC AND RTOS 42


RT-LINUX ARCHITECTURE
(REAL-TIME LINUX)

ESIOT ISI-LT - UNIBO EMBEDDED SYSTEMS BASED ON SOC AND RTOS 43


WINDOWS 8 EMBEDDED

ESIOT ISI-LT - UNIBO EMBEDDED SYSTEMS BASED ON SOC AND RTOS 44


WINDOWS IOT CORE

https://docs.microsoft.com/en-us/windows/iot-core/windows-iot

ESIOT ISI-LT - UNIBO EMBEDDED SYSTEMS BASED ON SOC AND RTOS 45


ARM mbed IoT OS ARCHITECTURE

ESIOT ISI-LT - UNIBO EMBEDDED SYSTEMS BASED ON SOC AND RTOS 46


REAL-TIME EMBEDDED SYSTEMS
• Real-time
– they must react and manage events and inputs within
specified time intervals
– they manage the execution of tasks/computations that
have deadlines
• Subclasses
– hard real-time
• deadlines are correctness requirements, they must
be satisfied (otherwise: failures)
• examples: safety-critical systems
– soft real-time
• deadlines should be respected in normal conditions
— can be violated in some cases and the violation
is meant to be managed
ESIOT ISI-LT - UNIBO EMBEDDED SYSTEMS BASED ON SOC AND RTOS 47
REAL-TIME SYSTEMS & DETERMINISM

IMPORTANT
• Determinism is the most important aspect of real-time
systems
– hard real-time, in particular
• Determinism in this case means that the system should be
predictable:
– the time needed to perform some task
– the maximum time required to execute some action or
getting some input or from a sensor or to react to some
interrupt
– the number of cycles required to exec some operation must
be always the same
• In these systems, the execution can be interrupted (by means
of interrupts), however the overhead (interrupt latency, context
switch, interrupt handler execution time) should be known

ESIOT ISI-LT - UNIBO EMBEDDED SYSTEMS BASED ON SOC AND RTOS 48


Real-Time Operating System
RTOS ORGANISATION
What is an RTOS?
• Structure similar to normal OSs
Kernel

– kernel File System RTOS


Networking
– file system USB
Graphics
File
System
USB, etc.

– networking Kernel Components Kernel


– USB Scheduler
Thread Management
– Graphics Message Queues
Graphics Networking
Semaphores
p
• Kernel tasks Mutexes
Timers
– task scheduling and management
Memory y Pools

– inter-task interaction & synchronisation


© 2013, Express Logic, Inc.

• semaphores
• queues / mailboxes — msg passing
– timer management
– I/O device management CPU execution modalities
- kernel mode
– memory management - user mode
– interrupt management & signals
ESIOT ISI-LT - UNIBO EMBEDDED SYSTEMS BASED ON SOC AND RTOS 49
RTOS BENEFITS
• Improving responsiveness and reducing overhead
• Simplifying resource sharing
• Simplifying development, debugging, maintenance
– for complex embedded system
• Enhancing portability
• Exploiting proper service layer & middleware
• Making application time-to-market quicker

ESIOT ISI-LT - UNIBO EMBEDDED SYSTEMS BASED ON SOC AND RTOS 50


RESPONSIVENESS AND OVERHEAD
• Programs based on systems with no RTOS are typically based
on the super-loop architecture, adopting polling as general
strategy to verify conditions and triggering functions and
actions or cooperative schedulers for executing tasks =>
different kinds of problems
– reduced efficiency
– weakness of cooperative schedulers
– ..
• An RTOS allows for:
– avoiding polling/looping by exploiting the possibility to
execute a "context switch" from a task to another one, at a
processor level
– support for pre-emptive multi-tasking
– maximise the CPU time for applications, minimising the
overhead of task management
ESIOT ISI-LT - UNIBO EMBEDDED SYSTEMS BASED ON SOC AND RTOS 51
RESOURCE MANAGEMENT
• An RTOS allows tasks to share resources and provides
functionalities to manage and control their access
– dynamic memory allocation/deallocation
– semaphores/mutex to control the access to HW
resource or realise critical sections
– mechanisms to avoid problems due to interferences
between priorities and critical sections
• e.g. the priority inversion problem (described later)

ESIOT ISI-LT - UNIBO EMBEDDED SYSTEMS BASED ON SOC AND RTOS 52


SIMPLIFYING DEVELOPMENT AND
DEBUGGING
• From an application perspective, an RTOS provides an
abstraction layer that simplify the access to the HW
– the development of applications does not require the
access and management of low-level HW aspects
(interrupts, timers, ports, etc.)
• RTOS interface: system calls
• Specific HW+SW support for debugging
• Modular development of an application

ESIOT ISI-LT - UNIBO EMBEDDED SYSTEMS BASED ON SOC AND RTOS 53


HIGH-LEVEL SERVICES &
MIDDLEWARE
• An RTOS enables the use of frameworks/platforms/
middleware that provide services, at different levels
• Examples
– File system
– TCP/IP network stack
– USB stack
– Graphics

ESIOT ISI-LT - UNIBO EMBEDDED SYSTEMS BASED ON SOC AND RTOS 54


PORTABILITY AND MAINTENANCE
• An application using the RTOS API does never access
directly to the HW
– this makes it possible to change the underlying HW in
a transparent way
– the application can be executed on any HW supported
by the RTOS

ESIOT ISI-LT - UNIBO EMBEDDED SYSTEMS BASED ON SOC AND RTOS 55


WHEN AN RTOS IS NOT USEFUL
• Simple super-loop applications
• Single-purpose / single-task applications
– typically with a dimension smaller than 32 KiB

ESIOT ISI-LT - UNIBO EMBEDDED SYSTEMS BASED ON SOC AND RTOS 56


ABOUT TASKS AND
SCHEDULING IN RTOS

ESIOT ISI-LT - UNIBO EMBEDDED SYSTEMS BASED ON SOC AND RTOS 57


PROCESSES, TASKS AND THREADS
• Process (definition)
– a program in execution
• has its own memory
• can have multiple threads
• Thread
– an independent thread of control or control flow
– threads part of the same process share the process memory
• Multi-threading: concurrent execution of multiple threads
– threads: often called tasks in RTOS
– a way for modularising an application
– notion of priority
• Scheduling done by the kernel
– to realise multi-tasking, multi-threading
– various strategies and algorithms
• pre-emptive vs. cooperative
• round-robin + priority-based

ESIOT ISI-LT - UNIBO EMBEDDED SYSTEMS BASED ON SOC AND RTOS 58


TASK STATES
• Example: µC/OS-III

ESIOT ISI-LT - UNIBO EMBEDDED SYSTEMS BASED ON SOC AND RTOS 59


CONTEXT SWITCH
• Thread/task context
– the information necessary for restarting the execution
of a thread when a context switch occurred
• content of processor registers, program counter,
stack pointer
– saved when a thread/task is preempted
– restored when a thread/task is resumed
• Context switch
– interruption of the execution of current thread
– control given to the kernel and eventually to another
thread
– has a cost

ESIOT ISI-LT - UNIBO EMBEDDED SYSTEMS BASED ON SOC AND RTOS 60


TASK PROGRAMMING
• Example: µC/OS-III

ESIOT ISI-LT - UNIBO EMBEDDED SYSTEMS BASED ON SOC AND RTOS 61


TASK COMMUNICATION AND
SYNCHRONISATION MECHANISMS
• Semaphores
• Communication based on message passing
• Event-based architectures

ESIOT ISI-LT - UNIBO EMBEDDED SYSTEMS BASED ON SOC AND RTOS 62


TASKS: TEMPORAL PARAMETERS

IMPORTANT
D

res

r e

• Temporal properties of tasks are defined by 4 fundamental


parameters
– release time: r
• the time point in which the task enters the ready queue, being
ready to be executed
– execution time: e (= WCET)
• maximum duration of the task
– response time: res
• interval time between release of the task and its completion
– deadline: D
• maximum time allows for executing the task
ESIOT ISI-LT - UNIBO EMBEDDED SYSTEMS BASED ON SOC AND RTOS 63
TASKS: TEMPORAL PARAMETERS

ESIOT ISI-LT - UNIBO EMBEDDED SYSTEMS BASED ON SOC AND RTOS 64


PERIODIC AND APERIODIC TASKS
• Task can be:
– periodic
• the task is released at a fixed temporal interval (period)
– aperiodic
• the task is released at arbitrary times
– sporadic
• like aperiodic, but with hard deadlines
• Designers must decide what to do when a deadline is not satisfied
– a task must continuous its execution (so delaying the other
tasks)? Or, its termination should be forced?

ESIOT ISI-LT - UNIBO EMBEDDED SYSTEMS BASED ON SOC AND RTOS 65


SCHEDULING FAMILIES
• Big loop scheduling (i.e. cooperative scheduling in a super-loop)
– each task is polled to check if it should be executed
– polling goes on either sequentially or following a priority order
– not efficient, low responsiveness
• Round-robin scheduling
– the processor is allocated turn by turn to ready tasks (threads)
• cooperative scheduling: the threads are executed up to their
completion or a blocking call
• preemptive scheduling: each thread executes for a time slice
+ preemption
• Priority-based scheduling
– the processor always executes the thread with the highest priority
– for threads with the same priority => round-robin
• preemption
– if there is ready thread with higher priority => this is executed

ESIOT ISI-LT - UNIBO EMBEDDED SYSTEMS BASED ON SOC AND RTOS 66


PRIORITY SCHEDULING
• All RTOSs support priority-based scheduling
– possibly integrated with round-robin
• Advantages
– max responsiveness
• Problems
– complexity and cost of pre-emption
– possibility of starvation
– inversion priority problem

ESIOT ISI-LT - UNIBO EMBEDDED SYSTEMS BASED ON SOC AND RTOS 67


SCHEDULING IN SYNCHRONOUS
AND ASYNCHRONOUS REAL-TIME
SYSTEMS
• Two main categories of real-time systems, from a scheduling
point of view
– synchronous RT systems
• strongly related to synchronous FSM and to the task
scheduling discussed in module 2.3
– asynchronous RT systems
• strongly related to asynchronous FSM

ESIOT ISI-LT - UNIBO EMBEDDED SYSTEMS BASED ON SOC AND RTOS 68


SYNCHRONOUS RT SYSTEMS
• A hardware clock is used to subdivide CPU time in temporal intervals
called frames
– similar to the period in sync FSM and period of the scheduler in
module 2.3
• A program must be subdivided into tasks so that each task can be
completely executed in single frame in the worst case
• Simple scheduling
– a scheduling table (list) keeps track of the tasks to be execute in
each frame
– if the execution of a task would take more than a frame, then the
task must be divided in sub-tasks, to be individually executed in
multiple frames
– frame duration is a very important parameter to choose when
designing the system
• Approach typically used in hard-real time systems

ESIOT ISI-LT - UNIBO EMBEDDED SYSTEMS BASED ON SOC AND RTOS 69


ASYNCHRONOUS RT SYSTEMS
• In asynchronous RT systems, a full-fledged pre-emptive priority-
based scheduler is used
– tasks are scheduled depending on their priority
– tasks with the same priority are scheduled using round-robin pre-
emptive scheduling
• Scheduler implementation is based on scheduling events that invoke
the scheduler
– scheduling events are generated:
• when a task is enqueued in the ready-queue
• by the timer, at a some frequency, in order to keep track of
time passing and realise round-robin pre-emption

ESIOT ISI-LT - UNIBO EMBEDDED SYSTEMS BASED ON SOC AND RTOS 70


ASSIGNING PRIORITIES AND
FEASIBLE ASSIGNMENTS
• A main aspect of scheduling in asynchronous RT system is about assigning
priorities to tasks so that the every task is executed on time, without
violating its deadline
• An assignment of priorities that respect this constraint is called feasible
assignment
• Example
– 2 tasks: P1 and P2
– P1: p1 = D1 = 2, e1 = 1 (p1 = periodo, D1 = deadline)
• must be executed every 2 time units and it needs 1 time unit to execute
– P2: p2 = D2 = 5, e2 = 2
• must be executed every 5 time units and it needs 2 time unit to execute
– Two possible priority assignments
• either P1 has a higher priority than P2, or viceversa
– However: only 1 is feasible
• P1 > P2 => feasible assignment
• P2 > P1 => assignment not feasible
ESIOT ISI-LT - UNIBO EMBEDDED SYSTEMS BASED ON SOC AND RTOS 71
TWO MAIN SCHEDULING
ALGORITHMS: RM AND EDF
• Different algorithms have been proposed in literature specialised for
real-time systems, identifying the necessary and sufficient conditions
for feasible assignments
• Two main algorithms
– Rate Monotonic (RM)
– Earliest Deadline First (EDF)

ESIOT ISI-LT - UNIBO EMBEDDED SYSTEMS BASED ON SOC AND RTOS 72


RATE-MONOTONIC (RM)
• Scheduling algorithm based on fixed-priority
– priorities defined statically, don’t change, and their value is given
by the inverse of the period
• so: the smaller is the period, the higher is its priority (in spite
of its execution time)
– for instance:
• if p1 < p2, then P1 is assigned with higher priority
• Theorem
– given a pre-emptive fixed-priority scheduler and a finite set of
periodic tasks T = {T1,T2,T3…} with associated periods P =
{p1,p2,p3,…} without precedence constraints, if it exists a
feasible assignment, then the assignment defined by the RM is
feasible

ESIOT ISI-LT - UNIBO EMBEDDED SYSTEMS BASED ON SOC AND RTOS 73


EXAMPLES

Two periodic tasks

Pre-emptive
scheduling with
priorities assigned
according to RM

(from [IES], p. 295)


ESIOT ISI-LT - UNIBO EMBEDDED SYSTEMS BASED ON SOC AND RTOS 74
EARLIEST DEADLINE FIRST (EDF)
• This algorithm dynamically computes and changes tasks priorities depending
on their deadlines
– can be used only in dynamic/asynchronous scheduler
• EDF assigns higher priorities to tasks that have nearer deadlines
– Like RM, also for EDF there is an analogous theorem — if it exists a
feasible assignment, the EDF finds it under the condition that given a set
T of N tasks with CPU usage parameter U is <= 1
• U = ∑ ei/pi, for each task i in [0..N-1]
– ei = execution time of task i-th, pi = period of task i-th
• EDF is not always applicable
– HW tasks, like for interrupt handlers, can require to have fixed priorities,
not modifiable
– EDF implies an overhead on the scheduler that could not be acceptable,
in some cases
• the overhead is given by the fact that task priorities must be
recomputed at each scheduling event

ESIOT ISI-LT - UNIBO EMBEDDED SYSTEMS BASED ON SOC AND RTOS 75

You might also like