0% found this document useful (0 votes)
21 views38 pages

Unit Iii Esd

The document covers key components and design approaches in embedded firmware development, including reset circuits, brown-out protection, oscillator units, real-time clocks, and watchdog timers. It discusses two main firmware design approaches: the Super Loop Model and Embedded Operating System (OS) Based Design, along with programming languages used, such as Assembly and high-level languages like C. The document emphasizes the importance of these components and approaches in ensuring reliable and efficient operation of embedded systems.

Uploaded by

Rayyan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views38 pages

Unit Iii Esd

The document covers key components and design approaches in embedded firmware development, including reset circuits, brown-out protection, oscillator units, real-time clocks, and watchdog timers. It discusses two main firmware design approaches: the Super Loop Model and Embedded Operating System (OS) Based Design, along with programming languages used, such as Assembly and high-level languages like C. The document emphasizes the importance of these components and approaches in ensuring reliable and efficient operation of embedded systems.

Uploaded by

Rayyan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 38

A8460-Embedded Firmware Design and

Development
UNIT -III
Mrs.J.Swetha Priyanka
Email:[email protected]
VARDHAMAN COLLEGE OF ENGINEERING
Shamshabad, Hyderabad – 501218, India.
Contents
 Reset Circuit
 Brown-out Protection Circuit
 Oscillator Unit
 Real Time Clock
 Watchdog Timer
 Embedded Firmware Design Approaches and Development
Languages
Reset Circuit
 A reset circuit is an essential component in digital systems, including microcontrollers,
microprocessors, and other electronic devices. Its primary purpose is to initialize the
system into a known, stable state when power is applied, ensuring that the device starts
operating correctly from the very beginning.
 Key Functions of a Reset Circuit:
 System Initialization:
 When power is first applied to the system, the reset circuit ensures that all internal
registers, peripherals, and memory are initialized to their default states (often zeros or a
known starting value). This prevents the system from starting with random,
unpredictable states that could lead to malfunction.
 Power-On Reset (POR):
• The reset circuit ensures that when the power supply is turned on or when the system is
powered after being off, the device starts from a known state. It typically holds the
system in a reset state for a brief period after the power is applied to allow time for the
system's components to stabilize.
 Correct Timing:
• The reset pulse must be of sufficient duration to allow the clock oscillator and other
internal circuits to stabilize. For example, the clock might need time to stabilize after
power is applied, and the reset signal ensures that the system waits for this stabilization
before starting normal operation.
• Fault Recovery:
• In case of a malfunction, software crash, or if the system enters an unknown state, the
reset circuit can force the system back to its initialized state, ensuring recovery without
manual intervention.
• The reset circuit ensures the device operates at a stable voltage during power ON.
• It initializes internal registers and hardware systems to a known state.
• The reset vector typically starts at address 0x0000 but can be relocated for bootloader
support.
• Reset signals can be active high or active low, depending on the processor.
• The reset pulse must be long enough for the clock oscillator to stabilize.
• Reset can be applied through a passive RC circuit or a standard reset IC like MAX810.
• A simple RC (Resistor-Capacitor) network is often used to create the delay required
for a reset pulse. The capacitor charges through the resistor when the system is powered
on, and once the voltage across the capacitor reaches a certain level, the reset is released.
• Some processors have built-in reset circuits and don’t require external components.
• The reset pulse width can be adjusted by changing resistance (R) and capacitance (C).
Brown-out Protection Circuit
• A brown-out protection circuit is a crucial feature in embedded systems and
microcontrollers, designed to ensure that the system remains stable during periods of low
voltage or voltage dips (referred to as "brown-outs"). Brown-out protection helps to prevent
unpredictable behavior or malfunction when the system’s supply voltage falls below a certain
threshold, which could otherwise lead to incorrect operations or data corruption.
 Brown-out protection prevents unexpected processor behavior due to low supply voltage.
 It is crucial for battery-powered devices to avoid voltage drops below the required threshold.
 Voltage drops can cause unpredictable processor behavior and data corruption.
 Some processors have built-in brown-out protection, while others require external circuits.
 Brown-out protection can be implemented using Zener diodes, transistors, or supervisor ICs.
 Zener diodes are used to monitor and protect the system from low voltage conditions (also
known as brown-outs).
 Zener diodes are components that exhibit voltage regulation characteristics, making them
