0% found this document useful (0 votes)
5 views9 pages

Unit 2

The document discusses firmware design approaches for embedded products, focusing on Conventional Procedural Based Design and Embedded Operating System Based Design. It outlines the execution flow, advantages and disadvantages of using Assembly and High-Level Languages, and the concept of interrupts in embedded systems. Additionally, it differentiates between C and Embedded C, and explains the role of compilers and cross-compilers in embedded firmware development.

Uploaded by

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

Unit 2

The document discusses firmware design approaches for embedded products, focusing on Conventional Procedural Based Design and Embedded Operating System Based Design. It outlines the execution flow, advantages and disadvantages of using Assembly and High-Level Languages, and the concept of interrupts in embedded systems. Additionally, it differentiates between C and Embedded C, and explains the role of compilers and cross-compilers in embedded firmware development.

Uploaded by

21012ec045
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

UNIT –

Embedded Firm ware design

Firm Ware design approaches for embedded product is purely dependent on complexity
of functions to be performed, speed of operation required. Two approaches are used for
Embedded Firm Ware design :
1) Conventional Procedural Based Firmware Design (also known as Super Loop
Model)
2 )Embedded Operating System Based Design
Firm ware execution flow is:
1. Configure the common parameters and perform initialisation for various H/W
components memory, registers, etc.
2. Start the first task and execute it
3. Execute the second task
4. Execute the next task
5. ….
6. ….
7. Execute the last defined task
8. Jump back to the first task and follow the same flow
Operation is an infinite loop based approach:
Void main ()
{
Configurations ();
Initializations ();
While (1)
{
Task 1();
Task 2 ();


Task n ();
}
}
As tasks are running inside an infinite loop the only way to come out of the loop is by either a
hardware reset or an interrupt assertion. It doesn’t require OS since there is no need for
scheduling which task is to be executed and assigning priority to each task. Example Card
reader, video game toy containing keypad and display unit.
Drawback:
1. Failure in any part of a single task will effect the total system. Watch dog timers helps in
coming out from the oloop when unexpected failure occurs or processor hangs up.
2. Lack of real timelines. If number of tasks to be executed within an application increases
time at which each task is repeated also increases.
Embedded Operating System Based Design:
Embedded Operating System Based Design contains OS , which can be a GPOS or
RTOS .Examples of Embedded products using Microsoft Windows XP OS are PDAs, hand held
devices/portable devices .OS based applications requires Driver Software for different H/W
present on the board to communicate with [Link] respond in a timely and predictable
manner to events .Windows CE, pSOS, VxWorks, ThreadX, Embedded Linux, Symbian are
examples of RTOS. Mobile phones, PDAs, hand held devices etc. using RTOS.
Embedded Firmware development Languages:
Embedded products use either A target Processor/Controller specific language( assembly or low
level language) Or A target Processor/Controller independent language ( C,C++, JAVA, etc.
high level language) Or A combination of Assembly and High level language.

Assembly Language based Development:


Assembly language is the human readable notation of machine language where as machine
language is a processor understandable language.
“Assembly language programming is the task of writing processor specific machine code in
mnemonic form , converting the mnemonics into actual processor instructions using an
assembler”
Embedded products use either A target Processor/Controller specific language( assembly or low
level language) Or A target Processor/Controller independent language ( C,C++, JAVA, etc.
high level language) Or A combination of Assembly and High level language.
Assembly language instruction format is Opcode followed by [Link] A, #30 it
moves decimal value 30 to8051 accumulator register. Here Mov A is Opcode and 30 is operand.
Same instruction written in machine language is 01110100 00011110Each line of an assembly
language is split into four fields as LABEL OPCODE,OPERAND,[Link]
language program written in assembly code is saved as .asm or .src file.

Advantages of Assembly Language based Development:


1. Efficient Code Memory and Data Memory Usage(Memory Optimization)
2. High Performance
3. Low Level Hardware Access
4. Code Reverse Engineering
Disadvantages of Assembly Language based Development:
1. High Development Time
2. Developer Dependency
3. Non -Portable

High Level Language based Development:


Most commonly used high level language for Embedded firmware application
development is ‘C’.Steps involved in High Level Language based Development is same as
Assembly Language based Development except that conversion of source file written in High
Level Language is done by a cross-compiler where as Assembly Language based Development
is carried out by [Link] –Compiler for different high level languages for the same
target processor are different

Advantages of High Level Language based Development:


