Unit 2 Rtos
Unit 2 Rtos
PROGRAMMING
UNIT II EMBEDDED C PROGRAMMING
Memory And I/O Devices Interfacing – Programming Embedded
Systems in C – Need For RTOS – Multiple Tasks and Processes – Context
Switching – Priority Based Scheduling Policies.
I/O DEVICES AND PORTS
PROCESSOR MEMORY BUS
• INTERNAL BUS
• MAIN BUS
• SYSTEM BUS
PERIPHERAL BUSES:
• Processor need to communicate with peripherals, that is external
input and output devices and this data pathway is called I/O BUS or
peripheral bus
• Different electrical and mechanical characteristics, applications ,made
from different materials,technologies
Processor memory bus and
peripheral bus
• All the peripherals needs an extra controller or an interfacing chip
between the processor and the peripheral
• I/O controller is needed to interface between the processor and I/O
devices
• This block diagram contains a USB controller, graphics controller,
network controller…and it connected to their respective devices
Embedded processor
Embedded processor
• I/O interface or I/O Controller are the external components to the processor
chip
• Embedded processors are designed to act as a single chip computer and it
contain memory and I/O controllers internal to the chip
• Processor memory bus is internal to the chip, and there is no need for an
external peripheral bus
• Extra memory and more peripheral controllers must be needed
• Embedded processor ,I/O components and memory are the major
components to makeup the embedded board
• Interconnected via buses on the embedded board.Such a bus is called an On
board bus
• It connects the microcontroller unit and u nits like EEPROM,SD and
LCD display
• Example:SPI,I2C bus
• Another buses like off board or external buses are used to connect
the board with other board or with external peripherals
• USB is an off board bus
• For these buses there are connectors in the board
• Ethernet,USB port,RS232
SERIAL PERIPHERAL INTERFACE
INTER-INTEGRATED CIRCUIT-I2C
OPERATING SYSTEMS
• It acts as a bridge between the user applications/tasks and the
underlying system resources through a set of system functionalities
and services
• It manages the system resources and makes them available to the user
applications or tasks on a need basis
• Make the system convenient to use
• Organize and manage the system resources efficiently and correctly
KERNAL
It is the core of the operating system and it is responsible for managing the system
resources and the communication among the hardware and other system services
It act as a abstraction layer between system resources and user applications
It contains a set of a system libraries and services
Process management
Primary memory management
File system management
I/Odevice management
Protection systems
Interrupt handler
REAL TIME OPERATING SYSTEMS
Middleware:
if there is no middleware support in Real time operating system, then the issue of time-taken integration of
processes occurs.
Error-free:
RTOS systems are error-free. Therefore, there is no chance of getting an error while performing the task.
Embedded system usage: Programs of RTOS are of small size. So we widely use RTOS for embedded systems.
Maximum Consumption: we can achieve maximum Consumption with the help of RTOS.
Task shifting: Shifting time of the tasks is very less.
REAL TIME OPERATING SYSTEMS(RTOS)
TYPES
TYPES
Hard Real Time :
In Hard RTOS, the deadline is handled very strictly which means that given task must start executing on specified
scheduled time, and must be completed within the assigned time duration.
Example: Medical critical care system, Aircraft systems, etc.
Firm Real time:
These type of RTOS also need to follow the deadlines. However, missing a deadline may not have big impact but could
cause undesired affects, like a huge reduction in quality of a product.
Example: Various types of Multimedia applications.
Soft Real time RTOS, accepts some delays by the Operating system. In this type of RTOS, there is a deadline assigned for
a specific job, but a delay for a small amount of time is acceptable. So, deadlines are handled softly by this type of RTOS.
• The application is decomposed into small, schedulable, and sequential program units known as “Task”, a
basic unit of execution and is governed by three time- critical properties; release time, deadline and execution
time.
• Release time refers to the point in time from which the task can be executed. Deadline is the point in time
by which the task must complete. Execution time denotes the time the task takes to execute.
Task Control block
• Task uses TCBs to remember its context. TCBs are data structures residing in RAM, accessible only
by RTOS
• TASK ID
• TASK STATE
• TASK TYPE
• TASK PRIORITY
• TASK POINTERS
• Depends on kernal
TASK/PROCESS SCHEDULING
Deals with synchronizing the concurrent access of a resource ,which is shared across multiple tasks and the
communication between various tasks
Memory Management
Two types of memory managements are provided in RTOS – Stack and Heap. Stack
management is used during context switching for TCBs.
Heap Memory which is used for program code, program data is called heap memory and
it is used for dynamic allocation of data space for tasks. Management of this memory is
called heap management.
Uses blocks of fixed size dynamic memory and the block is allocated for task on a need
basis
The blocks are stored in a Free Buffer Queue
No memory fragmentation issues
• Stack memory: Holds all temporary data such as variables local to the
process
• Data memory: Holds all global data for the process
• Code memory: Contains the program code corresponding to the
process
Stack and HEAP MEMORY
RTC
Timer Management
• Accurate time management is essential for providing precise time reference for all applications
• Real time Clock hardware timer
• RTCs are used in a variety of applications where they play a critical role in keeping accurate track of the
current time while also providing alarms, timers, and interrupt functions and helping to reduce power
consumption
• The hardware timer is programmed to interrupt the processor or controller at a fixed rate
• This timer interrupt is called timer tick
• Microseconds range
• System time is updated based on timer tick
• Timer tick interrupt is handled by Timer Interrupt handler of kernel
ERROR/EXCEPTION HANDLING
• A hardware interrupt is an electronic alerting signal sent to the processor from an external
device, like a disk controller or an external peripheral.
Software Interrupt
• For example, if the processor's arithmetic logic unit runs a command to divide a number by
zero, to cause a divide-by-zero exception, thus causing the computer to abandon the
calculation or display an error message. Software interrupt instructions work similar to
subroutine calls.
What is Task?
• Task is defined as the program in the execution and related
information maintained by the os for the program
• Task is also known as Job in the OS context
• The term Task,job,Process refer to the same entity in the os context
What is process?
• It requires various system resources like CPU for executing the process,memory
for storing the code corresponding to the process and associated variables, I/O
devices for information exchange
• Sequential in execution
Threads
• A thread is the primitive that can execute code
• A thread is a small program that has a specific function and purpose
within the overall application.
• Threads tend to be lower level than tasks and have minimal overhead.
• Light weight process
• A process can have many threads of execution
• Different threads which are the part of a process, share the same address
space, share the data memory, code memory and heap memory area
• Like process, threads maintain their own thread status, PC, and stack
Example
MULTITASKING
Multi-tasking :
Multi-tasking is the logical extension of multiprogramming. In this system, the CPU executes multiple jobs by
switching among them typically using a small time quantum, and these switches occur so frequently that the
users can interact with each program while it is running. Multitasking is further classified into two categories:
Single User & Multiuser.
Multiprocessing
:
Multiprocessing is a system that has two or more than two processors.
In this, CPUs are added for increasing computing speed of the system.
Because of Multiprocessing, there are many processes that are executed
simultaneously.
Multiprocessing is further classified into two categories: Symmetric
Multiprocessing and Asymmetric Multiprocessing.
Multiprocessing
Difference between multitasking and
multiprocessing
TASK SCHEDULING
• Determining which task or process is to be executed at a given point of
time is known as task scheduling or process scheduling
• Based on multitasking
• Scheduling policies forms the guidelines for determining which task is
to be executed
• The scheduling policies are implemented in an algorithm and it is run
by the kernel as a service
• The kernel service which implements the scheduling algorithm is
called ad scheduler
Process states
• Ready state from Running state
• Blocked or Wait state from Running state
• Ready state from Blocked or wait state
• Completed state
Factors
CPU utilization
Throughput
Turnaround time
Waiting time
Response time
Various queues
• Various queues maintained by OS during the course of its admittance
to execution completion
• Job queue
• Ready Queue
• Device Queue
• A process mitigates through all these queue during its journey from
admitted to completed stage
Types
• Pre emptive Scheduling
• Non preemptive scheduling