You are on page 1of 22

Embedded Systems

Development Tools and


Embedded C-Programming

1
Performance of the Host Machine

• An application program is developed that runs on the host machine


• It is the development platform
• A general purpose computer
• It has a more capable processor and more memory
• It has different I/O
• It has a capble Operating System (O/S)
• It contains many development tools to create output of binary image
• Once a program is written compile, linked it is moved to the Target platform
TARGET

• Output from the host machine to the target platform


• It consists of target hardware such as processor and runtime environment
• It is only needed for final output
• It does not contain any development tools
Software Development Process

C/C++ C/C++ Assembly

Compiler Compiler Assembler

Object
Object Object

Linker

Relocatble

Locator

Executable
Types of Embedded Tools
Embedded software tools
• Editor
• Assembler
• Compiler
• Linker
• Simulator
• Profiler
Embedded Hardware Tools’
• In-Circuit-Emulator
• Debugger
• Starter Kit
• Each can take one or more files as input and product a
single output file. This transformation process is
performed software running on a general purpose
computer
• Compiler, assembler, linker and locator run on a host
computer
• Embedded system of target platform runs only on its own
• These tools combined produce an executable binary image
• This output binary image runs on target embedded system

General Computer
• Create source file
• Type C code All these constitute the general procedure
• Build, Compile and Link
• Execute, Load and Runs

Embedded System
•Create Source file
•Type C code
•Compile/Asssemble (Translate into machine code on host)
•Link: Combine all object files and libraries resolve all symbols
•Locate: Assign memory address to code and data
•Execute: The excutable image is copied into the target processor
and Reset it
Embedded tools
Assembler -Programming language processor that translates an
assembly language program (the source program) to the machine
language program (the object program) executable by a computer.
Cross Compiler- This is a compiler that is capable of creating an
executable code for another platform or multiple platforms other
than the one on which it is running.
Emulator -This is a top end debugging tool that allows complex
real time evaluations to be carried out.
An Emulator cost more than other development tools because of
their high performance.
Simulator -A simulator is a program that runs on a PC and predicts
the outcome of the program. It allows the logic of the program to be
checked but cannot simulate hardware interface and timing factors.
Compiler
Linker
Etc.
Tools Processing

Source Code
Object Code

Preprocessor Linker

Libraries
Preprocessor Code Object Code

Compiler

Assembly Code Debugger

Assembler
Compiling

• A software program that converts source code


• High level language into low-level language
• Compiler translates program written in human-readable
language into machine readable language
cross compiler
This is a compiler that is capable of creating an executable
code for another platform or multiple platforms other than
the one on which it is running.
Used for cross-platform software development of binary
code
Most embedded systems have extremely limited resources
therefore will not be powerful enough to run a compiler
Cross-compilation can be less involved and less prone to
errors than native compilation
A cross compiler can generate an executable code for each
of the operating systems in para-virtualization
Etc.
WHAT IS EMBEDDED
C?
Whenever the conventional „C‟
language and its extensions are
used for programming embedded
systems, it is referred to as
“Embedded C” programming.
C for Embedded Systems vs. Embedded C
 C for Embedded Systems
• It is using the standard C language (mainly as described in ISO/IEC 9899
standard) but with a lot of customization and optimization to meet the
Embedded System requirements.
• C is generally used for desktop computers and can use the resources of
a desktop PC like memory, OS, etc. While C for Embedded Systems is
for microcontroller based applications so it has to deal with the limited
resources, such as RAM, ROM, I/O on an embedded processor.
 Embedded C
• It is an extension to the C standard (Under the ISO/IEC TR 18037
standard) to support specific complex topics in Embedded Systems
(Fixed point types, multiple memory areas, and I/O register mapping).
• Because Embedded C is an extension to the C standard, it uses the
same C language syntax.

13
C V/S EMBEDDED C

 „C‟ is a well  Embedded „C‟ can be


structured, well considered as a subset
of conventional „C‟
defined and language.
standardised general  A software program
purpose programming called „Cross
language. compiler‟ is used for
 A platform specific the conversion of
application , known as , programs written in
compiler is used for Embedded
the conversion of „C‟ to target
programs written in C processor/controller
specific
to the target processor instructions(machine
specific binary files. language).
Characteristic features of c programming that makes it a program of choice when designing
embedded systems which among other features include but not limited to:-

The programming space- limited spaces where there is need to


capitalise on throughput.
Disk space is normally small, normally granulated in Kbs not
Mbps
Robustness – a programming language in use for designing
operating systems.
Small code lines that achieve intended results.
Troubleshooting easy because of its wide use. A pool of
professionals to consult from.
Simpler to learn, understand, program and debug
COMPILER V/S CROSS COMPILER
 Cross compilers are
 Compiler is a software software tools used in cross
