Top Banner
Embedded Operating System Operating System History 1. What is the definition of an operating system? An operating system (commonly abbreviated OS and O/S) is the software component of a computer system that is responsible for the management and coordination of activities and the sharing of the resources of the computer. The operating system acts as a host for application programs that are run on the machine. 2. What are the major 2 hardware resources an embedded operating system is managing? CPU Time Memory Peripherals 3. Name 2 operating systems, which belong to the family UNIX (DEC, CP/M, MAC-OS) UNIX CTSS, UNIX, LINUX DEC VMS, Windows NT, Windows XP CP/M CP/M, MS-DOS, Windows 3.x MAC-OS MacOS, BeOS 4. What were the major motivations for developing operating systems in 60ies, 80ies and nowadays Sixties More efficient usage of resources, especially CPU time Multitasking Seventies and eighties Abstraction of the hardware Portable software components Nineties until nowadays Improvement of the GUI Communication / Networking Multimedia integration Device integration (e.g. USB) 5. How are Unix and C related? Unix is a multitasking, multi-user computer operating system originally developed in 1969 by a group of AT&T employees at Bell Labs, including Ken Thompson, Dennis Ritchie, Brian Kernighan, Douglas McIlroy, and Joe Ossanna. C is a general-purpose computer programming language developed in 1972 by Dennis Ritchie (member of the team which developed Unix) at the Bell Telephone Laboratories for use with the UNIX operating system. 6. Explain the hardware abstraction concept of MS-DOS. MS-Dos was one of the earliest operating system which implemented the concept of hardware abstraction. Generally, Hardware abstractions are sets of routines in software that emulate some platform- specific details, giving programs direct access to the hardware resources. They often allow programmers to write device-independent, high performance applications by avoiding standard Operating System (OS) calls to hardware.
33

Embedded Operating System...Embedded Operating System Operating System History 1. What is the definition of an operating system? An operating system (commonly abbreviated OS and O/S)

Apr 10, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Embedded Operating System...Embedded Operating System Operating System History 1. What is the definition of an operating system? An operating system (commonly abbreviated OS and O/S)

Embedded Operating System Operating System History 1. What is the definition of an operating system?

An operating system (commonly abbreviated OS and O/S) is the software component of a computer system that is responsible for the management and coordination of activities and the sharing of the resources of the computer. The operating system acts as a host for application programs that are run on the machine. 2. What are the major 2 hardware resources an embedded operating system is managing?

• CPU Time • Memory• Peripherals

3. Name 2 operating systems, which belong to the family UNIX (DEC, CP/M, MAC-OS)

• UNIX à CTSS, UNIX, LINUX• DEC à VMS, Windows NT, Windows XP• CP/M à CP/M, MS-DOS, Windows 3.x• MAC-OS à MacOS, BeOS

4. What were the major motivations for developing operating systems in 60ies, 80ies and nowadaysSixties

• More efficient usage of resources, especially CPU time• Multitasking

Seventies and eighties• Abstraction of the hardware• Portable software components

Nineties until nowadays• Improvement of the GUI• Communication / Networking• Multimedia integration• Device integration (e.g. USB)

5. How are Unix and C related?

Unix is a multitasking, multi-user computer operating system originally developed in 1969 by a group of AT&T employees at Bell Labs, including Ken Thompson, Dennis Ritchie, Brian Kernighan, Douglas McIlroy, and Joe Ossanna.

C is a general-purpose computer programming language developed in 1972 by Dennis Ritchie (member of the team which developed Unix) at the Bell Telephone Laboratories for use with the UNIX operating system.

6. Explain the hardware abstraction concept of MS-DOS.

MS-Dos was one of the earliest operating system which implemented the concept of hardware abstraction.

Generally, Hardware abstractions are sets of routines in software that emulate some platform-specific details, giving programs direct access to the hardware resources. They often allow programmers to write device-independent, high performance applications by avoiding standard Operating System (OS) calls to hardware.

Page 2: Embedded Operating System...Embedded Operating System Operating System History 1. What is the definition of an operating system? An operating system (commonly abbreviated OS and O/S)

7. Name 2 embedded Operating Systems used in the field of communication (transportation)• Field of Communication à Palm OS, Symbian OS, Windows CE• Transportation à QNX, VxWorks, OSEK, Integrity

Multitasking8. Explain the constraints of sequential programming in terms of performance and reacting on priorities.

In sequential programming, only one program is executed at a point. Thus the programs are executed sequentially by waiting for previous program to finish execution. The execution of programs is one by the priority that has been set for particular program. This may result in ‘Process Idle Time’.

9. What are the pro’s and con’s of single tasking? Pros Cons

Simple to develop

High amount of processor idle times resulting in an overall decrease of performanceà more expensive hardware required to increase performance

Static program flow, easy to debug Only one single processor supported per program

No problems with data consistency

No possibilities to “react” on high priority events unless explicitly coded

10. Explain the concept of cooperative multitasking.

The main concept of cooperative multitasking is to use “process idle time for additional process”. It is also known as non-preemptive or time sharing multitasking. Here, the amount of process idle time is allocated to another process. (No constant timeslot is decided like scheduled multitasking).

11. What are the pro’s and con’s of cooperative multitasking?

Pros Cons

Better utilization of the CPU time compared to single tasking

Because a cooperatively multitasked system relies on each process to regularly give time to other processes on the system, one poorly designed program can cause the whole system to hang.

Page 3: Embedded Operating System...Embedded Operating System Operating System History 1. What is the definition of an operating system? An operating system (commonly abbreviated OS and O/S)

It does not allow the system to rapidly deal with important external events like incoming data, which might require the immediate attention of one or another process.

12. Explain the concept of preemptive multitasking.

The main concept of preemptive multitasking is to allow interruption of program in case if an event with higher priority occurs.

13. What are the pro’s and con’s of preemptive multitasking?Pros Cons

Better utilization of the CPU time compared to single tasking

Risk of race and deadlock conditions, causing the system to crash

Supports the fast reaction on high priority events Hard to debug

Timeslice scheduling allows “pseudo-parallel” execution of several programs on a single CPU

Timeslices are a fundamental step towards realtime programming

14. Explain the concept of scheduled multitasking.• The concept of scheduled multitasking is to use a constant time slot for every process.• In this case, time itself acts as high priority interrupt, passing control to the scheduler.• Then the scheduler decides who gets the CPU time based on its scheduling algorithm.• The time occupied by the scheduler is also referred as task switch or latency time. (in general,

latency means delay)

15. Provide 3 examples for preemptive operating systems.• MAC OS 9.x• Windows NT, XP, Vista.

16. Explain the Windows Join() command.

Same as join() function in UNIX.Reference: Reactive System: a system having many high speed external interfaces (e.g. CANBus, ports) with several processes running in parallel. Design goals for an Embedded Os for such a system should be

• Support multitasking• Support priority scheduling• Fast latency

• Robust• Use as few resources as possible

Page 4: Embedded Operating System...Embedded Operating System Operating System History 1. What is the definition of an operating system? An operating system (commonly abbreviated OS and O/S)

Realtime 17. Explain the terms “hard realtime” and “soft realtime”.

A system is said to be real-time if the total correctness of an operation depends not only upon its logical correctness, but also upon the time in which it is performed.Hard Realtime: In hard Realtime, the completion of an operation after its deadline is considered useless i.e. if realtime criteria must be met, otherwise system fails. For example, a car engine control system is a hard real-time system because a delayed signal may cause engine failure or damage.Soft Realtime: In soft realtime, the completion of an operation after its deadline is tolerated i.e. realtime violation leads to minor impression errors (e.g., omitting frames while displaying a video). 18. Considering the initial definition of realtime, explain what is most important: The time an activity starts, the time the activity takes, the time the activity is finished?

A system is said to be real-time only if the total correctness of an operation is performed in predefined time. Else there are chances that system may crash. So, the most important is the time the activity is finished.

