Realtime Embedded System Design B. Ramamurthy 4/7/2019
Example real-time and embedded systems Domain Application Avionics Navigation; displays Multimedia Games; simulators Medicine Robot surgery; remote surgery; medical imaging Industrial systems Robot assembly lines; automated inspection Civilian Elevator control Automotive system; Global positioning system (GPS) 4/7/2019
Lets discuss some realtime system (RTS) characteristics Realtime response 4/7/2019
Realtime Characteristics RTS have to respond to events in a certain pre-detemined amount of time. The time constraints have to be considered during planning, design, implementation and testing phases. Internal failures due to software and hardware fault have be handled satisfactorily. You cannot simply pop-up a dialog error box that says “send report” or “don’t send report”. Also external failures due to outside sources need to be handled. 4/7/2019
Realtime Characteristics (contd.) Typical interaction in an RTS is asynchronous. Thus an RTS should have features to handle asynchronous events such as interrupt handlers and dispatcher and associated resources. Potential for race condition: when state of resources are timing dependent race condition may occur. Periodic tasks are common. 4/7/2019
Embedded System Is a special purpose system designed to perform a few dedicated functions. Small foot prints (in memory) Highly optimized code Cell phones, mp3 players are examples. The components in an mp3 player are highly optimized for storage operations. (For example, no need to have a floating point operation on an mp3 player!) 4/7/2019
Real-time system concepts A system is a mapping of a set of input into a set of outputs. A digital camera is an example of a realtime system: set of input including sensors and imaging devices producing control signals and display information. Realtime system can be viewed as a sequence of job to be scheduled. Time between presentation of a set of inputs to a system and the realization of the required behavior, including availability of all associated outputs, is called the response time of the system. 4/7/2019
Real-time system concepts (contd.) Real-time system is the one in which logical correctness is based on both the correctness of the output as well as their timeliness. A soft real-time system is one in which performance is degraded by failure to meet response-time constraints. A hard real-time system is one in which failure to meet a single deadline may lead to complete and catastrophic failure. More examples: Automatic teller: soft Robot vacuum cleaner: firm Missile delivery system: hard Given a system you should be able to classify it. 4/7/2019
Embedded Systems 4/7/2019
Requirements-Engineering Process Deals with determining the goals, functions, and constraints of systems, and with representation of these aspects in forms amenable to modeling and analysis. 4/7/2019
Types of requirements Standard scheme for realtime systems is defined by IEEE standard IEEE830. It defines the following kind of requirements: Functional Non-functional External interfaces Performance Logical database Design constraints (ex: standards compliance) Software system attributes Reliability, availability, security, maintainability, portability 4/7/2019
Simple kernels Polled loop: Say a kernel needs to process packets that are transferred into the DMA and a flag is set after transfer: for(;;) { if (packet_here) { process_data(); packet_here=0; } Excellent for handling high-speed data channels, a processor is dedicated to handling the data channel. Disadvantage: cannot handle bursts 4/7/2019
Simple kernels: cyclic executives Illusion of simultaneity by taking advantage of relatively short processes in a continuous loop: for(;;) { process_1(); process_2(); process_3(); … process_n(); } Different rate structures can be achieved by repeating tasks in the list: 4/7/2019
Cyclic Executives: Example: Interactive games Space invaders: for(;;) { check_for_keypressed(); move_aliens(); check_collision(); update_screen(); } check_keypressed() checks for three button pressings: move tank left or right and fire missiles. If the schedule is carefully constructed we could achieve a very efficient game program with a simple kernel as shown above. 4/7/2019
Interrupt driven systems Main program is a simple loop. Various tasks in the system are schedules via software or hardware interrupts; Dispatching performed by interrupt handling routines. Hardware and software interrupts. Hardware: asynchronous Software: typically synchronous Executing process is suspended, state and context saved and control is transferred to ISR (interrupt service routine) 4/7/2019
Interrupt driven systems: code example void main() { init(); while(TRUE); } void int1(void){ save (context); task1(); retore (context);} restore (context);} Foreground/background systems is a variation of this where main does some useful task in the background; 4/7/2019
Design methods: Finite state machines Finite state automaton (FSA), finite state machine (FSM) or state transition diagram (STD) is a formal method used in the specification and design of wide range of embedded and realtime systems. The system in this case would be represented by a finite number of states. Lets design the avionics for a drone aircraft. 4/7/2019
Finite State Machine (FSM) M = five tuple { S, i, T, Σ, δ } S = set of states i = initial state T = terminal state (s) Σ = events that bring about transitions δ = transitions Lets do this exercise for the avionics for fighter aircraft 4/7/2019
Drone aircraft avionics (simplified) else MA: Mission Assigned TD: Target Detected LO: Locked On EE: enemy Evaded ED: Enemy Destroyed MC: Mission Complete else TAK MA NAV TD else NAE MC TAK: Take off NAV: Navigate NAE: Navigate & Evade NAA: Navigate & Attack LAN: Land else LO NAA EE LAN ED 4/7/2019
State Transition table MA LO TD MC EE ED TAK NAV NAE LAN NAA 4/7/2019
Lets design a simple embedded/ realtime system Use the table to code a function with case/switch statement Or write a table-driven code Which is better and why? Lets implement this. I will show a demo later. 4/7/2019
Finite state automata and Co-routine based kernels void process_a(void){ for(;;) { switch (state_a) { case 1: phase_a1(); | case 2: phase_a2(); | …. case n: phase_an();}}} void process_b(void){ switch (state_b) { case 1: phase_b1(); | case 2: phase_b2(); | case n: phase_bn();}}} state_a and state_b are state counters; Communication between coroutines thru’ global variables; 4/7/2019
Summary We learned that realtime system requirements are quite different from that of regular systems. Discussed many approaches to designing realtime systems. Studied FSM based design of realtime systems Demo 4/7/2019