1. Reduced Development Time
2. Developer Independency
3. Portability
Disadvantages of High Level Language based Development:
Some Cross-Compilers available for High Level Language based design may not
be sufficient In generating optimized target processor specific [Link] required
for High Level Language based tools is high.
Mixing Assembly and High Level Language:
Assembly and High Level Languages are usually mixed in three ways namely
1. Mixing Assembly Language with High Level Language
2. Mixing High Level Language with Assembly Language
3. In –Line Assembly Programming
Mixing Assembly Language with High Level Language:
An idea how C51 Cross-Compiler performs the mixing of Assembly code with ‘C’
1. Write a simple function in C that passes parameters & returns values the way you want
your assembly routine to.
2. Use SRC directive so that C compiler generates an .SRC file instead of an .OBJ file
3. Compile C [Link] file contains assembly code generated for C code.
4. Rename .SRC file to .A51 file
5. Edit .A51 file and insert the assembly code
Inline Assembly Language Programming:
Inline Assembly language is a technique for inserting target processor/controller
specific assembly instructions at any location of a source code written in high level language ‘C’.
So it avoids the delay in calling an assembly routine from a ‘C’ [Link] key words are used
to indicate start and end of assembly instructions.
#pragma asm and #pragma endasm are used to indicate a block of code

Interrupt Concept:
Interrupt means event, which invites attention of the processor on occurrence of some
action at hardware or software interrupt instruction event
Action on Interrupt: In response to the interrupt, the routine or program, which is running
presently interrupts and an interrupt service routine (ISR) executes.
Interrupt Service Routine: ISR is also called device driver in case of the devices and called
exception or signal or trap handler in case of software interrupts
Interrupt approach for the port or device functions:
Processor executes the program, called interrupt service routine or signal handler or trap
handler or exception handler or device driver, related to input or output from the port or device
or related to a device function on an interrupt and does not wait and look for the input ready or
output completion or device-status ready or set
Hardware interrupt:
When a device or port is ready, a device or port generates an interrupt, or when it
completes the assigned action or when a timer overflows or when a time at the timer equals a
preset time in a compare register or on setting a status flag ( timer overflow or compare or
capture of time) Hardware interrupt generates call to an ISR
An automatic chocolate vending machine (ACVM)
Without interrupt mechanism, one way is the programmed I/O- transfer in which that
the device waits for the coin continuously, activates on sensing the coin and runs the service
routine.
In the event driven way is that the device should also awakens and activates on each
interrupt after sensing each coin-inserting event.

Mobile phone system