19. What is the definition of a realtime system?

A realtime system is a system that must satisfy explicit (bounded) response-time constraints or risk severe consequences, including failure. A failed system is a system which cannot satisfy one or more of the requirements laid out in the formal system specification.

20. Discuss the following statement: The development of realtime programs explicitly means “performance engineering”.

Development of realtime programs doesn’t explicitly mean performance engineering. This may be right or wrong depending on the application of the system. Considering a simple application, there is no need to go for complex solution or complex architecture. So, the development of realtime programs depends on the application. 21. Discuss the following statement: the ensurance of time constrains is handled by the OS, not by the application programmer.

The real time constraints in the system are handled by scheduler method and priorities, which are set by programmer in development stage. They are handled by OS as programmer wants. So, the ensurance of time constraints totally depends on the application programmer.

22. Discuss the following statement: Random events should be processed as fast as possible (get the data, store the data, get out)

Random events are considered as change in normal operation of system, which can be either safety measure or high priority task calling. These events always change the flow of execution of program. So, they are considered as interrupts and handles by interrupt service routine. That’s why random events should be processed as fast as possible.

23. Discuss the following statement: Realtime programming implies multitasking.

Not necessarily. Realtime just means execution of particular task/function in time constraints. It does not depend if system is single tasking or multitasking.

24. Discuss the following statement: in more complex multitasking scenarios, task priorities have to be defined.

Yes, the priorities have to be defined. In complex multitasking scenarios, events are responsible for switching of tasks. If task priorities are not specified, then it’s not possible to call proper tasks. Like in case of preemptive multitasking, if we don’t define the priorities; scheduler won’t be able to switch between tasks.

Page 5: Embedded Operating System...Embedded Operating System Operating System History 1. What is the definition of an operating system? An operating system (commonly abbreviated OS and O/S)

25. Discuss the following statement: the development of realtime systems is the task of gurus, it is far too complicated for normal developers.

The development of realtime systems are not easy, but provided the normal developer follows standard procedure; it’s not the task of gurus. Standard procedure includes obeying standard design patterns, understanding application and keeping time-constraints in mind.

26. Explain the terms release time, deadline, start time, completion time and computation time.

• Release Time(R) : This is the earliest time when a task can be start.(Triggering of task).

• Deadline (D) : Maximum acceptable Delay for a task to complete.• Start Time(S) : the actual time when task is started.• Completion Time (E) : the actual time when task is completed.• Computation Time(C) : Total runtime of an active task.

27. Explain the statement: during the design phase, CPU and memory resources are budgeted.

In design phase, the general architecture of the system is designed. In this phase, the developer has to allocate available CPU time and memory to all the tasks before starting with real programming. Designing system without considering both resources may lead to some condition where there are no sufficient resources for certain task to execute.

28. What data is typically stored in a task control block? Name 3 data items. The data about execution of the task is typically stored in Task Control Block. Some examples

are priority, estimated runtime, process identifier, pointer to the function containing task functionality, register values such as program counter or stack pointer etc.

29. Explain the usage of a state time diagram in multitasking context.

A state time diagram is used to describe the state (start, running, waiting, finished) over time. It also shows message flow between tasks. Generally, in a single controller system, only one task can have state ‘running’ in same timeslot. So, it can show in design if any task is overlapping with other task or not.

30. Describe the operation of a non-preemptive scheduler. Which steps are performed?

• Wait until the currently running task returns CONTROL to scheduler.• Save the internal task program counter in the corresponding TCB.• Set the task state of the old task to ‘sleeping’.• Decide which task will be processed next.• Load the register values and PC of the task from its TCB.• Start Execution of the new task.

31. Describe the operation of a preemptive scheduler. Which steps are performed?

• Wait for an interrupt to occur.• Save the program counter and register set of the interrupted task in the corresponding TCB.• Set the task state of the interrupted task to “sleeping”.• Decide which task will be processed next.• Load the register values and PC of the task from its TCB• Start execution of the new task

Page 6: Embedded Operating System...Embedded Operating System Operating System History 1. What is the definition of an operating system? An operating system (commonly abbreviated OS and O/S)

32. Why is the development of a preemptive scheduler more complex than a non- preemptive scheduler?

The concept of context switching (task switching) is there in preemptive scheduler. It gives control of CPU to the next task (having higher priority than current task) even if the current running task is not completed. If the priorities are not defined properly, it can lead the system to malfunction. So, development of a preemptive scheduler is more complex than a non-preemptive scheduler. 33. Why the creation of application code for a preemptive scheduler is easier compared to a non preemptive scheduler?

In preemptive scheduler, program waits for events and at that time program pauses. But non-preemptive schedulers don’t consider any event for scheduling. So, there are no breakpoints in the code. To provide the ‘pause’ functionality in the code, we must add additional code for that. This will increase the code size and will make the application code more complex. That’s why the creation of application code is easier in case of preemptive scheduler.

34. Which additional information has to be stored in the task control block of a preemptive scheduler compared to a non-preemptive scheduler?

Register values such as of program counter and stack pointer, so task can be resumed from its wait state. Also, other information maintained by the OS(open files, scheduling info, I/O devices being used etc.) 35. Draw and explain the task state diagram of an OSEK basic task.

There are three states of an OSEK basic task. Task is either ready or running or suspended depending on the events (and/or conditions).

36. Draw and explain the task state diagram of an OSEK extended task.

There are four states of an OSEK extended task. The task is either running or ready or suspended or waiting depending upon the events (and/or conditions). 37. What is the difference between an OSEK basic and extended task (state diagram and functionality)?

Basic tasks only release the processor, if • They terminate, • The OSEK operating system switches to a higher-priority task, or • An interrupt occurs which causes the processor to switch to an interrupt service routine (ISR).

Extended tasks are distinguished from basic tasks by being allowed to use the operating system

call WaitEvent, which may result in a waiting state. The waiting state allows the processor to be released and to be reassigned to a lower-priority task without the need to terminate the running extended task. So, extended tasks can wait for the events to occur, until then they will be in ‘waiting’ state.

In view of the operating system, management of extended tasks is, in principal, more complex than management of basic tasks and requires more system resources.

Page 7: Embedded Operating System...Embedded Operating System Operating System History 1. What is the definition of an operating system? An operating system (commonly abbreviated OS and O/S)

38. Describe the difference between a thread and a process. Both threads and processes are methods of parallelizing an application.Processes are independent execution units that contain their own state information, use their

own address spaces, and only interact with each other via inter process communication mechanisms (generally managed by the OS). Processes, in other words, are an architectural construct.

By contrast, a thread is a coding construct that doesn't affect the architecture of an application. A single process might contains multiple threads; all threads within a process share the same state and same memory space, and can communicate with each other directly, because they share the same variables.

Process ThreadHave their own address range Don’t have their own address space.Do not share resources Share global data and resourcesSupports memory protection Does not supports memory protectionCommunication is handled only via OS Communicate via global variables

39. Explain the difference between a multi-processing and a multi-threading operation system.

Multiprocessing: Several jobs can run at the same time. It refers to an application organized across multiple OS-level processes (usually done by utilization of multiple CPUs in single computer system)

Multi-threading: Same job can be broken logically and executed simultaneously and the results are combined at the end of processing. It refers to an application with multiple threads running within a process.

Multi-threading is a more "light weight" form of concurrency: there is less context per thread than per process. As a result thread lifetime, context switching and synchronization costs are lower. The shared address space (noted above) means data sharing requires no extra work.

Multi-processing has the opposite benefits. Since processes are insulated from each other by the OS, an error in one process cannot bring down another process. Contrast this with multi-threading, in which an error in one thread can bring down all the threads in the process. Further, individual processes may run as different users and have different permissions.

40. Explain the difference between static and dynamic scheduling policies.

