0% found this document useful (0 votes)
12 views106 pages

Ilovepdf Merged 1

The document outlines the syllabus and content for Module IV of the Embedded Systems course, focusing on programming tools and modeling programs. It covers the evolution of embedded programming tools, essential components like editors, compilers, and debuggers, as well as modeling techniques such as data flow graphs and finite state machines. The presentation is led by Dr. K. Ragavan from VIT University, detailing both theoretical and practical aspects of embedded software development.

Uploaded by

arshiaparmar03
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views106 pages

Ilovepdf Merged 1

The document outlines the syllabus and content for Module IV of the Embedded Systems course, focusing on programming tools and modeling programs. It covers the evolution of embedded programming tools, essential components like editors, compilers, and debuggers, as well as modeling techniques such as data flow graphs and finite state machines. The presentation is led by Dr. K. Ragavan from VIT University, detailing both theoretical and practical aspects of embedded software development.

Uploaded by

arshiaparmar03
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 106

School of Computer Science and Engineering

BCSE305L – Embedded Systems


Module ~ IV
Programming Tools

Presentation by
Dr.K.Ragavan
Assistant Professor Senior Grade I
Department of IOT
School of Computer Science and Engineering
VIT University, Vellore
Syllabus

Module:4 Programming Tools 7 hours

Evolution of embedded programming tools, Modelling


programs, Code optimization, Logic analyzers,
Programming environment.

2
Evolution of embedded
programming tools
Embedded Software

• Embedded Software is the software that


controls an embedded system. All embedded
systems need some software for their
functioning.

• Embedded software or program is loaded in


the microcontroller which then takes care of
all the operations that are running.
• developing this software, a number of
different tools are needed.

• These tools include


– editor,
– compiler,
– assembler,
– debugger,
– Linker, and
– simulators
1. Editor

• This is where you write the code for your embedded


system.

• The code is written in some programming language.


The most commonly used language is C or C++ and
Assembly languages.

• The code written in the editor is also referred to as


source code.
2. Compiler
• Compiler is used to convert a high level language
code into low level programming language..

• A compiler is used when you are done with the


editing part and made a source code.

• The function of compiler is to convert the source


code into object code.

• Object code is understandable by computers as it is a


low level programming language.
3.Assembler
• The function of an assembler is to convert a code
written in assembly language into machine
language.

• All the mnemonics and data is converted in to op


codes and bits by an assembler.

• computer understands binary and it works on 0 or 1,


so it is important to convert the code into machine
language.
4. Debugger
• Test whether the code you have written is free from
errors or not. So, a debugger is used for this testing.

• Debugger goes through the whole code and tests it


for errors and bugs.

• It tests your code for different types of errors for


example a run time error or a syntax error and
notifies you wherever it occurs.
5. Linker

• A linker is a computer program that combines one or


more object code files and library files together in to
executable program.
• Write larger programs in to small parts and modules
to make job easy and to use libraries in your
program.
• combined into a single file for execution, so this
function requires a linker.
6. Libraries

• A library is a pre written program that is ready to use


and provides specific functionality
• Arduino microcontroller comes with a number of
different libraries that you can download and use
while developing your software.
• controlling LED or reading sensor like an encoder can
be done with a library.
7. Simulator

• A simulator helps you to see how your code will


work in real time.
• You can see how sensors are interacting, you can
change the input values from sensors, and you can
see how the components are working and how
changing certain values can change parameters.
Evolution of embedded
programming tools
• Programming Tools:
• The microcontrollers can be programmed using
various Programming/Development tools like
Embedded Software
• from Mentor Graphics, IAR Systems, Keil
MicroVision from ARM Ltd., and Code Composer
Studio (CCS) from Texas Instruments.
Introduction to Code Composer
Studio:
• CCS is a TexIns proprietary cross platform IDE used to
convert C and assembly language code to
executable for TexIns processors,
• involving Digital Signal Processors, ARM, and other
microcontrollers.
• CCS combines editing, debugging and analysis tools
into a single IDE based on Eclipse open source
development tool.
Compilation (Build Process):CCS
• CCS uses a Code Generation Tool (often called CGT)
for compilation process also called as build process.

