1. EMBEDDED SYSTEM DESIGN
EET-4202
Embedded System Firmware Development
DUNSTON PRIYASAD
B.E.T. (HONS) (RAJARATA),
LECTURER (TEMP.)
DEPARTMENT OF ELECTRICAL AND ELECTRONIC TECH .
RAJARATA UNIVERSITY OF SRI LANKA
2. 1. CORE OF THE EMBEDDED SYSTEM
❖The core of an embedded system can be either one of below.
➢General Purpose and Domain Specific Processors
▪Microprocessors
▪Microcontrollers
▪Digital Signal Processors
➢Application Specific Integrated Circuits (ASICs)
➢Programmable Logic Devices (PLDs)
➢Commercial off the shelf Components (COTS)
3. General Purpose and Domain Specific Processors
❖Majority of the embedded systems are processor/controller based.
❖The processor may be microprocessor or a microcontroller or digital signal
processor, depending on the domain and application.
Microprocessor
❖A silicon chip with a Central Processing Unit (CPU), which is capable of
performing arithmetic as well as logical operations according to a pre-defined
set of Instructions, which is specific to the manufacturer.
❖In general, the CPU contains the Arithmetic and Logic Unit (ALU), Control Unit
and Working registers.
❖Microprocessor is a dependent unit and it requires the combination of other
hardware like Memory, Timer Unit, and Interrupt Controller etc. for proper
functioning.
❖Intel claims the credit for developing the first Microprocessor unit Intel 4004, a
4-bit processor which was released in Nov 1971.
4. General Purpose and Domain Specific Processors
Microcontroller
❖A highly integrated silicon chip containing a CPU, scratch pad RAM, Special
and General-purpose Register Arrays, On Chip ROM/FLASH memory for
program storage, Timer and Interrupt control units and dedicated I/O ports.
❖Microcontrollers can be considered as a super set of Microprocessors.
❖Microcontroller can be general purpose or application specific (Like Automotive
AVR from Atmel Corporation).
❖Since a microcontroller contains all the necessary functional blocks for
independent working, they found greater place in the embedded domain in
place of microprocessors.
❖Microcontrollers are cheap, cost effective and are readily available in the
market.
❖Texas Instruments TMS 1000 is considered as the world's first microcontroller.
5. General Purpose and Domain Specific Processors
Digital Signal Processor (DSP)
❖Powerful special purpose 8/16/32 bit microprocessors designed
specifically to meet the computational demands and power constraints of
today's embedded audio, video, and communications applications.
❖Digital Signal Processors are much faster than the general-purpose
microprocessors in signal processing applications.
❖DSPs implement algorithms in hardware which speeds up the execution
whereas general purpose processors implement the algorithm in firmware
and the speed of execution depends primarily on the clock for the
processors.
❖DSP can be viewed as a microchip designed for performing high speed
computational operations for “addition”, “subtraction”, “multiplication”
and “division”.
6. Harvard and Von-Neumann Processor/Controller Architecture
❖The terms Harvard and Von-Neumann refers to
the processor architecture design.
❖Microprocessors/controllers based on the Von-
Neumann architecture shares a single common
bus for fetching both instructions and data.
Program instructions and data are stored in a
common main memory.
❖Microprocessors/controllers based on the
Harvard architecture will have separate data
bus and instruction bus. This allows the data
transfer and program fetching to occur
simultaneously on both buses.
❖ With Harvard architecture, the data memory can be read and written while the program memory is
being accessed. These separated data memory and code memory buses allow one instruction to
execute while the next instruction is fetched (Pre-fetching).
❖ Figure 1.1
7. Harvard V/s Von-Neumann Processor/Controller Architecture
Harvard Architecture Von-Neumann Architecture
Separate buses for Instruction and Data
fetching
Single shared bus for Instruction and Data
fetching
Easier to Pipeline, so high performance can
be achieved
Low performance Compared to Harvard
Architecture
Comparatively high cost Cheaper
No memory alignment problems Allows self modifying codes
Since data memory and program memory are
stored physically in different locations, no
accidental program memory corruption.
Since data memory and program memory are
stored physically in same chip, program
memory may corrupt accidentally.
8. Application Specific Integrated Circuits (ASICs)
❖A microchip designed to perform a specific or unique application. It is
used as replacement to conventional general purpose logic chips.
❖ASIC integrates several functions into a single chip and thereby
reduces the system development cost.
❖Most of the ASICs are proprietary products. As a single chip, ASIC
consumes very small area in the total system and thereby helps in the
design of smaller systems with high capabilities/functionalities.
❖ASICs can be pre-fabricated for a special application or it can be
custom fabricated by using the components from a re-usable “building
block” library of components for a particular customer application.
❖Some ASICs are proprietary products , the developers are not
interested in revealing the internal details.
9. Programmable Logic Devices (PLDs)
❖Logic devices provide specific functions, including device-
to-device interfacing, data communication, signal
processing, data display, timing and control operations, and
many other function a system must perform.
❖Logic devices can be classified into two categories - Fixed
and Programmable. The circuits in a fixed logic device are
permanent.
❖Programmable logic devices (PLDs) offer a wide range of
logic capacity, features, and speed- and these devices can
be re-configured to perform any number of functions at
any time.
❖Designers can use inexpensive software tools to quickly
develop, simulate, and test their logic designs in PLD based
design.
10. Programmable Logic Devices (PLDs)
Field Programmable Gate Arrays (FPGAs) and Complex Programmable Logic Devices
(CPLDs) are the two major types of programmable logic devices.
FPGA
❖FPGA is an IC designed to be configured by a designer after manufacturing.
❖Logic gate is Medium to high density ranging from 1K to 500K system gates.
❖FPGAs are used for data processing and storage, to instrumentation,
telecommunications, and digital signal processing.
CPLD
❖A complex programmable logic device (CPLD) is a programmable logic device with
complexity between that of PALs and FPGAs, and architectural features of both.
❖CPLDs, by contrast, offer much smaller amounts of logic - up to about 10,000 gates.
❖CPLDs offer very predictable timing characteristics and are therefore ideal for critical
control applications.
FPGA
CPLD
11. Commercial off the Shelf Component (COTS)
❖COTS products are designed in such a way to provide easy integration
and interoperability with existing system components.
❖Typical examples for the COTS hardware unit are remote controlled toy
car control unit including the RF circuitry, high performance, high frequency
microwave electronics (1 to 300 GHz), high bandwidth analog-to-digital
converters, devices and components for operation at very high
temperatures, IR imaging arrays, UV/IR Detectors etc.
❖A COTS component in turn contains a General-Purpose Processor (GPP) or
Application Specific Instruction Set Processor (ASIP) or Application Specific
Integrated Chip (ASIC)/Application Specific Standard Product (ASSP) or
Programmable Logic Device (PLD)CPLDs, by contrast, offer much smaller
amounts of logic - up to about 10,000 gates.
❖The major advantage of using COTS is that they are readily available in
the market, cheap and a developer can cut down development time to a
great extend.
❖There is no need to design the module yourself and write the firmware .
IMU
Bluetooth
GPS
12. Assignment 3
1. Compare and contrast the differences between Microprocessors and
Microcontrollers using a table.
2. Write five examples each for Microprocessors, Microcontrollers, and Digital
Signal Processors while naming the manufacturer, release date, speed, and
bus width.
3. Describe the functions of below given types of memories in embedded
systems.
a. Flash Memory
b. Read Only Memory
c. PROM (OTP)
d. Masked ROM
e. EPROM
f. EEPROM
g. NVRAM
13. 2. EMBEDDED FIRMWARE
❖It’s the control algorithm (Program instructions) and or the configuration settings that
an embedded system developer programs into the embedded system’s code
(Program) memory.
❖It is an essential part of an embedded system.
❖The embedded firmware can be developed in various ways, like,
➢Write the program in high-level languages like Embedded C/C++ using an Integrated Development
Environment (The IDE will contain an editor, compiler, linker, debugger, simulator, etc.) IDEs are different
for different families of processors/controllers.
➢Write the program in Assembly Language using the Instructions Supported by your application’s target
processor/controller
14. 1.1 EMBEDDED FIRMWARE DESIGN & DEVELOPMENT
❖ The embedded firmware is responsible for controlling the various peripherals of the
embedded hardware and generating responses following the functional requirements of the
product.
❖ The embedded firmware is usually stored in a permanent memory (ROM) and it is non-
alterable by end users.
❖ Designing embedded firmware requires an understanding of the particular embedded
product hardware, like,
➢Various component interfacing
➢Memory map details
➢I/O port details
➢Configuration and register details of various hardware components
❖ The embedded firmware development process starts with the conversion of the firmware
requirements into a program model using various modeling tools. (Ex: Flow charts,
Pseudocodes)
❖ The firmware design approaches for embedded products are purely dependent on the
complexity of the functions to be performed and the speed of operation required.
15. 2.1 EMBEDDED FIRMWARE DESIGN & DEVELOPMENT
❖ There exist two basic approaches for the design and implementation of embedded
firmware, namely;
a) The “Super Loop” based approach
b) The Embedded “Operating System” based approach
a) Super Loop based approach
❖ The Super loop based firmware development approach is Suitable for applications that
are not time-critical and where the response time is not so important (Embedded systems
where missing deadlines are acceptable).
❖ It is very similar to conventional procedural programming, where the code is executed task
by task
❖ The tasks are executed in a never-ending loop.
❖ The task listed at the top of the program code is executed first and the tasks just below
the top are executed after completing the first task.
16. a) Super Loop based approach
❖ A typical super loop implementation will look like that in Figure 1.1
❖ A “C” language program code for a super loop is given below.
Figure 1.1
#include <xc.h>
int main(void main ()
{
Configurations ();
Initializations ();
while (1)
{
Task 1 ();
Task 2 ();
:
Task n ();
}
}
17. a) Super Loop based approach
Pros:
❖ It doesn’t require an operating system for task scheduling and monitoring and is free from
OS-related overheads.
❖ Simple design, reduced memory footprint
Cons:
❖ Non-real-time in execution behavior (As the number of tasks increases, the frequency at which
a task gets CPU time for execution also increases)
❖ Any issues in any task execution may affect the functioning of the product (This can be
effectively tackled by using Watch Dog Timers for task execution monitoring)
Enhancements:
❖ Combine the Super loop based technique with interrupts
❖ Execute the tasks (like keyboard handling) that require real-time attention as Interrupt Service
routines.
18. b) The Embedded “Operating System” based approach
❖ The embedded device contains an Embedded Operating System, which can be either:
➢ A Real Time Operating System (RTOS)
➢ A Customized General Purpose Operating System (GPOS)
❖ The Embedded OS is responsible for scheduling the execution of user tasks and allocating system
resources among multiple tasks.
❖ It involves many OS-related overheads apart from managing and executing user-defined tasks.
❖ Microsoft® Windows XP Embedded is an example of GPOS for embedded devices.
❖ Point of Sale (PoS) terminals, Gaming Stations, Tablet PCs, etc, are examples of embedded devices
running on embedded GPOSs.
❖ ‘Windows CE’, ‘Windows Mobile’, ‘QNX’, ‘VxWorks’, ‘ThreadX’, ‘MicroC/OS-II’, ‘Embedded Linux’,
‘Symbian’, etc, are examples of RTOSs employed in Embedded Product development
❖ Ariel Defense Systems, Medical Instruments, Flight Control Systems, Industrial Robotics, etc., are
examples of embedded devices that run on RTOSs
19. 2.2 EMBEDDED FIRMWARE DEVELOPMENT LANGUAGES
a. Assembly Language
b. High-Level Languages
➢Subset of C (Embedded C)
➢Subset of C++ (Embedded C++)
➢Any other high-level language with a supported Cross-compiler
c. Mix of Assembly & High-level Language
➢Mixing High-Level Language (Like C/C++) with Assembly Code
➢Mixing Assembly code with High-level language (Like C/C++) - Inline Assembly
20. a. Assembly Language
❖ ‘Assembly Language’ is the human-readable notation of ‘machine language’.
❖ ‘Machine language’ is a processor-understandable language.
❖ Machine language is a binary representation, and it consists of 1s and 0s.
❖ An Assembly language program written for one processor/controller family will not work with others.
❖ Assembly language programming is the process of writing machine code in mnemonic form,
converting the mnemonics into actual processor instructions (machine language) and associated data
using an assembler.
❖ The general format of an assembly language instruction is an Opcode followed by Operands.
❖ The Opcode tells the processor/controller what to do, and the Operands provide the data and
address.
❖ It is not necessary that all opcodes should have Operands following them. Some of the Opcode
implicitly contains the operand, and in such a situation, no operand is required. The operand may be
a single, dual operand, or more.
21. a. Assembly Language
The 8051 Microcontroller Assembly Instructions
MOV A, #30
// Moves decimal value 30 to the 8051 Accumulator register. Here, MOV A is the Opcode and 30 is
the operand (single operand).
01110100 00011110
// The first 8-bit binary value 01110100 represents the opcode MOV A, and the second 8-bit binary
value 00011110 represents the operand 30.
Each line of an assembly language program is split into four fields as:
LABEL OPCODE OPERAND COMMENTS
LABEL is an optional field. A ‘LABEL’ is an identifier used to represent where data or code is located.
LABEL is commonly used for representing a memory location, address of a program, sub-routine,
code portion etc.
22. a. Assembly Language
ATmega328p Microcontroller Assembly Instructions for a delay object with inner
loop
DELAY:
LDI r18, 255 ; Outer loop counter
DELAY_OUTER:
LDI r19, 255 ; Inner loop counter
DELAY_INNER:
DEC r19 ; Decrement inner loop counter
BRNE DELAY_INNER ; If not zero, repeat inner loop
DEC r18 ; Decrement outer loop counter
BRNE DELAY_OUTER ; If not zero, repeat outer loop
RET ; Return from subroutine
Attachment 1: AVR
instruction set
Attachment 2:
ATmega328p Data Sheet
23. a. Assembly Language
❖The symbol ; (Semicolon) represents the start of a comment. Assembler ignores the text in
a line after the ; symbol while assembling the program.
❖DELAY is a label for representing the start address of the memory location where the
piece of code is located in code memory.
❖The above piece of code can be executed by giving the label DELAY as part of the
instruction.
24. Assembly language file to Machine code translation
❖The Assembly language program written in assembly code is saved as a “.asm” (Assembly
file) file or a “.src” (source file) file or a format supported by the assembler.
❖Similar to ‘C’ and other high-level language programming, it is possible to have multiple
source files called modules in assembly language programming.
❖The software utility called ‘Assembler’ performs the translation of assembly code to
machine code.
❖The assemblers for different families of target machines are different.
25. Assembly language file to Machine code translation
Figure 2.2: The Assembly Language to machine language conversion process
26. Advantages of using Assembly language
❖Efficient Code Memory & Data Memory Usage (Memory Optimization)
➢The developer is well aware of the target processor architecture and memory organization, so 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.
❖ Low-level Hardware Access
➢Most of the code for low-level programming, like accessing external device-specific registers from the OS
kernel, device drivers, and low-level interrupt routines, etc, is making use of direct assembly coding.
❖Code Reverse Engineering
➢It is the process of understanding the technology behind a product by extracting the information from
the finished product.
➢It can easily be converted into assembly code using a disassembler program for the target machine.
27. Drawbacks of using Assembly language
❖Longer Development time
➢The developer takes a lot of time to study about architecture, memory organization, addressing modes and
instruction set of the target processor/controller.
➢More lines of assembly code are required for performing a simple action.
❖Developer dependency
➢There is no common written rule for developing assembly language-based applications.
❖ Non-portable
➢Target applications written in assembly instructions are valid only for that particular family of processors and cannot
be reused for another target processor/controller.
➢If the target processor/controller changes, a complete re-writing of the application using assembly language for the
new target processor/controller is required.
28. b. High-Level Language
❖ The embedded firmware is written in high-level languages like
C and C++.
❖ A software utility called a ‘cross-compiler’ converts the high-
level language to target processor-specific machine code.
❖ The software program called linker/locater is responsible for
assigning an absolute address to object files during the linking
process.
❖ The Absolute object file created from the object files
corresponding to different source code modules contains
information about the address where each instruction needs to
be placed in code memory.
❖ A software utility called ‘Object to Hex file converter’
translates the absolute object file to the corresponding hex file
(binary file).
#include <util/delay.h>
void delay_ms(uint16_t ms) {
while (ms--) {
_delay_ms(1);
}
}
The C Language code for a precise delay
30. Advantages of using high-level languages
❖Reduced Development time
➢Developer requires less or little knowledge on internal hardware details and architecture of the target
processor/Controller.
❖Developer independent
➢The syntax used by most of the high-level languages is universal, and a program written in a
high-level language can be easily understood by a second person knowing the syntax of the
language.
❖Portability
➢An Application written in a high-level language for a particular target processor /controller
can be easily converted to another target processor/controller-specific application with little
or less effort.
31. Drawbacks of using high-level languages
❖The cross compilers may not be efficient in generating the optimized target processor-specific
instructions.
❖Target images created by such compilers may be bulky and non-optimized in terms of performance
as well as code size.
❖The investment required for high level language-based development tools (IDE) is high compared to
Assembly Language based firmware development tools.
32. c. Mixing of Assembly Language with High Level Language
❖ Embedded firmware development may require the mixing of Assembly Language with high-level
language or vice versa.
❖ High-level language and low-level language can be mixed in three different ways.
A. Mixing Assembly Language with High-level languages like ‘C’
• Assembly routines are mixed with ‘C’ in situations where the entire program is written in ‘C’ and
the cross compiler in use does not have built-in support for implementing certain features like ISR.
B. Mixing High-level languages like ‘C’ with Assembly Language
• The source code is already available in assembly language, and the routine written in a high-
level language needs to be included in the existing code.
C. In-line Assembly
• Inline assembly is another technique for inserting the target processor/controller specific
assembly instructions at any location of source code written in the high-level language ‘C’
❖ The passing of parameters and return values between the high-level and low-level languages is
cross-compiler specific.
33. THANK YOU
DUNSTON PRIYASAD
B. E. T. (HONS) (RAJARATA),
LECTURER (TEMP. )
DEPARTMENT OF ELECTRICAL AND ELECTRONIC TECH.
RAJARATA UNIVERSITY OF SRI LANKA