Static scheduler is just like a list of predefined tasks that has to be done. There can be no alteration in it.

Dynamic scheduler defines the task scheduling during runtime. when performing dynamic scheduling, whenever the scheduler decides which task to execute next (and for how long), it looks at a list of tasks requesting the processor at that point in time and then decides which to use next. Examples are the "earliest-deadline first" scheduler. Here, the schedule changes if some task has nothing to do and does not request resources.

Function Calling 41. Explain the mechanism of a C function call on assembly level. Based on this, explain why it is not possible to pass parameters to an interrupt service routine.

Whenever a function is called in C, the return address is stored in stack. All the registers that would be used in function are saved in stack. And program counter is set to the start address of the function. Upon returning, all the registers are reset from stack. The program counter is set to the return address which is read from stack.

Here, while calling a function, Caller saves and restores all registers required for parameter passing, including return value, while Callee (function) saves and restores all registers used inside the function.

à Interrupts never process data as it is too much time consuming. They just store the data. So

Page 8: Embedded Operating System...Embedded Operating System Operating System History 1. What is the definition of an operating system? An operating system (commonly abbreviated OS and O/S)

there is no need to pass arguments. Also, if interrupt service routine has parameter to pass, it has to be stored in stack before the function is itself called. This can consume some time, which is not intended.

42. Upon calling a function, which registers are typically saved by the caller, which registers are typically saved by the callee? Explain why!

Caller saves function parameter registers, while Callee saves registers used in the function.Caller is the main program that is calling some another function. Here, the function doesn’t

have access to all the registers in caller. So, the function parameter registers have to be called by caller. Caller saves everything before calling a callee(a subroutine) and resumes everything after the callee is executed. While in a function, it has access to every registers defined/declared within it. Again, the same callee can be called from different locations. So, it’s beneficial if the registers used in a function are saved from callee.43. What is the advantage of using registers instead of the stack to pass parameter data to a function? What is the advantage of the stack?

The stack contains all the addresses and data parameters that are being used by the function. The main advantage of using registers over stack is to reduce chances of executing wrong data. As if there is a mismatch between the sequence of data storing in stack and the sequence of data reading from stack, the whole program can crash.

The main advantage of using stack could be higher execution speed as there is no need of copying registers.

44. Explain the concept of the ARM function calling conventions. Why is such a definition especially important for a company like ARM, which is not selling chips but intellectual property?

The parameters passed in functions are copied to variable registers. Normally, R0, R1 are used to pass argument values into a subroutine and to return a result value from a function; while R2, R3 is only used to pass arguments. Then stack pointer is copied with all the values of registers.Here, the registers conventions are defined by the Compiler and Core. For companies like ARM, which is not selling chips but just intellectual property, it’s possible that core and complier are made from different vendors. So, to keep interoperability such kind of single ‘hard’ definitions are must. 45. Explain how an interrupt service routine is called. What happens on assembly level?

An interrupt Service Routine(ISR) is called by external events. ISR is called from a Interrupt handler. Whenever an interrupt occurs, the control moves to a particular address vector table. On Assembly Level:

• Program Counter is set to corresponding entry of IRQ Vector Table • Interrupt Handler Code (ISR = Interrupt Service Routine) is executed• Normal program flow is resumed (LR + 4 is stored to PC)

46. Describe and discuss the design principle of an interrupt service routine.

• ISR do not support parameter passing• ISR should not process the data (too time consuming) • ISR must be as short as possible• Typical implementation• Get the data• Store the data• Get out

47. Explain the concept of C function pointers. Where are they being used?

• The concept of the function pointer is to call a pointer to specific function instead of calling function directly. As function calls are static only (in C), to change the call chain the entire code has to be changed and recompiled. While using function pointers, to change the call chain, only

Page 9: Embedded Operating System...Embedded Operating System Operating System History 1. What is the definition of an operating system? An operating system (commonly abbreviated OS and O/S)

function pointers need to be changed.• The main use of C Function Pointers are to improve flexibility:• Reuse algorithms for variable functions• Providing callback functions for exception handling by parameter• Dynamically changing the call chain reacting on internal or external events• Configuring components by implementing container concepts• Function Pointers are used as a basic element to implement a scheduler.

My OS 48. Draw a class diagram of the developed non-preemptive Operating System.

49. Write the pseudo of an application task of the developed non-preemptive operating system (including scheduler calls).Pseudo of a Task of a developed non-preemptive OS (non-preemptive multitasking.):

Non preemptive multitasking means: the scheduler is not interrupting the task, but the task returns control to the scheduler voluntarily.int task1(int taskEntryPoint){

switch (taskEntryPoint){

case 1: // Application Code Section 1taskEntryPoint++; //next sectionbreak;…case n:// Application Code Section ntaskEntryPoint = -1; //Finished execution)break;

}return (taskEntryPoint);

} 50. Discuss the following scheduling algorithm: (priorityForNextTask = a * Taskpriority + b * TaskEntryPoint). What happens if a > b, what happens if b > a? (Note: low value of priority -> high priority) The behavior of the scheduler depends on the values of a and b:b < a àhere a is bigger, so task priority has more influence on Scheduler. so it will try to start execution

Page 10: Embedded Operating System...Embedded Operating System Operating System History 1. What is the definition of an operating system? An operating system (commonly abbreviated OS and O/S)

of all tasks as fast as possibleb > a à here b is bigger, so taskentrypoint has more influence on scheduler. So it will try to finish all high priority tasks first(Checking the code, it is not clear if the higher priority task is completed, or the execution of all task as soon as possible is done.)51. How can the presented MyOS be extended to support preemptive multitasking? Additional requirements should be added such as,

• Timer• Some assembly code to directly set and reset the program counter and to save the controller

registers• Own tasks stacks

Scheduling algorithms 52. What is a taskset?

A task is a function controlled by the scheduler. The total of all controlled tasks is called the taskset.

53. Explain the meaning of a planning algorithm of a scheduler and a dispatching algorithm.

Planning algorithm of a scheduler decides which task has to be fired after current running task. While, the proper switching between this two tasks is done by dispatching algorithm.

54. What does it mean, if a taskset is stable or feasible?

A scheduling algortihm, which under overload conditions ensures that at least a critical subset of tasks is executed is called stable.

A taskset, which can be executed under all given circumstances is called feasible.

55. Explain the design goal: Validation of Scheduleability (Optimal scheduling strategy) Validation of schedueability focuses on checking for a test which ensures the feasibility or at

least stability of a taskset.Optimal scheduling strategy checks whether we can implement an algorithm which finds

optimal scheduling strategy in finite time.

56. What are the advantages and disadvantages of static scheduling?With static scheduling strategies, a dispatching table containing the execution times for the

individual tasks is generated offline.Advantages:

• Minimal latency times• Extremely deterministic behavior of the system

Disadvantages:• Very inflexible• Supports only cyclic execution of tasks• No reaction on events possible (reactive)

57. What are the advantages and disadvantages of dynamic scheduling?With dynamic scheduling strategies, the priority of the tasks is calculated during runtime (online).Advantages:

• Very flexible• Supports reaction on events – a must for reactive systems

Disadvantages:

• Synchronization between tasks must be explicitly implemented

Page 11: Embedded Operating System...Embedded Operating System Operating System History 1. What is the definition of an operating system? An operating system (commonly abbreviated OS and O/S)

• Runtime overhead• Hard to debug (Race conditions)

58. Explain the scheduling strategy “First In, First Out”, “Fixed Priority”, “Round Robin”, “Least time remaining“, “Least Laxity Remaining”. What risk is related to this strategy?First In First Out:

The task waiting for the longest time is executed.Risk:No Priorities can be set. Hence, trouble in meeting realtime criterion. Throughput is low since processes hog the CPU.Approach: Non-preemptiveImplementation: SimpleRealtime suitability: Not suitable for hard realtime constraints