• It is used to generate executables for a target device.


This process takes source codes written in C, C++
and/or Assembly Language and produces executable
at the output called binaries
• After the assembly language files are
generated by the compiler, an assembler
converts them to relocatable object files.
• These object files are linked to the runtime
libraries included in the project by a linker.
• The linker produces executables from these
files using protocols mentioned in the
command file
Components for embedded
programs
 We consider code for three structures or components
that are commonly used in embedded software:
 The state machine
 The circular buffer
 The queue
 State machines are well suited to reactive systems
such as user interfaces.
 Circular buffers and Queues are useful in digital
signal processing.

19
State machine
 When inputs appear intermittently rather than as periodic
samples, it is often convenient to think of the system as
reacting to those inputs.

 The reaction of most systems can be characterized in


terms of the input received and the current state of the
system.

 This leads naturally to a finite-state machine style of


describing the reactive system’s behaviour.

20
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 & The output is the
buzzer.
21
Circular buffer
 The data stream style makes sense for data that comes in
regularly and must be processed on the fly.

 In an embedded system we must not only emit outputs in


real time, but we must also do so using a minimum
amount of memory.

 The circular buffer is a data structure that lets us handle


streaming data in an efficient way.

22
 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 every time we add a sample we automatically
overwrite the oldest sample, which is the one that needs to
be thrown out.

23
24
Queue
 Queues are also used in signal processing and event
processing.
 Queues are used whenever data may arrive and depart at
somewhat unpredictable times or when variable amounts
of data may arrive.
 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.
 Another way to design the queue is to use an array to
hold all the data.

25
26
School of Computer Science and Engineering

BCSE305L – Embedded Systems


Module ~ IV Programming Tools
MODELLING PROGRAMS

Presentation by
Dr.K.Ragavan
Assistant Professor Senior Grade I
Department of IOT
School of Computer Science and Engineering
VIT University, Vellore
Syllabus

Module:4 Programming Tools 7 hours

Evolution of embedded programming tools, Modelling


programs, Code optimization, Logic analyzers,
Programming environment.

2
MODELS OF PROGRAMS

3
Modelling programs
• Creating a model for the embedded system provides
a time-saving and cost-effective approach to the
development of dynamic control systems, based on
a single model maintained in a tightly integrated
software suite.
• It refers to a visual method for designing complex
control systems

Dr.K.Ragavan, SCOPE, VIT Vellore 4


Modelling programs
• Modelling processes are used for software analysis and
design before software implementation.
• A software analysis and design helps
– A description of the system requirement
– A description of how system works
– Shows system validation
• Graphical modelling languages use a diagram technique
with named symbols that represent concepts and lines that
connect the symbols and represent relationships and
various other graphical notation to represent constraints.
Dr.K.Ragavan, SCOPE, VIT Vellore 5
Dr.K.Ragavan, SCOPE, VIT Vellore 6
Dr.K.Ragavan, SCOPE, VIT Vellore 7
Dr.K.Ragavan, SCOPE, VIT Vellore 8
MODELS OF PROGRAMS
 In this section we develop models for programs that are
more general than source code.
 There are many different types of source code - assembly
languages, C code, and so on.
 But we can use a single model to describe all of them.
 Once we have such a model we can perform many useful
analyses on the model more easily than we could on the
source code.

9
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 more precisely with only one
entry and exit point is known as a basic block.

10
 Before we are able to draw the data flow graph for this
code we need to modify it slightly.
 There are two assignments to the variable x it
appears twice on the left side of an assignment.
 We need to rewrite the code in single-assignment
form, in which a variable appears only once on the left
side.

11
12
ADVANTAGES of DFG
• Data flow graph models help in a simple code
design.

• which the program mostly breaks into Number of


DFGs.

• A DFG models a fundamental program element


having an independent path.

