10
Embedded Systems Design and Software - Assignment 2 Naveen N. Murthy [1MS09EC062] March 31, 2013

Embedded Systems Assignment2_ 1MS09EC062

Embed Size (px)

DESCRIPTION

quetions on embedded system and answers

Citation preview

  • Embedded Systems Design andSoftware - Assignment 2

    Naveen N. Murthy [1MS09EC062]

    March 31, 2013

  • Embedded Systems Design and Software 1

    1) [Q3] Explain with an example how the Round Robin architectureworks. When is it not suitable?Solution:

    The Round-Robin is one of the simplest architectures possible forembedded software. In this architecture, there are no interrupts. The mainloop simply checks each I/O device in turn and services those that needservice [1].

    Example

    Consider the example of a digital multimeter which measures resistance,current and potential, each in various ranges. This can be implemented usinga Round-Robin architecture. The position of the rotary switch is noted and,depending on that, the code branches to the corresponding operation. Aswitch-case statement decides what course of action to take.

    Here, the delay involved in running through the entire main loop is notmuch 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 inthe worst-case scenario.

    Any system wherein a priority order needs to be assigned to the variousI/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 interruptsaffects system response.

    Disable interrupts for 125 usec for task code to use a pair of temperaturevariables it shares with ISR that reads temperatures from hardware andwrites them into variables.

    Disable interrupts for 250 usec for task code to get time accuratelyfrom variables it shares with ISR that responds to timer interrupt.

    A special signal received from another processor shall be respondedwith 625 usec.

    Naveen N. Murthy [1MS09EC062]

  • Embedded Systems Design and Software 2

    Solution:

    Figure 1: Worst case Interrupt Latency

    Interrupts are disabled in our hypothetical system for at most 250 usecat a time. The interrupt routine needs 300 usec, for a total worst-case timeof 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 twoperiods of time during which interrupts are disabled. The system willreenable the interrupts after a maximum of 250 usec, and the microprocessorwill jump to the interrupt routine.

    Consider the processor to be replaced with another one at exactly halfthe speed. All the processing times are doubled, interrupts are disabled fortwice as long, the interrupt service routine takes twice as long, but the 625usec deadline remains the same.

    Interrupts will be disabled for up to 500 usec at a time, and the interruptservice routine needs 600 usec to do its work. The total of these two is 1100usec, much longer than the 625 usec deadline. Thus, in this case, the systemwill not meet the deadline.

    3) [Q8] What are the three different states of task in RTOS? How is thestate 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 threestates:

    Naveen N. Murthy [1MS09EC062]

  • Embedded Systems Design and Software 3

    Figure 2: Task States of RTOS

    a. Running: This implies that the present task is being executed. Inmost systems which are not multi-processor, only one task is in therunning state at any given state.

    b. Ready: This implies that some other task is being executed but if themicroprocessor 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 themicroprocessor becomes available. Tasks enter this state when theyare 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 notin the blocked state, the one with the highest priority runs, and the rest ofthem wait in the ready state.

    Naveen N. Murthy [1MS09EC062]

  • Embedded Systems Design and Software 4

    4) [Q9] What is a reentrant function? Give the three rules to decidereentrant function.Solution:

    Reentrant functions are functions that can be called by more than onetask and that will always work correctly, even if the RTOS switches fromone task to another in the middle of executing the function. They form animportant 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 nonatomicway unless they are stored on the stack of the task that called thefunction 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 thesystem. An event is basically a Boolean flag that tasks can set or reset andthat other tasks can wait for. Some standard features of events are givenbelow:

    a. More than one task can be in the blocked state waiting for the sameevent, 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 anysubset of events within the group.

    c. Different RTOS deal in different ways with the issue of resetting anevent after it has occurred and tasks that were waiting for it have beenunblocked. Some RTOS reset events automatically; others require thatyour task software do this.

    Naveen N. Murthy [1MS09EC062]

  • Embedded Systems Design and Software 5

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

    Intertask communication between two tasks or between an interruptroutine 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. Thedownside is that they can carry only 1-bit information saying that ithas 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 forany one of several events at the same time, whereas it can only waitfor one semaphore.

    c. Queues allow the sending of a lot of information from one task toanother. Queues are more flexible than events but have inherentdisadvantages. They are more microprocessor intensive and offer manyopportunities for bugs to appear in the code.

    7) [Q15] Explain the need for interrupts in processing system. Explainthe various events that take place when a processor is interrupted.Solution:

    Interrupts make sure that the embedded system reacts rapidly to externalevents 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. Inthis method, it takes a longer time to respond to the event. An interruptis a signal which causes the processor to stop whatever it is doing and toexecute 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 pinrequires service. Thus, the processor need not continuously monitor thepin; an IRQ signal is generated whenever an interrupt occurs.

    Naveen N. Murthy [1MS09EC062]

  • Embedded Systems Design and Software 6

    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 registersneed to pushed onto the stack, called saving the context, and popped backat the end, known as restoring the context.

    Disabling Interrupts

    Usually the ISR is made non-interruptible. Thus, interrupts are disabledat the beginning of an ISR. An alternative to this is to enable only thoseinterrupts which are of higher priority than the one under consideration.

    ISR

    Finally the processor looks up the address of the ISR in the Interrupt VectorTable (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 aninterrupt is generated to when the source of the interrupt is serviced. It is ameasure 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 interruptsare disabled: Disabling of interrupts is essential to avoid the shareddata problem. However, this delays the response time of the processorto interrupts.

    b. The period of time it takes to execute any interrupt routines forinterrupts that are of higher priority: The interrupt underconsideration is serviced only after the interrupts with higher prioritythan itself are all serviced.

    c. The time taken for the microprocessor to stop whatever it is doing, dothe necessary bookkeeping, and start executing the ISR: This differsfrom microprocessor to microprocessor, and can be obtained from theofficial documentation.

    Naveen N. Murthy [1MS09EC062]

  • Embedded Systems Design and Software 7

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

    9) [Q17] Explain the reasons why the systems with conventional OS failto respond to real time problems. Also, explain how these are taken care inRTOS.Solution:

    Some reasons to explain the fast response of RTOS in comparison withconventional OS are given below.

    On a desktop computer the operating system takes control of themachine as soon as it is turned on and then starts the applications.In an embedded system, at boot-up time, the application usually getscontrol first, and it then starts the RTOS. Thus, the application andthe RTOS are much more tightly tied to one another than are anapplication and its desktop operating system.

    Conventional OS try to protect themselves from their applications suchas checking the validity of any pointer passed into a system function.Many RTOSs skip this step in the interest of better performance andhence, a very fast response time is obtained.

    Whether they need it or not, conventional OSs contain system functionsas file managers, I/O drivers, utilities, and memory management.RTOSs typically include just the services that are needed for theembedded 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 thusthe pre-assigned priority order is very important.

    Naveen N. Murthy [1MS09EC062]

  • Embedded Systems Design and Software 8

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

    Hard RTOS

    Systems with absolute deadlines, such as high risk systems includingnuclear reactor systems, are called hard real-time systems.

    When an event occurs, it should be serviced within the predictable timeat all times in a given hard real time system [2]..

    Predictability is achieved by making sure that the functions alwaystake the same predefined time intervals in case of varying rates ofoccurrences of the events.

    Tasks that avoid semaphores for data protection are preferable, sincetheir worst case performance does not depend upon characteristics ofevery 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 thedeadlines are called soft real-time systems.

    When an event occurs, it is excusable if it is not serviced within therequired time, for a small percentage of occurrences.

    Naveen N. Murthy [1MS09EC062]

  • Embedded Systems Design and Software 9

    Worst case performance is not so critical as in hard RTOS since a fewfailed 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, FirstEdition

    [2] Kamal, R., 2008 Embedded Systems - Architecture, Programming and DesignMcGraw-Hill Publications

    Naveen N. Murthy [1MS09EC062]