Embedded System Design (BEC601) Module-3
Module-3:
RTOS and IDE for Embedded System Design:
Operating System basics, Types of operating systems, Task, process and threads (Only
POSIX Threads with an example program), Thread pre-emption, Pre-emptive Task
scheduling techniques, Task Communication, Task synchronization issues – Racing and
Deadlock, How to choose an RTOS, Integration and testing of Embedded hardware and
firmware, Embedded system Development Environment – Block diagram (excluding Keil).
(Text 2: Ch-10 (Sections 10.1, 10.2, 10.3, 10.5.2 , 10.7, [Link], [Link] only), Ch 12,
Ch-13 (a block diagram before 13.1 only).
Operating System basics
An Operating System (OS) is an interface between computer user and computer
hardware.
Some popular Operating Systems include Linux Operating System, Windows
Operating System, etc.
Its main responsibilities include:
1. Process Management: Handles the creation, scheduling, and termination of
processes (programs in execution).
2. Memory Management: Allocates and manages the system's RAM among running
processes efficiently and safely.
3. File System Management: Manages files and directories on storage devices,
including reading, writing, and access control.
4. Device Management: Controls and coordinates the use of hardware devices like
printers, hard drives, and keyboards through device drivers.
5. User Interface: Provides a user interface (GUI) that allows users to interact with the
system.
6. Security and Access Control: Protects data and resources by enforcing access
permissions and authentication.
7. Resource Allocation: Allocates CPU time, memory, and I/O devices to various tasks
and users.
Curated By: [Link] [Link],Atria IT
Embedded System Design (BEC601) Module-3
Hence, the OS acts as a bridge between the user and the computer hardware, ensuring smooth
and efficient operation.
Kernel
It is the core of the operating system and is responsible for managing the system and the
communication among the hardware and other systems services.
The Kernel contains different services for handling the following,
● Process Management
● Primary Memory Management
● File system Management
● I/O System Management
● Secondary Storage Management
● Protection System
● Interrupt Handler
There are two kinds of kernel designs-Monolithic and Microkernel.
Monolithic Kernel:
Every basic service like the process and memory management, interrupt handling and I/O
communication, file system, etc. run in kernel space. It is constructed in a layered fashion,
application at the top, then the libraries in user-space.
Micro Kernel:
There is the server for managing memory issues, one server does process
management, another one manages drivers, and so on. Because these servers do not
run in kernel space ”context switches” are not required, to allow user processes to
enter the privileged mode.
Microkernel offers the following benefits:
Robustness
configurability
Curated By: [Link] [Link],Atria IT
Embedded System Design (BEC601) Module-3
Types of Operating systems:
Depending on the type of kernel and services,purpose and type of computing systems where
OS is deployed and the responsiveness to applications,operating systems are classified into
two types.
1. General purpose OS -(GPOS)
2. Real time OS-(RTOS)
Difference between General purpose operating system and Real time operating system
General Purpose
Feature Operating System (GPOS) Real-Time Operating System (RTOS)
Designed for general tasks
like browsing, gaming, and Designed for time-critical applications like robotics,
Purpose office work aerospace, or medical devices
Strict timing constraints; must respond within a
Timing No strict timing constraints defined time
Windows, macOS, Linux FreeRTOS, VxWorks, RTLinux,Windows
Examples (Ubuntu) CE,QNX.
Less predictable; may delay
Determinism tasks based on load Highly predictable and deterministic behavior
Task Uses complex, fair
Scheduling scheduling algorithms Uses priority-based or deadline-driven scheduling
High latency and less
Latency consistent Very low and consistent latency
Resource Usage Uses more memory and CPU Lightweight, optimized for minimal resource use
A Real-Time Operating System (RTOS) is designed to manage hardware resources and run
applications in a way that ensures predictable and timely responses. Its key responsibilities
include:
1. Task/Process Management: It deals with setting up the memory space for the tasks,
loading task’s code into the memory space, allocating system resources, setting up a
task control block(TCB) for the task and task termination/deletion.
A TCB is a data structure used by an RTOS to store all the information about a task.
Every task in the system has its own TCB. It holds all the essential data that the OS
needs to manage, schedule, and switch between tasks efficiently. It contains:
Task ID or name
Task state (Ready, Running, Blocked, etc.)
Program Counter (PC)
CPU register values
Task priority
Stack pointer
Stack information (base address, size)
Scheduling information (e.g., time slice)
Task delay or timing information
Pointers to communication resources (e.g., message queues)
Curated By: [Link] [Link],Atria IT
Embedded System Design (BEC601) Module-3
2. Task Scheduling: It deals with sharing the CPU among various tasks. A Kernel
application called ‘Scheduler’ handles the task scheduling. Scheduler is an algorithm
which performs the efficient and optimal scheduling of tasks to provide a deterministic
behaviour.
3. Task Synchronization: It deals with synchronizing the concurrent access of a resource
which is shared across multiple tasks and the communication between various tasks.
4. Error/Exception Handling:
It deals with registering and handling the errors occurred /exceptions raised during the
execution of tasks. Insufficient memory, deadlocks, timeouts, deadline missing, bus
errors, divide by zero error, unknown instruction execution etc, are examples of
errors/exceptions.
Error/exceptions can happen at the kernel level services or at task level.
Deadlock-example for kernel level, timeout –example for task level
5. Real-Time Clock Management: Maintains accurate timing for time-sensitive tasks and
ensures deadlines are met.
6. Interrupt Handling:
Responds quickly and efficiently to hardware or software interrupts with minimal latency.
It deals with handling of various types of interrupts. Interrupts provide real time behavior
to systems. Interrupts inform the processor that an external device or an associated task
requires immediate attention of the CPU. Interrupts can be either synchronous or
asynchronous. Interrupts which occurs in sync with the currently executing task is known
as synchronous interrupts.
Priority among the interrupts will be assigned by RTOS and each interrupt can be enabled
or disabled individually. Most of RTOS kernel implements ‘Nested Interrupts’
architecture. Interrupt nesting allows the pre-emption (interruption) of an interrupt service
routine (ISR),servicing an interrupt by high priority interrupt.
7. Resource Management: Manages limited resources (CPU, memory, I/O) to avoid
conflicts and ensure high reliability.
8. Memory Management:
This offers predictable and efficient memory allocation with minimal fragmentation.
RTOS makes use of ‘block’ based memory allocation technique, instead of the usual
dynamic memory allocation. RTOS kernel uses blocks of fixed size of dynamic memory
and the block will be allocated for a task on a need basis. These blocks are stored in a
‘Free Buffer Queue. Few RTOS kernels implement ‘Virtual Memory’ concept for
memory allocation if the system supports secondary memory storage (like HDD or
FLASH).
9. Reliability and Stability: Ensures consistent system behavior, especially in critical
environments where failure is not an option.
10. Hard Real Time System: A Hard real time system must meet the deadline for a task
without any slippage. Missing any deadline may produce catastrophic results. Ex. Air Bag
control system. Hard RTS does not implement virtual memory model for handling the
memory. This eliminates the delay in swapping in and out the code corresponding to the
task to and from the primary memory.
11. Soft Real Time System: It does not guarantee meeting deadlines but offer best effort to
meet the deadline. Ex. ATM.
Hence, a RTOS is built to run applications where timing, reliability, and precision are
crucial.
Curated By: [Link] [Link],Atria IT
Embedded System Design (BEC601) Module-3
Tasks, Process and Threads:
Tasks/Process:
The term task refers to something that need to be done.
The Task is also known as ‘job’ in the operating system context.
A program or part of it in the execution is also called a ‘Process’.
The term ‘Task’, ‘Job’ and ‘Process’ refer to the same entity in the operating system
context and most often they are used interchangeable.
Multiple instance of a same program can be executed simultaneously.
A Process is sequential in execution.
The structure of a process:
o The concept of process leads to concurrent execution of task and there by the
efficient utilisation of the CPU and other system resources.
o It is achieved through the sharing of CPU among the process
Memory organization of process
Curated By: [Link] [Link],Atria IT
Embedded System Design (BEC601) Module-3
Process state transition diagram-Typical Transitions:
The state transition diagram gives the details of all possible states that process will be going
through and their transitions form one state to next possible state based on the event
generated. The cycle through which a process changes its state from ‘newly created’ to
‘execution completed’ is known as ‘Process Life cycle’
Created: Process is created and moved to the ready queue.
Ready: Scheduler assigns CPU to the process.
Waiting: Process requests I/O and is blocked if I/O is not available.
Waiting → Ready: I/O is complete; process goes back to ready.
Running → Ready: CPU is taken away before the completion of execution (e.g., due
to time slice ending in round-robin scheduling).
Running → Terminated: Process completes execution.
Threads:
● A thread is a primitive that can execute code
● A Thread is a single sequential flow of control within a process.
● A thread is also known as ‘Light weighted Process’
● A Process can have many threads of [Link] threads , which are part of a
process
Curated By: [Link] [Link],Atria IT
Embedded System Design (BEC601) Module-3
●
Difference between thread and process:
Curated By: [Link] [Link],Atria IT