ES Module 5
ES Module 5
OS SERVICES
Goal:
The OS goals are perfection and correctness to achieve the following:
1. Facilitating easy sharing of resources as per schedule and allocations. Resources mean
processor(s), memory, I/Os, devices, virtual devices (e.g., pipes, sockets).system timer,
keyboard, displays, printer and other such resources, which processes (tasks or threads)
request from the OS. No processing task or thread uses any resource until it has been
allocated by the OS at a given instance.
2. Facilitating easy implementation of the application-program with the given system-
hardware. An application programmer for a system can use the OS functions that are
provided in given OS without having to write the codes for the services (functions) that
follow.
3. Optimally scheduling the processes on one (or more CPUs if available) and providing an
appropriate context-switching mechanism.
4. Maximizing the system performance to let different processes (tasks or threads) share the
resources most efficiently with protection and without any security breach. Examples of
security breach are tasks obtaining illegal access to other task-data directly without
system calls, overflow of the stacks into memory and overlaying of PCBs at the
memory.
5. Providing management and functions for the processes memory. Devices and I/Os and
other functions.
6. Providing management and organization function for the devices files and virtual devices
and I/Os.
7. Providing easy interfacing and management function for the network protocol and
networking.
8. Providing portability of application on different hardware configurations.
9. Providing interoprobability of application on different networks.
10. Providing a common set of interface that integrates various device applications through
the standard and open systems.
The OS goals are perfection, correctness, portability, imperability and providing a common
set of interfaces for the system, and orderly access and control when managing the
processes.
Kernel:
• The OS is the middle layer between the application software and system hardware. An
OS includes some or all of the following structural units.
1. Kernel with file management and device management as part of the kernel in the
given OS.
2. Kernel without file management and device management as part of the kernel in
the given OS and any other needed function not provided for at the kernel.
• The kernel is the basic structural unit of any OS in which the memory space of the
functions, data and stack are protected from access by any call other than the system-
call.
• Table 2 gives the functions (services) in the kernel, they are as per the OS design.
• The kernel has management functions for processes, resources, ISRs, ISTs, files,
device drivers and 10 subsystems and network subsystems.
Table 3 Request for a Resource or Operating System (OS) Service by a Running Process
Example 3:
(a) # define OS TICK PER SEC 100/µCOS-II function to define the number of ticks per
second = 100 before the beginning of main () and initiating of OS by OSInit () function/. (b)
[Link]. of ECE, BGSIT 7
MODULE 5
OSTickInit ()/icons-II function to initiate the defined number of ticks per second after the
beginning of the first task and creation of all the tasks to which the context will be switched
by the OS on the tick. It initiates SysC1kIntr interrupts every 10 MS as OS ticks/s = 100 "/.
Event Functions:
• In case of IPC, there is waiting for only one semaphore post event or mailbox
message-posting event. Provisioning of event functions in an OS offers an advantage
that there can be wait for more than one event and the events can also be from the
different tasks or ISRs.
• The queue messages can be from the different tasks or ISRs. Queues can offer the
same advantage that there can be wait for more than one messages. However, the OS
functions for queue execute in more time than the event-functions. Same OS supports
and some do not support event functions. The event-functions enable OS actions after
a group of events. The OS event functions can be understood as follows: There is an
event register. It has 8 or 16 or 32 event-flags, which form the groups. Each bit of the
group in the register corresponds to one event flag in a set of flags.
• An event register creates using an OS function. OS EventCreate (). An event register
can be divided into groups, each group assigned to different tasks. For example, a 16-
bit register can be divided into four groups. Group 0 is from bit 0 to bit 3. group I
from bit 4 to bit 7. Group 2 is from bit 8 to bit 11 and group 3 is from bit 12 to bit 15.
An OS function, OSEventQuery() queries an event register to find the event register
existence and its contents. An event register deletes using an OS function,
OSEventDelete ().
• Each event sets one of the bits at the event register using the SET (event Flag)
function. Event flag in the register can be set by an ISR or task. CLEAR (event Flag)
cigars the flag in the event register. An event flag can be cleared by an ISR or task.
• A task can use the WAIT ALL function for the occurrences of setting all the event
flags in a group. [Wait till AND operation between all flags in the group equals to
true. The task can use WAIT ANY function for an occurrence of setting of any of the
event flags in the group. [Wait till OR operation between all flags in the group equals
to true.]
MEMORY MANAGEMENT
Memory Allocation
• When a process is created, the memory manager allocates the memory addresses
(blocks) to it by mapping the process address space. Threads of a process share the
memory space of the process.
• The memory manager of the OS has to be secure, robust and well protected. There
must be control such that there are no memory leaks and stack overflows Memory
leaks mean attempts to write in the memory block not allocated to a process or data
structure. Stack overflow means that the stack exceeds the allocated memory block(s)
when there is no provision for additional stack space. Table 5 gives memory-
management strategy.
RTOS UCOS-II provides for memory partitioning. A task must create a memory partition
or several memory partitions by using function OSMemCreate (). Then the task is
permitted to use the partition or partitions. A partition has several memory blocks. A task
gets a memory block or blocks from the partition by using function OSMemGet (). A task
releases a memory block or blocks to the partition by using function OSMemPut ().
Therefore, the task consists of several fixed size memory blocks. The fixed size memory
blocks allocation and de-allocation time takes fixed time (deterministic). Therefore, it leads
to a predictable task-performance.
Dynamic address The manager dynamically allocates the addresses initially bound
relocation to the relative addresses. It adds the relative address to address
with relocation register. The memory manager now dynamically
changes only the contents of relocation register. It also takes into
account a limit-defining register so that the relocated addresses are
within the limit of available addresses. This is also called run-time
dynamic address binding.
Memory protection to Memory protection to the OS functions means that the system call
OS functions (call to an OS unction) and function call in user space are distinct.
The OS function code. Data and stack are in the protected memory
area. It means that when a user function call attempts to write or
read in the exclusive memory space allocated to the OS functions,
it is blocked and the system generates an error. The memory of
kernel functions is distinct and can be addressed only by the
systems calls. The memory space is called kernel space.
Memory protection Memory protection to the tasks means that a task function call
among the tasks cannot attempt to write or read in the exclusive area of memory
space allocated to another task. The protection increases the
memory requirement for each task and also the execution. time of
the code of the task.
The memory manager allocates memory to the processes and manages it with appropriate
protection. There may be static and dynamic allocations of memory. The manager
optimizes the memory needs and memory utilization. An RTOS may disable the support to
the dynamic block allocation, MMU support to the dynamic. Page allocation and dynamic
binding as this increases the latency of servicing the tasks and ISRs. An RTOS may or may
not support memory protection in order to reduce the latency and memory needs of the
processes.
• There are number of device drive ISRs for each device in a system, each driver-
function of a device (e.g. open, close, read) calls a separate ISR. Device manages
(inside or outside the kernel space) is the software that manages these for all. When
device driver functions are a part of the OS (inside or outside the kernel space), the
device manager effectively operates and adopts appropriate strategy for obtaining
optimal performance for the devices.
• The manager coordinates between application process, driver and device controller. A
process sends a request to the driver functions by an interrupt using SWI: and the
driver provides the actions on calling and executing the ISR. The device manager
Function Actions
Device detection and Provides the codes for detecting the presence of various
addition devices, then adding(initializing, configuring and testing)
them for the use of OS device driver functions. A
manager can provide for tracking the hardware inventory
(list of devices present in the system and connected to the
system).
Device deletion Provides the codes for denying the device resources.
Device allocation and Allocates and registers the port fit may be a register or
registration memory) addresses for the various devices at distinctly
different addresses and also includes codes for detecting
any collision between them.
Detaching and Detaches and deregisters the port (it may be a register or
deregistration memory) addresses for the various devices at distinctly
different addresses and also includes codes for detecting
any collision between existing addresses in case of
addresses reallocation to the remaining attached
(registered) devices.
Restricting device to a Restricts a device access to one process(task) only, at an
specific process instant.
Device sharing Permits sharing of access of a device to the set of
processes, but to one process (task) at an instant.
Device control A manager can also provide for remote control of the
devices from the remote server at the service provider.
(For example, mobile devices with server at the service
provider)
Device access management (i) sequential access, (ii) random access, (iii) semi-
random access. (iv) serial communication may be by
UART or USB, and (v) 4 (or more) serial bits in parallel
Device buffer management Device hardware may merely have a single byte buffer, or
double buffer or 8-byte buffer. A device buffer manager
uses a memory manager to buffer the I/O data streams
from the device that sends the data and manages
computations without wait while the buffer receives the
data at a slow rate. Also used are the multiple buffers and
producer-consumer-type bounded buffers.
Device queue. circular- Device IO data streams from the device can be organized
queue or blocks of queue as the queues, circular queues and blocks of queues.
management
Backup and restoration A manager can also provide for the backup and
restoration for drivers.
Commands Action(s)
create and open create is for creating and open is for creating (if not
created earlier) and configuring and initializing the
device.
write Write into the device buffer or send output from the
device and advance the pointer (cursor).
read Read from the device buffer or read input from the
device and advance the pointer (cursor).
Close and delete close is for de-registering the device from the system
and delete is for close (if not closed earlier) and
detaching the device.
1. First argument: Defines the chosen device and its functions by passing as argument,
the device descriptor (a number),
2. Second argument: Defines the control option or use option for the IO device. Network
devices control by defining baud rate or other parameters. Its use is as per function
defined as a second argument. Controlled device will be according to the first
argument.
3. Third argument: Values needed by the defined function are at the third argument.
Example 5:
Status ioctl (fd. FIOBAUDRATE. 19.200) is an instruction in RTOS VxWorks. The fd is the
device descriptor (an integer returned when the device is opened) and FIOBAUDRATE is a
pointer for IO baud rate function that takes value of baud rate = 19.200 from third argument.
This configures the device for operation at the 19.200-baud rate.
• A device driver ISR uses several OS functions. Examples are as follows: intlock() to
disable interrupts system, intUnlock () to enable interrupts intConnect() to connect a
C function to an interrupt vector (the interrupt vector address for a device ISR points
to a specific C function). Function intContext () finds whether interrupt is called when
an ISR was in execution.
• UNIX OS makes it feasible for devices and files to have an analogous implementation
as far as possible. A device has open (), close (), read(), write() functions analogous to
a file open, close, read and write functions. APIs and kernel interfaces in BSD
(Berkley sockets for devices) UNIX are open. [Link] and write. The following are
the in-kernel commands: (i) select. which is to first check whether a read or write will
succeed. (ii) ioctl to transfer driver-specific information to the device driver. (iii) stop
to cancel the output activity from the device. (iv) strategy to permit a block mad or
write or character read or write.
The device manager initializes controls and drives the physical and virtual devices of the
system. The main classes of devices are char devices and block devices. Device driver
functions may be similar to file functions, open, read. I seek, write and close.
Table 8 Set of Command Functions in the Portable Operating System Interface (POSIX) File
System
seek List seek or set the file Setting the pointer for the appropriate place in the file for the
pointer next read of write
• Should a file having integers differ from a file having bytes? Should a file having
bytes differ from a file having characters? Due to the differing approaches to device
and file management interfaces, the development of a set of standard interfaces
becomes must. Only then can systems he portable. A standard set of interfaces is
called POSIX. from IEEE POSIX stands for portable operating system interface
standard for coding programs when using the multiple threads. The X after I is
because of the interfaces being similar to the ones in Unix. It is according to the
definitions at the AT & T UNIX System V Interface. POSIX defines the functions:
open, close. cad, write, Iseek and fentl. Function Iseek is to move the pointer position
in the byte stream. Function fent is for ile control. The POSIX standard for file
operations are as the operations on a finear sequence of bytes.
• Window NT assumes a file as the named entity for a record of bytes placed
sequentially and the OS has the command functions, createFile, ReadFile. WriteFile
and SetFilePointer, and CloseHandle for creating a file. reading a file, writing a file
and setting the file pointer from the present to a new location. A file in Unix has
open(1, close ), read (), write () functions analogoes to a device,open, close, read and
write functions. The BSD Unix interface differs slightly from Unix.
1. Block file system. Its a Its application n generates records to be saved into the
memory. These are first structured f the file. from the start to the end of the file
pointer (byte index) points to a byte from the start index=0 to N-I in a file of N bytes,
Just as each process has a processor descriptor (PCB); a file system has a data
structure, called file descriptor into a suitable format and then translated into block
streams. A file pointer (record) points to a block
2. Byte stream file system. Its application generates record streams. These streams are to
be saved into are first t structured into a suitable format and then translated into byte
streams. A the memory. These are (Table 8.9). The structure differs from one file
manager to another. File descriptor, fd. for a file is an integer, which returns on
opening a file. fd points to the data structure of the file. fd is usable till the closing of
the file.
I/O Subsystems:
1/O ports are the subsystems of OS device management systems. Drivers communicate with
the many devices that use them. I/O instructions depend on the hardware platform. I/O
systems differ in different OSes. Subsystems of a typical 10 system are as given in Table 10.
There are two types of IO operations-synchronous and asynchronous. There may be separate
functions for synchronous and asynchronous operations in an RTOS. In case of traditional
OS. Only synchronous IOs may be supported.
Synchronous IO operations are at certain fixed data transfer rates. Therefore, a task (process)
blocks tills till completion of the 10. For example, a write function, write() for 1 kB data
transfer to a buffer. Synchronous IO operation means once synchronous 10 initiates, the data
transfer will block the task till 1 kB data gets transferred to the buffer. Similarly, read () once
initiated blocks the task till 1 kB is read.
Table 10 Input/Output (I/0) Subsystem in a Typical I/0 System in an Operating System (OS)
Subsystems
Action(s) and Layers between the Subsystems
Hierarchy
Application An application having an I/O system. There may also be a
sublayer between the application and I/O basic functions
Example 6:
POSIX has the following asynchronous functions: aio_read () and aio_write for the
asynchronous read and write in an I/O system. Therefore, an aio_read () and aio_write () do
not block the task till completion of the 10. ain_list() is to initiate a list of certain maximum
asynchronous I/O port requests. ain_error (). aio_cancel, aio suspend are functions for
asynchronous 10 error status retrieval and for cancelling and suspending I/O operations,
respectively. Suspension is till the next port device interruption or till a timed out aio_return
returns the status of completed operations.
I/O subsystems are an important part of OS services. Examples are the UART access and the
parallel port access. There are synchronous and asynchronous 10s. A task gets blocked during
the synchronous IOs, for example, fread() or write (). RTOSes support asynchronous IOs. for
example, aio read() and aio_write also in order to not to block a task during the IOs.
Fig. 1 (a), (b), (c) Three alternative systems in three real-time operating systems for
responding to a hardware source call on interrupts
Fig. 1 (a), (b), (c) Three alternative systems in three real-time operating systems for
responding to a hardware source call on interrupts
• There are two functions, ISR and OS functions, in two memory blocks. An i-th
interrupt source causes ith ISR, ISR_i to execute. The routine sends an ISR enter
message to the OS. The message is stored at the memory allotted for OS messages.
When the ISR finishes, it sends ISR exit to the OS and there is return and either there is
the execution of interrupted process (task) or rescheduling of the processes (tasks). OS
action depends on the event messages, whether the task waiting far the event is a task of
higher priority than the interrupted task at the interrupt.
• On certain OS, there may be a function OSISRSemPost (). The ISR semaphore is a
special semaphore. which OSISRSemPost () posts and on return from the OS to be
taken by the calling ISR itself. OS ensures that OSISRSemPost executing ISR is
returned after any system call from the ISR.
Example 9
Consider the RTOS COS-II. Assume that a microcontroller has a hardware timer, which is
programmed to interrupt every 10 ms. The microcontroller on timer interrupt calls and PC
changes to an ISR vector address. ISR_Timer_Addr. At ISR_Timer_Addr. there is a routine
ISR Timer for servicing the timer interrupt. ISR_Timer first executes OSIntEnter () just after
the start of ISR_Timer is called. ISR Timer then executes OSIntExit () before the return code.
The OSIntEnter() sends the message to the RTOS that there should be context-switch and
return from the ISR only after any system call is made by the ISR or until the OSIntExit ()
executes in the ISR code. Any task waiting for the post of semaphore or mailbox message or
queue message should not start on execution of the post function within the ISR or in any
other task or ISR. RTOS schedules that later on return from ISR.
The multiple ISRs may be nested and each ISR of low priority sends high priority ISR
interrupt message(ISM) to the OS to facilitate return to it on the completion and return from
the higher priority interrupt. Nesting means when an interrupt source call of higher priority,
for example, system real-time clock interrupt SysC1kIntr) occurs, then the control is passed
to higher priority SysC1kIntr and on return from the higher priority the lower priority ISRS
[Link]. of ECE, BGSIT 18
MODULE 5
or tasks starts executing. The number of ISRs can be nested with execution order in sequence
to their priorities. Each ISR on letting a higher priority interrupt call sends the ISM (step 4)to
the RTOS.
There is common stack for the ISR nested calls, similar to the nested function calls.
• Figure 1 (b) shows the steps. On interrupt of a task. say. k-th task. the OS first gets the
hardware source call step 1) and initiates the corresponding ISR after saving the
present process status (or context) (step 2). The called ISR (step 3) during execution
then can post one or more outputs (step 4) for the events and messages into the
mailboxes or queues
• Assume that there are the routine (i-th ISR) and two processes (OS and j-th task) in
three memory blocks other than the interrupted k-th task. An i-th interrupt source
causes the OS to get the notice of that. then after step 1 it finishes the critical code till
the pre-emption point and calls the i-th ISR ISR executes (step 3) after saving the e
context (step 2) onto a stack. The preemption point is the last instruction of the critical
part of the presently running OS function, after which the ISR being of highest
priority is called. The ISR in step 4 can past the event or mailbox message(s) to the
OS for initiating the j-th task or k-th task after the return (step 5) from the ISR and
after retrieving the j-th or k-th task context.
• The events or mailbox messages are stored at the memory allotted for OS messages.
The OS initiates the j-th task (if is of higher priority than the interrupted task k) or
runs the interrupted task k
• The ISR must be short and it must simply post the messages for another task. This
task runs the remaining codes whenever it is scheduled (according to priorities). OS
schedules only the tasks (processes) and switches the contexts between the tasks only.
ISR executes only during a temporary suspension of a task.
• OS may provide for nesting or an OS may provide for the ISRs such that the OS
initiates running of the ISR calls from a priority ordered FIFO.
• The system priorities are ISRS and then tasks (or ISTs). IST is just a task initiated on
signal or message from an ISR (for example, task j in above example).
Example 10
Each device event has the codes for an ISR, which executes only on scheduling by the RTOS
and provided an interrupt is pending for its service. Consider mobile PDA device example.
The 5 steps for the interrupt servicing by first interrupting the RTOS process are as follows:
Assume that using RTOS. touch screen ISR. ISR_TouchScreen has been created using a
function OS ISR_Create (). The ISR can share the memory heap with other ISRs. A function,
IntConnect connects the touch screen event with the event identifier in an interrupt handler,
ISR_handler.
Let a touch screen event occur, which means the user of the mobile device taps the screen at
a select icon or menu (step 1). After saving context of current process (step 2) the OS sends
the signal on behalf of the ISR handler to the initiate ISR_TouchScreen (step 3). An interrupt
service thread or a Task TouchScreen Input IST_TouchScreen waits using a function OS
[Link]. of ECE, BGSIT 19
MODULE 5
eventPend () for message (an object, such as semaphore, mailbox or queue message) (step 4)
from the ISR_TouchScreen. The IST executes as per its priority Task or IST
_TouchScreenPriority among the other pending ISTs or tasks before it starts executing.
Before return from the ISR_TouchScreen, it sends a message to the kerel using a OS
ISR_Exit() just before the end of the codes in the ISR_TouchScreen (step 5). The
ISR_TouchScreen can be restarted on the next interrupt event and gets ready for the next
hardware event of tap on the screen.
RTOS First Interrupting on an Interrupt, then RTOS Initiating the ISR and then an
ISR
An RTOS can provide for two levels of ISRs, a fast-level ISR. FLISR and a slow-level ISR
(SLISR). The FLISK can also be called hardware interrupt ISR and the SLISR as software
interrupt ISR FLISR is called just the ISR in RTOS Windows CE. The SLISR is called
interrupt service thread (IST) in Windows CE. The use of FLISR reduces the interrupt
latency (waiting period) for an interrupt service and jitter (worst-case and best-case latencies
difference) for an interrupt service.
An IST functions as a deferred procedure call (DPC) of the ISR. An i-th IST is a thread to
function interrupt source call.
Figure 1(c) shows seven steps on the interrupt. On interrupt, the RTOS first gets the hardware
source call 1) and initiates the corresponding ISR after finishing the critical section and
reaching the pre (step) emption point and then saving the processor status (or context) (step
2). The ISR executes the device- and platform-dependent code (step 3). The ISR at the start
can mask (disable) further pre-emption from the same or other hardware sources. The ISR
during execution then can send one or more outputs for the events and messages into the
mailboxes or queues for the ISTS (step 4). The IST executes the device and platform-
independent code. The ISR just before the end, unmasks (enable) further pre-emption from
the same or other hardware sources (step 5).
There are the ISRs and number of ISTS, RTOS and tasks in the memory blocks other than the
interrupted task. Any interrupt source causes the RTOS to get the notice of that, then
completes the critical code till the pre-emption point and calls the ISR. ISR executes after
saving the context onto a stack. The ISR can post message(s) into the FIFO for the IST(s)
after recognizing the interrupt source and its priority. The ISTs jn the FIFO that have received
the messages from the ISR(s) executes (step 6) as per their priorities on return (step 5) from
the ISR. The ISR has the highest priority and pre-empts all pending ISTs and tasks.
When no ISR or IST is pending execution in the FIFO. the interrupted task runs on return
(step7).
The ISRs must be short, run critical and necessary codes only, and then they must simply
send the initiate all or messages to ISTs into t FIFO. It is the IST. which runs the remaining
codes as per the priority-bused schedule. The system priorities are in order of ISRS, ISTs and
tasks. The ISTs are SLISRS running device independent codes as per the device priorities on
signals (SWIs) from the ISR The ISTs run in the kernel space.
The ISTs do not lead to priority inversion and have the priority inheritance mechanism.
Example 11
Consider Mac OS X. The Mac OS X is RTOS for the mobile device, for example, iPod. An
interrupt handler first receives the primary interrupt and then it generates a software
interrupt known as a secondary interrupt. The secondary software interrupt is sent to initiate
an IST.
The OS does not receive the actual interrupt but the low level process intercepts the interrupt.
It calls a low-level (hardware level) ISR, LISR. It resets the pending interrupt bit in the device
interrupt controller and calls a device-specific ISR, say, DISR, The DISR, posts a message to
an IST, specific to the device. The message notifies to the IST, that an interrupt has occurred,
and then the DISR, returns to LISR. LISR resets another pending interrupt bit in the device
interrupt controller and calls the another device-specific ISR. say, DISR
When no further interrupts are pending, the OS control returns to the currently executing
thread. which was interrupted and when the OS passed control to the LISR.
The IST, are scheduled by the OS. the IST, finds that the SWI has occurred, it starts and run
he codes. ISTs run as if a thread is running.
An RTOS uses one of the three strategies on interrupt calls: (i) an ISR servicing directly
after merely informing the RTOS at the start of ISR: (ii) kernel intercepting the call and
calling the corresponding SRs and tasks, RTOS kernel schedules only the tasks (processes)
and ISR executes only during a temporary suspension of the task by the RTOS: (iii) kernel
intercepting the call and calling the ISR. Which initiates and queues the calls into a
priority FIFO, The ISR signals the SWs for the ISTs. The RTOS kernel schedules the ISTs
as priority queue and then tasks processes as per the priority queue.
Function Activities
Basic 05 functions Process management, resources management, device
management, I/O devices subsystems and network devices and
subsystems management.
Process priorities User-level priorities allocation, called static priority allocation or
management: real time priority allocation is permitted. The real-time priorities
priority allocation are higher than the dynamically allocated priorities to the OS
functions and the idle priority allotted to low priority threads.
The idle priority thread or task is one which runs when no other
high priority ones are running.
An embedded system with a single CPU can run only one process at an instance. The process
at any instance may either be an ISR, kernel function or task. An RTOS use in embedded
system facilities the following,
1. An RTOS provides running the user threads in kernel space so that they execute fast.
2. An RTOS provides effective handling of the ISRs, device drivers, ISTs, tasks or
threads and the disabling and enabling of interrupts in the user mode critical section
codes. A critical section means a section of codes or a resource or codes that must run
without blocking. One critical section is when there is a shared data or resource with
the other routines or tasks. RTOS provides for effective handling of such a situation.
3. An RTOS provides memory allocation and de-allocation function in fixed time and
blocks of memory and restricting the memory accesses only for the stack and other
critical memory block.
4. An RTOS provides the effectively scheduling and running and blocking of the tasks
in cases.
5. I/O management with devices, files, mailboxes, pipes and sockets becomes simple
using an RTOS and RTOS provides for the use of message queue and mailbox, pipes,
sockets and other IPC functions. RTOS provides for the use of semaphore(s) by tasks
or for the shared resources (critical sections) in a task or OS functions.
6. Effective management of the multiple states of the CPU and internal and external
physical or virtual devices. Assume that the following actions are concurrently
needed in an application.
I. Physical devices timer, UART and keyboard have issued the interrupts and the
service routines are to be executed.
II. A file is taken as a virtual device. The file also must be opened with its pointer to
its first record.
III. A physical timer is to configure its control register.
IV. Another timer gets a count input from the system clock.
V. A virtual device, a file, gets the inputs for writing onto it.
VI. A timer states changes on timer and generates a need for its service.
VII. A file states changes on transfer of all needed records to it.
VIII. A timer executes a service routine on timeout.
IX. A file needs execution of a function, close{} by effectively using a common
method to handle these needs, the RTOS solves all the problems.
• The embedded system hardware source call generated interrupts. On interrupt, if the
interrupt is not masked (disabled) the interrupt saves the current process (a task or
thread or OS function) context on a stack and executes the ISR corresponding to that
interrupt. It is done by an RTOS by one of the three methods by a given RTOS
environment. Interrupts are masked by disable interrupt command and unmasked by
enable interrupt commands.
• The ISR can only post (send) the messages for the RTOS and parameters for the tasks.
No ISR instruction should block any task. Therefore, the ISR should not use mutex
locks and should not use OS pending function for the IPCs. Only an RTOS initiates
the actions according to the ISR- posted signals.
• Semaphores, queues, mailboxes and pipes and the RTOS control states of the tasks
and interaction with the tasks. The variables and task-switching flags must always be
under the RTOS control. No ISR instruction should wait for using the messages. The
ISR should execute the codes that should not wait for actions by the RTOS and tasks.
• RTOS provides for nesting of ISRs. This means that running ISR can be interrupted
by a higher priority interrupt and the higher priority ISR starts executing, blocking the
running of low priority ISR, when the high priority interrupt service completes and
there is return to the low priority interrupt after retrieving the saved context from the
stack for the low priority interrupt. A task can wait and take the messages (IPCs) and
post (send) the messages using the system cells. A task or ISR should not call another
task or ISR. Each ISR or task has to be under the control of the RTOS. Such an
attempt should generate an error.
Each ISR Design Consisting of Shorter Code:
• As ISRs have higher priorities over the task, the code should be made short so that the
tasks do not wait longer to execute. A design principle is that the ISR code should be
optimally short and the detailed computations be given to an IST or task by posting
the message or parameters for that. The frequent posting of the messages by the IPC
functions from the ISRs should be avoided. When there are frequent interrupts from
the same source, then the messages can be first put in the buffer on each interrupt and
when the buffer is sufficiently filled, the IPC message can be posted for ready buffer.
This is because if the buffer is not used and the IPC messages are posted frequently by
making system calls, OSMsgQPost ( ) functions, there will be frequent context
switches and hence wastage of time.
• In certain RTOSses, servicing the interrupts, there are two levels, fast level ISRs and
slow level ISTs, the priorities are first for the ISRs, then for the ISTs and then the task
the ISRs post the messages for the ISTs and do the detailed computations. If RTOS is
providing for only one level, then use the tasks as ISTs.
Design each Task with an Infinite Loop from Start (Idle State) up to Finish (Last State):
• Each task has a while loop which never terminates. A task waits for an IPC or signal
to start. Tee task, which gets the signal runs or takes the IPC for which it is waiting,
runs from the point where it was blocked or pre-empted. In pre-emptive scheduler, the
high priority task can be delayed for some period to let the priority task execute.
Design in the Form of Tasks for the Better and Predictable Response Time Control:
• The RTOS provides the control over the response time of different task. The different
tasks are assigned different priorities and those tasks which system needs to execute
with faster response are separated out. For example, in a mobile phone device there is
need for faster response to the phone call receiving task then the user key input. In
digital camera the task for recording the image needs faster response then the task for
downloading the image on a computer through USB port.
• System of multiple tasks makes the design modular. The tasks provide modular
design. For example, in a mobile phone device we consider the user key input and
display as separate task. When the display size changes and new display hardware is
introduced, only the codes for the display tasks and resource and data sharing tasks
and ISRs need to be modified.
• When a new functionality is introduced in the system, the user key input task and new
functionality associated task need to be modified.
System of multiple task encapsulates the code and data of one task from the other.
Design with Taking Care of the Time Spent in the System Calls:
• The expected time in general depends on the specific target processor of the imbedded
system and the memory access times. However in order to provide the relative
magnitude of the time taken for the basic actions at a pre-emptive schedular, a new
parameter is defined. It defines the time taken for an action by an RTOS schedular in
terms of an assumed scaling parameter, S. S emphasizes the relative magnitudes of
execution times the for various actions in a typical RTOS.
• Let time taken for the simplest instruction be tmin. The minimum time is when the
semaphores P and V are assigned certain initial values, true or false. Let S be defined
in units of Ts, the Ts and tminsa depend on a specific target processor of the
embedded system and the memory access time.
• The RTOS create ( ) function to create a task takes longer CPU time then writing in to
a queue and reading form the queue and using a semaphore takes the least. Therefore,
Use Appropriate Precedence Assignment Strategy and Use Pre-emption in Place of Time
Slicing:
• The task of higher priority pre-empts the low priority tasks and ISRs pre-empt the
tasks. Therefore, an appropriate precedence is chosen. The ISRs have higher priorities
over the ISTs and tasks. A mode of scheduling the tasks is assigning them equal
priorities and allotting time slice for round robin mode. Time slicing is done in certain
specific cases, for example in a network router when it is routing the packets of
multiple clients.
• Create tasks at start up only and avoid creating and deleting tasks later. The only
advantage of deleting is the availability of additional memory space. Suppose a task is
deleted by an OSTaskDelete ( ) Function. Now a situation can be that a task is waiting
for a semaphore (to let other task finish the critical section) or is waiting for a queue
(or mail box) message for a pointer at the RTOS, and the pointer is for a message to
the task that has been deleted. A prolonged blockage or a deadly embrace or a
deadlock will then occur. An RTOS may not provide protection for this situation
Certain RTOS provide an option to make a semaphore deletion safe.
• Often, the CPU may not be running any task. All tasks may be waiting for pre-
emption (for transition from ready place to running place). The CPU at that instant
may associate the RTOS for the following. Read the internal queue. Manage the
memory. Search for a free block of memory. Delete or dispatch a task. Perform the
internal and IPC functions.
• If memory allocation and de-allocation are done by task the number of RTOS
functions is reduced. The reduced interrupt latency periods as execution of these
functions takes significant time by RTOS where as the RTOS pre-empts a task.
Further, if fixed sized memory blocks are allocated, then the predictability of time
taken in memory allocation is there.
Design with Taking Care of the Shared Resource or Data among the Tasks:
• The ISR should be like a function or should take care of problem from the shared
resources or data such as buffer or global variables. Disabling of running of other task
for a longer period increases worst case interrupt latency periods for all the interrupts.
While executing the critical section codes. If possible, instead of disabling the
interrupts only the task switching flag changes should be used. It is done by using
semaphore. Thus, only the pre-emption by RTOS should be prevented. Disabling pre-
• Use an RTOS, which is hierarchical as well as scalable so that has only the needed
function or at the ported sections of kernel. This is because the pre-emption
scheduling increases the interrupt latency periods because of the time spent in context
switching and saving and retrieving pointers for the RTOS functions like memory
allocation, and IPCs. The functions for the memory management, file system
functions, IPC (e.g., pipe, signal, socked and RPC) are provided outside the kernel in
a hierarchical and scalable RTOS. MMU is disabled for predictive response time of
the tasks. Hierarchical RTOS means the RTOS functions portable after extending and
interfacing other functions abilities and configuring for specific processor and set of
devices. Scalable RTOS means portable into for system ROM image after the limited
RTOS functions in the kernel space as per the application needs. For example, if
queue and pipe functions are not required in embedded system design, then these
functions are not ported in scalable RTOS.
Semaphores:
A semaphores encapsulates the data during a critical section or encapsulates a buffer from a
reading task or writing into the buffer by multiple tasks concurrently. Example 15 gives
another example.
Queues:
A queue can be used to encapsulate the messages to a task at an instance from the multiple
from the multiple tasks. Assume that a display task is posted a menu for display on a touch
screen in a PDA. Multiple tasks can post the messages into the queue for display. When one
tasks is posting the messages and these messages are displayed, another task should be
blocked from posting the messages.
We can write a task, which takes the input messages from other tasks and posts these
messages to the displayed task only after querying whether the queue is empty.
1. Disabling of all other interrupts of lower priority when running the hard realtime
tasks.
2. Preemption of higher priority task by lower priority tasks.
3. Some critical code in the assembly to meet the real time constraint (deadline) fast.
4. Task running in kernel space. This saves the time required to first check whether
access is outside the memory space allocated to kernel functions.
5. Provision of asynchronous IOs.
6. Provision of spin locks.
7. Predictions of interrupt latencies and context switching latencies of the tasks. This is
achieved by writing all functions which on execution always take the same time
intervals in case of varying rates of occurrences of the events.
8. Response in all the time slots for the given events in the system and thus providing the
guaranteed task deadlines even in case of sporadic and a periodic tasks. Sporadic tasks
means tasks executed on the sudden bursts of the corresponding events at high rates,
and a periodic tasks mean tasks having no definite period of event occurrence.
A soft real time is one in which deadlines are mostly met. Soft real time means that only the
precedence and sequence for the task operations are defined, interrupt latencies and context
switching latencies are small but there can be a few deviations between expected latencies of
the tasks and observed time constraints and a few deadline misses are accepted. The
preemption period for the soft real time task in a worst case may be about a few milliseconds.
Mobile phone, digital cameras and orchestra playing robots are of soft real time systems.
1. Use compressed data structure provided the de-compression algorithm plus compressed
data structure combined together take less memory in the compared with the case when
only unpacked data structure is used.
2. Make the codes compact and fitted in small memory areas without affecting the code
performance. This is called memory optimization. Code means code compiled and
assembled executable in the given system. It also reduces the total amount of CPU
cycles, and thus, the total energy requirements.
3. Use declaration as unsigned byte, especially within the for and while loops, if there is a
variable, which always has value between 0 and 255. When using data structures, limit
the maximum size of the queues, lists and stacks size to 256. Byte arithmetic takes less
time than integer arithmetic. Follow a rule that uses unsigned bytes especially within
[Link]. of ECE, BGSIT 28
MODULE 5
the for and while loops for a short integer if possible, to optimize use of the RAM and
ROM available in the system. Avoid if possible the use of ‘long’ integers and ‘double’
precision floating point value bytes especially within the for and while loops.
4. Avoid use of library functions if a simpler coding is possible. Library functions are the
general functions. use of general function need more memory in several cases. Follow a
rule that avoids use of library functions in case a generalized function is expected to
take more memory especially when is coding is simple.
5. Configure the RTOS functions. For example, if queues are not needed the RTOS queue
functions are not ported in the ROM image. Use a configurable, scalable, hierarchical
RTOS which will help the ROM mage to execute the needed function at the kernel.
6. Optimize the RAM use for the stacks. It is done by three methods: (i) reducing the
number of tasks that interact with the OS, (ii) reducing the number of nested calls and
call at best one more function from a function (one function calling another function
and that calling the third and so on means nested calls), (iii) optimize the number of
tasks. (Less number of tasks are to be brought first into an initiated task list and there
are the frequent interactions with the OS and context savings and retrievals stack on
context switching, thus giving more memory and time overheads.) This optimizes the
use of the stack. As a rule reduce the use of frequent function calls and nested calls and
thus reduce the time and RAM memory needed for the stacks, respectively.
7. Optimize the allocation of stacks. A method is that allocated stack areas on allocation
are filled with the specific bytes or specific set of bytes. Then find that in worst cases of
running of the embedded system, how many filled bytes do not change. Then reduce
the allocated stack spaces by rewriting the task, buffer and other memory creation
codes.
8. In case the software design can be made fast with the instruction set of the target
processor, the assembly codes be used. This also allows the efficient use of memory.
The device-driver programs in the assembly especially provide efficiency due to the
need to use the bit set-reset instructions for the control and status registers. Only a few
assembly codes for using the device I/O port addresses control and status registers are
needed. The best use is made of available features for the given applications. Assembly
coding also helps in coding for atomic operations. A modifier register can be used in
the C program for fast access to a frequently used variable. If portAdata is frequently
employed, it is used as follows, 'register unsigned byte portAdata'. The modifier
register directs the compiler to place portAdata in a general purpose register of the
processor. As a rule, use the assembly codes for simple functions like configuring the
device control register port addresses and bit manipulations if the instruction set is
clearly understood. Use assembly codes for the atomic operations for increment and
addition. Use modifier 'register’ in C program for a frequently used variable.
9. Calling a function causes context saving on a memory stack and on return the context is
retrieved. This involves time and can increase the worst-case interrupt latency. There is
a modifier inline. When the inline modifier is used, the compiler inserts the actual
codes at all the places where these operators are used. This reduces the time and stack
overheads in the function call and return. But, this is at the cost of more ROM being
needed for the codes. If used, it increases the size of the program but gives a faster
speed. Using the modifier directs the compiler to put the codes for the function (in curly
braces) instead of calling that function. As a rule, use inline modifies for all frequently
used small sets of codes in the function or the operator overloading functions if the
ROM is available in the system. A vacant ROM memory is an unused resource. Why
[Link]. of ECE, BGSIT 29
MODULE 5
not use it for reducing the worst-case interrupt latencies by eliminating the time taken
in the frequent save and retrieval of the program context?
10. When a variable is declared static, the processor accesses with less number of
instructions than from the stack. As long as shared data problem does not arise ,the use
of static(global) variables can be Optimized. These are not used as the arguments for
passing the values. A good function is one that has no arguments to be passed. The
passed values are saved on the stacks in case of interrupt services calls and other
function calls. Besides obviating the need for repeated declarations, the use of global
variables thus reduce the worst-Case interrupt latency and the time and stack overheads
in the function call and return. But this is at the cost of the codes for eliminating shared
data problem, As a rule, use static (global ) variables if shared data problems are
tackled and use static variables in case it needs saving frequently on the stack.
11. Combine two functions if possible. For example, the search functions for finding
pointers t a list item and pointers of previous list items combine into one. If present is
false the pointer of the previous list item retrieves the one that has the item. As a rule,
combine whenever feasible two functions of more of less similar codes.
12. Use if feasible, alternatives to the switch-case statements, a table of pointers to the
functions. This saves the processor time in deciding which set of statements to execute
in place of performing the conditional tests all down a chain.
13. When using C++, configure the compiler for not permitting the multiinheritance,
templates, exceptional handling, new style casts, virtual base classes and namespaces.
As a rule, for using C++, use the classes without multiple inheritance, without template,
with run- time identification and with throw able exceptions.
14. When using Java, use the J2ME and configure the device classes. As a rule, us J2ME
with device configurations when programming small-devices code in Java.
An embedded system has to perform tasks continuously from powerup may also be left in
power-ON state; therefore, power saving during execution is important. A microcontroller
used in the embedded system must provide for executing Wait and Stop instructions and
operation in power-down mode. One way to do this is to cleverly incorporate into the
software the Wait and Stop instructions. For example, a program can be such that it reduces
the brightness level of the LCD panel so that it takes less power when the system is used in a
fully lighted room. A sensor senses the light level at specific intervals.
An embedded system may need to be run continuously, without being switched off; the
system design, therefore, is constrained by the need to limit power dissipation while it is
running. Total power consumption by the system in running , waiting, and idle states should
also be limited. A program can provide for auto-switch over the standby mode in the case
System is not used within a specified time interval and stop mode when the s5 or 10 or 20
seconds. A call attend mode can be switched off if there is no talk for over a minute.
The current needed at any instant in the processor for an embedded system depends on the
state and mode of the processor. The following are the typical values in six states of the
processor.
Yet another method is disable use of certain structural units of the processor - for example,
caches - when not necessary and to keep in disconnected state those structure nit needed
during a particular software portion execution, for example, timers or IO units. The software
designer should enable the use of caches in a processor by an appropriate instruction, to
obtain greater performance during run of a section of a program, while simultaneously
disabling the remaining sections in order to reduce the power dissipation and minimize the
system energy requirement. Hardware designers should select a processor with multiway
cache units so that only that part of a cache unit gets activated that has the data necessary to
execute a subset of instructions. This also reduces power dissipation.
In a CMOS circuit, power dissipates only at the instance of change in input . Therefore,
unnecessary glitches and frequent input change increase power dissipation. VLSI circuit
design have a unique way of avoiding power dissipation. A circuit design is made such that it
eliminates all removable glitches, thereby eliminating any frequent input changes.
Another is too operate the system at the lowest voltage levels in the idle state by selecting
power-down mode in that state.
1) The processor goes into a stop state when it receives a ‘stop’ instruction. The stop state
also occurs in the following conditions:
i. On disabling the clock inputs to the processor.
ii. On stopping the external clock circuit functions.
iii. On the processor operating in auto-shutdown mode. When in the stop state, the
processor disconnects with the buses (buses become in tri-state). The stop state can
change to a running state. The transition to the running state is either because of a
user interrupt or because of the periodically occurring wake-up interrupts.
2) The processor goes into a waiting state either on receiving
RTOS Task Scheduling Models, Interrupt Latency and Response Times of the
Tasks As Performance Metrics
Following are the common scheduling models used by schedulers.
• Figure 2(b) shows the cooperative scheduling model. Figure 2(c) shows the task
program contexts at various instances. Task A1 context has a pointer for task A1,
ADDR_A1. Task A2 context has a pointer for task A2, ADDR_A2. Task A3 context
has a pointer for task A3, ADDR_A3.
Fig 2: (a) First three task in set of tasks A1 to AN into which the embedded software is
broken for the example in the text (b) Cyclic scheduling (c) Message from the schedule and
task program contexts at various instances in washing machine tasks
• Figure 3(a) shows a scheduler in which the scheduler inserts into a list the ready for
sequential execution in cooperative model. Program counter PC changes whenever the
CPU starts executing another process. Figure 3(b) shows how the PC changes on
switch to another context. The scheduler switches the context such that there is
sequential execution of different tasks, which the scheduler calls from the list one by
one in a circular queue.
• Cooperative means that each ready task cooperates to let a running one finish. None of
the tasks does a block anywhere during the ready to finish states. The services in the
order in which a task is initiated on interrupt and placed in ready list. We can say that
the task priority parameter sets as per its position in the queue.
• Worst-case latency is the same for each task. It is ttotal. It is time-period of the circular
[Link] longer the queue, the greater is the [Link] a task is running ,all other ready
tasks must wait. For an i-th task,let the event detection time when an event is brought
into a list be dti,switching time from one task to another be sti and task execution time
be eti. Then if there are n tasks in the ready list,the worst-case latency with scheduling
when including the ISRs execution times will be:
• Here the tISR is the sum of all execution times for the ISRs. Remember, the Tworst
should always be less than the deadline,td for any of the task in the list.
Figure 3 (a)An OS scheduling in which the scheduler inserts into a list the ready task for a
sequential execution in a cooperative mode (b) PC assignments at different times, when the
scheduler calls the tasks one by one in the circular queue from the list
The Cooperative Scheduling of Ready Tasks Using an Ordered list as per precedence
constraints:
Cyclic Scheduling AN OS scheduler can let the system schedule the various tasks in real
time as follows: Let us assume that we have periodically occurring three tasks, the need for
their service arises after periodically. Let the time-frames be allotted to the first task, the
task executes at t1, t1 +Tcycle , t1 + 2 x Tcycle , …….second task frames at t2, t2 + Tcycle,
t2 + 2 x Tcycle and the third task at t3, t3 + T, t3 + 2’Tcycle,…… . Start of a time frame is
the scheduling point for the next task in the cycle. Tcycle is the cycle for repeating the cycle
of execution of tasks in order 1, 2 and 3 and equals start of task 1 time frame to end of task 3
frame. Tcycle is the period after which each the task time frame allotted to that repeats.
Each of the N tasks in a cyclic scheduler completes in its allotted time frame when the time
frame size is based on the deadline. A cyclic scheduler is clock-driven and is useful for the
periodic tasks. It repeats the schedule decided after computation based on the period of
occurrences of task instance. Each task has the same priority for execution in the cyclic
mode.
Figure 5(a) The tasks C1 to C5 round robin (b) Task program contexts at five instances in
the round robin(time slice)scheduling scheduler for C1 to C5 with Tslice = 4ms.
• Figure 5(b) shows at different time slices the real-time schedules, process contexts and
saved contexts.
• Figure 5(a) The tasks C1 to C5 round robin (b) Task program contexts at five instances
in the round robin(time slice)scheduling scheduler for C1 to C5 with Tslice = 4ms.
Figure 6: (a) The Programming Model for the cooperative time-sliced scheduling of the task
(b) The program counter assignments on the scheduler call to tasks at two consecutive time slice.
• When a p-th task has high execution time,etp,the worst-case latency of the lowest
priority task can exceed its deadline. To overcome this problem, it is better than the OS
defines a lower time slice for each task. Each task has codes in an infinite loop. Cyclic
scheduling with time slicing is simple and there is no insertion or deletion into the
queue or list. Figure 6(a) shows a programming model for cyclic time-sliced round
robin [Link] 6(b) shows PC on context switches when the scheduler call to
tasks at two consecutive time [Link] task is allocated a maximum time interval =
tslice/N, where tslice is the timer after which a timer (with the OS)interrupts and
initiates a new cycle.
• The OS completes the execution of all ready tasks in one cycle within a time
slice,N*tslice in this mode,Let Tworst be the sum of the maximum times for all the
tasks if there are N tasks in [Link],when tslice> or = Tworst ,the Tworst equals:
{(dti+sti+eti)+(dti+sti+eti)+…..+(dti+sti+eti)+(dti+sti+eti)}+tISR.
• If N*tslice equals the sum of the maximum times for each task,then each task is
executed once and finishes in one cycle [Link] a task finishes the execution before
the maximum time it can take,there is a waiting period between the two [Link]
worst-case latency for any task is N*tslice.A task may periodically need execution .
• The period for the required repeat execution of a task is an integral multiple of
[Link] each task to run only once,the N*tslice should also be less that the greatest
common factor of all the task periods.
• The estimation of response time for each task is easy in time slice cyclic round robin
[Link] a K-th [Link] task responds within its task period plus the sum
of the maximum times taken during a time slice from the task 1 to task(k-1).The
response time of the m-th task at the end of the list is the maximum.
• An alternative model strategy can be the decomposition of a task that takes an
abnormally long time to be [Link] decomposition is into two or four or more
[Link] one set of tasks(or the odd numbered tasks) can run into slice,tslice and
another set of tasks(or the even-numbered tasks)in another time slice,tslice.
• Another alternative strategy can be the decomposition of the long time-taking task into
a number of sequential states or a number of node places and transitions as in the
[Link] one of its states or transitions runs in the first cycle,the next state in the
second cycle and so [Link] task then reduces the response times of the remaining tasks
that are executed after a state.
[Link]. of ECE, BGSIT 39
MODULE 5
Pre-emptive Scheduling Model:
• Cooperative schedulers schedule such that each ready task cooperates to let the running
one finish. However, a disadvantage of the cooperative scheduler is that a long
execution time of a low-priority task makes a high-priority task wait at least until it
finishes.
• There is a further disadvantage if the cooperative scheduler is cyclic but without a
predefined tslice. Assume that an interrupt for service from the first task occurs just at
the beginning of the second task. The first task service waits till all other remaining
listed or queued tasks finish.
• The time-slicing scheduler is simpler in design and extremely valuable in many
applications where there is a need to use the resources of the embedded systems
sequentially, or none of the tasks has a shorter deadline than the tslice or tcycle.
• Round robin scheduler also give appropriate time slice to let a task finish with the
allotted time frame. Now consider the problem with round robin.
• Let there be N tasks from task 1 to task N and let the assigned order of priority for
interrupt servicing be from 1(highest)to N(lowest).Assume now that an interrupt occurs
in the time-slicing scheduling just after the cycle starts. It means task 1 misses by a
flick the chance of running from start to finish as task i will not get serviced till the
cycle up to task N finishes or till the defined period tslice expires.
• Can the higher-priority task preempt a lower priority by blocking it? If yes, then this
can solve the problem of large worst case latency for high priority tasks. The hardware
polls to determine whether an ISR or task with a higher priority than the present one
needs service at the end of an instruction during execution. If yes, then the higher
priority ISR or task is executed. Similarly, the RTOS preemptive scheduler can block a
running task at the end of an instruction by a message to the task and let the one with
the higher priority take control of the CPU.
• Now consider a preemptive scheduler by a simple example. Suppose there is a stream
of coded message reaching at port A of an embedded system. It then decrypts and re-
transmits to port B after encoding each decrypted message.
• Figure 7(a) shows the tasks for the multiple processes of this application. Five
processes are executed at five tasks,B1,B2,B3,B4 and [Link] consider preemptive
scheduling by a scheduler function by another example. Consider an embedded system
for reading a port A input and decrypting the input data, encoding it and sending it to
another port B output .The system can be partitioned into multiple tasks. Five tasks are
task B1, B2, B3, B4 and [Link] 7(a) shows the assigned functions to the task and
ISR. The order of priorities is as follows.
1. Task B1:Check for a message at port A.
2. TaskB2:Read port A.
3. TaskB3:Decrypt the message.
4. TaskB5:Transmit the encoded message to the port.
• Figure 7(b) gives the symbols used to show the preemptive scheduler actions shown in
figure 7(c).A higher priority task takes control from a lower priority task. A higher
priority task switches into the running state after blocking the low priority task. The
context saves on the preemption. Figure 7(c) shows the following.
Fig 7 (a) First five tasks B1 to B5 (b)The symbols used for the states in a preemptive
scheduling (c) The task program contexts at the various instances.
• RTOS manages the processes and provides for preemption of lower priority process by
higher priority process. Let the priority of task_1>task_2>task_3>task_4……>task N.
Figure 8(a) shows the preemptive scheduling of N tasks. figure 8(a) also shows the
context switching whenever the process switches from a task to the RTOS to a task.
Figure 8(b) shows PC assignments on the scheduler call to pre-empt task 2 when the
priority of task_1>task_2>task_3.
• Each task has an infinite loop from start(idle state)up to finish(refer to task 1, task 2,
and task N,three boxes at the bottom of this figure).Last instruction of task 1 points to
the next pointed address,*[Link] case of the infinite loop,*next points to the same task
1 [Link] is unlike a cooperative scheduler, where it signals the next task execution to
the OS and OS now initiates and runs the next task in the ready list.
Figure 8(a) Preemptive scheduling of the tasks (b) Program Counter assignments on a scheduler call
to preempt task 2. Priority of task_1> task_2> task_3
Fig 9 The Petri net model for the task with a preemptive scheduler and one critical section
where it takes a semaphore and release on critical section over
Fig 9 Shows a Petri net concept-based model which models ans helps in designing the codes
for a task that has a critical section in its [Link] figure shows places by the circles and
transitions by the [Link] following are the places and transitions.
1. Each task is in the idle state to start with, and a token to the RTOS is
taskSwitchFlag=rest.
2. Consider the task_J_Idle place, which currently has highest priority among the ready
tasks. When the RTOS creates task-J, the place task_J_Idle undergoes a transition to the
ready state, task_J_Ready [Link] RTOS initiates idle to ready transition by
executing a function, task_J_create().A transition from the idle state of the task is fired
as follows. RTOS sends two tokens, RTOS_CREATE Event and taskJSwitchFlag. The
output token from the transition is taskSwitchFlag=true.
EDF Precedence:
• When a task becomes ready, its will be considered at a scheduling point. The scheduler
does not assign any priority. It computes the deadline left at a scheduling point.
Scheduling point is an instance at which the scheduler blocks the running task and re-
computes the deadlines and runs the EDF algorithm and finds the task to be run.
• An EDF algorithm can also maintain a priority queue based on the computation when
the new task inserts. When the number of tasks becomes large, the computation
complexity increases for insertion into the queue. Another EDF algorithm can also
OS Security Issues:
• When a doctor has to dispense to multiple patients, protection of the patients from any
confusion in the medication becomes imperative. When an OS has to supervise multiple
processes and their access to the resources, protection of memory and resources from
any unauthorized writes into the PCB or resources, or mix up of accesses of one by
another becomes imperative. The OS security issue is a critical issue.
Figure 10 (a) Development process of an embedded system (b) Edit-test-debug cycle during
the implementation phase of the development process
The developer uses four main approaches to the edit-test-debug cycles.
Software Tools:
• The tools are required for the application software high-level language programming.
Also required are the RTOS, testing debugging, assembly language programming (for
implementing the device-driver functions and system integration tools. Table 14 lists
the software tools in software and hardware embedded system. Table 14 Software
Modules and Tools for implementation of an Embedded System
Software tools are used to develop software for designing an embedded system. Sophisticated
tools-Integrated development environment and prototype development tools are needed for
integrated development of system software and hardware. The testing and debugging tools
are needed for testing and debugging.
• A source code engineering tool is of great help for source code development, compiling
and cross-compiling. The tools are commercially available for embedded C/C++ code
engineering, testing and debugging. The features of a typical tool are comprehension,
navigation and browsing, editing, debugging, configuring (disabling and enabling the
C++ features) and compiling. A tool for C and C++is SNIFF+. It is from WindRiver
Systems. A version, SNIFF+ PRO has full SNIFF+ code as well as debug module.
• Main features of the tool are as follows:
1. It searches and lists the definitions, symbols, hierarchy of the classes and class
inheritance trees. [The symbols include the class members. A tree is a data
structure. A data structure tree has a root. From n the roots, the branches emerge
and from the branches more branches emerge. On the branches, finally there are
the leaves (terminating nodes).]
2. It searches and lists the dependencies of symbols and defined symbols, variables,
functions (methods)and other symbols.
3. It monitors, enables and disables the implementation virtual functions. Use of
virtual functions is for dynamic run -time binding.
4. It finds the complete effect of any code change on the source code.
5. It searches and lists the dependencies and hierarchy of the included header files.
6. It navigates to and fro between the implementation and symbol declaration.
7. It navigates to. In a daughter class with the same name and number and types of
arguments as in the parent class. Over-ridden method is the method of the parent
class, which has been redefined at the daughter class.)
8. It browses through information regarding instantiation (object creation) of a class.
9. It browses through the encapsulation of variables among the members and
browses through the public, private and protected visibility of the members.
10. It browses through object component relationships.
11. It automatically removes error-prone and unused tasks.
12. It provides easy and automated search and replacement.
• The embedded software programmer for sophisticated applications uses a source code
engineering tool for program coding, profiling, testing and debugging of embedded
system software.
Figure 11 (a) Simple Integrated development environment (IDE) (b) Sophisticated IDE
• During the development process, a host system is used before locating and burning
the codes in the target board. The target board hardware and software is later copied
to get the final embedded system, which will function exactly as the one tested and
debugged and finalized during the development process.
It a full-fledged computer. It has software tools (Table 11 and must include the following:
• Program development tool kit or IDE has an editor. The editor is used for writing C
codes or assembly mnemonics or C ++ or Java Visual C++ using the keyboard of the
host system (PC) for entering the program. Using GUIS, it allows the addition, deletion,
insert, appending previously and files at written lines or files, merging record and files
at the specific positions. It creates a source file that positions in creates a sour stores the
edited file. It also has an appropriate name (given by the programmer). It can use
previously created files and can also integrate the various source files. It can save
different versions of the source files. Program development kit or IDE has the code
generation tools (assembler. compiler. loader and linker).
• A high-level language is machine-independent. It will have an expression like X = X +
2.3 or X=2* Y +V*Z+ 19 and so on. When we use a high-level language C. a tool is
needed for obtaining the machine codes a target system. The programmer writes the
mnemonics or C program. using the editor. The mice and keyboard combinations of the
host system (PC) or host system are for entering the program codes. Each language
needs a compiler. The codes may not be executable using an interpreter.
1. An interpreter does expression-by -expression (line-by-line) translation to the
machine-executable codes.
2. A compiler uses the complete set of the expressions. It may also include the
expressions from the library routines; that is standard tailor-made programs. Whereas
an interpreter helps in on-line execution of the codes, a compiler helps in the off-line
programming for obtaining the executable machine codes later. The C programs are
used with an interpreter as well as with a compiler. A cross-compiler is a compiler
that created binary executable files for the for target system processor.
3. An assembly language program has the mnemonics that are machine-dependent.
Example of a mnemonic is SBC A. Ox0B. It means an instruction, which subtracts,
along with the previous'carry', the A register of the processor with the hexadecimal
number Ox0B. An assembly mnemonic is specific to a processor or microcontroller. It
is according to the instructions provided in the instruction set. The assembly
mnemonics needs an interpreter to translate into the machine codes that are executed
on a specific processing device.
4. A dissembler translates the object codes into the mnemonics form of assembly
language. It helps in understanding the previously made object codes.
5. An assembler is a program that translates the assembly mnemonics into the binary
encodes and instructions, that is, into an executable file, called object file. It also
creates a list file that can be printed. The list file has address, source code (assembly
language mnemonic) and object codes in hexadecimal. The object file has addresses
that are to be allocated again during actual run of the assembly language program. A
loader is a program that helps in this task by reallocating addresses before loading the
code and operands in the computer memory.
6. A linker links the needed object code files and library code files. This is before the
loader reallocates the addresses, and puts the codes at the physical addresses in the
memory, and the program runs. Loader performs the analogous functions on host
machine as the locator does on a target system in conjunction with a device
programmer.
Cross-Assembler: It converts object codes or executable codes for a processor to other codes
for another processor and vice versa. The cross-assembler assembles the assembly codes of
the target processor as the assembly codes of the lets us use a processor of the host system
(PC) used in the system development. Later, it provides the object codes for the target
processor. These codes will be the ones actually needed in the finally developed system.
Code generation tools are used for creating and compiling at the host system. Then codes are
tested at the host system using simulators and number of latest software tools like profiler,
memory scope, stethoscope and memory and code coverage scope.
Target System:
• A target system has a processor. ROM memory for ROM image of the embedded
software, RAM for stack. temporary variables and memory buffers, peripherals and
interfaces. Figure 12(a) and (b) show simple and sophisticated target systems,
respectively. Some target systems have 8 or 16 MB flash memory and 64 MB SDRAM.
A target system may possess the RS232 as well as 10/100-base Ethernet connectivity or
USB port.
Fig.13: Various software tools and chain of actions of linker at host and locator in an
embedded system
Locator Output File in Binary Image Motorola-S and Intel Hex Formats
Binary bit mapped (binary image) means bytes are sent in a sequence as per starting address
to the end address.
• Motorola S-record format is an industry standard for storing the locator file. Before its
use by the device programmer or ROM-mask programmer. It is called S-record because
it has first character as 'S' in each line. A line is as follows: first character is S, second
character is 2 (for specifying the record type), third and fourth characters are for a
hexadecimal number, say 14 (to specify that there are 20 bytes in that ne), the
remaining 40 characters (nibbles) divide as the address (3 bytes) and data (16 bytes)
and checksum +1 byte). Table 16 shows a typical S-record as a locator output and
device programmer input. It is left as an exercise to the reader to show that Add for line
6 in the record of Table 16 will be 0x000037.
• Intel hex file format is another industry standard for storing the locator file output,
before its use by the device programmer or ROM-mask programmer. A line is as
follows: first character (colon), second and third characters for data counts (assume =
10 in hexadecimal in case N d =16) in the line (address bytes, checksum byte and data
type bye excluded, only actual data bytes at the line, which are to be burned in ROM
are counted), fourth to seventh address (2 bytes), sixth and seventh as 0 and 0 to specify
data 28 ROM data and the remaining 32 characters as the data (16 bytes) and 2
characters for the checksum byte). Table 17 shows an Intel hex file, which corresponds
to the same data as at the Motorola S-record in Table 17 as a locator output and device
programmer input. It is left as an exercise to the reader to show that Add for line 6 in
Figure 14 (a) Memory Map (Princeton architecture) (b) Memory map (Architecture
architecture)