Dr.K.Ragavan, SCOPE, VIT Vellore 13


DISADVANTAGE OF DFG
• A DFG gives that unit of a system, which has no
control conditions and thus a single path for the
program flow.

• Delay is Very high for complex applications

• Execution time is also high

Dr.K.Ragavan, SCOPE, VIT Vellore 14


Control/Data Flow Graphs
 Our fundamental model for programs is the control/data flow graph
(CDFG).
 As the name implies, the CDFG has constructs that model both data
operations (arithmetic and other computations) and control
operations (conditionals).
 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:
 Decision nodes
 Data flow nodes.
 A data flow node encapsulates a complete data flow graph to represent
a basic block.
 A decision node to describe all the types of control in a sequential
program.
15
Data flow nodes

16
Decision nodes

17
Dr.K.Ragavan, SCOPE, VIT Vellore 18
Dr.K.Ragavan, SCOPE, VIT Vellore 19
ADVANTAGES - (CDFG) Modelling
• a variable value changing above a limit or below a
limit or falling within a range is also like an event
that activates a certain process.

• Guides us how software to be tested for each path


starting from a decision node

• Helps in analysing the program in terms of


complexity

Dr.K.Ragavan, SCOPE, VIT Vellore 20


Dr.K.Ragavan, SCOPE, VIT Vellore 21
FSM Model

Dr.K.Ragavan, SCOPE, VIT Vellore 22


Dr.K.Ragavan, SCOPE, VIT Vellore 23
A STATE MACHINE AS:
• A set of input events
• A set of output events
• A set of states
• A function that maps states and input to output
• A function that maps states and inputs to states (which
is called a state transition function)

Dr.K.Ragavan, SCOPE, VIT Vellore 24


Dr.K.Ragavan, SCOPE, VIT Vellore 25
Finite States Machine(FSM) Model
• A finite state machine is one that has a limited or
finite number of possible states.

• A finite state machine can be used both as a


development tool for approaching and solving
problems and as a formal way of describing the
solution for later developers and system maintainers.

• There are a number of ways to show state machines,


from simple tables through graphically animated
illustrations.

Dr.K.Ragavan, SCOPE, VIT Vellore 26


Example
• The formal description of this state machine is the
following: States:
• A: if input == 1 then { output 0, state = B} else { output
0, state = A}
• B: if input == 1 then { output 0, state = C} else { output
0, state = A}
• C: if input == 1 then { output 0, state = C} else { output
1, state = A}
• The initial state is A.
• The final state is C
Dr.K.Ragavan, SCOPE, VIT Vellore 27
A: if input == 1 then { output 0, state = B} else { output 0, state = A}
B: if input == 1 then { output 0, state = C} else { output 0, state = A}
C: if input == 1 then { output 0, state = C} else { output 1, state = A}
The initial state is A.
The final state is C

Dr.K.Ragavan, SCOPE, VIT Vellore 28


Dr.K.Ragavan, SCOPE, VIT Vellore 29
Dr.K.Ragavan, SCOPE, VIT Vellore 30
Dr.K.Ragavan, SCOPE, VIT Vellore 31
Dr.K.Ragavan, SCOPE, VIT Vellore 32
Dr.K.Ragavan, SCOPE, VIT Vellore 33
Dr.K.Ragavan, SCOPE, VIT Vellore 34
Dr.K.Ragavan, SCOPE, VIT Vellore 35
Dr.K.Ragavan, SCOPE, VIT Vellore 36
Dr.K.Ragavan, SCOPE, VIT Vellore 37
Dr.K.Ragavan, SCOPE, VIT Vellore 38
Dr.K.Ragavan, SCOPE, VIT Vellore 39
SEQUENTIAL PROGRAM MODEL
• Use of multiple function calls sequentially

Dr.K.Ragavan, SCOPE, VIT Vellore 40


Example Sequential Program
Model=VM
• Run function get_user_input ( ) for obtaining input for
choice of chocolate from child.
• Run function read_coins ( ) for reading the coins
inserted into VendingMachine(VM) for cost of
chocolate.
• Run function deliver_chocolate() for delivering the
chocolate.
• Run function display_thanks() for displaying ‘Collect
the nice chocolate. Visit again!’

