You are on page 1of 19

RTOS

 RTOS (real time operating system) is an operating system for embedded system
 It performs low level operations such as servicing interrupts, managing & servicing
I/O devices (keypad, display, timers, communication ports ..), memory management,
scheduling of tasks (processes) etc.
 RTOS hides system hardware from user/application.
 Applications use API functions (system calls) to access RTOS services.
RTOS executes system call and return result to User application
Concept of Process & Thread
Process (or Task) :
 Embedded application software can be thought of as consisting of many processes
 Process is an action of execution of the program.
 Process is defined by its own program code, data and stack
Process & Thread
 When process is created, RTOS allocates memory space and instantiates data
structure called Process Control Block (PCB)
 PCB :- Process Context (Program status word, SP, PC & other CPU registers value),
process ID, Process state, Process priority, pointers to parent and daughter process,
pointer to system resources, pointer to access permission descriptor for sharing
resources globally and with other process
 Context switching
 User mode (application) and Kernel mode (RTOS) processes
 a process can create one or more other processes (referred to as child processes) and
these processes in turn can create child processes to form process tree.

Threads:
 Threads are subunits of a process which may execute simultaneously
 Process may contain multiple threads. All threads of a process run in address space of
same process.
 Have their own PC, stack and registers which are private and never shared
 Advantages:- reduces context switching overhead, improves responsiveness
Process & Thread
Concept of Process & Thread
 RTOS schedules execution of processes
 Switching processes at fast rate gives feeling of multi-processing
 Process Status :- ready, running, blocked, terminated, sleeping
[A] Non Preemptive Task(Process) scheduling:
(1)Round Robin (Circular Queue):
 Processes are executed sequentially from ready linked list
 RTOS keeps track of currently executing process. It updates linked list upon insertion
and removal of a process. New process is inserted at the end of linked list
 Circular FIFO buffer can be used to form ready list of processes
 Newly ready process is inserted at the end of the queue

 Simple architecture :– no interrupts, no shared data, no latency concerns.


Attractive option for some applications
(2) Round Robin Scheduling with Time Slicing:
 RTOS defines a time slot for each process for its execution Tslot
 In a single schedule cycle ( time slice Tslice) processes are taken sequentially
 If a process doesn’t finish in Tslot it is blocked until it get its turn in the next time slice

 Tslice is fixed whereas Tslot is variable


 If process finishes before Tslot there is waiting period
(3) Round Robin with Priority based Ready List
 Processes in ready queue are ordered as per their priority but executed in turn
(circularly) from ordered list
 Scheduling is still non-preemptive as no process is preempted by any other

 Time to execute all processes in ready queue is termed as one cycle


 The processes are ordered based on priority at the beginning of every cycle.
(Newly created processes are added in the list only at the beginning of cycle).
Timing parameters:
 Release time : an instant the process is ready for execution
 Execution (run) time : time period of process
 Turn around time (TAT): time from release to finish
 Absolute deadline (d) : an instant by which process must finish
 Slack time = (d-t) – remaining run time of process at time t
= deadline – estimated completion time (negative slack means missed
deadline)
Scheduling Algorithms
[B] Preemptive Scheduling:
 Process may be blocked at any instant to allow higher priority task to run. This is
called preemption.
 In preemptive scheduling, Priorities are assigned to processes using various criteria.
 Following scheduling algorithms are commonly used

 Shortest Remaining Runtime First


 Priorities are assigned such that shorter the remaining execution time,
higher the priority
 Earliest Deadline First (EDF)
 Earlier the deadline, higher the priority
 Least Slack time First (LSF) or Least Laxity First (LLF)
 Smaller the slack, higher the priority
 Example :- A scheduler is invoked every 1 unit of time and selects process from ready
queue to run. (a) How processes are scheduled with Least Slack Time first policy ? (b)
Find total time spent in wait by all process, total no. of context switches and no. of deadline
missed for each scheduling.
In case of tie, following criteria would be used in that order (i) process already running
should be preferred over others (ii) process with earlier deadline should be selected (iii)
processes should be scheduled in Round robin fashion

Ans:

Slacktime(t) = deadline - t - time remaining to finish process at t


The slack time of processes when they became ready (released) is given by
P0=18 (at t=0), P1=4 (at t=10), P2=19 (at t=4) and for P3=5 (at t=5).

>slack time of running process remains constant whereas for waiting process it decreases
Commercial RTOS
 Study of features of RTOSs is necessary for choosing suitable one for specific system
 Many commercial RTOSs come with development tools that facilitate real time
application development

 uC/OS (MicroController Operating System)


 RTOS from Micrium Corporation that support over 100 different processor
architectures ranging from 8-bit to 64-bit
 The Real-Time Kernel is a highly portable, ROMable, very scalable, fully
preemptive, deterministic
 Allows integration with other software packages such as μC/TCP-IP, μC/GUI,
μC/USB, μC/CAN, μC/Modbus, μC/Bluetooth for obtaining greater scalability
 Certified by FAA (Federal Aviation Administration) to be used in avionics
 VxWorks
 Multitasking RTOS from Wind River. It is hard real time.
 High accuracy, predictable response and less context switch time

 Supports both Symmetric and Asymmetric Multi-Processing to facilitate multi-core


processors
 Spacecraft, robotics and prograMPmmable controller, Networking and
Communication components (routers, cellular base stations)
Commercial RTOS
 QNX
 It is Microkernel based Unix based RTOS.

 Kernel include only basic services such as CPU scheduling, interprocess


communication, interrupt redirection and timers
 It has unique feature of tight integration of message passing and CPU scheduling
 Intended for mission critical applications => Medical instrumentation, Process
control, Air traffic control, Internet routers & telematics devices,
 New version QNX Neutrino (compact, fast and fault tolerant) is used as platform
for many portable embedded systems
Commercial RTOS
 FreeRTOS:
 Portable, open source, light weight Kernel
 FreeRTOS provides the core real time scheduling functionality, inter-task
communication, timing and synchronisation primitives only
 Additional features (command consol, networking stack etc.) can then be
included with add on
 Free RTOS scheduler - preemptive, cooperative and hybrid configuration
options, with optional time slicing.
 You can use free RTOS with tools such as keil, Arduino, STM32 IDE, GCC
POSIX
 POSIX (Portable Operating System Interface)
 POSIX is standard for defining APIs (or system calls)
 If RTOS vendors come equipped with own proprietary APIs, application code
cannot be moved to other RTOS platform
 Application code developed using POSIX APIs is portable across all POSIX
compliant RTOSs
 RTOSs who defines APIs as per POSIX are called POSIX compliant RTOSs
 Mostly POSIX compliant RTOS => LynxOS, QNX
 Partially POSIX compliant RTOS => Nucleus RTOS, VxWorks
POSIX APIs for Device driver
Device driver APIs:
 fd=open(devicename path, int flags)
 Directory path where device name is defined

 Flags - O_RDONLY, O_WRONLY, or O_RDWR


 returns unique device file descriptor (saved in fd)
 read(fd, *buff, nbytes)
 Read nbytes from fd and saves to buffer pointed by buff
 returns number of bytes read
 write(fd, *buff, nbytes)
 Writes nbytes from buffer pointed by buff to fd
 returns number of bytes written

 ioctl(fd, option, &arg)


 Option – request code available in board support package,

arg – value specific to request code


 e.g. Request code can be “SPI_slave” and arg can be 8-bit slave add
 close(fd)
 Deallocates device and cleans data structure
Example – ADC read with I2C

You might also like