Fixed priorities:The task with the highest priority gets the CPU. Risk: Low priority tasks tend to starve.Approach: Non-preemptive or preemptiveImplementation: SimpleRealtime suitability: Often used for realtime operating systems

Round Robin:Classic approach from mainframe computing – every task receives for a certain time the CPU.

The order in which the tasks are called is static.Risk: due to high waiting time, deadlines are hardly met in such system. Round robin scheduling

involves extensive overhead, especially with small time unit.Approach: PreemptiveImplementation: SimpleRealtime suitability: Not suitable for hard realtime constraints

Least time remaining:The task with the least time remaining is executed. This strategy focuses on finishing as many

tasks as possible. Risk: Big tasks tend to starve.Approach: PreemptiveImplementation: ComplexRealtime suitability: Suitable for hard realtime constraints

Least Laxity Remaining:The task closest to its deadline is executed first.Risk: works only on the current state of the system.Approach: PreemptiveImplementation: Very complex.Realtime suitability: Most suitable for hard realtime constraints

Page 12: Embedded Operating System...Embedded Operating System Operating System History 1. What is the definition of an operating system? An operating system (commonly abbreviated OS and O/S)

Execution Time59. Why is it critical, if a task misses its deadline?

As we know, the timing constraints are of fundamental importance while designing a real time system. Hence, a missed deadline results in a cascade of timing problems, usually resulting in the system to crash.

60. Explain the term “Reentrance”.

-> A task can be called in more than one context at the same time. When a reentrant task is executing, another process can interrupt the execution and then begin to execute that same reentrant function.

61. What happens if a non- reentrant task is called in more than one context? (need to be checked)- A subroutine can fail to be reentrant if has access to a global variable which the subroutine

modifies in such a way that a property, which the subroutine expects to hold at the start of the subroutine, no longer holds when the recursive invocation is made.

This is important for subroutines updating a global data structure. The global data structure is always expected to be in a consistent state when entering or leaving a subroutine. A subroutine updating the global data structure may temporarily violate the consistent state intending to reestablish it before it completes. Any other subroutine invoked from this subroutine cannot rely on the global data structure being in a consistent state. In particular, if a recursive invocation is made the subroutine itself cannot rely on the global data structure being in a consistent state when it is entered.

62. How can you find out whether a task is reentrant or not? Which code pattern do you have to check?

• Must hold no static or global non-constant data .• Must not modify its own code

Page 13: Embedded Operating System...Embedded Operating System Operating System History 1. What is the definition of an operating system? An operating system (commonly abbreviated OS and O/S)

• Must not call non re-entrant computer programs or subroutines63. What is the tool Absint WCET used for?

It is a tool used for the computation of the maximum length of time the task could take to execute on a specific hardware platform. Absinlt is based on statistically analysing a tasks intrinsic cache and pipeline behaviour.

64. Explain the stability function with Cn = execution time of a task and Tn the interval, in which this task is called.

If we consider n tasks with Cn execution time of a task and Tn the intervals in which tasks are called,

The taskset is stabe as long as the stability function U(n) is less than or equal to 1;

65. Explain 3 methods to calculate or measure the worst case execution time Dynamic Measurement of WCET

Dynamic Measuerment is typically performed as a “stresstest”Testcases are not selected based on the functionality but are selected based on the longest

runtime Critical parameters , high peripheral loads.The quality of the measurement depends highly on the tester.

Advantages:• Good testcases generate good results• Always possible

Disadvantages:• Uncertainty as to whether the worst case has been measured or not.• High(manual) test efforts.

Static Measurement of WCETUse a tool to calculate the cycle of the longest program flow.Consideration of loops, decisions etc.Consideration of data value , parameters etc.Consideration of hardware aspects like pipelines, cache etc.

Advantages:• Tools can be integrated into a build process • Worst case time is calculated

Disadvantages:• High configuration efforts especially for system level analysis.• Latencies, blocking not considered.• Uncertainty • Pessimistic approach, increases hardware costs.

Absinlt aiT Absinlt aiT is used for analysis of WCET.Analysis with aiT is based on:

compiled and linked executablestart address of the task/isr root functionmemory areas with minimum and maximum access times

SymTA/S

Page 14: Embedded Operating System...Embedded Operating System Operating System History 1. What is the definition of an operating system? An operating system (commonly abbreviated OS and O/S)

SymTA/S stands for Symbolic Timing Analysis for Systems.SymTA/S focuses exclusively on system timing and performance. Detailed functionality is

abstracted, and only those properties that impact timing are modeled.They main advantages of this approach are: efficient modeling; unrivalled analysis speed;

applicability in early design phase (when functions have not even been implemented); flexibility and independence of specific hardware and software.

SymTA/S is not a single, monolithic tool but rather a flexible and extensible tool suite.

66. Discuss the following approach: A developer has measured the execution time of all critical tasks. To ensure that all relevant code parts are being checked, he has also measures the test coverage C0, which is 100%. Is this approach safe under all conditions? Explain!

Test coverage C0 just checks if every line of code is executed or not. It doesn’t check anything about the runtime (execution time) or data consistency. So, even though C0 functionality is 100%, there is no surety of satisfied operation of critical tasks.

67. Explain the following terms: worst-case-execution-time, best-case-execution-time, low level time analysis, system level time analysis. Worst case execution time : of a computational task is the maximum length of time a task takes to execute on a specific hardware platform.Best case execution time : is the minimum length of time a task runs on a dedicated hardware platform.Low level time analysis: considers the execution time of a single task without considering interruption or blocking.System level time analysis: considers interaction between tasks and interrupts. 68. How could you use a free running timer to measure the load of a system?

• Using idle time to measure load of a system:• By using hook tasks (functions).• A timer should be enabled whenever execution comes to background task and it should stop

whenever the execution of other task has started.69. Describe 3 aspects which have a significant impact on the runtime of a function.

• ISR• Tasks• containers • functions

70. Do interrupt service routines change the time behaviour of tasks? Explain this using the terms Start Time, Computation Time and End Time.

An interrupt service routine is a callback subroutine which is triggered by the reception of an interrupt. ISR can change the time behaviour of a task.

When an interrupt occurs the current task is suspended and the ISR is executed. After the ISR is executed the control is transferred back to the task previously running. Hence the End time of the task increases, which in turn increases the computation time.

71. Describe the concept of measuring the worst case execution time dynamically versus statically. What are the pros and cons of both approaches? Dynamic Measurement of WCET

Dynamic Measuerment is typically performed as a “stresstest”Testcases are not selected based on the functionality but are selected based on the longest runtime

Critical parameters, high peripheral loads.The quality of the measurement depends highly on the tester.Advantages:

Page 15: Embedded Operating System...Embedded Operating System Operating System History 1. What is the definition of an operating system? An operating system (commonly abbreviated OS and O/S)

• Good testcases generate good results• Always possible

Disadvantages:• Uncertainty as to whether the worst case has been measured or not.• High (manual) test efforts.

Static Measurement of WCETUse a tool to calculate the cycle of the longest program flow.Consideration of loops, decisions etc.Consideration of data value , parameters etc.Consideration of hardware aspects like pipelines, cache etc.

Advantages:• Tools can be integrated into a build process• Worst case time is calculated

Disadvantages• High configuration efforts especially for system level analysis.• Latencies, blocking not considered.• Uncertainty • Pessimistic approach, increases hardware costs.

72. Why is dynamic measurement of worst case execution time typically executed as stress test?

Dynamic Measuerment is typically performed as a “stresstest”:Testcases are not selected based on the functionality but are selected based on the longest

runtime.Critical parameters, high peripheral loads.

73. How can you use a oscilloscope to measure the execution time? The oscilloscope connected to a binary port.Software sets and resets the port .