useful in situations where a voltage needs to be controlled or limited.
 The Zener diode sets the low voltage threshold, and the transistor controls reset activation.
 Supervisor ICs like DS1232 from Maxim Dallas provide reliable brown-out protection.
Oscillator Unit
 An oscillator unit is an essential component in many electronic systems, including
microcontrollers, microprocessors, and communication devices. It generates a periodic
waveform (usually a sine wave or a square wave) that is used to drive various circuits,
including timing and synchronization systems. The frequency of the oscillator defines the
rate at which the system operates and is critical for the overall functioning of the system.
 A microprocessor/microcontroller operates in sync with a clock signal, like a heartbeat in
living beings.
 The frequency of the oscillation (measured in Hertz, Hz) determines how quickly the
system operates. For example, a microcontroller might operate at a frequency of 16 MHz,
meaning it performs 16 million cycles per second.
 The oscillator unit generates the clock signal required for the processor’s operation.
 Some processors have built-in oscillators and need only an external quartz crystal or ceramic
resonator.
 Quartz crystals and ceramic resonators function similarly but have physical differences.
 Processors without built-in oscillators require external clock sources like quartz crystal
oscillators.
 The processor's speed depends on the clock frequency but has a maximum limit for stable
operation.
 Higher clock frequencies increase power consumption.
 The accuracy of program execution depends on the accuracy of the clock signal.
 Clock accuracy is measured in parts per million (ppm).
Microcontroller Microprocessor
C : Capacitor
Y : Resonator

Oscillator
Quartz crystal unit
resonator C C
Oscillator
Y
unit

Fig: Oscillator circuitry .using quartz crystal and


quartz crystal oscillator
Real-Time Clock (RTC)
 Real-Time Clock (RTC) keeps track of time, date, and day of the
week.
 It functions even without power using a backup battery.
 RTC chips are available from manufacturers like Maxim/Dallas
and ST Microelectronics.
 It provides a timing reference for embedded systems and OS-
based devices.
 RTC can interrupt the OS kernel for tasks like system time
updates and software timer management.
 The processor can be interrupted at predefined intervals or
when the RTC reaches a set value (alarm function).
Watchdog Timer
 A Watchdog Timer (WDT) is an essential component in embedded systems,
microcontrollers, and microprocessors designed to monitor the system's operation and
ensure it remains in a working state. The purpose of the watchdog timer is to detect
and recover from malfunctions or software crashes by resetting the system if it
becomes unresponsive.
 Key Functions of a Watchdog Timer:
 1. Monitoring System Activity
 2. Resetting the System on Failure
 3. Ensuring System Reliability
 A watchdog timer monitors firmware execution and resets the system if it hangs.
 It works by counting up or down and generating a reset signal when the count limit is
reached.
 The firmware must reset the watchdog timer regularly to prevent unintended resets.
 Most processors have a built-in watchdog timer with control and status registers.
 If not built-in, an external watchdog timer IC can be used for the same function.
 The DS1232 microprocessor supervisor IC integrates a hardware watchdog timer.
 In modern embedded systems, watchdog timeout can trigger an interrupt instead of a
reset.
Microprocess
or/
Controller
Watchdog
Free running
counter
Reset pin

Watchdog Reset

System clock

Fig: Watchdog timer for firmware execution supervision


Embedded Firmware Design Approaches
 The firmware design approaches for embedded product is purely
dependent on the complexity of the functions to be performed,
the speed of operation required, etc. Two basic approaches are
used for Embedded firmware design. They are ‘Conventional
Procedural Based Firmware Design’ and ‘Embedded Operating
System (OS) Based Design’. The conventional procedural based
design is also known as ‘Super Loop Model’.
1. The Super Loop Based Approach
2. The Embedded Operating System (OS) Based Approach
1. The Super Loop Based Approach
 The Super Loop approach is used for non-time-critical embedded