When reset key is pressed resets the system to an initial state. When the reset key is
pressed the system awakens and activates a reset interrupt through a hardware signal from the
reset key. On the interrupt, an ISR suspends all activity of the system, sends signal to display
function for displaying the initial reset state menu and graphics on the LCD screen, and also
activates LCD display-off timer device for 15 s timeout.
The system again awakens and activates on interrupt through internal hardware signal
from the timer device and runs another ISR to send a control bit to the LCD device. The ISR
Routine is the device-driver LCD off-function for the LCD device. The devices switches off by
reset of a control bit in it.
Hardware device sources of interrupts:
Hardware sources can be internal or external for interrupt of on-going routine and
thereby diversion to corresponding ISR. The internal sources from devices differ in different
processor or microcontroller or device and their versions and families. External sources and ports
also differ in different processors or microcontrollers
Internal Hardware Device Sources:
1. Parallel Port
2. UART Serial Receiver Port
3. Synchronous Receiver byte Completion
4. UART Serial Transmit Port-Transmission Complete
5. Synchronous Transmission of byte completed
6. ADC Start of Conversion
7. ADC End of Conversion
8. Pulse-Accumulator overflow
9. Real Time Clock time-outs
10. Watchdog Timer Reset
11. Timer Overflow on time-out
12. Timer comparison with Output compare Registers
13. Timer capture on inputs
External hardware related interrupt at INTR Pin in 80x86 processor:
When INTR pin activates on an interrupt from the external device, processor issues two
cycles of acknowledgements in two clock cycles through INTA (interrupt acknowledgement)
pin.
During the second cycle of acknowledgement, the external device sends the type of interrupt
information on data bus. Information is for one byte for n. 80x86 actions is execution as per
action on software instruction INT n,
Software Interrupt:
When software run-time exception condition (division by 0 or overflow or illegal
Opcode detected) the processor-hardware generates an interrupt, called trap, which calls an ISR
When software run-time exception condition defined in a program occurs, then a software
instruction (SWI) is executed─ called software interrupt or exception or signal, which calls an
ISR .When a device function is to be invoked, for example, open (initialize/configure) or read or
write or close , then a software instruction (SWI) is executed─ called software interrupt to
execute the required device driver function for open or read or write or close operations.
Sources of interrupts due to Processor Hardware detecting Software error:
Software sources for interrupt are related to processor detecting computational error
during execution such as division by 0, illegal Opcode or overflow (for example, multiplication
of two numbers exceeding the limit)
Software error Related Sources:
1. Division by zero detection (or trap) by hardware
2. Over-flow detection by hardware
3. Under-flow detection by hardware
4. Illegal Opcode detection by hardware
Examples of Software error exception or trap related sources:
Division by zero (also known as type 0 interrupt as it is also generated by and software interrupt
instruction INT 0 instruction in 80x86). Overflow (also known as type 2 interrupt as it is also
generated by INT 2 instruction) in 80x86. These two interrupts, type 0 and 2 generated by the
hardware with the ALU part of the processor.
Software Interrupt by a software instruction:
Software interrupt is interrupt-generated by a software instruction Int n in 80x86 processor or
SWI m in ARM7, where n is interrupt type and m is 24 bits related to ISR address pointer and
ISR input parameters pointer
Steps on interrupt of type n or on Software Instruction INT n in 80x86:
1. INT n means executes interrupt of type n
2. n can be between 0 and 255.
3. INT n causes the processor vectoring to address 0x00004 × n for finding IP and CS
registers values for diversion to the ISR.
Software Instruction Related Interrupts Sources:
Handling of –ve number square root throws an exception, that means executes an SWI, which is
handled by SWI instruction SWI n in the instruction set of a processor
Software interrupt instructions:
Software instructions are also used for trapping some run-time error conditions (called
throwing exceptions) and executing exceptional handlers on catching the exceptions.
Examples:
1. Instruction, SWI in 68HC11.
2. Single byte instruction INT0 in 80x86. It generates type 0 interrupt
3. Type 0 interrupt means generation of interrupt with corresponding vector address
0x00000.
4. Instead of the type 0 interrupt by instruction, 8086 and 80x86 hardware may also
generate interrupt on a division by zero.
5. Single byte 8086 and 80x86 instruction TYPE3 (corresponding vector address
0x00C0H). This generates an interrupt of type 3, called break point interrupt.
6. Break point interrupt instruction is like a PAUSE instruction.
7. PAUSE─ a temporary stoppage of a running program enables a program to do some
housekeeping, and then return back to instruction after the break point by pressing any
key.
DIFFERENCE BETWEEN C AND EMBEDDED C:
1. C is used for desktop computers, while embedded C is for microcontroller based
applications.
2. C has the luxury to use resources of a desktop PC like memory, OS, etc. While
programming on desktop systems, we need not bother about memory.
3. Embedded C has to use with the limited resources (RAM, ROM, I/Os) on an embedded
processor. Thus, program code must fit into the available program memory. If code
exceeds the limit, the system is likely to crash.
4. Compilers for C (ANSI C) typically generate OS dependant executables.
5. Embedded C requires compilers to create files to be downloaded to the
microcontrollers/microprocessors where it needs to run. Embedded compilers give access
to all resources which is not provided in compilers for desktop computer applications.
6. Embedded systems often have the real-time constraints, which is usually not there with
desktop computer applications.
7. Embedded systems often do not have a console, which is available in case of desktop
8. For embedded applications, we need to optimally use the resources, make the program
code efficient, and satisfy real time constraints, if any. All this is done using the basic
constructs, syntaxes, and function libraries of ‘C’.
Compiler Vs. Cross Compiler:
1. Compiler is a S/W tool that converts a source code written in high level language for a
particular OS running on a specific target processor architecture.
2. Source code is converted to the target processor specific machine instructions.
3. Development is platform specific
4. Termed as Native Compilers
5. Cross compilers are the S/W tools used in cross-platform applications.
6. Here compiler running on a target processor /OS converts the source ode to machine
code for a target processor whose architecture and instruction set is different from the
processor on which the compiler is running
INTERRUPTS SERVICE MECHANISM:
Interrupt Latency: A period between occurrence of an interrupt and start of execution of the
ISR. The time taken in context switching is also included in a period, called interrupt latency
period, lat.
Minimum Interrupt-latency period: Tlat, is the sum of the periods as follows. Time to be
taken is for the response and initiating the ISR instructions. This includes the time to save or
switch the context (including the program counter and registers) plus the time to restore its
context.
For example, in the ARM7 processor, this period equals two clock cycles plus zero to twenty
clock cycles for finishing an ongoing instruction plus zero to three cycles for aborting the data.

Common questions

Powered by AI

Implementing embedded systems using high-level languages presents challenges such as potentially inefficient conversion of source code to target-specific machine instructions, as high-level code is often less optimized compared to assembly language. This inefficiency can be compounded by the limitations of some cross-compilers in generating optimized processor-specific instructions . Additionally, high-level tools may require significant investment, and the systems often have real-time constraints that are more challenging to meet with high-level abstractions . These challenges can be mitigated by combining high-level language development with inline assembly for performance-critical sections and selecting robust cross-compilers known for producing efficient machine code. Optimizing code and carefully managing resources within the high-level language can also help address these issues .