74. in an OSEK environment, how could you use the hook functions and an oscilloscope for measuring the load of a system, considering, that the idle time of the system is represented by the average runtime of the endless loop of a background task? Same as que 68 for hook functions.An oscilloscope for measuring average runtime can be done by connecting it to one of the pins.75. Discuss the following statement: The design of a system complying with theoretically possible worst-case-execution-time (also called pessimistic estimation) is a safe but very often too expensive design approach.

Theoretically possible worst-case-execution-time is the most pessimistic time of all the available time. To satisfy system for this time, one must require fast processor and more amount of memory than it should have. This upgradation increases total system cost, but the system is totally safe against all possible runtime problems.

Synchronization and Messaging Concepts 76. Why are synchronization functions required in a multitasking operating system?

• In multitasking operating system, more than one task shares (uses) same resources. In case of shared resources, task can access certain resource as long as it is not being used by another task. This results in couple of requirements such as

• A task must know whether a resource is in use or not.• A mechanism must be provided which allows to send a task “on holiday” (Suspend)• And a mechanism is required to get the task back “to work” (resume)• Now, task can only be called by scheduler. So, they don’t share any information using function

Page 16: Embedded Operating System...Embedded Operating System Operating System History 1. What is the definition of an operating system? An operating system (commonly abbreviated OS and O/S)

parameters to know the status of other task implicitly. That’s why synchronization functions are required in a multitasking operating system. Such functions are Alarms, Remote Procedure Calls, Messages.

77. What is an event?

In general, an event is any external input to the program.An event is an action that is usually initiated outside the scope of a program and that is handled

by a piece of code inside the program. Typically events are handled synchronous with the program flow, that is, the program has one or more dedicated places where events are handled.

Typical sources of events include the user (who presses a key on the keyboard, in other words, through a keystroke). Another source is a hardware device such as a timer.

78. Explain the concept of an OSEK event.

In OSEK, events can be generated by tasks (basic and extended), by category 2 ISR or by incoming or outgoing messages (OSEK/COM). Extended tasks can wait for an event (as they have a waiting/pending status). Tasks can wait for one or more events to occur, and can use events as signal to change the state. Waiting task can check the occurrence of the event, but does not know who send it.

79. Explain the OSEK eventmask. OSEK eventmask is the unique id given to every event defined in OSEK. It is the value in power of 2. (such as 1,2,4,8,16,…)

80. What is an OSEK alarm?

• Alarms are similar to events, but are time triggered. Alarms can be used to either start an event or a task

• Typical applications include:• Perform a tasks every x ms (à cyclic tasks).• Send an event x ms after a task has been finished (à buffer time).• Send an event every x ms.• Send an event at the absolute time x.

81. Explain the concept of an OS message.

• Messages are used to exchange information between tasks containing data (which is cannot be done with events or alarms).

• Messages are typically implemented using a FIFO queue.• Transmission usually supports n:m broadcasting.• Data can either be transmitted “by value” or “by reference”.

Page 17: Embedded Operating System...Embedded Operating System Operating System History 1. What is the definition of an operating system? An operating system (commonly abbreviated OS and O/S)

There are a variety of different concepts to implement messaging:• Shared global data (also referred to as common data)• Pipes• Streams• Remote Procedure Calls

82. Explain the OSEK message concept.

In OSEK, Messages can be combined with en event, i.e. an event is generated to wake up the task receiving the data. Messages can be internal (i.e. between tasks running on the same controller) or external (i.e. between two controllers connected via a network).

External messages are transmitted via so called Interaction Protocol Data Units (I-PDU). This allows distribute/bundle the messages to the data container size of the network (e.g. CAN: 8 byte)

83. Explain the shared memory concept for passing data between tasks.Shared memory areas, i.e. several tasks addressing the same global variable are the most

efficient way to transmit data between 2 tasks, but unfortunately, it is also the most dangerous way to do it. As tasks can be interrupted between their executions, it would be possible that one task using a variable is interrupted with some other task using the same variable. If it is not constant, it’s possible that when the previous task is resumed, it has a different value of the same variable.

OSEK Introduction 84. Explain the OSEK history.

OSEK (Offene Systeme und deren Schnittstellen für die Elektronik in Kraftfahrzeugen; English: "Open Systems and their Interfaces for the Electronics in Motor Vehicles") is a standards body founded in 1993 by a German automotive company consortium (BMW, Robert Bosch GmbH, DaimlerChrysler, Opel, Siemens, and Volkswagen Group) and the University of Karlsruhe. In 1994, the French cars manufacturers Renault and PSA Peugeot Citroën joined the consortium.

85. What are the major components of OSEK? Provide their names and describe their tasks.Major components

• OSEK-OS (Operating System kernel)• OSEK-OIL (OSEK Implementation Language)• OSEK-ORTI (OSEK Runtime Library)• OSEK-COM (OSEK Communication)• OSEK-NM (OSEK Network Management)• OSEK-TIME (OSEK Realtime Extensions)

86. Explain the extension of OSEK towards AUTOSAR.

The AUTOSAR re-uses the OSEK specifications: the operating system is a backwards compatible

Page 18: Embedded Operating System...Embedded Operating System Operating System History 1. What is the definition of an operating system? An operating system (commonly abbreviated OS and O/S)

superset of OSEK OS which also covers the functionality of OSEKtime, and the communication module is derived from OSEK COM.

87. What is the OIL Configuration? What is it needed for?

The goal of OIL is to provide a mechanism to configure an OSEK application inside a particular CPU. This means for each CPU there is one OIL description. All OSEK system objects are described using OIL objects. The OIL description of the OSEK application is considered to be composed of a set of OIL objects. A CPU is a container for these OIL objects. OIL defines standard types for its objects. Each object is described by a set of attributes and references. OIL defines explicitly all standard attributes for each OIL object.

To reach the goal of OSEK of portable software, a way has been defined to describe the configuration of an application using OSEK. This specification only addresses a single central processing unit (CPU) in an electronic control unit (ECU), not an ECU network.

88. Explain the relation between an OSEK Counter and an OSEK Alarm.

The OSEK operating system provides a two-stage concept to provide services for processing recurring events. The recurring events (sources) are registered by implementation specific counters. The OSEK operating system does not provide a standardized API to manipulate counters directly. Based on counters, the OSEK operating system software offers alarm mechanisms to the application software.

89. Explain the relation between events and an extended task.Extended tasks are distinguished from basic tasks by being allowed to use the operating system

call WaitEvent, which may result in a waiting state. The waiting state allows the processor to be released and to be reassigned to a lower-priority task without the need to terminate the running extended task. So, extended tasks wait for the events to occur, until then they will be in ‘waiting’ state.

State Machine Basics 90. What is a state machine?

A finite state machine is an abstract machine that defines a finite set of conditions of existence (called “states”), a set of behaviors or actions performed in each of those states, and a set of events that cause changes in states according to a finite and well-defined rule set.

91. Where state machines are used?

• Objects with behavior, that is significant different depending on internal object condition (state, operation mode etc.)

• Major use case for state machines: reactive systems, e.g.• All devices with direct user interactions (MP3 player, mobile phone...)• All devices communicating to other devices via networks (Routers, Printers ...)

92. What is a reactive system?

A system having many ‘high speed’ external interfaces (e.g. CANBus, ports) with several processes running in parallel.

93. Explain the terms state, event, transition, action expression, guard condition.State: a kind of operation mode of an object (or a system). A state represents an internal condition of the software. Depending on the state, the software can react differently on same events.Event: Events are signals which are sent to the software. They can be considered as software interrupts. Events can be fired e.g. by external input e.g. from a user or an event may be time-related (cyclic, timeout, specific time).Events can be

Page 19: Embedded Operating System...Embedded Operating System Operating System History 1. What is the definition of an operating system? An operating system (commonly abbreviated OS and O/S)

considered à if the state machine is in a state which reacts on the eventignored à if the state machine is in a state which does not react on the event