applications.
 Tasks execute sequentially in an infinite loop without an operating
system.
 A hardware reset or interrupt is needed to break the loop.
 This approach is cost-effective and used in low-cost embedded products.
 It is suitable for tasks that must follow a strict sequence, like card readers.
 Used in simple applications like electronic toys with keypads and displays.
 The main drawback is that a failure in one task can halt the entire system.
 Lack of real-time responsiveness can cause delays or missed events.
 Hardware and software watchdog timers can help recover from failures.
 Using faster processors can improve performance and responsiveness.
2. The Embedded Operating System (OS) Based Approach
 OS-based embedded systems use either a General Purpose OS (GPOS)
or a Real-Time OS (RTOS).
 GPOS-based systems are similar to PC-based applications, running on
OS like Windows Embedded.
 GPOS is used in devices like handhelds, POS terminals, and patient
monitoring systems.
 OS-based applications require driver software to communicate with
hardware.
 RTOS is used in embedded systems requiring real-time response.
 RTOS ensures timely and predictable task execution with pre-emptive
multitasking.
 It provides flexible resource scheduling and inter-task communication.
 Examples of RTOS include VxWorks, ThreadX, MicroC/OS-III, and
Embedded Linux.
Embedded Firmware Development Languages
 Programming can be done using either Assembly language, which
is specific to a processor/controller, or High-Level Languages
like C, C++, and Java, which are independent of the hardware.
In some cases, a combination of both approaches is used to
optimize performance and flexibility.
1. Assembly Language based Development
2. High Level Language Based Development
3. Mixing Assembly and High-Level Language
1. Assembly Language based Development
 Assembly language is a human-readable form of machine language, using mnemonics
instead of binary code.
 It is processor-dependent, meaning programs written for one processor won’t work on
another.
 Assembly programming was widely used in early computing and is still essential for
low-level system tasks.
 Instructions consist of an opcode (operation) and operands (data required for
execution).
 Labels in assembly code help manage memory locations and improve code readability.
 Assembly language programs are structured with separate lines for each instruction.
 Modular programming in assembly helps manage large programs by dividing them into
smaller, reusable modules.
 Assemblers convert assembly language into machine-readable code.
 Pseudo-ops (assembler directives) help define memory locations, initialize variables, and
structure the program.
 Assembly is still used for critical tasks like device drivers and system-level interactions
with hardware.
1.1. Source File to Object File Translation
 Assemblers convert Assembly code into machine code, and different processors
require different assemblers.
 Some assemblers are proprietary, while others are freely available or require a
license.
 Keil’s A51 Macro Assembler is a popular assembler for the 8051
microcontroller.
 Assembly source files are stored as .src or .asm and converted into .obj object
files.
 Object files are relocatable and require a linker to assign absolute memory
addresses.
 The PUBLIC keyword exports variables or functions for use in other modules.
 The EXTRN keyword imports variables or functions from other modules.
 Multiple modules exporting the same function using PUBLIC cause linker
errors.
 If a module imports a function using EXTRN but no module exports it, linker
warnings or errors occur.
1.2. Library File Creation and Usage
 Libraries are collections of object modules used by the linker, containing only
necessary modules for program creation.
 Library files have a .lib extension and help in source code hiding while
allowing function usage.
 Developers can distribute libraries with function details without revealing the
source code.
 Libraries are added to projects for use in development.
 Commercial assemblers/compilers provide pre-written libraries for tasks like
multiplication and floating-point arithmetic.
 ‘LIB51’ from Keil Software creates libraries for A51 Assembler/C51 Compiler
for 8051 microcontrollers.
1.3. Linker and Locater
 The linker and locator link object modules and assign absolute addresses in a
multi-module project.
 It generates an absolute object module by extracting object files from the
library and assembler output.
 The linker resolves external dependencies among modules.
 Absolute object files have fixed memory locations and no relocatable code or
