CONTENTS Components of embedded programs Models of program multi-tasking and task scheduling timing specifications run-time exception handling analysis and optimization of execution time, analysis and optimization of energy and power Analysis and optimization of program size program validation and testing COMPONENTS FOR EMBEDDED PROGRAMS There are three structures or components that are commonly used in embedded software: state machine: well suited to reactive systems such as user interfaces circular buffer: useful in digital signal processing queue: useful in digital signal processing State Machines • In some systems inputs appear intermittently rather than as periodic samples • Some systems are reacting to those inputs • The reaction of most systems based on the input received and the current state of the system. • Therefore the reactive system’s behavior can be described based on finite-state machine style. • The state machine style of programming is an efficient implementation of computations in embedded system. • Finite-state machines are usually first encountered in the context of hardware design. The behavior implementation of simple seat belt controller • The controller’s job is to turn on a buzzer if a person sits in a seat and does not fasten the seat belt within a fixed amount of time • This system has three inputs and one output • The inputs are a sensor for the seat to know when a person has sat down • seat belt sensor that tells when the belt is fastened, and a timer that goes off when the required time interval has elapsed. • The output is the buzzer. Appearing below is a state diagram that describes the seat belt controller’s behavior. The behavior implementation of simple seat belt controller • IDLE 0----- The idle state is in force when there is no person in the seat. • SEATED 1 ---When the person sits down, the machine goes into the seated state and turns on the timer. • BELTED 2---- If the seat belt goes on first, it enters the belted state. • BUZZER 3---If the timer goes off before the seat belt is fastened, the machine goes into the buzzer state. • When the person leaves the seat, the machine goes back to idle state. Stream-Oriented Programming and Circular Buffers • The circular buffer is a data structure that lets us handle streaming data in an efficient way. • At each point in time, the algorithm needs a subset of the data stream that forms a window into the stream. • The window slides with time as we throw out old values no longer needed and add new values. • Since the size of the window does not change, we can use a fixed-size buffer to hold the current data. • The buffer points to the location at which the next sample will be placed, which is the one that needs to be thrown out. • When the pointer gets to the end of the buffer, it wraps around to the top. Efficient implementation of a circular buffer. Queues • Queues are also used in signal processing and event processing • Queues are used whenever data may arrive and depart at somewhat unpredictable times • A queue is often referred to as an elastic buffer. • One way to build a queue is with a linked list • This approach allows the queue to grow to an arbitrary size. • But in many applications we are unwilling to pay the price of dynamically allocating memory. • Another way to design the queue is to use an array to hold all the data. • We used a circular buffer in Previous Example to manage interrupt-driven data; here we will develop a non-interrupt version. • As our initialization code shows, we initialize them to the same position. • As we add a value to the tail of the queue, we will increment tail. • Similarly, when we remove a value from the head, we will increment head. • When we reach the end of the array, we must wrap around these values example when we add a value into the last element of q, the new value of tail becomes the 0th entry of the array. MODELS OF PROGRAMS • Fundamental model for programs is the control/data flow graph(CDFG). • CDFG has constructs that model both data operations (arithmetic and other computations)and control operations(conditionals). • Part of the power of the CDFG comes from its combination of control and data constructs. Data Flow Graphs • A data flow graph is a model of a program with no conditionals. • In a high-level programming language, a code segment with no conditionals. • Precisely, with only one entry and exit point—is known as a basic block. • As the C code is executed, we would enter this basic block at the beginning and execute all the statements. • The data flow graph, we use two types of nodes in the graph— 1) Round nodes denote operators and 2) Square nodes represent values. • The value nodes may be either inputs to the basic block, such as a and b, or variables assigned to within the block, such as w and x1. • The data flow graph for the code makes the order in which the operations are performed in the C code An extended data flow graph for our sample basic block. Standard data flow graph for our sample basic block. Advantages Of The Data flow Graph • Reduce pipeline or cache conflicts. • We can also use it when the exact order of operations simply doesn’t matter • The data flow graph defines a partial ordering of the operations in the basic block. Control/Data Flow Graphs
• A CDFG uses a data flow graph as an element, adding constructs
to describe control. • In a basic CDFG, we have two types of nodes 1) Decision nodes and 2) Data flow nodes. • A data flow node encapsulates a complete data flow graph to represent a basic block. • We can use one type of decision node to describe all the types of control in a sequential program. • The jump/branch is, after all, the way we implement all those high-level control constructs. • The rectangular nodes in the graph represent the basic blocks. • The diamond-shaped nodes represent the conditionals. • The node’s condition is given by the label, • The edges are labeled with the possible outcomes of evaluating the condition. CDFG(Control/Data Flow Graphs ) C code CDFG for a while loop • The CDFG is not necessarily tied to high-level language control structures. • We can also build a CDFG for an assembly language program. • A jump instruction corresponds to a nonlocal edge in the CDFG. • Some architectures, such as ARM and many VLIW processors, support predicated execution of instructions, which may be represented by special constructs in the CDFG.