[Select]

Hardware


Index

 

Timer module

Introduction

The Timer module provides an abstraction of the hardware timers. It is used by the Kernel in order to provide the monotonic timer used for the system clock, interval timer, monotonic timer, and system timed events. The module also provides an interface to allow other hardware timers to be controlled by other components. Timers may run off independant clock sources and so may have different granularity and ranges of rates at which they may generate interrupts.

Each hardware implementation has an independant Timer module implementation specific to the timers which are available to the operating system.

Overview

Timers are numbered from 0. The number of timers provided by the hardware can be read using SWI Timer_ReturnNumber. Timers may be claimed and released by components using SWI Timer_Claim and Timer_Release. The rate at which a timer is running can be modified after it has been claimed by using Timer_SetRate. The relationship between timer rates and external measurements can be obtained by using SWI Timer_Convert.

Many of the SWIs take a number of flags to indicate the measurement format of the timer. The measurement format flags take the form of 8 bits:

   bit 0-2 = Unit scaler :
         0 = invalid
         1 = scaled by 1/1000000000
         2 = scaled by 1/1000000
         3 = scaled by 1/1000
         4 = scaled by 1
         5 = scaled by 1000
         6 = scaled by 1000000
         7 = scaled by 1000000000
   bit 3   = Invalid
   bit 4-5 = Measurement type :
         0 = native ticks
         1 = frequency (interrupts per second)
         2 = period (in seconds)
         3 = invalid
   bit 6-7 = Invalid

For example, to request a frequency of 100 Hz one could use a measurement type of 1, a scaler of 4 (scale by 1) and a value of 100. Alternatively, this could be represented as a period of 1/100th second by using a measurement type of 2, a scaler of 3 (scale by 1/1000) and a value of 10.

For SWIs which take an input rate the measurement format flags are held in the bits 0-7 of the SWI flags.

For SWIs which return a rate the measurement format flags are held in bits 8-15 of the SWI flags.

Timer 0 is reserved for use by the Kernel.

SWIs

Timer_ReturnNumber (&?0)
On entry
   R0 = flags (must be 0)
On exit
   R0 = number of timers available

This SWI is used to find the number of timers available to the operating system. Timers are numbered from 0, so the maximum timer number that may be used is the value returned - 1.

Timer_Claim (&?1)
On entry
   R0 = flags:
           bits 0-7  = measurement format for the timer rate
           bits 8-15 = measurement format to return timer rate
           bits 16-31 reserved (must be 0)
   R1 = timer number
   R2 = timer value
   R3 = pointer to function to call on interrupt
   R4 = value to pass in R12 to interrupt function
On exit
   R2 = timer rate in form specified by R0 bits 8-15, or 0 if the timer rate
         cannot be represented

This SWI is used to claim a timer for dedicated use by a client. Only a single client may claim a timer; subsequent claims will return an error. The timer specified will be set to the rate given and interrupts will call the routine specified. The interrupt routine may corrupt R0-R3 but should preserve all other registers.

An error will be returned if the input measurement format in R0 bits 0-7 is not valid or cannot be provided by the timer.

If the meaurement format used for return in R0 bits 8-15 is invalid the value returned in R2 will be 0, but no error will be raised. The return value is provided as a convenience.

Timer_Release (&?2)
On entry
   R0 = flags (must be 0)
   R1 = timer number

This SWI is used to release a previously claimed timer. The IRQ will no longer cause the specified routine to be called.

Timer_SetRate (&?3)
On entry
   R0 = flags:
           bits 0-7 = measurement format for the timer rate
           bits 8-15 = measurement format to return timer rate
           bits 16-31 Reserved (must be 0)
   R1 = timer number
   R2 = timer value
On exit
   R2 = timer rate in form specified by R0 bits 8-15, or 0 if the timer rate
          cannot be represented

This SWI is used to change the rate used by a timer. Only timers which have been claimed can have their rate changed; unclaimed timers will return an error. The timer specified will be set to the rate given.

An error will be returned if the input measurement format in R0 bits 0-7 is not valid or cannot be provided by the timer.

If the meaurement format used for return in R0 bits 8-15 is invalid the value returned in R2 will be 0, but no error will be raised. The return value is provided as a convenience.

Timer_Convert (&?4)
On entry
   R0 = flags:
           bits 0-7 = measurement format for the timer rate
           bits 8-15 = measurement format to return timer rate
           bits 16-31 Reserved (must be 0)
   R1 = timer number
   R2 = timer value
On exit
   R2 = timer rate in form specified by R0 bits 8-15

This SWI is used to convert between timer rate formats. The values converted will be checked to ensure that the timer is capable of those rates.

An error will be returned if the input measurement format in R0 bits 0-7 is not valid or cannot be provided by the timer.

An error will be returned if the meaurement format used for return in R0 bits 8-15 is invalid.


This documentation is copyright 3QD Developments Ltd 2013 and may not be reproduced or published in any form without the copyright holders permission. RISC OS is subject to continuous development and improvement as such all information is reproduced by 3QD Developments Ltd in good faith and is believed to be correct at the time of publication E&OE. 3QD Developments Ltd cannot accept any liability for any loss or damage arising from the use of any information provided as part of the RISC OS Documentation.

HTML document version 1.03 3rd November 2015