BCS402 MODULE 4 Notes
BCS402 MODULE 4 Notes
BCS402 MODULE 4 Notes
Introduction
Data Abort
Fast Interrupt Request
Interrupt Request
Prefetch Abort
Software Interrupt
Reset
Undefined Instruction
(Explain the concept of exception priorities in ARM processors, as detailed in handling exceptions.
Describe the priority mechanism employed by ARM processors for managing simultaneous exceptions )
Handling Exceptions in ARM Processors:
In ARM microcontrollers, the link register (lr) is a special register that holds the return
address for function calls and exceptions.
When an exception (like an IRQ - Interrupt Request) occurs, the processor saves the
address of the instruction that was being executed into the link register (lr).
For example, if the exception happened at instruction address 0x1000, lr would typically
hold 0x1008 (current instruction address + 8 bytes).
Avoiding Corruption:
It's critical not to overwrite or corrupt the link register (lr) when handling exceptions
because it's needed to return to where the main program execution should continue after
handling the exception.
When an IRQ exception is handled, the processor ensures that after the exception handler
finishes, it returns to the instruction immediately following the one that was interrupted.
Therefore, lr should be set to (current lr value - 4) to ensure it points to the correct return
address.
Table 9.4:
This table (which would be provided in ARM documentation or reference manuals) lists
important addresses and offsets related to different types of exceptions. It helps
developers understand how to manage return addresses correctly during exception
handling.
After an exception handler (like an IRQ handler) finishes its job, it must set lr to the
appropriate value to resume execution correctly.
Typically, for IRQs, lr is set to (current lr value - 4) to point to the next instruction after
the interrupted one.
ARM microcontrollers (MCUs) often use interrupts to handle events asynchronously. When
an interrupt occurs, the processor stops its current execution, saves its current state, and
jumps to an Interrupt Service Routine (ISR) to handle the interrupt. After handling the
interrupt, it needs to return to the interrupted task. This example illustrates how that return
process typically works in ARM assembly language.
Example 9.2 This example shows that a typical method of returning from an IRQ and FIQ
handler is to use a SUBS instruction:
handler
<handler code>
...
Interrupt Handling: When an interrupt occurs, the microcontroller saves where it was
interrupted (in the lr register) and starts running the ISR code.
Returning from ISR: To go back to the interrupted task, the ISR uses SUBS pc, lr, #4. This
instruction subtracts 4 from the lr register and sets the Program Counter (pc) to this new value.
Automatic Restoration: The SUBS instruction also restores important flags that tell the
microcontroller's processor about its current state (CPSR), ensuring everything continues
smoothly.
Example 9.3 This example shows another method that subtracts the offset from the link register
r14 at the beginning of the handler.
9.2 Interrupts
Types of Interrupts on ARM Processors
Interrupt Effects
Interrupts Suspend Normal Program Flow: When an interrupt occurs, the ARM
processor temporarily stops executing its current task and jumps to handle the interrupt.
This is to quickly respond to external events or software requests.
In this section we will focus mainly on IRQ and FIQ interrupts. We will cover these topics:
■ Assigning interrupts
■ Interrupt latency
System Design Choice: Designers choose which hardware devices can trigger which types of
interrupts, using either hardware, software, or a combination. This decision depends on the
specific embedded system requirements.
Standard Practice:
Software Interrupts (SWI): Reserved for calling privileged operating system routines,
like switching program modes.
Interrupt Requests (IRQ): Typically used for general-purpose interrupts, such as
periodic timers. IRQs have lower priority and slightly longer latency compared to FIQs.
Fast Interrupt Requests (FIQ): Dedicated to urgent tasks needing immediate
processing, like memory block transfers. FIQs are used for specific applications, freeing
IRQs for broader system operations in embedded designs.
Interrupt Latency
(Explain the concept of interrupt latency in embedded systems. Describe factors that contribute to
interrupt latency and techniques to minimize it.)
Definition: Interrupt latency is the time from when an external interrupt signal is raised
to when the processor starts executing the specific Interrupt Service Routine (ISR) code.
Importance: Minimizing interrupt latency is crucial because delays can lead to slower
system response times, impacting overall system performance.
(Describe IRQ (Interrupt Request) and FIQ (Fast Interrupt Request) exceptions in ARM microcontrollers. )
Triggering Conditions: IRQ and FIQ exceptions occur when their respective interrupt
masks are cleared in the Current Program Status Register (CPSR), allowing interrupts of
that type to be processed.
Execution Stage Consideration: Before handling the interrupt, the ARM processor
completes the current instruction in its execution stage. This ensures determinism in
interrupt handling, especially for instructions that require multiple cycles to complete.
Standard Procedure for IRQ and FIQ Exceptions:
1. Mode Change: The processor switches to a specific interrupt request mode
corresponding to the type of interrupt raised (IRQ or FIQ).
2. Saving State:
The CPSR of the previous mode is saved into the Saved Program Status
Register (SPSR) of the new interrupt request mode.
The Program Counter (PC) value is saved into the Link Register (LR) of
the new mode.
3. Disabling Interrupts: IRQ or both IRQ and FIQ exceptions are disabled in the
CPSR. This prevents another interrupt of the same type from interrupting the
current handler.
4. Branch to Vector Table: The processor jumps to a specific entry in the vector
table, which contains addresses of interrupt service routines corresponding to
different interrupt types.
Variations in Procedure: The exact handling varies slightly between IRQ and FIQ
exceptions due to their different characteristics and priorities.
(Explain the process of enabling and disabling FIQ (Fast Interrupt Request) and IRQ (Interrupt Request)
exceptions on ARM microcontrollers.)
The ARM processor core has a simple procedure to manually enable and disable
interrupts that involves modifying the cpsr when the processor is in a privileged mode.
Table 9.5 shows how IRQ and FIQ interrupts are enabled. The procedure uses three ARM
instructions. The first instruction MRS copies the contents of the cpsr into register r1.
The second instruction clears the IRQ or FIQ mask bit. The third instruction then copies
the updated contents in registerr1 back into the cpsr, enabling the interrupt request.
Disabling or Masking IRQ and FIQ Exceptions
(Explain the fundamental considerations in designing and implementing interrupt stacks for ARM
microcontrollers.)
Interrupt Stack Basics: Interrupts and exceptions in ARM microcontrollers use dedicated
stacks. Each mode (like IRQ) has its own stack pointer register for efficient context switching.
Operating System Requirements: Different operating systems have specific needs for
how stacks are organized and managed.
Target Hardware: Physical memory limits dictate where stacks can be located and their
maximum size.
Design Decisions:
Location: Typically, stacks grow downwards in memory. This ensures efficient use of
memory and clear boundaries between different memory regions.
Size: The stack size depends on whether the system needs to handle nested interrupts
(where interrupts can occur while another interrupt is being processed). More complex
interrupt handling requires larger stacks.
Avoiding Stack Overflow: Stack overflow occurs when the stack extends beyond its
allocated memory, leading to system instability. Techniques to prevent this include:
IRQ Mode Stack Setup: Before enabling interrupts, the IRQ mode stack must be properly
configured. During system initialization, the maximum stack size should be determined to ensure
sufficient memory allocation.
Layout A: Traditional stack layout places the interrupt stack below the code segment.
This can risk overwriting critical data if the stack overflows.
Layout B: In this layout, the interrupt stack is positioned at the top of memory, above the
user stack. This design prevents critical system data corruption in case of a stack
overflow and allows the system to recover more effectively.
Firmware
Firmware is crucial for embedded systems as it's often the first code to run on a
new platform. It can range from a full software system to basic startup and
bootloader functions.
ARM has developed a firmware package called the ARM Firmware Suite (AFS).
AFS is designed purely for ARM-based embedded systems. It provides support for a
number of boards and processors including the Intel XScale and StrongARM processors.
The package includes two major pieces of technology, a Hardware Abstraction Layer called
μHAL (pronounced micro-HAL) and a debug monitor called Angel.
μHAL provides a low-level device driver framework that allows it to operate over different
communication devices (for example, USB, Ethernet, or serial).
The speed of this activity depends upon whether the OS takes advantage of the ported μHAL
API call to access the hardware. μHAL supports these main features:
The second technology, Angel, allows communication between a host debugger and a
target platform.
It allows to inspect and modify memory, download and execute images, set breakpoints,
and display processor register contents.
All this control is through the host debugger.
The Angel debug monitor must have access to the SWI and IRQ or FIQ vectors.
Angel uses SWI instructions to provides a set of APIs that allow a program to open, read,
and write to a host filing system.
IRQ/FIQ interrupts are used for communication purposes with the host debugger.
RedBoot is a firmware tool developed by Red Hat. It is provided under an open source license
with no royalties or upfront fees. RedBoot is designed to execute on different CPUs (for
instance, ARM, MIPS, SH, and so on). It provides both debug capability through GNU
Debugger (GDB), as well as a bootloader. The RedBoot software core is based on a HAL.
RedBoot supports these main features:
Communication—configuration is over serial or Ethernet. For serial, X-Modem protocol
is used to communicate with the GNU Debugger (GDB). For Ethernet, TCP is used to
communicate with GDB. RedBoot supports a range of network standards, such as bootp,
telnet, and tftp.
Flash ROM memory management—provides a set of filing system routines that can
download, update, and erase images in flash ROM. In addition, the images can either be
compressed or uncompressed.
Full operating system support—supports the loading and booting of Embedded Linux,
Red Hat eCos, and many other popular operating systems. For Embedded Linux,
RedBoot supports the ability to define parameters that are passed directly to the kernel
upon booting.
10.2 Example: Sandstone
Sandstone is a basic system designed for the ARM Evaluator-7T platform, which uses an
ARM7TDMI processor. Its main tasks are setting up the platform environment, loading a
bootable image into memory, and starting the operating system.
It demonstrates how to initialize a simple platform and boot software like applications or
operating system images.
Sandstone is fixed after it's built and uses ARM assembler for its code. It provides a
structured directory layout for source code and build files and focuses on initializing and
booting processes.
Feature Configuration: Sandstone only supports ARM instructions for its code. This means it
is written exclusively using instructions that the ARM processor can execute.
Tool chain: Sandstone is built using the ARM Developer Suite 1.2. This tool chain includes
the necessary software tools (like compilers, assemblers, linkers, etc.) needed to develop
software for ARM processors.
Image size: The size of the bootable image generated by Sandstone is 700 bytes. This
indicates how much space the initial program that Sandstone loads into memory occupies.
Source: The total size of the source code for Sandstone is 17 KB (Kilobytes). This includes all
the files and lines of code that make up the system.
Memory remapped: This likely refers to the process within Sandstone where it reconfigures
memory mappings. Memory remapping can involve changing how physical memory addresses
are mapped to virtual addresses, which can be crucial for efficiently utilizing memory resources
or handling specific hardware configurations.
Location: sand/build/src/sand.s
Description: This file contains the source code of Sandstone written in ARM assembler.
Location: sand/build/obj/
Description: After compiling the sand.s source file, the assembler produces an object
file which is stored in this directory.
Location: sand/build/image/
Description: This directory houses the final executable or image file of Sandstone. It
includes both the compiled Sandstone code and the payload.
Payload Image:
Location: sand/payload/
Description: The payload image, which is the software loaded and executed by
Sandstone, is stored in this directory.
Reference: sand/readme.txt
Description: The readme.txt file located in the sand directory provides detailed
instructions on how to build the example binary image for the ARM Evaluator-7T using
Sandstone. It includes information on compiling, linking, and configuring the build
environment.