ES Module4
ES Module4
in
5. :
6. :
7. Execute the last defined task
8. Jump back to the first task and follow the same flow
The order in which the tasks to be
executed are fixed & they are hard coded
in the code itself. Also the operation is an
infinite loop based approach. We can
visualize the operational sequence listed
above in terms of a ‘C’ program code as
shown:
Almost all tasks in embedded applications are non-ending and are repeated infinitely
throughout the operation. This repetition is achieved by using an infinite loop. Hence this
approach is called as 'Super loop based approach’. The only way to come out of the loop is
either a hardware reset or an interrupt assertion.
Advantage of Super Loop Based Approach:
It doesn't require an operating system.
There is no need for scheduling which task is to be executed and assigning priority to
each task.
The priorities are fixed and the order in which the tasks to be executed are also fixed.
The code for performing these tasks will be residing in the code memory without an
operating system image.
Applications & Examples of Super Loop Based Approach:
This type of design is deployed in low-cost embedded products and products where
response time is not time critical. Some embedded products demands this type of approach
if some tasks itself are sequential. For example, reading/writing data to and from a card
using a card reader requires a sequence of operations
A typical example of a 'Super loop based’ product is an electronic video game toy
containing keypad and display unit.
Drawbacks of Super Loop Based Approach:
Any failure in any part of a single task will affect the total system: If the program
hangs up at some point while executing a task, it will remain there forever and
ultimately the product stops functioning. Watch Dog Timers (WDTs) can be used to
overcome this.
Lack of real timeliness: If the number of tasks to be executed within an application
increases, the time at which each task is repeated also increases. This brings the
probability of missing out some events.
Embedded Operating System (OS) Based Approach
The operating system based approach contains operating systems, which can be either a
General Purpose Operating System (GPOS) or a Real Time Operating System (RTOS) to host
the user written application firmware.
The GPOS based design is similar to a conventional PC based application
development where the device contains an operating system and you will be creating and
running user applications on top of it. Example of a GPOS is Microsoft Windows XP
Embedded. Examples of Embedded products using Microsoft Windows XP OS are Personal
Digital Assistants (PDAs), Hand held devices/Portable devices. OS based applications also
require 'Driver software' for different hardware present on the board to communicate with
them.
Real Time Operating System (RTOS) based design approach is employed in embedded
products demanding Real-time response. RTOS responds in a timely and predictable
manner to events. RTOS contains a Real Time kernel responsible for performing pre-
emptive multitasking, scheduler for scheduling tasks, multiple threads, etc. A RTOS allows
flexible scheduling of system resources like the CPU and memory and offers some way to
communicate between tasks. 'Windows CE', 'pSOS', 'ThreadX', 'MicroC/OS-II’, 'Embedded
Linux', 'Symbian’, etc. are examples of RTOS employed in embedded product development.
Mobile phones, handheld devices, etc. are examples of 'Embedded Products' based on
RTOS.
Embedded Firmware Development Languages
For embedded firmware development, we can use either:
a target processor/controller specific language (Generally known as Assembly
language or low level language) or
a target processor/controller independent language (Like C, C++, JAVA, etc.
commonly known as High Level Language) or
a combination of Assembly and High level Language.
When a program is too complex or too big; the entire code can be divided into sub-
modules and each module can be re-usable. This concept is called as Modular
Programming. Modular programs are usually easy to code, debug and alter.
Source File to Object File Translation
Translation of assembly code to machine code is performed by assembler. The assemblers
for different target machines are different. A51 Macro Assembler from Keil software is a
popular assembler for the 8051 family microcontroller. Various steps involved in the
conversion of a program written in assembly language to corresponding binary file/machine
language are shown below:
Each source module is written in Assembly and is stored as .src file or .asm file. Each
file can be assembled separately to examine the syntax errors and incorrect assembly
instructions. On successful assembling of each .src/.asm file a corresponding object file is
created with extension '.obj’. The object file does not contain the absolute address of where
the generated code needs to be placed on the program memory and hence it is called a re-
locatable segment. It can be placed at any code memory location and it is the
responsibility of the linker/locater to assign absolute address for this module.
Library File Creation and Usage: Libraries are specially formatted, ordered program
collections of object modules that may be used by the linker at a later time. When the
linker processes a library, only those object modules in the library that are necessary to
create the program are used. Library files are generated with extension '.lib'. LIB51' from
Keil Software is an example for a library creator and it is used for creating library files for
A51 Assembler/ C51 Compiler for 8051 specific controller.
Linker and Locater: Linker and Locater is a software utility responsible for "linking the
various object modules in a multi-module project and assigning absolute address to each
module". Linker is a program which combines the target program with the code of other
programs (modules) and library routines. During the process of linking, the absolute
object module is created.
An absolute object file or module does not contain any re-locatable code or data. All
code and data reside at fixed memory locations. The absolute object file is used for creating
hex files for dumping into the code memory of the processor/ controller. BL51' from Keil
Software is an example for a Linker & Locater for A51 Assembler/ C51 Compiler for 8051
specific controller.
Object to Hex File Converter: This is the final stage in the conversion of Assembly
language (mnemonics) to machine understandable language (machine code). Hex File is the
representation of the machine code and the hex file is dumped into the code memory of the
processor/controller. The hex file representation varies depending on the target
processor/controller make.
HEX files are ASCII files that contain a hexadecimal representation of target
application. Hex file is created from the final 'Absolute Object File' using the Object to Hex
File Converter utility. 'OH51' from Keil software is an example for Object to Hex File
Converter utility for A51 Assembler/C51 Compiler for 8051 specific controller.
Advantages of Assembly Language Base Development:
Efficient Code Memory and Data Memory Usage (Memory Optimization): Since
the developer is well versed with the target processor architecture and memory
organization, optimized code can be written for performing operations. This leads to
less utilization of code memory and efficient utilization of data memory.
High Performance: Optimized code not only improves the code memory usage but
also improves the total system performance. Through effective assembly coding,
The various steps involved in high level language based embedded firmware
development is same as that of assembly language based development except that the
conversion of source file written in high level language to object file is done by a cross-
compiler. The various steps involved in the conversion of a program written in high level
language to corresponding binary file/machine language is illustrated in below figure:
The program written in any of the high level language is saved with the corresponding
language extension (.c for C, .cpp for C++ etc). Any text editor like 'notepad' or 'WordPad '
from Microsoft® or the text editor provided by an Integrated Development (IDE) tool
supporting the high level language can be used for writing the program. Most of the HLLs
support modular programming approach and hence can have multiple source files called
modules. Translation of high level source code to executable object code is done by a cross-
compiler. Cross-compilers for different HLLs for same target processor are different. C51 is
a popular Cross-compiler available for 'C' language for the 8051 family of micro controller.
Conversion of each module's source code to corresponding object file is performed by the
cross compiler. Rest of the steps are same as that of the steps involved in assembly
language based development.
Input Modules: It includes the names of all the object files, library files and other files that
are included in the linking process.
Memory Map: It lists the starting address, length, relocation type and name of each
segment in the program.
Symbol Table: It contains the name, value and type for all symbols from different input
modules.
Inter Module Cross Reference: The cross reference listing includes the section name,
memory type and module names in which it is defined and all modules where it is accessed.
Program Size: It contains the size of various memory areas, constants and code space for
the entire application.
Warnings and Errors: It contains the warnings and errors that are generated while linking
a program. It is used in debugging link errors.
LINK / LOCATE RUN COMPLETE. 0 WARNING(S), 0 ERROR(S).
5. Hex file (.HEX File)
Hex file is the binary executable file created from the source code. The absolute object file
created by the linker/locater is converted into processor understandable binary code. Hex
files embed the machine code in a particular format. The format of Hex file varies across the
family of processors/controllers.
Intel HEX and Motorola HEX are the two commonly used hex file formats in
embedded applications.
1. Intel Hex File Format: Intel HEX file is composed of a number of hex records. Each
record is made up of five fields in the following format:
:llaaaattdd….cc
Each group of letters corresponds to a different field, and each letter represents a
single hexadecimal digit. Each field is composed of at least two hexadecimal digits (which
make up a byte) as described below:
Field Description
: The colon indicating the start of every Intel HEX record
ll Record length field representing the number of data bytes (dd) in the record.
aaaa Address field representing the starting address for subsequent data in the record.
tt Field indicating the HEX record type. According to its value it can be of the
following types:
00: Data Record
01: End of File Record
02: 8086 Segment Address Record
04: Extended Linear Address record
dd Data field that represents one byte of data. A record can have number of data
bytes. The number of data bytes in the record must match to the number
specified by the ‘ll' field
cc Checksum field representing the checksum of the record. Checksum is calculated
by adding the values of all hexadecimal digit pairs in the record and taking
modulo 256.
2. Motorola HEX file format: Motorola file is an ASCII text file where the HEX data is
represented in ASCII format in lines. The lines in Motorola HEX file represent a HEX
Record. Each record is made up of hexadecimal numbers that represent machine-language
code and/or constant data. The general form of Motorola Hex record is given below:
SOR RT Length Start Address Data / Code Checksum
In other words it can be represented as: Stllaaaaddddd...cc
The fields of the record are explained below:
Field Description
SOR Stands for Start of record. The ASCII Character 'S' is used as the Start of
Record. Every record begins with the character 'S'
RT Stands for Record type. The character “t” represents the type of record in the
general format. There are different meanings for the record depending on the
value of t:
0: Header. Indicates the beginning of Hex File
1: Data Record with 16bit start address
2: Data record with 24bit start address
9: End of File Record
Length Stands for the count of the character pairs in the record. Two ASCII characters
(ll) 'Il represent the length field. Each ‘l’ can take values 0 to 9 and A to F.
Start Address field representing the starting address for subsequent data in the
Address record.
(aaaa)
Code/ Data field that represents one byte of data. A record can have number of data
Data bytes. The number of data bytes in the record must match to the number
(dd) specified by ‘ll’
Check- Checksum field representing the checksum of the record. Checksum is
sum calculated by adding the values of all hexadecimal digit pairs in the record and
(cc) taking modulo 256.
DISASSEMBLER / DECOMPILER
Disassembler is a utility program which converts machine codes into target processor
specific Assembly codes/instructions. The process of converting machine codes into
Assembly code is known as 'Disassembling’. In operation, disassembling is complementary
to assembling/cross assembling.
Decompiler is the utility program for translating machine codes into corresponding
high level language instructions. Decompiler performs the reverse operation of
compiler/cross-compiler. The disassemblers/decompilers for different family of processors
/controllers are different. Disassemblers/Decompilers are deployed in reverse engineering.
Disassemblers/ Decompilers are powerful tools for analysing the presence of
malicious codes (virus information) in an executable image. Disassemblers/Decompilers are
available as either freeware tools readily available for free download from internet or as
commercial tools.
SIMULATORS, EMULATORS AND DEBUGGING
Simulators and emulators are two important tools used in embedded system development.
Simulator is a software tool used for simulating the various conditions for checking the
functionality of the application firmware. The Integrated Development Environment (IDE)
itself will be providing simulator support and help in debugging the firmware for checking
its required functionality. In certain scenarios, simulator refers to a soft model (GUI model)
of the embedded product. Emulator is hardware device which emulates the functionalities
of the target device and allows real time debugging of the embedded firmware in a hardware
environment.
Simulators
Simulators simulate the target hardware and the firmware execution can be inspected
using simulators. The features of simulator based debugging are listed below:
1. Purely software based.
2. Doesn't require a real target system.
3. Very primitive (Lack of featured I/O support. Everything is a simulated one)
4. Lack of Real-time behaviour
Advantages of Simulator Based Debugging: Simulator based debugging techniques are
simple and straightforward. The major advantages of simulator based firmware debugging
techniques are:
No Need for Original Target Board: Simulator based debugging technique is purely
software oriented. IDE's software support simulates the CPU of the target board.
Since the real hardware is not required, firmware development can start well in
advance and this saves development time.
Simulated I/O Peripherals: Simulator provides the option to simulate various I/O
peripherals. Hence it eliminates the need for connecting I/O devices for debugging
the firmware.
Simulates Abnormal Conditions: It helps the developer in simulating abnormal
operational environment for firmware and helps the firmware developer to study the
behaviour of the firmware under abnormal input conditions.
Limitations of Simulator based Debugging: Though simulation based firmware possess
certain limitations and we cannot fully rely upon the simulator-based firmware debugging.
Some of the limitations of simulator-based debugging are:
Deviation from Real Behaviour: Simulation based firmware debugging is always
carried out in a development environment where the developer may not be able to
debug the firmware under all possible combinations of input. We may get some
particular result and it need not be the same when the firmware runs in a production
environment.
Lack of Real Timeliness: The major limitation of simulator based debugging is that
it is not real-time in behaviour. The debugging is developer driven and moreover in a
real application the I/O condition may be varying or unpredictable. Simulation goes
for simulating those conditions for known values.
program controls the downloading of user code into the code memory, inspects and
modifies register/ memory locations; allows single stepping of source code, etc. The monitor
program implements the debug functions as per a pre-defined command set from the debug
application interface.
The first step in any monitor program development is determining a set of commands for
performing various operations like firmware downloading, memory/ register inspection/
modification, single stepping, etc. The entire code stuff handling the command reception
and corresponding action implementation is known as the "monitor program". The
most common type of interface used between target board and debug application is RS-
232C Serial interface.
The monitor program contains the following set of minimal features:
1. Command set interface to establish communication with the debugging application
2. Firmware download option to code memory
3. Examine and modify processor registers and working memory (RAM)
4. Single step program execution
5. Set breakpoints in firmware execution
6. Send debug information to debug application running on host machine.
4. In Circuit Emulator (ICE) Based Firmware Debugging
Emulator' is a self-contained hardware device which emulates the target CPU. The emulator
hardware contains necessary emulation logic and it is hooked to the debugging application
running on the development PC on one end and connects to the target board through some
interface on the other end. The Emulator POD (shown in figure) forms the heart of any
emulator system and it contains the following functional units:
Emulation Device: is a replica of the target CPU which receives various signals from the
target board through a device adaptor and performs the execution of firmware under the
control of debug commands from the debug application.
Emulation Memory: is the RAM incorporated in the Emulator device. It acts as a
replacement to the target board's EEPROM where the code is supposed to be
downloaded after each firmware modification. Hence the original EEPROM memory is
emulated by the RAM of emulator. This is known as 'ROM Emulation'.
Emulator Control Logic: is the logic circuits used for implementing complex hardware
breakpoints, trace buffer trigger detection, trace buffer control, etc. They are also used
for implementing logic analyzer functions in advanced emulator devices. The 'Emulator
POD' is connected to the target board through a 'Device adaptor' and signal cable.
Device Adaptors: act as an interface between the target board & emulator POD. Device
adaptors are used for routing the various signals from pins assigned for the target
processor. The device adaptor is connected to the emulator POD using ribbon cables.
5. On Chip Firmware Debugging (OCD)
Today almost all processors/controllers incorporate built in debug modules called On Chip
Debug (OCD) support. It is a very good feature supporting fast and efficient firmware
debugging. The On Chip Debug facilities integrated to the processor/ controller are chip
vendor dependent and most of them are proprietary technologies. Processors/controllers
with OCD support incorporate a dedicated debug module to the existing architecture.
Usually the on-chip debugger provides the means to set simple breakpoints, query the
internal state of the chip and single step through code. OCD module implements dedicated
registers for controlling debugging.
BDM and JTAG are the two commonly used interfaces to communicate between the
Debug application running on Development PC and OCD module of target CPU.
Background Debug Mode (BDM) interface is a proprietary On Chip Debug solution
from Motorola. BDM defines the communication interface between the chip resident debug
core and host PC where the BDM compatible remote debugger is running.
Chips with JTAG debug interface contain a built-in JTAG port for communicating
with the remote debugger application. JTAG is the acronym for Joint Test Action Group.
The signal lines of JTAG protocol are GIVEN below:
Test Data In (TDI)
Test Data Out (TDO)
Test Clock (TCK)
Test Mode Select (TMS)
Test Reset (TRST)