Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

Embedded Systems Design and

Software - Assignment 2
Naveen N. Murthy [1MS09EC062]
March 31, 2013

Embedded Systems Design and Software

1) [Q3] Explain with an example how the Round Robin architecture


works. When is it not suitable?
Solution:
The Round-Robin is one of the simplest architectures possible for
embedded software. In this architecture, there are no interrupts. The main
loop simply checks each I/O device in turn and services those that need
service [1].
Example
Consider the example of a digital multimeter which measures resistance,
current and potential, each in various ranges. This can be implemented using
a Round-Robin architecture. The position of the rotary switch is noted and,
depending on that, the code branches to the corresponding operation. A
switch-case statement decides what course of action to take.
Here, the delay involved in running through the entire main loop is not
much and is usually masked by the time taken to turn the rotary switch.
Hence, the Round-Robin architecture is usually sufficient in simple systems.
The Round-Robin architecture is not suitable in the following cases.
If any device requires a response time less than the total loop time in
the worst-case scenario.
Any system wherein a priority order needs to be assigned to the various
I/O devices.
A single additional I/O device may cause problems in this architecture.
2) [Q7] With the help of timing signals, explain how disabling of interrupts
affects system response.
Disable interrupts for 125 usec for task code to use a pair of temperature
variables it shares with ISR that reads temperatures from hardware and
writes them into variables.
Disable interrupts for 250 usec for task code to get time accurately
from variables it shares with ISR that responds to timer interrupt.
A special signal received from another processor shall be responded
with 625 usec.

Naveen N. Murthy [1MS09EC062]

Embedded Systems Design and Software

Solution:

Figure 1: Worst case Interrupt Latency


Interrupts are disabled in our hypothetical system for at most 250 usec
at a time. The interrupt routine needs 300 usec, for a total worst-case time
of 550 usec, within the 625 usec limit, as illustrated in Fig. 1.
The interrupt will never be delayed for 375 usec, the sum of the two
periods of time during which interrupts are disabled. The system will
reenable the interrupts after a maximum of 250 usec, and the microprocessor
will jump to the interrupt routine.
Consider the processor to be replaced with another one at exactly half
the speed. All the processing times are doubled, interrupts are disabled for
twice as long, the interrupt service routine takes twice as long, but the 625
usec deadline remains the same.
Interrupts will be disabled for up to 500 usec at a time, and the interrupt
service routine needs 600 usec to do its work. The total of these two is 1100
usec, much longer than the 625 usec deadline. Thus, in this case, the system
will not meet the deadline.
3) [Q8] What are the three different states of task in RTOS? How is the
state of each task tracked?
Solution:
Tasks are the basic building blocks of software written under an RTOS.
It is usually a subroutine. Each task in an RTOS is always in one of three
states:
Naveen N. Murthy [1MS09EC062]

Embedded Systems Design and Software

Figure 2: Task States of RTOS


a. Running: This implies that the present task is being executed. In
most systems which are not multi-processor, only one task is in the
running state at any given state.
b. Ready: This implies that some other task is being executed but if the
microprocessor becomes available, this task has things that it could do.
Any number of tasks can be in this state.
c. Blocked:
Here, the task has nothing to do right now even if the
microprocessor becomes available. Tasks enter this state when they
are waiting for an external event.
The various states of a task in RTOS are illustrated in Fig. 2.
Scheduler
Scheduler is a part of the RTOS which keeps track of the state of each task.
It looks at priorities assigned to each task. Among the tasks that are not
in the blocked state, the one with the highest priority runs, and the rest of
them wait in the ready state.

Naveen N. Murthy [1MS09EC062]

Embedded Systems Design and Software

4) [Q9] What is a reentrant function? Give the three rules to decide


reentrant function.
Solution:
Reentrant functions are functions that can be called by more than one
task and that will always work correctly, even if the RTOS switches from
one task to another in the middle of executing the function. They form an
important part of the working of RTOS.
Reentrancy of a function can be decided by applying 3 rules.
Rule 1: A reentrant function may not use variables in a nonatomic
way unless they are stored on the stack of the task that called the
function or they are the private variables of that task.
Rule 2: A reentrant function can only call other reentrant functions.
Rule 3: A reentrant function may only use the hardware in an atomic
way.

5) [Q10] What is an event? Give 3 standard features of an event.


Solution:
An important aspect of RTOS is the management of events within the
system. An event is basically a Boolean flag that tasks can set or reset and
that other tasks can wait for. Some standard features of events are given
below:
a. More than one task can be in the blocked state waiting for the same
event, and the RTOS will unblock all of them when the event occurs.
The tasks are then executed according to the priority assigned to them.
b. Typically groups of events are formed in RTOS. Tasks can wait for any
subset of events within the group.
c. Different RTOS deal in different ways with the issue of resetting an
event after it has occurred and tasks that were waiting for it have been
unblocked. Some RTOS reset events automatically; others require that
your task software do this.

Naveen N. Murthy [1MS09EC062]

Embedded Systems Design and Software

6) [Q11] Give a comparison of methods for inter task communication.


Solution:
Intertask communication between two tasks or between an interrupt
routine and a task is possible using queues, pipes, mailboxes, semaphores,
and events. A comparison between these methods is given below:
a. Semaphores are usually the fastest and simplest methods. The
downside is that they can carry only 1-bit information saying that it
has been released.
b. Events take up a little more microprocessor time than semaphores.
The advantage of events over semaphores is that a task can wait for
any one of several events at the same time, whereas it can only wait
for one semaphore.
c. Queues allow the sending of a lot of information from one task to
another. Queues are more flexible than events but have inherent
disadvantages. They are more microprocessor intensive and offer many
opportunities for bugs to appear in the code.

