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.
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.
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.
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.
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.
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.
|R0||=||Seconds between the last stop watch start, and its stop.|
|R1||=||Fractional microseconds between the last stop watch start, and its stop.|
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.
|R0||=||Seconds since system boot.|
|R1||=||Fractional microseconds since system boot.|
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.
*TimerStart uses SWI Timer_Start to start the stop watch.
*TimerStop uses SWI Timer_Stop to stop the stop watch and then reports the time.
*TimerValue uses SWI Timer_Value to reports the time since boot with greater accuracy than the OS_ReadMonotonicTime SWI.