tool that converts a platform development
source code written in applications. (In cross
platform development , the
a high level language compiler running on a
on top of a particular particular target
operating system processor/OS converts the
running on a specific source code to machine
target processor code for a target processor
whose architecture and
architecture. instruction set is different
from the current
development environment
OS).
Code Compilation process

File.i File.s
File.c
Preprocessor Compiler Assembler

File.o

Other object files

Linker script Linker

Library files

File.map File.hex

17
Code Compilation process

 Preprocessing
It is the first stage of compilation. It processes preprocessor directives like
include-files, conditional compilation instructions and macros.
 Compilation
It is the second stage. It takes the output of the preprocessor with the
source code, and generates assembly source code.
 Assembler stage
It is the third stage of compilation. It takes the assembly source code and
produces the corresponding object code.
 Linking
It is the final stage of compilation. It takes one or more object files or
libraries and linker script as input and combines them to produce a
single executable file. In doing so, it resolves references to external
symbols, assigns final addresses to procedures/functions and variables,
and revises code and data to reflect new addresses (a process called
relocation). 18
Timers
Timers are used to measure specific time intervals. But in electrical
engineering terms, timers are also referred to as counters often.
 They are used to keep a record of time for different events
occurring in an embedded systems.
The timer is a simpler binary counter which is configured in a circuit
or a system as per the need to count the pulses in the system.
The value of the timer is automatically set to zero once it is at its
maximum value. Once the maximum value for the timer is reached,
an interrupt is generated with an overflow flag.
 The timer can be used to measure the time elapsed or the external
events occurring for a specific time interval.
They are used to maintain the operation of the embedded system in
sync with the clock. The clock can be an external clock or the
system clock.
Functionality of timer devices in embedded systems
A timer is a device that generates a signal pulse at specified time intervals.
 A time interval is a real-time measure of time, such as 4 milliseconds.
 Internally, a simple timer may consist of a register, a counter, and a simple controller
 Number of clock cycles = Desired real-time value / Clock cycle
 To obtain a duration of 3 milliseconds from a clock cycle of 10 nanoseconds (100

MHz). We must count :( 3x10-6 s) / (10x10-9 s/cycle) = 300 cycles.


 If a timer is an up counter, it counts up from the initial value toward 0xFF. A down
counter counts down, toward 0x00.
 Suppose a timer input clock of period 1µs and an up counter output of 25000 then time
elapsed for the event is 25000 x 1µs = 0.025s = 25 milliseconds
 The maximum time interval a timer can measure is known as the timer’s range, whereas
the resolution of a timer defines the minimum interval it can measure.
 The timer module has an additional output, overflow flag that indicates the counter
reaches its maximum output, in which case the timer rolls over to 0.
 We can count the number of times the timer overflows, and thus extend the range of
time we can measure. Therefore elapsed time = (stop count – start count) + number of
overflows x (2n-1), where, n = 16 for a 16-bit counter.
 The output signal may thereby trigger an interrupt at the processor or set a bit that the
processor can read. To restart the timer, software reloads the count register with the
same or a different initial value.
clock sources
 The crystal resonator gives the highest stability in frequency with
temperature and drift in the circuit. The crystal in association with an
appropriate resistance in parallel and a pair of series capacitance at both pins
resonates at the frequency, which is either double or single times the crystal-
frequency.
 The internal ceramic resonator, if available in a processor, saves the use
of the external crystal and gives a reasonable though not very highly stable
frequency. A typical drift of the ceramic resonator is about ten minutes per
month compared to the typical drift of 1 or 5 minutes per month of a crystal.
 The external IC-based clock oscillator has a significantly higher power
dissipation compared to the internal processor-resonator. It provides a higher
driving capability, which might be needed when the various circuits of
embedded system are concurrently driven.
 Silicon oscillators are typically a fully integrated version of the RC
oscillator with the added benefits of current sources, matched resistors and
capacitors, and temperature-compensation circuits for increased stability.
watchdog timer
A watchdog timer is an electronic timer that can be used to
automatically detect software anomalies and reset the processor if
any occur. It is sometimes called computer operating properly
timer. A watchdog timer is responsible for the following functions:
It is used to reset to the original state whenever some
inappropriate events take place
Helps guard against system hang by continually checking for
liveliness as it can result in an infinite loop
Can be used in mobile phones to save power. An application in
mobile phone is that display is off in case no GUI interaction takes
place within a watched time interval.
Used as a temperature controller and enforcing timing
constraints

You might also like