Transition: Transitions connect two states and they are triggered by events. They may be subject to a guard condition (if the guard evaluates to false at runtime the transition is not taken)Action Expression: Action Expressions are typically implemented as small functions (increases maintainability), which are executed when the event is considered.Guard Condition: Guard Conditions are typically implemented as small functions (increases maintainability). If the guard condition is true, the event is considered, otherwise it is ignored 94. Explain the switch case pattern for state machine coding.In switch case pattern for state machine coding, all the tasks are considered as case of switch-case pattern. The main task (loop task) continuously checks for any occurrence of event. When it gets an event, it switches to particular state (after checking a guard condition if any). Here, all the action expressions are defined as function in each case. A general concept could be understood from code given below.

Critical Sections and Data Consistency 95. What is a critical section? Provide 2 examples for critical sections.

In concurrent programming a critical section is a piece of code that accesses a shared resource (data structure or device) that must not be concurrently accessed by more than one thread of execution. A critical section will usually terminate in fixed time, and a thread, task or process will only have to wait a fixed time to enter it (i.e. bounded waiting). Some synchronization mechanism is required at the entry and exit of the critical section to ensure exclusive use, for example a semaphore.For Example:

• Access of global Data• Copying data from register with time constraints.

96. Explain the term data consistency. Which conditions lead to a data consistency problem?

Data consistency summarizes the validity, accuracy, usability and integrity of related data between applications and across the IT enterprise. This ensures that each user observes a consistent view of the data, including visible changes made by the user's own transactions and transactions of other users or processes.

Data Consistency problems may arise at any time but are frequently introduced during or following recovery situations when backup copies of the data are used in place of the original data.

In embedded environment, data consistency can be defined as follows:For every operation on data it has to be ensured, that the data is transferred from a defined

initial state to a well defined end state.97. What is a destructive non-atomic operation?

• An atomic operation is one that can be performed in a single step, without the possibility of interruption. Generally, an operation that compiles down to a single machine instruction will be atomic, though there are exceptions. An operation (or set of operations) is atomic if it appears to the rest of the system to occur instantaneously.

• Non-atomic Operation: non atomic operation is one that can be interrupted. Normally most of

Page 20: Embedded Operating System...Embedded Operating System Operating System History 1. What is the definition of an operating system? An operating system (commonly abbreviated OS and O/S)

the memory related operations are non-atomic operations (containing more than one machine instructions). Now, if a non-atomic operation is being executed, and there is an interrupt, then there are chances that this operation will not be succeeded. If it relates to some memory read or write operation, it is quite obvious that process may get wrong data or corrupt the memory.

• In a real system, the operations can be more complex and the errors introduced extremely subtle. For example, reading a 64-bit value from memory may actually be implemented as two sequential reads of two 32-bit memory locations. If a process has only read the first 32 bits, and before it reads the second 32 bits the value in memory gets changed, it will have neither the original value nor the new value but a mixed-up garbage value.

• Furthermore, the specific order in which the processes run can change the results, making such an error difficult to detect, reproduce and debug.

98. Explain an inconsistent state change in the context of data consistency.Consider an example shown below.

The reading / writing operation is secured in a function. The program however does not expect a state change between sequence points. One task calls the function and function starts executing. Now before the function is done execution, another task (with higher priority) calls the same function. In this case, the function will stop execution for first task and will start execution for second task. This is considered as inconsistent state change.

99. Explain which combination of read/write operations lead to problems in a non-atomic access scenario.The basic trivial non-atomic implementation:

• reads the value in the memory location;• adds one to the value;• Writes the new value back into the memory location.

Now, imagine two processes are running incrementing a single, shared memory location:• the first process reads the value in memory location;• the first process adds one to the value;• but before first process can write the new value back to the memory location it is suspended,

and the second process is allowed to run:• the second process reads the value in memory location, the same value that the first process

read;• the second process adds one to the value;• the second process writes the new value into the memory location.• The second process is suspended and the first process allowed to run again:• the first process writes a now-wrong value into the memory location, unaware that the other

process has already updated the value in the memory location.

Page 21: Embedded Operating System...Embedded Operating System Operating System History 1. What is the definition of an operating system? An operating system (commonly abbreviated OS and O/S)

100. Explain, under which conditions accessing the following data is safe in a multitasking context: global data, file static data, function static data, function local data.

• Global Data:• File Static Data:• Function Static Data:• Function Local Data:

101. Explain which combination of read/write operations lead to problems in a state change scenario.

Here, as shown in example, the sequence (e.g. function) starts in state 1 and ends in state 2 àunexpected behavior

Additional problems:• State changes are represented by state variable• In addition we have message variables• The compiler does not make a difference

Locking Mechanisms, Deadlocks and Priority Inversion 102. Explain the guard mechanisms: busy waiting versus semaphores.

Busy waiting and semaphores are both guard mechanisms to deal with critical sections.Busy WaitingIdea:

Define a global variable showing weather a resource is occupied.The process requesting the resource loops until the variable shows that access is possible.After a certain time the point of rescheduling is reached and control is given back to the process

holding the resource.Advantage

• Very simple concept• Can be applied without OS support

Disadvantage• CPU time is consumed during waiting (busy waiting)• Synchronization is spread all over the program • Synchronization mechanisms are not directly visible• Atomic access to variable required

Page 22: Embedded Operating System...Embedded Operating System Operating System History 1. What is the definition of an operating system? An operating system (commonly abbreviated OS and O/S)

SemaphoreIdea:

Similar approach like Busy Waiting, but task hands the control back to the OS for rescheduling.A semaphore is a not negative number, on which 2 operations are defined:

P(s) : if s > 0 s– else block requesting process (passeeren)V(s) : s++ (vrijgeven)

Semaphores support the concept that a certain number of tasks may access the resource at the same time.Advantage

• Does not spoil valuable CPU time while waiting.Disadvantage

• Has to be supported by the OS.• Synchronization is spread over the program.

103. What are the design rules for a section secured by semaphores in an OSEK program?

• In OSEK, semaphores are called Resources.• Two operations are defined for entering and leaving critical sections:• StatusType GetResource ( ResourceType <ResID> ) • StatusType ReleaseResource ( ResourceType <ResID> ) • Design rules• Critical sections must be short• It is not allowed to use services which are points of rescheduling for non preemptable tasks

(TerminateTask, ChainTask, Schedule and WaitEvent) in critical sections.

104. What is a race condition? A race condition or race hazard is a flaw in a system or process whereby the output and/or

result of the process are unexpectedly and critically dependent on the sequence or timing of other events. The term originates with the idea of two signals racing each other to influence the output first.

Race conditions can occur in electronics systems, especially logic circuits, and in computer software, especially multithreaded or distributed programs.

A critical race occurs when the order in which internal variables are changed determines the eventual state that the state machine will end up in.

A non-critical race occurs when the order in which internal variables are changed does not alter the eventual state. In other words, a non-critical race occurs when moving to a desired state means that more than one internal state variable must be changed at once, but no matter in what order these internal state variables change, the resultant state will be the same anyway.

105. What is a deadlock? Describe a typical deadlock situation caused by semaphores. A deadlock is a situation where in two or more competing actions are waiting for the other to

finish, and thus neither ever does. Usually this is a problem related with semaphores / resources.Task A holds resource A and waits for resource B.Task B holds resource B and waits for A.Several tasks share the same resource under mutual exclusion and there is no rule defining

which task gets priority under all conditions.

106. Describe 2 approaches to prevent deadlocks.Watchdog:

Page 23: Embedded Operating System...Embedded Operating System Operating System History 1. What is the definition of an operating system? An operating system (commonly abbreviated OS and O/S)

• After a certain time of inactivity, the system reboots.• Used especially for systems without direct user involvement (e.g. automotive).

“All or none” algorithm:• In case a set of tasks needs exclusive access to several resources, the algorithm frees all claimed

resources in case of failure.“Forcing Message” algorithm:

