Pyromaniac

Pyromaniac PRM: High resolution timer (TimerMod)

Pyromaniac PRM: High resolution timer (TimerMod)

RISC OS PyromaniacHigh resolution timer (TimerMod)

Introduction and Overview

The standard SWI OS_ReadMonotonicTime SWI provides a centisecond time since the system has booted. This is not sufficient for some tasks, and a greater resolution is required for some interfaces. The TimerMod module provides a means of accessing a timer at a higher resolution than the standard.

Technical details

The TimerMod abstracts away the interfaces required for accessing an incrementing timer, at an undefined resolution. All timings are returned in units of microseconds, although the accuracy of the timings may be far less than this. The module provides access to a single-user stopwatch timer, and an incrementing timer.

Stop watch

The stop watch is essentially an interval timer which can be started and stopped arbitrarily. The SWI Timer_Start and SWI Timer_Stop SWIs provide a means by which the stop watch can be started, and stopped. The timer has a simple life cycle:

  • The user issues SWI Timer_Start, and the module resets the start time to 0.
  • The user issues SWI Timer_Stop, and the module returns the elapsed time since the initial Timer_Start call.
  • Subsequent calls to SWI Timer_Stop, return the same value as the last call to Timer_Stop.

There is only a single stop watch, so this interface is only suitable for a debug and diagnostic purposes. Using this interface within distributed components may interfere with other users of the interface.

Timer

The timer counts upwards from 0 at system boot, and can be retrieved with SWI Timer_Value. This value is unaffected by the stop watch, and will continue incrementing whilst the system is running. When the system is reset, the timer will reset and begin counting from 0 again.

Hardware implementation

On all machines the module uses the CMOS clock for time calculations to 1 centisecond resolution. Microsecond resolution is provided by hardware specific timers.

  • On RiscPC, A7000 and Archimedes machines, the 2MHz IOMD/IOC timer 0 is used.
  • On RISC OS 5 machines, the HAL counter 0 is read. On the Iyonix this provided by the XScale 80321 and runs at 200MHz. It also works on the Raspberry Pi which has a 1MHz timer.
  • On RISC OS Pyromaniac, the host system timer is used.

SWI calls

Timer_StartSWI &490C0
Starts the timer stop watch
None
None
Interrupts are undefined
Fast interrupts are enabled
Processor is in SVC mode
SWI is not re-entrant

The Timer_Start SWI is used to reset the timer stop watch and begin it running. Repeated calls whilst the stop watch is running will reset the stop watch to 0.

Timer_StopSWI &490C1
Stops the timer stop watch
None
R0=Seconds between the last stop watch start, and its stop.
R1=Fractional microseconds between the last stop watch start, and its stop.
Interrupts are undefined
Fast interrupts are enabled
Processor is in SVC mode
SWI is not re-entrant

The Timer_Stop SWI is used to stop the stop watch timer, and return the interval between the start of the stop watch, and its stop. Subsequent calls to the SWI will return that value again, until the stop watch is started again.

The returned value is broken into two registers, containing the second and microsecond measures of the interval between the start and stop.

Timer_ValueSWI &490C2
Returns the current value of the monotonic time
None
R0=Seconds since system boot.
R1=Fractional microseconds since system boot.
Interrupts are undefined
Fast interrupts are enabled
Processor is in SVC mode
SWI is not re-entrant

The Timer_Value SWI is used to read the value of the Monotonic Timer to a greater accuracy. The Monotonic timer starts when the system boots and increases during the system's runtime.

The returned value is broken into two registers, containing the second and microsecond measures of the time since the system booted.

*Commands

*TimerStart
Starts the timer stop watch
*TimerStart
None

*TimerStart uses SWI Timer_Start to start the stop watch.

*TimerStart
*TimerStop
Stops the timer stop watch and reports the interval
*TimerStop
None

*TimerStop uses SWI Timer_Stop to stop the stop watch and then reports the time.

*TimerStop Elapsed time: 13.279904
*TimerValue
Report the time since boot
*TimerValue
None

*TimerValue uses SWI Timer_Value to reports the time since boot with greater accuracy than the OS_ReadMonotonicTime SWI.

*TimerValue Elapsed time: 83.432451