NetBurner 3.5.7
PDF Version
Timers

Topics

 High Resolution Delay Timer
 High-precision microsecond delay functionality.
 
 Interval Timer
 
 Stopwatch Timer
 

Detailed Description

Hardware based high resolution timers:

Timer API Hardware Reference

Overview

NetBurner provides three hardware timer APIs:

API Header Purpose
HiResDelay (DelayObject) HiResDelay.h Blocking microsecond-precision delays
IntervalTimer IntervalTimer.h Periodic callbacks, semaphore posts, or flag sets
StopWatch stopwatch.h High-resolution elapsed time measurement

Each API allocates timers from the underlying CPU's hardware timer peripherals. The number of available timers and the specific hardware used varies by CPU family. This document maps each platform to its timer hardware and documents resource limits.

Platform-to-CPU Mapping

Platform CPU Architecture Timer Hardware
MOD5441X MCF5441X ColdFire DMA Timers + PIT Timers
NANO54415 MCF5441X ColdFire DMA Timers + PIT Timers
SB800EX MCF5441X ColdFire DMA Timers + PIT Timers
MODM7AE70 SAME70 Cortex-M7 TC (Timer Counter) Channels
SBE70LC SAME70 Cortex-M7 TC Channels
SOMRT1061 MIMXRT10xx Cortex-M7 Quad Timers (QTimer)
MODRT1171 MIMXRT11xx Cortex-M7 Quad Timers (QTimer)

Timer Availability Summary

CPU Family HiResDelay Pool IntervalTimer Pool StopWatch Source Total HW Timers
MCF5441X 4 DMA timers (shared with StopWatch) 2 PIT timers (PIT 1-2) 1 DMA timer (shared from same 4) 4 DMA + 4 PIT
SAME70 12 TC channels (shared pool) 12 TC channels (shared pool) SysTick (no timer consumed) 12 TC
MIMXRT10xx 12 QTimer channels (shared pool) 12 QTimer channels (shared pool) System QTimer pair (no user timer consumed) 12 QTimer
MIMXRT11xx 12 QTimer channels (shared pool) 12 QTimer channels System QTimer pair (no user timer consumed) 12 QTimer

System-Reserved Timers

Each CPU reserves certain timer hardware for the RTOS system tick. These timers are not available to user code and are already excluded from the timer API allocation pools.