data.
 These files are used to create hex files for loading into a processor/controller.
 ‘BL51’ from Keil Software is a linker & locator for A51 Assembler/C51
Compiler for 8051 microcontrollers.
1.4. Object to Hex File Converter
 The final stage of converting assembly language to machine code is generating
a hex file.
 The hex file is loaded into the processor/controller's code memory.
 Hex file format depends on the target processor, e.g., ‘Intel HEX’ for Intel and
‘Motorola HEX’ for Motorola.
 HEX files are ASCII files representing the target application in hexadecimal
format.
 The Object to Hex File Converter utility creates hex files from the absolute
object file.
 ‘OH51’ from Keil Software is an example of such a utility for the A51
Assembler/C51 Compiler for 8051.
1.5. Advantages of Assembly Language Based
Development
 Efficient Code Memory and Data Memory Usage(Memory Optimization):
A developer with a strong understanding of the processor architecture and
memory organization can write optimized code, reducing code size and
efficiently using data memory. This is crucial in embedded systems, where
memory is limited and external memory access can affect system performance.
 High Performance: Optimised code not only improves the code memory usage but
also improves the total system performance. Through effective assembly coding,
optimum performance can be achieved for a target application.
 Low Level Hardware Access: Most of the code for low level programming like
accessing external device specific registers from the operating system kernel, device
drivers, and low level interrupt routines, etc. are making use of direct assembly coding
since low level device specific operation support is not commonly available with most
of the high-level language cross compilers.
 Code Reverse Engineering: Reverse engineering is the process of extracting
information from a finished product to understand its technology. Hackers often use it
to uncover the design of proprietary products. Even with code memory protection, it
may be possible to bypass security, retrieve the code, and convert it into assembly using
a disassembler.
1.6. Drawbacks of Assembly Language Based
Development
 High Development Time: Assembly language is difficult to program as it
requires deep knowledge of processor architecture, memory, and registers.
Learning it is time-consuming and can delay product development. A skilled
developer familiar with the processor can help. Additionally, assembly code is
longer, as tasks that require one instruction in C may need multiple lines in
Assembly.
 Developer Dependency: Assembly language has no fixed rules like high-level
languages, giving developers freedom in memory and register use. Different
programmers may take different approaches, making code hard to understand or modify
later if not properly documented. Without documentation, even the original developer
may struggle to recall decisions. Proper documentation helps reduce dependency on
specific developers, but for large and complex code, documenting every line may not be
practical.
 Non-Portable: Assembly language programs are specific to a processor family and
cannot be reused for different processors, requiring a complete rewrite for new
hardware. This lack of portability is a major drawback. However, mastering Assembly
allows developers to fully optimize and maximize a processor’s performance.
2. High Level Language Based Development
 Assembly programming is time-consuming, complex, and requires in-depth
processor knowledge.
 High-level languages like C, C++, and Java simplify embedded firmware
development.
 Cross-compilers convert high-level code into processor-specific machine code.
 C is the most popular language for embedded development due to its portability
and tool support.
 Modular programming allows multiple source files to be used in embedded
development.
 Each high-level language needs a dedicated cross-compiler to generate machine
code.
 Modular programming in assembly helps manage large programs by dividing them
into smaller, reusable modules.
 Keil’s C51 cross-compiler is widely used for 8051 microcontroller development.
 The process of converting high-level code to machine code is similar to assembly-
based development, except a compiler replaces the assembler.
2.1. Advantages of High Level Language Based
Development
 Reduced Development Time: High-level language-based firmware development
requires minimal knowledge of the target processor's internal hardware, memory
organization, and registers. The cross-compiler handles the hardware-specific details,
reducing the need for developers to learn assembly instructions, thereby saving time
and effort. This approach makes embedded development more accessible to a broader
range of programmers, not just specialized architects. High-level languages also allow
tasks to be completed with fewer lines of code compared to Assembly, simplifying
development and improving efficiency.
 Developer Independency: The syntax used by most of the high level languages are