7) [Q15] Explain the need for interrupts in processing system. Explain


the various events that take place when a processor is interrupted.
Solution:
Interrupts make sure that the embedded system reacts rapidly to external
events even if it is in the middle of doing something else. Without interrupts,
the system uses the process of polling to react to external occurrences. In
this method, it takes a longer time to respond to the event. An interrupt
is a signal which causes the processor to stop whatever it is doing and to
execute some different task.
The various events that take place during an interrupt are detailed below.
Interrupt Request
This signal tells the microprocessor that the chip connected to that pin
requires service. Thus, the processor need not continuously monitor the
pin; an IRQ signal is generated whenever an interrupt occurs.

Naveen N. Murthy [1MS09EC062]

Embedded Systems Design and Software

Saving and Restoring the Context


Manipulation of registers can be seen inside Interrupt Service Routines (ISR).
This affects the original values stored in the registers. Thus, the registers
need to pushed onto the stack, called saving the context, and popped back
at the end, known as restoring the context.
Disabling Interrupts
Usually the ISR is made non-interruptible. Thus, interrupts are disabled
at the beginning of an ISR. An alternative to this is to enable only those
interrupts which are of higher priority than the one under consideration.
ISR
Finally the processor looks up the address of the ISR in the Interrupt Vector
Table (IVT) and executes it.
8) [Q16] What is interrupt latency? Explain the factors affecting it.
Solution:
In computing, interrupt latency is the time that elapses from when an
interrupt is generated to when the source of the interrupt is serviced. It is a
measure of how fast the embedded system responds to each interrupt.
Factors that affect interrupt latency include:
a. The longest period of time during which that interrupt or all interrupts
are disabled: Disabling of interrupts is essential to avoid the shared
data problem. However, this delays the response time of the processor
to interrupts.
b. The period of time it takes to execute any interrupt routines for
interrupts that are of higher priority:
The interrupt under
consideration is serviced only after the interrupts with higher priority
than itself are all serviced.
c. The time taken for the microprocessor to stop whatever it is doing, do
the necessary bookkeeping, and start executing the ISR: This differs
from microprocessor to microprocessor, and can be obtained from the
official documentation.

Naveen N. Murthy [1MS09EC062]

Embedded Systems Design and Software

d. The time taken for the ISR to save the context and accomplish the
desired response: The shorter the ISR, the faster it can be serviced
and the processor can go back to its main task.

9) [Q17] Explain the reasons why the systems with conventional OS fail
to respond to real time problems. Also, explain how these are taken care in
RTOS.
Solution:
Some reasons to explain the fast response of RTOS in comparison with
conventional OS are given below.
On a desktop computer the operating system takes control of the
machine as soon as it is turned on and then starts the applications.
In an embedded system, at boot-up time, the application usually gets
control first, and it then starts the RTOS. Thus, the application and
the RTOS are much more tightly tied to one another than are an
application and its desktop operating system.
Conventional OS try to protect themselves from their applications such
as checking the validity of any pointer passed into a system function.
Many RTOSs skip this step in the interest of better performance and
hence, a very fast response time is obtained.
Whether they need it or not, conventional OSs contain system functions
as file managers, I/O drivers, utilities, and memory management.
RTOSs typically include just the services that are needed for the
embedded system and this can be configured beforehand by the user.
Schedulers in RTOSs are more simple-minded than conventional OS.
They just schedule tasks depending on the assigned priority, and thus
the pre-assigned priority order is very important.

Naveen N. Murthy [1MS09EC062]

Embedded Systems Design and Software

10) [Q19] Differentiate between hard and soft RTOS highlighting the
advantages and disadvantages of each.
Solution:

Hard RTOS
Systems with absolute deadlines, such as high risk systems including
nuclear reactor systems, are called hard real-time systems.
When an event occurs, it should be serviced within the predictable time
at all times in a given hard real time system [2]..
Predictability is achieved by making sure that the functions always
take the same predefined time intervals in case of varying rates of
occurrences of the events.
Tasks that avoid semaphores for data protection are preferable, since
their worst case performance does not depend upon characteristics of
every other task that uses the semaphore.
Examples: Automobile engine control system and anti-lock brake.
Advantages

Extremely good response time.


Highly useful for critical environments.
Disadvantages

Higher complexity of code since fast code is required.


Failure to respond for a very small percentage of time can also be
catastrophic.
Soft RTOS
Systems that demand good response but that allow some fudge in the
deadlines are called soft real-time systems.
When an event occurs, it is excusable if it is not serviced within the
required time, for a small percentage of occurrences.
Naveen N. Murthy [1MS09EC062]

Embedded Systems Design and Software

Worst case performance is not so critical as in hard RTOS since a few


failed responses are permissible.
Examples: Mobile phones, digital cameras.
Advantages

Complexity of coding reduces.


100 % response is not necessary.
Disadvantages

Cannot be used in environments where human life is at stake.


Since the code is not as predictable as in hard RTOS, there could be a
rare case where conditions spin out of control.

References
[1] Simon, D., 2005 An Embedded Software Primer Pearson Education, First
Edition
[2] Kamal, R., 2008 Embedded Systems - Architecture, Programming and Design
McGraw-Hill Publications

Naveen N. Murthy [1MS09EC062]

You might also like