Hardware interrupts are triggered by external or internal events within a hardware component, such as a timer overflow or the arrival of new data on a serial port. These interrupts signal the processor to execute an ISR associated with specific hardware tasks, like managing the state of a peripheral device. For instance, in an automatic chocolate vending machine, a hardware interrupt might occur when a coin is inserted, prompting the system to activate the product dispense mechanism . Software interrupts, conversely, are initiated by software events, such as exceptions or special instructions. These are used often to handle computational errors like division by zero or to invoke system-level functions during program execution. For example, an SWI (Software Interrupt) instruction might be used in an ARM processor to handle an exception thrown by a runtime error such as illegal Opcode detection .

The interrupt latency period is critical in embedded systems because it represents the time delay between the occurrence of an interrupt and the start of execution of the relevant Interrupt Service Routine (ISR). This time is important for applications requiring real-time processing where minimizing delay is crucial for maintaining system performance and ensuring predictable responses to events. It is calculated as the sum of the time taken to save or switch the context, including program counter and registers, plus the time taken to restore the context and start executing the ISR . For example, in an ARM7 processor, this period includes two clock cycles plus additional cycles for completing ongoing instructions and managing data aborting, which could total up to 25 clock cycles .

Watch dog timers play a critical role in conventional procedural based firmware designs by providing a mechanism to recover from unanticipated system failures, such as a task hanging due to an error. These timers help mitigate the drawback of the super loop model, where failure in a single task could impact the entire system. A watch dog timer is programmed to reset the system if the normal execution flow is not maintained, essentially serving as a fail-safe that prompts the system to reboot and restore to a known good state in case of software anomalies or infinite loops . This ensures the system remains operational and can recover automatically from faults without requiring external intervention .

Interrupt-driven programming is preferred in embedded systems because it allows the processor to respond to events as they occur, rather than polling for signals continuously, which improves system efficiency and responsiveness. Interrupt Service Routines (ISRs) play a crucial role as they are executed in response to interrupts. When an interrupt occurs, the processor suspends the current task and executes the ISR specific to that interrupt, which processes the event and manages the device requiring attention . This mechanism enables the system to handle asynchronous events like hardware signals or software exceptions efficiently, minimizing latency and optimizing resource use .

The main differences between Conventional Procedural Based Firmware Design, also known as the Super Loop Model, and Embedded Operating System Based Design revolve around task management and the need for scheduling. In the Conventional Procedural Based Design, tasks are executed in an infinite loop without any need for an operating system since tasks are managed sequentially; there is no scheduling involved, and the loop continues unless interrupted by a hardware reset or interrupt assertion . This approach is suitable for simple applications like card readers or video games with keypads. However, if a task fails, it affects the entire system, and real-time constraints may be difficult to manage as the number of tasks increases . On the other hand, Embedded Operating System Based Design incorporates an OS (either GPOS or RTOS), which manages tasks by scheduling them and assigning priorities. This is essential in systems that require timely and predictable responses, such as PDAs and mobile phones using RTOS .

Mixing assembly language with high-level language in embedded firmware development combines the efficiency and low-level access of assembly with the ease of use and portability of high-level languages like C. This approach can optimize performance by using assembly for critical sections of code and high-level language for more complex logic. Typical methods of implementation include writing a function in C, compiling it to generate an assembly code (.SRC file), and then inserting custom assembly code into it before final compilation . Inline assembly allows embedding assembly instructions directly within a C code block using specific pragmas like #pragma asm and #pragma endasm, providing precise control without the overhead of function calls .

The use of real-time operating systems (RTOS) in embedded systems enhances functionality by providing deterministic scheduling and real-time task management that meets stringent timing requirements. Unlike systems without an OS, where tasks execute serially in a loop, an RTOS allows for concurrent task execution with defined priorities, improving system responsiveness and efficiency. An RTOS can handle time-sensitive events predictably, which is essential in devices like mobile phones and PDAs requiring reliable operation and multitasking . Additionally, RTOS supports synchronized inter-process communication and resource management, reducing system complexity by abstracting the intricate handling of hardware interactions and task scheduling .

Using assembly language in embedded firmware development offers several advantages and disadvantages. Advantages include efficient use of code and data memory, high performance, and low-level hardware access, which are crucial for optimizing embedded systems with limited resources . Code written in assembly can be highly optimized for speed and size, which is beneficial for performance-critical tasks. However, there are significant disadvantages. Development time is longer due to the complexity of writing in assembly, and the developer is more dependent on the specific knowledge of the processor architecture. Assembly code is also non-portable across different architectures, making software maintenance and updates more challenging .

Cross compilers differ from native compilers in that they generate executable code for a different processor architecture than the one they run on. In embedded system development, this is particularly important because the development environment typically uses a powerful host system to write and compile code, which is then executed on a different, often resource-constrained, target processor . Native compilers create code for the same architecture and OS they are running on, suitable for desktop applications, whereas cross compilers facilitate developing applications for embedded platforms where the development and target environments differ significantly .

You might also like