universal and a program written in the high level language can easily be understood by a
second person knowing the syntax of the language. Certain instructions may require
little knowledge of the target hardware details like register set, memory map etc. Apart
from these, the high level language based firmware development makes the firmware,
developer independent. High level languages always instruct certain set of rules for
writing the code and commenting the piece of code. If the developer strictly adheres to
the rules, the firmware will be 100% developer independent.
 Portability: High-level language applications are converted to machine code using a
cross-compiler, making them highly portable. With minimal modifications like updating
header files and register definitions, the same code can be recompiled for different
processors, provided the cross-compiler supports them. This flexibility simplifies
adaptation to new hardware with little effort.
2.2. Limitations of High Level Language Based
Development
 High-level languages offer more advantages than their limitations.
 Some cross-compilers may generate non-optimized, inefficient machine
code.
 Manually written Assembly code can achieve the same task with fewer
instructions and better performance.
 More instructions in high-level language increase execution time.
 Modern cross-compilers are improving optimization for code size and
performance.
 High-level languages may not be ideal for precise low-level hardware
access.
 Development tools for high-level languages are more expensive than
Assembly-based tools.
3. Mixing Assembly and High Language
 Certain embedded firmware development situations may demand
the mixing of high-level language with Assembly and vice versa.
High level language and assembly languages are usually mixed in
three ways; namely,
1. Mixing Assembly Language with High Level Language
2. Mixing High Level Language with Assembly
3. In-line Assembly programming.
3.1. Mixing Assembly with High Level Language
Mixing C and Assembly is useful for handling Interrupt Service Routines (ISRs) and precise hardware control.
Mixing ‘C’ and Assembly is little complicated in the sense—the programmer must be aware of how parameters are pass
from the ‘C’ routine to Assembly and values are returned from assembly routine to ‘C’ and how ‘Assembly routine’ is invok
from the ‘C’ code.
Passing parameter to the assembly routine and returning values from the assembly routine to the caller ‘C’ function and t
method of invoking the assembly routine from ‘C’ code is cross compiler dependent
Different cross compilers implement these features in different ways depending on the general-purpose registers and t
memory supported by the target processor/controller.
Let’s examine this by taking Keil C51 cross compiler for 8051 controller. The objective of this example is to give an idea on
how C51 cross compiler performs the mixing of Assembly code with ‘C’.
1.Write a simple function in C that passes parameters and returns values the way you want your assembly routine to.
2. Use the SRC directive (#PRAGMA SRC at the top of the fi le) so that the C compiler generates an .SRC file instead of an
.OBJ fi le.
3. Compile the C file. Since the SRC directive is specified , the .SRC fi le is generated. The .SRC fi le contains the assembly
code generated for the C code you wrote.
4.Rename the .SRC fi le to .A51 fi le.
5. Edit the .A51 fi le and insert the assembly code you want to execute in the body of the assembly function shell included in
the .A51 fi le.
 The special compiler directive SRC generates the Assembly code corresponding to the
‘C’ function and each lines of the source code is converted to the corresponding
Assembly instruction.
 You can easily identify the Assembly code generated for each line of the source code
since it is implicitly mentioned in the generated .SRC fi le.
 By inspecting this code segments, you can find out which registers are used for holding
the variables of the ‘C’ function and you can modify the source code by adding the
assembly routine you want.
3.2. Mixing High Level Language with Assembly
Mixing high-level languages like C with Assembly language can be useful in specific scenarios where
both performance optimization and ease of development are required.
1.Integrating C with Existing Assembly Code:
If a project already has a substantial amount of Assembly code, but certain features or enhancements
need to be added, writing those parts in C can save time and reduce complexity.
Instead of rewriting the entire program in C, developers can write only the necessary functions in C
and integrate them with the Assembly code.
2.Assembly for Performance, C for Complexity
Assembly language is often used in embedded systems for optimized performance, efficient memory
utilization, and fine control over hardware.
However, writing complex logic (e.g., mathematical operations like 16-bit multiplication or division in
an 8051 microcontroller) in Assembly can be tedious and error-prone.
Instead of implementing such complex operations in Assembly, developers can use C for these parts,
making development easier while still maintaining the benefits of Assembly for performance-critical
sections.
3.Using Built-in C Libraries in Assembly
Many cross-compilers provide built-in libraries for common functions like graphics rendering,
string operations, and mathematical calculations.
Instead of implementing these functions from scratch in Assembly, developers can use existing C
libraries, reducing development time and ensuring reliability.
4.Function Calls and Parameter Passing Between C and Assembly
When calling a C function from Assembly or vice versa, understanding how parameters
are passed and results are returned is crucial.
Parameters can be passed using:
CPU registers (e.g., AX, BX in x86)
Stack memory (pushing values onto the stack before calling the function)
Fixed memory locations (predefined memory addresses)
The method of passing parameters and returning values depends on the calling
convention used by the cross-compiler.
Different compilers may handle function calls differently, so developers must refer to the
specific compiler documentation when mixing C and Assembly.
Mixing C and Assembly provides a balance between efficiency (using Assembly for
performance-critical tasks) and ease of development (using C for complex logic).
Understanding how function calls work, how data is passed, and how different compilers
handle these interactions is essential for seamless integration.
 A typical example is given below for the Keil C51 cross compiler
 C51 allows passing of a maximum of three arguments through general purpose
registers R2 to R7. If the three arguments are char variables, they are passed to the
function using registers R7, R6 and R5 respectively.
 If the parameters are int values, they are passed using register pairs (R7, R6), (R5, R4)
and (R3, R2).
 If the number of arguments is greater than three, the first three arguments are passed
through registers and rest is passed through fi xed memory locations.
 Return values are usually passed through general purpose registers. R7 is used for
returning char value and register pair (R7, R6) is used for returning int value. The ‘C’
subroutine can be invoked from the assembly program using the subroutine call
Assembly instruction.

Where Cfunction is a function written in ‘C’. The prefi x _ informs the cross compiler that the
parameters to the function are passed through registers. If the function is invoked without
the _ prefix, it is understood that the parameters are passed through fi xed memory
locations.
Up to three arguments are passed in registers (R7–R2).
If arguments exceed three, the rest are stored in memory.
Return values are stored in R7 (char) or (R7, R6) (int).
Use LCALL _Function Name in Assembly to call a C function.
The _ prefix ensures register-based parameter passing; while omitting it uses
memory instead.
This method improves performance by minimizing memory access and making
function calls more efficient.
3.3 Inline Assembly
1. Definition of Inline Assembly
Inline assembly is another technique for inserting target processor/controller specific Assembly
instructions at any location of a source code written in high level language ‘C’.
Inline assembly allows embedding assembly instructions directly within a C program.
This is useful when we need to write processor-specific instructions while still keeping most of the
code in C.
This approach is different from calling an external assembly function; here, the assembly code is
inserted inside the C code itself.
2. Avoiding Function Call Overhead:
This avoids the delay in calling an assembly routine from a ‘C’ code (If the Assembly instructions to
be inserted are put in a subroutine as mentioned in the section mixing assembly with ‘C’)."
Normally, calling an assembly function from C requires a function call, which introduces:
Stack operations (pushing and popping parameters).
Context switching (saving and restoring registers).
Inline assembly avoids this overhead by placing assembly instructions directly inside the C function,
making execution faster.
 3. Using Special Keywords for Inline Assembly
• Special keywords are used to indicate the start and end of Assembly instructions.
• Inline assembly requires special keywords to define the start and end of the assembly block inside
a C program.
• These keywords tell the compiler that the enclosed statements should be treated as assembly code
rather than C code.
 The keywords are cross-compiler specific. C51 uses the keywords #pragma asm and
#pragma endasm to indicate a block of code written in assembly.

The method for mixing Assembly with C varies across different cross-compilers.
Users should refer to their specific cross-compiler documentation for proper
implementation

You might also like