Dr.K.Ragavan, SCOPE, VIT Vellore 41


Sequential Program Model=VM

Dr.K.Ragavan, SCOPE, VIT Vellore 42


Sequential Program Model
• In the Sequential Program Model, the
functions or processing requirements are
executed in sequence.
• It is same as the conventional procedural
programming.
• Here the program instructions are iterated
and executed conditionally and the data gets
transformed through a series of operations.
• Finite State Machines (FSMs) and Flow Charts
are used for modelling sequential program.

• The FSM approach represents the states,


events, transitions and actions, whereas the
Flow Chart models the execution flow.
Sequential Program Model
(continued)
• 'Seat Belt Warning' system is illustrated below:
Concurrent/Communicating Process
Model
• The concurrent or communicating process
model models concurrently executing
tasks/processes.

• It is easier to implement certain requirements


in concurrent processing model than the
conventional sequential execution.
Difference b/w sequential vs
concurrent
• Sequential execution leads to a single sequential
execution of task and thereby leads to poor
processor utilisation, when the task involves I/O
waiting, sleeping for specified duration etc.

• Concurrent: If the task is split into multiple


subtasks, it is possible to tackle the CPU usage
effectively by switching the task execution, when
the subtask under execution goes to a wait or
sleep mode.
Draw back - concurrent
• However, concurrent processing model
requires additional overheads in

• task scheduling,
• task synchronisation
• communication.
example, consider the implementation
of the 'Seat Belt Warning' system
• We can split the tasks into:
• 1. Timer task for waiting 10 seconds (wait timer task)
• 2. Task for checking the ignition key status (ignition key
status monitoring task)
• 3. Task for checking the seat belt status (seat belt
status monitoring task)
• 4. Task for starting and stopping the alarm (alarm
control task)
• 5. Alarm timer task for waiting 5 seconds (alarm timer
task)
Concurrent/Communicating Process
Model (continued)
• The tasks cannot be executed randomly or
sequentially.
• We need to synchronise their execution
through some mechanism.
• For example, the alarm control task is
executed only when the wait timer is expired
and if the ignition key is in the ON state and
seat belt is in the OFF state.
• We will use events to indicate these scenarios.

• The wait_timer_expire event is associated


with the timer task event and it will be in the
reset state initially and it is set when the
timer expires
• Similarly, events ignition_on and ignition_off
are associated with the task ignition key status
monitoring

• the events seat_belt_on and seat_belt_off


are associated with the task seat belt status
monitoring
Class diagram concurrent process
model – seat belt warning system
Object-Oriented Model
• The object-oriented model is an object based
model for modelling system requirements.

• • It disseminates a complex software


requirement into simple well defined pieces
called objects.
• Object-oriented model brings re-usability,
maintainability and productivity in system
design.
• In the object-oriented modelling, object is an
entity used for representing or modelling a
particular piece of the system.
• Each object is characterised by a set of unique
behaviour and state
• A class is an abstract description of a set of
objects and it can be considered as a
'blueprint' of an object.

• • A class represents the state of an object


through member variables and object
behaviour through member functions.
• The member variables and member functions
of a class can be private, public or protected

• • Private member variables and functions are


accessible only within the class, whereas
public variables and functions are accessible
within the class as well as outside the class.
• The protected variables and functions are
protected from external access
• However classes derived from a parent class
can also access the protected member
functions and variables.

• The concept of object and class brings


abstraction, hiding and protection
School of Computer Science and Engineering

BCSE305L – Embedded Systems


Module ~ IV Programming Tools
Code Optimization
Presentation by
Dr.K.Ragavan
Assistant Professor Senior Grade I
Department of IOT
School of Computer Science and Engineering
VITDr.K.Ragavan,
University, Vellore
SCOPE, VIT Vellore 1
Code Optimization
• The idea is that code executed on an embedded
system has to be optimised both to utilise available
limited resources in way that meets all system
requirements.
• In practical terms, embedded code is written to make
optimum use of processor or compiler features, as
well as managing the memory or power requirement.

