Chapter - 9 - Embedded Firmware Design & Development
Chapter - 9 - Embedded Firmware Design & Development
1
@ McGraw-Hill Education
PROPRIETARY MATERIAL. © 2009 The McGraw-Hill Companies, Inc. All rights reserved. No part of this PowerPoint slide may be displayed, reproduced or
distributed in any form or by any means, without the prior written permission of the publisher, or used beyond the limited distribution to teachers and educators
permitted by McGraw-Hill for their individual course preparation. If you are a student using this PowerPoint slide, you are using it without permission.
2
@ McGraw-Hill Education
Syllabus Contents
• Introduction
• Typical Embedded System
• Characteristics and Quality Attributes of
Embedded Systems
• Hardware Software Co-Design and Program
Modeling
• Embedded Firmware Design and Development
• Real-Time Operating System (RTOS) based
Embedded System Design
• The Embedded System Development
Environment
• Trends in the Embedded Industry 3
@ McGraw-Hill Education
4
@ McGraw-Hill Education
5
@ McGraw-Hill Education
6
@ McGraw-Hill Education
Pros:
Doesn’t require an Operating System for task scheduling and
monitoring and free from OS related overheads
Simple and straight forward 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)
9
@ McGraw-Hill Education
Enhancements:
Combine Super loop based technique with interrupts
Execute the tasks (like keyboard handling) which
require Real time attention as Interrupt Service routines
10
@ McGraw-Hill Education
Assembly Language
High Level Language
Subset of C (Embedded C)
Subset of C++ (Embedded C++)
Any other high level language with supported Cross-compiler
Mix of Assembly & High level Language
Mixing High Level Language (Like C) with Assembly Code
Mixing Assembly code with High Level Language (Like C)
Inline Assembly
13
@ McGraw-Hill Education
14
@ McGraw-Hill Education
16
@ McGraw-Hill Education
17
@ McGraw-Hill Education
18
@ McGraw-Hill Education
;##################################################################
##
; 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
DJNZ R1, DELAY ; Decrement R1 and loop till
R1= 0
RET ; Return to calling program
19
@ McGraw-Hill Education
20
@ McGraw-Hill Education
Drawbacks:
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)
Machine Code
(Hex File)
High level language to machine language
28
Conversion process
@ McGraw-Hill Education
29
@ McGraw-Hill Education
Keywords
do if static while
36
@ McGraw-Hill Education
Logical Operations
Operator Operation Comments
Performs logical AND operation. Output is true (logic 1) if
&& Logical AND both operands (left to and right to of && operator) are true
Performs logical OR operation. Output is true (logic 1) if
|| Logical OR either operand (operands to left or right of || operator) is
true
! Logical NOT Performs logical Negation. Operand is complemented
(logic 0 becomes 1 and vice versa)
39
@ McGraw-Hill Education
//exiting from loop Loops can be exited in two ways. First one is normal exit where loop is exited when the
break; expression/test for condition becomes false. Second one is forced exit. break and goto
goto label statements are used for forced exit.
break exits from the inner most loop in a deeply nested loop, whereas goto transfers the
program flow to a defined label.
42
@ McGraw-Hill Education
43
@ McGraw-Hill Education
//###########################################################
//using do while loop
//###########################################################
char *status_reg = (char*) 0x3000;
do
{
//###########################################################
//using for loop
//###########################################################
char *status_reg = (char*) 0x3000;
for (;(*status_reg!=0x01););
44
@ McGraw-Hill Education
&arr[0] 0x8000
arr[0] 0x10
//Selective initialization
arr[0] = 5;
arr[1] = 10;
arr[2] = 20;
arr[3] = 3;
arr[4] = 2;
46
@ McGraw-Hill Education
47
@ McGraw-Hill Education
input 0x45 10
The content of memory location representing the variable input (0x45) can be
accessed and modified by using a pointer of type same as the variable (char for
the variable input in the example)
In Embedded C the same is achieved through
48
@ McGraw-Hill Education
input 0x45 10
p 0x00 0x45
49
@ McGraw-Hill Education
Arrays are not equivalent to pointers and pointers are not equivalent to
arrays
The expression array name [] is equivalent to a pointer, of type specified
by the array, to the first element of an array
E.g. for the character array char arr[5], arr[ ] is equivalent to a character
pointer pointing to the first element of array arr (This feature is referred
as ‘equivalence of pointers and arrays’)
The array features like accessing and modifying members of an array
can be achieved using a pointer and pointer increment/decrement
operators
Arrays and pointer declarations are interchangeable when they are used
as parameters to functions
50
@ McGraw-Hill Education
52
@ McGraw-Hill Education
54
@ McGraw-Hill Education
58
@ McGraw-Hill Education
{
//Function body (Declarations & statements)
//Return statement
}
The ‘Linkage Type’ specifies the linkage for the function. It can
be either ‘external’ or ‘internal’
The ‘static’ keyword for the ‘Linkage Type’ specifies the
linkage of the function as internal whereas the ‘extern’ ‘Linkage
Type’ specifies ‘external’ linkage for the function
61
@ McGraw-Hill Education
63
@ McGraw-Hill Education
64
@ McGraw-Hill Education
{ struct employee
//variable 1 declaration { char emp_name [20];//
Allowed maximum length for
//variable 2 to declaration name = 20
int emp_code;
//…………… char DOB [10]; // DD-
MM-YYYY Format (10
//variable n declaration character)
};
}; 65
@ McGraw-Hill Education
typedef struct
{
char x;
int y;
} exmpl;
68
@ McGraw-Hill Education
Byte 3 of
Data
exmpl.y
Memory
4(x + 1) + 3 4(x + 1) + 2 4(x + 1) + 1 4(x + 1)
Address
Memory
4x + 3 4x + 2 4x + 1 4x
Address
Memory
4(x + 1) + 3 4(x + 1) + 2 4(x + 1) + 1 4(x + 1)
Address
70
@ McGraw-Hill Education
73
@ McGraw-Hill Education
};
Each bit field variable is defined with a name and an associated
bit size representation
If some of the bits are unused in a packed fashion, the same
can be skipped by merely giving the number of bytes to be74
@ McGraw-Hill Education
80
@ McGraw-Hill Education
82
@ McGraw-Hill Education
84
@ McGraw-Hill Education
86
@ McGraw-Hill Education
Volatile pointer
Volatile pointers is subject to change at any point after they are
initialized. Typical examples are pointer to arrays or buffers
modifiable by Interrupt Service Routines and pointers in dynamic
memory allocation. Pointers used in dynamic memory allocation
can be modified by the realloc() function. The general form of
declaration of a volatile pointer to a non-volatile variable is given
below.
88
@ McGraw-Hill Education
Infinite loops are created using various loop control instructions like while (),
do while (), for and goto labels
//Infinite loop using while
while (1)
{
} while (1);
for (; ; ;)
{
}
Bitwise AND
Operator ‘&’ performs Bitwise AND operations. Bitwise AND
operations are usually performed for selective clearing of bits and
testing the present state of a bit (Bitwise ANDing with ‘1’)
Bitwise OR
Operator ‘|’ performs Bitwise OR operations. Bitwise OR operation
is usually performed for selectively setting of bits and testing the
current state of a bit (Bitwise ORing with ‘0’)
91
@ McGraw-Hill Education
Bitwise NOT
Bitwise NOT operations negates (inverts) the state of a bit. The
operator ‘~’ (tilde) is used as the Bitwise NOT operator in C.
92
@ McGraw-Hill Education
Toggling Bits
Toggling a bit is performed to negate (toggle) the current state of a
bit. If current state of a specified bit is ‘1’, after toggling it
becomes ‘0’ and vice versa. Toggling is also known as inverting
bits. The Bitwise XOR operator is used for toggling the state of a
desired bit in an operand.
flag ^= (1<<6); //Toggle bit 6 of flag
94
@ McGraw-Hill Education
Testing Bits
Bitwise operators can be used for checking the present status of a bit without modifying it for decision
making operations.
95
@ McGraw-Hill Education
For Super loop based embedded firmware design, code the ISR as
per the support from the cross-compiler in use for target
processor.
The example given below illustrates the coding of ISR in
Embedded C for C51 Cross compiler for 8051 processor
void interrupt_name (void) interrupt x using y
{
/*Process Interrupt*/
}
interrupt_name is the function name for ISR
96
@ McGraw-Hill Education
99
@ McGraw-Hill Education
Dynamic Storage
Memory
Alterable Data
100
@ McGraw-Hill Education
free()
The ‘C’ memory management library function free() is used for
releasing or de-allocating the memory allocated in the heap memory
by malloc() or calloc() functions
free (ptr);
realloc()
realloc() function is used for changing the size of allocated bytes in
a dynamically allocated memory block
realloc (pointer, modified size);
102