Embedded Design Handbook

ID 683689
Date 8/28/2023
Public
Document Table of Contents

7.5.9.1. Timer Memory

The timer_memory_section.tcl script is located in the bsp/timer_hal directory. This Tcl script reserves 2048 bytes of the tightly coupled instruction memory. The reserved space is used to store the timer interrupt service routines.

The timer_memory_section.tcl script takes the tightly_coupled_instruction memory region and separates out 2048 bytes of the memory region into a new region called timer_isr_region. The next line of code adds a section mapping the .isrs section to the timer_isr_region.

# Create tightly_coupled_memory region.
add_memory_region tightly_coupled_instruction_memory $slave $offset $new_span
# Create a second region called timer_isr memory_region.
add_memory_region timer_isrs_region $slave $split_offset $split_span
# Create memory mapping to map .isrs to timer_isrs_region.
add_section_mapping .isrs timer_isrs_region

The timer_interrupt_latency.h file is also updated to reflect the change in the section mapping of the timer_interrupt_latency_irq() timer interrupt service routine to .isrs instead of .exceptions. The timer interrupt service routines are now stored in the timer_isr_region.

The interrupt service routines must be located in the new .isrs section. Otherwise, the linker uses the default setting, defeating the purpose of declaring a special memory section for the interrupt service routine.

To locate the interrupt service routines in the new .isrs section, complete the following steps:

  1. Add a section mapping to map the .isrs section to the newly added memory region.
  2. Edit your source files to ensure the interrupt service routines are mapped to the new memory section.
  3. Compile your project files and check the linker.x and tcm_isr.objdump files to ensure that the section mapping and memory regions are declared correctly and contain the interrupt service routine.
Note: For more information about linker memory regions, refer to the Nios® II Software Build Tools chapter in the Nios® II Software Developer’s Handbook.