Hardware timer device driver (TimerManager)


Contents


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

The number of timers provided by the hardware can be read using Timer_ReturnNumber. Timers may be claimed and released by components using 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 Timer_Convert.


Technical details

A number of timers may be provided by a TimerManager hardware device driver. These timers can be claimed by a single client at any time. The timer's rate may be defined in a number of different forms, to allow clients to specify the rate in the most natural manner. Not all timers may support the exact rate requested, so clients should expect to handle different forms of timers.

Timers are numbered from 0, and timer 0 is reserved for use by the Kernel as the monotonic timer.

Measurement format

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(s)Meaning
0-2

Unit scaler:

ValueMeaning
0Invalid
2Scaled by 1/1000000
3Scaled by 1/1000
4Scaled by 1
5Scaled by 1000
6Scaled by 1000000
7Scaled by 1000000000

3Reserved, must be zero
4-5

Measurement type:

ValueMeaning
0Native ticks
1Frequency (interrupts per second)
2Period (in seconds)
3Invalid

6-7Reserved, must be zero

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.


SWI calls


TimerManager_ReturnNumber
(SWI &58B80)

Return number of supported timers
On entry
R0=Flags (must be 0)
On exit
R0=Number of timers available
Interrupts
Interrupts are undefined
Fast interrupts are enabled
Processor mode
Processor is in SVC mode
Re-entrancy
SWI is not re-entrant
Use

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.

Related APIs
None

TimerManager_Claim
(SWI &58B81)

Claim a hardware timer
On entry
R0=

Flags:

Bit(s)Meaning
0-7Measurement format for the timer rate
8-15Measurement format for the returned timer rate
16-31Reserved, must be zero

R1=Timer number
R2=Timer rate, using the measurement format from bits 0-7
R3=Pointer to function to call on interrupt
R4=Value to pass in R12 to interrupt function
On exit
R2=Actual timer rate, using the measurement format from bits 8-15, or 0 if the rate cannot be represented
Interrupts
Interrupts are undefined
Fast interrupts are enabled
Processor mode
Processor is in SVC mode
Re-entrancy
SWI is not re-entrant
Use

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.

Related vectors
TimerManager_Release, TimerManager_SetRate, TimerManager_Convert

TimerManager_Release
(SWI &58B82)

Release a hardware timer
On entry
R0=Flags (must be zero)
R1=Timer number
On exit
None
Interrupts
Interrupts are undefined
Fast interrupts are enabled
Processor mode
Processor is in SVC mode
Re-entrancy
SWI is not re-entrant
Use

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

Related vectors
TimerManager_Claim

TimerManager_SetRate
(SWI &58B83)

Change the rate used by a hardware timer
On entry
R0=

Flags:

Bit(s)Meaning
0-7Measurement format for the timer rate
8-15Measurement format for the returned timer rate
16-31Reserved, must be zero

R1=Timer number
R2=Timer rate, using the measurement format from bits 0-7
On exit
R2=Actual timer rate, using the measurement format from bits 8-15, or 0 if the rate cannot be represented
Interrupts
Interrupts are undefined
Fast interrupts are enabled
Processor mode
Processor is in SVC mode
Re-entrancy
SWI is not re-entrant
Use

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.

Related vectors
TimerManager_Claim, TimerManager_Convert

TimerManager_Convert
(SWI &58B84)

Convert between rate formats used by a hardware timer
On entry
R0=

Flags:

Bit(s)Meaning
0-7Measurement format for the timer rate
8-15Measurement format for the returned timer rate
16-31Reserved, must be zero

R1=Timer number
R2=Timer rate, using the measurement format from bits 0-7
On exit
R2=Timer rate in form specified by R0 bits 8-15
Interrupts
Interrupts are undefined
Fast interrupts are enabled
Processor mode
Processor is in SVC mode
Re-entrancy
SWI is not re-entrant
Use

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.

Related vectors
TimerManager_Claim, TimerManager_SetRate

Document information

Maintainer(s):
History:
RevisionDateAuthorChanges
117 Nov 2022GerphInitial version
  • Created from Select technical documentation.
Related:http://www.riscos.com/support/developers/riscos6/hardware/timer.html
Disclaimer:

© Gerph, 2022.