CPU Reserved Hardware Purpose Configured In
MCF5441X PIT 0 RTOS system tick (OSTickISR) platform/*/source/hal.cpp via sim2.pit[0]
1 PIT 3 Debugger Reserved by convention
SAME70 ARM SysTick RTOS system tick (SysTick_Handler) platform/*/source/hal.cpp via SysTick_Config()
MIMXRT10xx/11xx TMR4 channels 2-3 RTOS system tick (SysTick_Handler) platform/*/source/hal.cpp via SysTmrLo/SysTmrHi on TMR4

Key points**:


Platforms**: MOD5441X, NANO54415, SB800EX

The 1 has 4 DMA timers (DMA Timer 0-3), accessed through sim2.timer[0..3]. These are 32-bit free-running timers clocked at CPU_CLOCK / 2 (~75 MHz at 150 MHz CPU clock).

The 1 has 4 PIT (Programmable Interrupt Timer) modules. PIT 0 is reserved for the RTOS system tick, and PIT 3 is reserved for the debugger. PIT 1 and PIT 2 are available for application IntervalTimer use.


Platforms**: 1, SBE70LC

The SAME70 has 4 TC blocks (TC0-TC3), each with 3 channels, totaling 12 TC channels (timers 0-11). These are managed by a unified dispatch system (timer_dispatch.cpp) with a 16-bit timerInUse bitmask.

Each option is evaluated with ClockCheck() and the best-fit is chosen. The 16-bit compare register limits the maximum divider per clock source to 65535.

Clock (HiResDelay)**: Uses TC_CMR_TCCLKS_TIMER_CLOCK2 (PERIPH_CLOCK / 8). At 300 MHz CPU, PERIPH_CLOCK is typically 150 MHz, giving 18.75 MHz timer clock (75/4 ticks per microsecond).

Short-delay busy-wait**: Delays <= 20 us use a calibrated busy-wait loop (magic number 55).

Max single HiResDelay**: ~3400 us per hardware delay cycle (16-bit compare register at 18.75 MHz). Longer delays are handled by chaining multiple 3001 us delays.

StopWatch on SAME70 uses the ARM SysTick timer, which is already running for the RTOS tick. No additional hardware timer is consumed.


Platforms**: 1

The MIMXRT10xx has 3 QTimer modules (TMR1[0..2]), each with 4 channels, totaling 12 QTimer channels (timers 0-11). HiResDelay and IntervalTimer share this pool.

StopWatch on MIMXRT10xx uses a pre-allocated linked QTimer pair (SysTmrLo / SysTmrHi) that is already set up by the HAL for system timekeeping. No user QTimer channel is consumed.


Platforms**: MODRT1171

The MIMXRT11xx has the same 3 QTimer modules x 4 channels = 12 QTimer channels as MIMXRT10xx. The IntervalTimer implementation is structurally identical to MIMXRT10xx.

Key difference from MIMXRT10xx**: The MIMXRT11xx IntervalTimer.cpp does not include the DelayObject (HiResDelay) implementation. There is no separate HiResDelay.cpp for this CPU. HiResDelay is not available on MIMXRT11xx platforms.

Identical to MIMXRT10xx. Uses the pre-allocated SysTmrLo / SysTmrHi QTimer pair. No user timer consumed.

Resolution**: 1 / (PERIPH_CLOCK / 16) seconds per tick, same as MIMXRT10xx.

Source files**:


All three APIs accept FIRST_UNUSED_TIMER (defined as -1 in constants.h) as the default timer parameter. This triggers automatic allocation of the next available hardware timer.

Return Value Meaning
>= 0 Success: allocated timer number
-1 No hardware timer available (all in use)
-2 Invalid frequency (IntervalTimer: < 1 Hz in code, recommended >= 20 Hz)
CPU Max Concurrent DelayObjects Max Concurrent IntervalTimers StopWatch Cost
1 3 (if StopWatch uses 1 DMA timer) 2 (PIT 1-2) 1 DMA timer (shared)
SAME70 12 minus active IntervalTimers 12 minus active DelayObjects Free (SysTick)
MIMXRT10xx 12 minus active IntervalTimers 12 minus active DelayObjects Free (system QTimer)
MIMXRT11xx N/A (not available) 12 Free (system QTimer)

CPU HiResDelay IntervalTimer StopWatch Timer Dispatch
1 arch/coldfire/cpu/1/source/HiResDelay.cpp arch/coldfire/cpu/1/source/IntervalTimer.cpp + pitr_sem.cpp arch/coldfire/cpu/1/source/stopwatch.cpp N/A (direct register access)
SAME70 arch/cortex-m7/cpu/SAME70/source/HiResDelay.cpp arch/cortex-m7/cpu/SAME70/source/IntervalTimer.cpp arch/cortex-m7/cpu/SAME70/source/stopwatch.cpp arch/cortex-m7/cpu/SAME70/source/timer_dispatch.cpp
MIMXRT10xx Combined in IntervalTimer.cpp arch/cortex-m7/cpu/MIMXRT10xx/source/IntervalTimer.cpp arch/cortex-m7/cpu/MIMXRT10xx/source/stopwatch.cpp N/A (inline in IntervalTimer.cpp)
MIMXRT11xx Not available arch/cortex-m7/cpu/MIMXRT11xx/source/IntervalTimer.cpp arch/cortex-m7/cpu/MIMXRT11xx/source/stopwatch.cpp N/A (inline in IntervalTimer.cpp)
CPU StopWatch Resolution StopWatch Convert
1 2.0 / CPU_CLOCK sec/tick ticks * 2.0 / CPU_CLOCK seconds
SAME70 1.0 / CPU_CLOCK sec/tick ticks / CPU_CLOCK seconds
MIMXRT10xx/11xx 1.0 / (PERIPH_CLOCK / 16) sec/tick ticks / (PERIPH_CLOCK / 16) seconds
CPU Clock Variable Typical Value StopWatch Tick
1 CPU_CLOCK 150 MHz ~13.3 ns
SAME70 CPU_CLOCK 300 MHz ~3.3 ns
MIMXRT10xx PERIPH_CLOCK 132 MHz ~121 ns
MIMXRT11xx PERIPH_CLOCK 240 MHz ~66.7 ns