• A task may send a specific message forcing a defined state change at the receiver independent from its history.

107. Describe the priority inversion problem caused by semaphores.Priority inversion means ‘inverting priorities’.Consider there is a task L, with low priority. This task requires resource R. Consider that L is

running and it acquires resource R. Now, there is another task H, with high priority. This task also requires resource R. Consider H starts after L has acquired resource R. Now H has to wait until L relinquishes resource R. Everything works as expected up to this point, but problems arise when a new task M starts with medium priority during this time.

At this stage, H is blocked on R, M is ready to run, L has acquired R. Since M is highest priority unblocked task currently, it will be scheduled first and it will eat up all the processing power until it finishes, not allowing any other task to run. This would block L from running. Since L cannot run, L cannot relinquish R. Since R is still in use (by L), H cannot run. So as you see above, M will run till it is finished, then L will run - at least up to a point where it can relinquish R - and then H will run. Thus, in above scenario, tasks with lower priority run before task with high priority, effectively giving us a priority inversion.

In priority inversion a high priority task waits because a low priority task has a semaphore. A typical solution is to have the task that owns a semaphore run at (inherit) the priority of the highest waiting task. But this simplistic approach fails when there are multiple levels of waiting: task A waits for a binary semaphore locked by task B, which waits for a binary semaphore locked by task C. Handling multiple levels of inheritance without introducing instability in cycles is complex and problematic.When 2 semaphores are involved, we very likely face a deadlock situation.

108. Describe the implementation and benefit of the OSEK priority ceiling protocol. Idea: When occupying a resource, the priority of the task is increased to the highest priority of all tasks which might request this resourceAdvantage: Occupation time of the resource is reduced.

Page 24: Embedded Operating System...Embedded Operating System Operating System History 1. What is the definition of an operating system? An operating system (commonly abbreviated OS and O/S)

109. Explain the concept of the OSEK priority ceiling protocol. What does it prevent?

• To avoid the problems of priority inversion and deadlocks the OSEK operating system requires following behavior:

• At the system generation, to each resource its own ceiling priority is statically assigned. The ceiling priority shall be set at least to the highest priority of all tasks that access a resource or any of the resources linked to this resource. The ceiling priority shall be lower than the lowest priority of all tasks that do not access the resource, and which have priorities higher than the highest priority of all tasks that access the resource.

• If a task requires a resource, and its current priority is lower than the ceiling priority of the resource, the priority of the task is raised to the ceiling priority of the resource.

• If the task releases the resource, the priority of this task is reset to the priority which was dynamically assigned before requiring that resource.

• Priority ceiling results in a possible time delay for tasks with priorities equal or below the resource priority. This delay is limited by the maximum time the resource is occupied by any lower priority task.

• Tasks which might occupy the same resource as the running task do not enter the running state, due to their lower or equal priority than the running task. If a resource occupied by a task is released, other task which might occupy the resource can enter the running state. For preemptable tasks this is a point of rescheduling.

Extended State Machines 110. What is a hierarchical state machine?

An HSM is a state machine where states can be grouped into a composite state. Actions defined for such a composite state then apply automatically to all states contained therein. This allows a considerable simplification of the state diagram. Composite states are those that contain other states. If a transition originates from a composite state, it is taken whenever a substate does not handle the corresponding event itself. A state can thus pass on the handling of a specific event to its enclosing state i.e. from higher level to lower level. This is called Hierarchical State machine.

111. Why the implementation of a hierarchical state machine is much more complicated compared to a flat state machine?

• A pattern being able to represent hierarchical state machines becomes very complex• History of states need to considered• State changes may take place on entry level

Page 25: Embedded Operating System...Embedded Operating System Operating System History 1. What is the definition of an operating system? An operating system (commonly abbreviated OS and O/S)

• A state change on a higher level usually has a consequence on the lower level.• The values of several state changes need to be synchronised

112. What is an active object? DefinitionIn UML a State Machine is always attached to an object (or to all objects of a class). An object, in conjunction with a State Machine attached to it, is commonly called an active object (e.g. the presented clock).

113. Explain the divide and conquer principle in the context of complex state machines.• Complex states are such states, that contain(possibly nested) state machines. When complex

states are present in a state machine, then eventually more than one state may be active at a time. This causes complex implementation, which is harder to understand and harder to maintain.

• Divide and conquer is a powerful principle in computer Science:• Break up a complex problem into smaller sub problems which can be treated separately. • Applied to design of state machines, it can be rephrased:• Break-up a complex state machine associated with an Active Object into a hierarchy of simpler

active objects.• Complex state machines should be replaced by several active objects with simpler state

machines. 114. Describe the concept of the Lookup Table Pattern for state machines.

• Data structure containing representing transitions and state actions• Table containing the Action, Guard and target state pointers• A loop checking the states and calling the corresponding functions

115. Discuss the pros and cons of the switch case and the lookup table pattern for state machines.

Switch case Lookup tableCode is easier to understand More complex for coding perspectivePattern uses less code Lookup table is faster in executionMore flexibility in dealing with events (e.g. Bit masks)

Pattern is better to maintain.

Page 26: Embedded Operating System...Embedded Operating System Operating System History 1. What is the definition of an operating system? An operating system (commonly abbreviated OS and O/S)

Debugging and Testing 116. Explain the terms verification and validation Verification

During the verification of the software it is checked if the software complies with its specification. Verification can be done on requirements, design and code level. Verification can be performed for individual components as well as for the complete system.

Validation

Validation is performed after completing the verification process. Here, it is checked if the software complies with the expectations of the customer, i.e. if the software is accepted. Validation requires an operational system.

117. Describe a strategy to develop testcases for a system • from requirements• from the architecture

o Use Cases diagramso State diagramso Activity diagrams

• Always consider expected and not expected behavior• Examples of unexpected behavior

o Wrong user inputo Wrong timingso Wrong transfer protocolso Failing hardware

118. Explain the importance of the three debugging steps “make the misbehavior

reproducible”, ”locate the buggy code section”, ”identify the root cause of the misbehavior”

Make the misbehavior reproducible: When a program crashes in a particular test case, we must identify the test case and try to reproduce the scenario.

Locate the buggy code section: After reproducing the misbehavior, locate in which section of the code error has occurred using breakpoint technique or by inserting stubs.

Identify the root cause: Finally, once the error portion is identified, analyze the portion and locate the bug.

119. Explain the concepts of code simplification and code tracing

Code Simplification:Codes are simplified in order to test them more efficiently. Following are few ways to do it.

• Provide stubs for complex input, output or control routines• Replace input routines by constant values• Replace asynchronous calls by synchronous calls (ActivateTask instead of Alarms)• Take out recursive functions• Replace dynamic objects by static objects

Code Tracing:

• Make the executed sections visible.• Basic

o Using printf or couto Use stepping through the code

• Extended

Page 27: Embedded Operating System...Embedded Operating System Operating System History 1. What is the definition of an operating system? An operating system (commonly abbreviated OS and O/S)

o Using trace toolso Using OS extensionso Using debugger profilingo Using test coverage tools

120. Explain the concept of section testing / slicing

Section Testing:• Check a section of code to determine whether the misbehavior is inside or outside the

examined sectionso Slicing concept

• Very often the code is too complex for simple testing.o Simplify the code to test the basic functionalityo Perform testso If ok, increase the complexity and repeat the tests

121. Explain the concept of OSEK hook functions

Hooking in programming is a technique employing so-called hooks to inject additional code into a system. At defined locations, the system hands over control to a hook function. After it has finished, the hook function is expected to call the original handler.

Hook functions are usually used for debugging purposes.OSEK provides the following hooks

o ErrorHook(StatusType inError)o PreTaskHook()o PostTaskHook()

o StartupHook()o ShutdownHook()

122. Explain 4 major rules for efficient debugging • Work systematically

