Module 4 - Embedded Firmware Design
Module 4 - Embedded Firmware Design
Module 4 - Embedded Firmware Design
Introduction - The control algorithm (Program instructions) and or the configuration settings
that an embedded system developer dumps into the code (Program) memory of the embedded
system. It is an un-avoidable part of an embedded system.
The product
duct will continue serving the assigned task till
hardware breakdown occurs or a corruption in embedded
firmware.
The task listed on top on the program code is executed first and
the tasks just below the top are executed after completing the
first task
1. Doesn’t require an Operating System for task scheduling and monitoring andfree
from OS related overheads
2. Simple and straight forward design
2. 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 Super loop based technique with interrupts
‘Windows
Windows CE’, ‘Windows Mobile’,‘QNX’, ‘VxWorks
VxWorks’,
‘ThreadX
ThreadX’, ‘MicroC/OS-II’, ‘Embedded Linux’, ‘Symbian
Symbian’
etc are examples of RTOS employed in Embedded
Product development
o Subset of C (Embedded C)
o Subset of C++ (Embedded C++)
o Any other high level language with supported Cross-compiler
Cross
Mix of Assembly & High level Language
o Mixing High Level Language (Like C) with Assembly Code
o Mixing Assembly code with High Level Language (Like C)
o Inline Assembly.
The operand may be a single operand, dual operand or more.. For example,
MOV A, #30
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.
Assembly language instructions are written one per line. A machine code program
consists of a sequence of assembly language instructions, where each statement contains
a mnemonic (Opcode + Operand)
Operand). Each line of an assembly language program is split
into four fields as:
LABEL OPCODE OPERAND COMMENTS
LABEL is an optional
tional field. A ‘LABEL’ is an identifier used extensively in programs to
reduce the reliance on programmers for remembering where data or code is located.
LABEL is commonly used for representing a memory location, address of a program,
sub-routine, code portion . Labels are always suffixed by a colon and begin with a valid
character. Labels can contain number from 0 to 9 and special character _ (underscore).
;###############################################################
; SUBROUTINE FOR GENERATING DELAY
; DELAY PARAMETR PASSED THROUGH REGISTER R1
; RETURN VALUE NONE,REGISTERS USED: R0, R1
;###############################################################
##### DELAY: MOV R0, #255 ;Load Register R0 with 255
Each source file can be assembled separately to examine the syntax errors and
incorrect assembly instructions
Assembling of each source file generates a corresponding object file. The object
file does not contain the absolute address of where the generated code needs to be
placed (a re-locatable code) on the program memory
3. Non portable:
Target applications written in assembly instructions are
valid only for that particular family of processors and
cannot be re-used for another target
processors/controllers.
If the target processor/controller changes, a complete re-
writing of the application using assembly language for
new targetprocessor/controller is required.
Library Files
Source File 1
Module
(.c /.c++ etc) Object File 1
Cross-compiler
(Module-1)
Source File 2
Module
(.c /.c++ etc) Object File 2
Cross-compiler
(Module-2)
In line Ass
Assembly
Assembly routines are mixed with ‘C’ in situations where the entire
program is written in ‘C’ and the cross compiler has built in support for
implementing certain features like ISR( Interrupt service subroutine).
For accessing certain low level hardware , the timing specifications may
be very critical and cross compiler generated machine code may not be
able to offer the required time specifications accurately.
2. The entire source code is planned in Assembly code for various reasons
like optimized code, optimal performance, efficient code memory
utilization but some portions of the code may be tedious and difficult to
code in assembly. For example 16-bit multiplication/division program in
8051 assembly code has around 35 lines of code. Built in library functions
written in C must be included
The functions written in ‘C’ use parameter passing to the function and returns
values to the calling functions. The programmer must be aware of how
parameters are passed to the function and how values returned from the
function and how function is invoked from the assembly language
environment. A typical example for c51 cross compiler is given below.(note:
a cross compiler compiles HLL program to processor specific machine code.
C51 is the cross compiler used for 8051 microcontroller).
lcall _Cfunct
Note - Passing parameter to the function and returning values from the
function using CPU registers , stack memory and fixed memory. Its
implementation is cross compiler dependent and varies across compilers.
3. 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 high level language ‘C’
Special keywords are used to indicate the start and end of Assembly
instructions
Mov A,#13H
#pragma ensasm
Keil C51 uses the keywords #pragma asm and #pragma endasm to
indicatea block of code written in assembly.