Module-2
Module-2
Design Concepts
Module-2
Contents
• Various hardware software trade-offs are used for making a decision on the
hardware-software partitioning.
COMPUTATIONAL MODELS IN
EMBEDDED DESIGN
• Data Flow Graph/Diagram (DFG) Model
• The Data Flow Graph ( DFG) model translates the data
processing requirements into a data flow graph.
• The Data Flow Graph (DFG) model is a data driven model in
which the program execution is determined by data.
• This model emphasises on the data and operations on the
data which transforms the input data to output data.
• Indeed Data Flow Graph (DFG) is a visual model in which
the operation on the data (process) is represented using a
block (circle) and data flow is represented using arrows.
• An inward arrow to the process (circle) represents input
data and an outward arrow from the process (circle)
represents output data in DFG notation.
The computational requirement is • Embedded applications which are computational intensive
x = a + b; and y = x – c and data driven are modelled using the DFG model.
Control Data Flow Graph/Diagram
(CDFG) • The Control DFG ( CDFG) model is used for
modelling applications involving conditional
program execution.
• CDFG models contains both data operations
and control operations.
• The CDFG uses Data Flow Graph (DFG) as
element and conditional (constructs) as
decision makers.
• CDFG contains both data flow nodes and
decision nodes, whereas DFG contains only
data flow nodes.
• If flag = 1, x = a + b; else y = a – b;
• This requirement contains a decision making
process.
State Machine
• The State Machine model is used for modelling reactive or event-driven
embedded systems whose processing behaviour are dependent on state
transitions
• Embedded systems used in the control and industrial applications are typical
examples for event driven systems.
• The State Machine model describes the system behaviour with ‘States’,
‘Events’, ‘Actions’ and ‘Transitions’.
• State is a representation of a current situation.
• An event is an input to the state. The event acts as stimuli for state transition.
• Transition is the movement from one state to another.
• Action is an activity to be performed by the state machine.
Finite State Machine
• A Finite State Machine ( FSM) model is one in which the number of
states are finite.
• As an example let us consider the design of an embedded system for
driver/passenger ‘Seat Belt Warning’ in an automotive using the FSM
model.
• The system requirements are captured as.
1. When the vehicle ignition is turned on and the seat belt is not fastened within
10 seconds of ignition ON, the system generates an alarm signal for 5 seconds.
2. The Alarm is turned off when the alarm time (5 seconds) expires or if the
driver/passenger fastens the belt or if the ignition switch is turned off, whichever
happens first.
Finite State Machine
• Assembly routines are mixed with ‘C’ in situations where the entire
program is written in ‘C’ and the cross compiler in use do not have a
built in support for implementing certain features like Interrupt Service
Routine functions (ISR) or if the programmer wants to take advantage
of the speed and optimised code offered by machine code generated
by hand written assembly rather than cross compiler generated
machine code.
• Mixing ‘C’ and Assembly is little complicated in the sense—the
programmer must be aware of how parameters are passed from the ‘C’
routine to Assembly and values are returned from assembly routine to
‘C’ and how ‘Assembly routine’ is invoked from the ‘C’ code.
Mixing High Level Language with
Assembly (e.g. ‘C’ with Assembly
Language)
Mixing the code written in a high level language like ‘C’ and Assembly
language is useful in the following scenarios:
1. The source code is already available in Assembly language and a routine written in
a high level language like ‘C’ needs to be included to the existing code.
2. The entire source code is planned in Assembly code for various reasons like
optimised code, optimal performance, efficient code memory utilisation and proven
expertise in handling the Assembly, etc.
But some portions of the code may be very difficult and tedious to code in Assembly.
For example 16bit multiplication and division in 8051 Assembly Language.
3. To include built in library functions written in ‘C’ language provided by the cross
compiler. For example Built in Graphics library functions and String operations
supported by ‘C’.
Inline Assembly
• Inline assembly is another technique for inserting target
processor/controller specific Assembly instructions at any location of a
source code written in high level language ‘C’.
• This avoids the delay in calling an assembly routine from a ‘C’ code (If
the Assembly instructions to be inserted are put in a subroutine as
mentioned in the section mixing assembly with ‘C’).
• Special keywords are used to indicate that the start and end of Assembly
instructions.
• The keywords are cross-compiler specifi c. C51 uses the keywords
#pragma asm and #pragma endasm to indicate a block of code written in
assembly.
PROGRAMMING IN EMBEDDED C
• Whenever the conventional ‘C’ Language and its extensions are used for programming
embedded systems, it is referred as ‘Embedded C’ programming.
• Programming in ‘Embedded C’ is quite different from conventional Desktop application
development using ‘C’ language for a particular OS platform.
• Desktop computers contain working memory in the range of Giga bytes and storage memory
in the range of Giga/Tera bytes.
• For a desktop application developer, the resources available are surplus in quantity and the
developer is not restricted in terms of the memory usage.
• This is not the case for embedded application developers.
• Almost all embedded systems are limited in both storage and working memory resources.
• Embedded application developers should be aware of this fact and should develop
applications in the best possible way which optimises the code memory and working memory
usage as well as performance.
C v/s. Embedded C
C Embedded C
• ‘C’ is a well structured, well defined and • Embedded ‘C’ can be considered as a subset of
standardised general purpose programming conventional ‘C’ language.
language with extensive bit manipulation support. • Embedded ‘C’ supports all ‘C’ instructions and
• ‘C’ offers a combination of the features of high incorporates a few target processor specific
level language and assembly and helps in functions/instructions.
hardware access programming. • The standard ANSI ‘C’ library implementation is
• The conventional ‘C’ language follows ANSI always tailored to the target processor/controller
standard and it incorporates various library fi les library files in Embedded ‘C’.
for different operating systems. • The implementation of target processor/controller
• A platform (operating system) specific application, specific functions/instructions depends upon the
known as, compiler is used for the conversion of processor/controller as well as the supported
programs written in ‘C’ to the target processor (on cross-compiler for the particular Embedded ‘C’
which the OS is running) specific binary fi les. language.
Compiler vs. Cross-Compiler
Compiler Cross-Compiler
• Compiler is a software tool that converts a source • Cross-compilers are the software tools used
code written in a high level language on top of a in cross-platform development applications.
particular operating system running on a specific
target processor architecture (e.g. Intel • In cross-platform development, the
x86/Pentium). compiler running on a particular target
• Here the operating system, the compiler program processor/OS converts the source code to
and the application making use of the source code machine code for a target processor whose
run on the same target processor.
architecture and instruction set is different
• The source code is converted to the target processor
specific machine instructions.
from the processor on which the compiler
is running or for an operating system which
• The development is platform specific.
is different from the current development
• Compilers aregenerally termed as ‘Native Compilers’.
environment OS.
A native compiler generates machine code for the
same machine (processor) on which it is running. • Keil C51 is an example for cross-compiler.