Dr.K.Ragavan, SCOPE, VIT Vellore 2


Dr.K.Ragavan, SCOPE, VIT Vellore 3
Dr.K.Ragavan, SCOPE, VIT Vellore 4
To produce an efficient code
Two issues in code optimization is
• Semantic equivalence of the source program must not be
changed
• It must be achieved without changing the algorithm of the
program

• Program becomes inefficient because of programmer or due


to compiler transformation
• Now where code optimization should be applied – before
code generation or after code generation

Compiler phases
– Front end (3 phases)
– back end Dr.K.Ragavan, SCOPE, VIT Vellore 5
Dr.K.Ragavan, SCOPE, VIT Vellore 6
Compile Time Evaluation
• we optimize the code at the compile time – two techniques
– constant folding
– constant propogation
• Constant Folding – technique of evaluating an expression whose
operands are known to be constants at compile time itself
Example: Length = (22/7)*d
• Above 22/7 is a constant expression
• So first solve the constant expression before and keep the
constant value – so called folding the constant and place the value
at compile time since evaluated at compile time and keep the
value of reuse
Dr.K.Ragavan, SCOPE, VIT Vellore 7
Dr.K.Ragavan, SCOPE, VIT Vellore 8
Example – finding area of circle

So values of variables are directly substituted at the place of


refrence or useage and executed at compile time itself

Dr.K.Ragavan, SCOPE, VIT Vellore 9


• Above is the 3 address code
• So 4*I is not executed second time for T4 and value of T1 is taken for
T4
• So no redundant expression in the
Dr.K.Ragavan, SCOPE, optimized
VIT Vellore code 10
Dr.K.Ragavan, SCOPE, VIT Vellore 11
Dr.K.Ragavan, SCOPE, VIT Vellore 12
Replace an expression having more pritority with less
priority expression

Dr.K.Ragavan, SCOPE, VIT Vellore 13


 Strength reduction used to eliminate the
multiplication from the induction variable
computation.
 Strength reduction is a compiler optimization
where expensive operations are replaced
with equivalent but less expensive
operations.
 The classic example of strength reduction
converts "strong" multiplications inside a
loop into "weaker" additions
Dr.K.Ragavan, SCOPE, VIT Vellore 14
Strength Reduction
c = 7;
for (i = 0; i < N; i++)
{
y[i] = c * i;
}

c = 7;
k = 0;
for (i = 0; i < N; i++)
{
y[i] = k;
k = k + c;
} Dr.K.Ragavan, SCOPE, VIT Vellore 15
Loop Optimization
 Loops are important targets for optimization
because programs with loops tend to spend a
lot of time executing those loops.
 There are three important techniques in
optimizing loops:
 Code motion
 Induction variable elimination
 Strength reduction.
Dr.K.Ragavan, SCOPE, VIT Vellore 16
 Code motion lets us move unnecessary code out of
a loop.
 Consider the following loop:
for (i = 0; i < N*M; i++)
{
z[i] = a[i] + b[i];
}

We optimize the
code in inner loop
Dr.K.Ragavan, SCOPE, VIT Vellore
17
 An induction variable is a variable whose
value is derived from the loop iteration
variable’s value.

Dr.K.Ragavan, SCOPE, VIT Vellore 18


Loop invariant method
• Computation inside the loop is avoided and thereby
computation overhead on compiler is avoided

Dr.K.Ragavan, SCOPE, VIT Vellore 19


Loop unrolling
• Number of jumps and tests can be reduced by writing the code
two times

So we reduce the no of steps to some extent by repeating the


operation in the body Dr.K.Ragavan, SCOPE, VIT Vellore 20
Loop fusion or loop jamming
• Several loops are merged to one loop

Dr.K.Ragavan, SCOPE, VIT Vellore 21

You might also like