o Get the problem reproducible, o then localize the place where it goes wrong, o then find the root cause

• Use debugging techniques likeo slicingo tracingo stubbingo hooks

• Know what the program does, do not guess• Bring in a second pair of eyes early• Even if the program behaves ok, it may be buggy!• And finally, after you changed the code, check for side effects

System on Chip

Page 28: Embedded Operating System...Embedded Operating System Operating System History 1. What is the definition of an operating system? An operating system (commonly abbreviated OS and O/S)

123. Describe the development trends in microcontroller design Development Trend

• Moving from discrete systems to integrated systemso reducing production costso decreasing power consumptiono decreasing EMC problemso decreasing required space (costs)o improving robustness and lifetime

• Increasing integrated featureso From 8 bit to 64 bito From KB flash to MB flasho From 10 MHz to several 100 MHzo Highly sophisticated drivers (Bluetooth, stepper engine,..)

• Increasing number of variantsMajor application areas

• Large batch productionso automotiveo mobile o handheldso consumer electronics (MP3 player, digital cameras,...)

124. What is an ASIC

DefinitionAn application-specific integrated circuit (ASIC) is an integrated circuit (IC) customized for a particular use, rather than intended for general-purpose use. For example, a chip designed solely to run a cell phone is an ASIC.

125. What is the difference between a system on chip and a system in package?

System on Chip System in Package

System-on-a-chip or system on chip (SoC or SOC) refers to integrating all components of a computer or other electronic system into a single integrated circuit (chip). It may contain digital, analog, mixed-signal, and often radio-frequency functions – all on one chip. A typical application is in the area of embedded systems.

An alternative is a system in package (SiP) comprising a number of chips in a single package. The development costs for SiP are lower, but in large volumes, SiP productions costs are higher compared to SoC.

126. What is an FPGA? Definition:A field-programmable gate array (FPGA) is a semiconductor device that can be configured by the customer or designer after manufacturing—hence the name "field-programmable” - using a hardware description language (HDL). FPGAs can be used to implement most logical functions (restrictions exists with analog ports) that an application-specific integrated circuit (ASIC) can perform.

127. Describe the concept of the ARM AMBA bus The important aspect of a SoC is not only which components or blocks it houses, but also how they

are interconnected. AMBA is a solution for the blocks to interface with each other.The objective of the AMBA specification is to:

Page 29: Embedded Operating System...Embedded Operating System Operating System History 1. What is the definition of an operating system? An operating system (commonly abbreviated OS and O/S)

• facilitate right-first-time development of embedded microcontroller products with one or more CPUs, GPUs or signal processors,

• be technology independent, to allow reuse of IP cores, peripheral and system macrocells across diverse IC processes,

• encourage modular system design to improve processor independence, and the development of reusable peripheral and system IP libraries

• minimize silicon infrastructure while supporting high performance and low power on-chip communication

Some of the types areAHB Advanced High Performance Bus

Memory, CPU,...ASB Advanced System Bus

High Performance Peripherals, Graphic Controller,...APB Advanced Peripheral Bus standard peripherals like Timer, UART, PIO,...

128. Describe the development process in case a new ASIC will be used for the project. What are

the major risks, how can they be countered?

Hardware Software Co-Development• Late start of software development• Increased risks due to buggy hardware• Many stakeholders and parallel developments

o Chip designo Tool developmento Software architectureo External driver librarieso OS Development

Since the software has to be developed after the completion of hardware, there will be shortage

of time. Therefore, it is a good solution to produce both software and hardware simultaneously. This involves a great amount of risk.

Risk Reduction

Phase 1 – Chip Concept• Start development at TIER1 based on simulations or comparable chips• Focus – implementation of new software concepts

Phase 2 – Chip Design finished• Use FPGA implementation• Focus on software migration, driver development and test of IPO’s

Phase 3 – First SiP or SoC available• First real tools available

Page 30: Embedded Operating System...Embedded Operating System Operating System History 1. What is the definition of an operating system? An operating system (commonly abbreviated OS and O/S)

• Focus on development of real prototypes for customer

129. Describe the embedded build process

130. Describe the history and trend of ASIC debugging solutions Debugging SolutionsEmulator

Device emulating the real chipProviding additional debugging interfaces compared to real chip

• Full Emulation System (1990)o Chip and Peripherals are fully probable o Physical Setup: discrete, FPGA basedo Applicable for simple systems (<10MHz, few peripherals)o Different behaviour between EVA and Flash

• Bond Out Chip (2000)o Data and adress lines of the BO chip have external accesso Emulator control data and adress lineso Applicable for slow systems <20MHzo EVA and Flash same behaviour

• Real Chip - Embedded Ice (2005)o Access to the chip via internal debug support unito Data access requires CPU timeo Applicable for fast systems >20MHzo EVA and Flash nearly same behavior

Hardware Driver 131. Describe 5 peripherals of the MB467B Microcontroller

Peripherals

Page 31: Embedded Operating System...Embedded Operating System Operating System History 1. What is the definition of an operating system? An operating system (commonly abbreviated OS and O/S)

• CAN bus• USART• RFM

• PWM• Binary Port• SPI

132. Describe the port structure of a microcontroller? How can the software access a port?

Typical LayoutPort Function Register (PFR)

Controls Function of Port (binary, analogue, serial, special)Data Direction Register (DDR)

Controls direction of data (in, out)Port Data Register

Data send to or received from the port 133. Describe the register structure of a typical binary port

The hardware header file “mb91467b.h” provides pointers to all registers.One binary port represents 8 binary “lines”.PORTEN = 0x3; // enable I/O PortsDDR22 = 0x00; // Set Port22 as input (SW2,SW3)PFR22 = 0x00; DDR26 = 0xff; // Set Port26 as output (7Segment Display SEG1)PFR26 = 0x00;PDR26 = 0x00; if(PDR22_D0 == 0) //SW2 pressed (Bit 0 == _D0)PDR26=0x12; //Set port26 to value 0x12HWWD_CL = 0; //Reset Hardware Watchdog

134. Explain the functionality of a USART port

Universal Asynchronous Receiver Transmitter• Different Standards are available, e.g. RS-232 or RS-485• On MCU’s often realised as USART, supporting an additional synchronous mode• Asynchronous• No synchronisation signal

o Start bit can come anytimeo Identification of data using fixed baudrate

• Configurationo Baudrate

Page 32: Embedded Operating System...Embedded Operating System Operating System History 1. What is the definition of an operating system? An operating system (commonly abbreviated OS and O/S)

o Data sizeo Parityo Stopbit

135. Explain the structure of the SPI bus

Serial Peripheral Interface (SPI)• Synchronous serial data link• Full duplex mode• Master/Slave• Transmissions often consist of 8-bit words

136. Describe the usage of an external IRQ signal. What has to be done to use this signal

(hardware and software)

In order to overcome the disadvantages of the following solutions, IRQ signal is used.• Sending

o Busy waiting until next character is being sent• Receiving

o FIFO has to be checked permanently for new characterso If not, data is lost

For example if we use RFM as interrupt, the following has to be done in the use IRQ signal.

• Connect the RFM pin to an external IRQ pin of the MCU

• Enable the external IRQ in the IRQ vector table (file vector.c)

• Provide the address of the interrupt service routine (file vector.c)

• Initialize the IRQ in Softune software

• Write the Interrupt Service routine (ISR)

137. Describe the structure of a typical ISR

Page 33: Embedded Operating System...Embedded Operating System Operating System History 1. What is the definition of an operating system? An operating system (commonly abbreviated OS and O/S)

We consider RFM as an interrupt. • Read status from RFM12 (to determine the cause of the IRQ)• Depending of the send / receive state

o Read Rx character from FIFOo Store Rx character in internal data structure

• oro Read next Tx character from internal data structureo Write Tx character to FIFO

• Process end-of protocol characters (change state)• Clear IRQ request