Hardware reference
Timers
On this page
Two timers at 0x0ac0_0000, both clocked at 1 MHz from 80 MHz. Timer 0 runs free and is the firmware’s only clock. Timer 1 is a one-shot that raises IRQ 6; the idle loop uses it to bound each sleep.
Registers
| Offset | Address | Register | Type | Description |
|---|---|---|---|---|
+0x00 |
0x0ac0_0000 |
TIMER0_LOAD |
u32 WO | Written 0xffff_ffff, so timer 0 free-runs. |
+0x04 |
0x0ac0_0004 |
NOW |
u32 RO | Microseconds, counting up. The firmware’s only clock; wraps after 2³² µs (71.6 minutes). |
+0x08 |
0x0ac0_0008 |
TIMER0_CONTROL |
u32 WO | Written 0x80 to start timer 0. |
+0x10 |
0x0ac0_0010 |
TIMER0_PRESCALE |
u32 WO | 0x4f: 80 MHz divided to 1 MHz. |
+0x14 |
0x0ac0_0014 |
TIMER1_LOAD |
u32 WO | One-shot delay in microseconds. |
+0x1c |
0x0ac0_001c |
TIMER1_CONTROL |
u32 WO | One-shot control: 0xc1 starts, 0 stops. Read back only in a test image. |
+0x20 |
0x0ac0_0020 |
TIMER1_MODE |
u32 WO | Written 0. |
+0x24 |
0x0ac0_0024 |
TIMER1_PRESCALE |
u32 WO | 0x4f, as for timer 0. |
Source: Timers · 40 bytes
TIMER0_CONTROL, TIMER1_CONTROL
Both timers use this layout.
| Bits | Field | Description |
|---|---|---|
| 7 | ENABLE |
Set in both start values; starts the count inferred. |
| 6 | BIT6 |
Set in timer 1’s one-shot start value. Not isolated from bit 0. |
| 1 | FIRED |
Reads set once the one-shot has fired: observed in a test image; the firmware itself does not read it. |
| 0 | BIT0 |
Set in timer 1’s one-shot start value. Not isolated from bit 6. |
Source: TimerControl · 4 bytes
Programming
Timer 0 is started once at bring-up: TIMER0_LOAD = 0xffff_ffff, TIMER0_PRESCALE = 0x4f, TIMER0_CONTROL = 0x80. From then on NOW counts microseconds.
Timer 1 needs TIMER1_PRESCALE = 0x4f and TIMER1_MODE = 0, also set at bring-up, and source 6 enabled in the interrupt controller so that its expiry ends a wait for interrupt. To wait with a timeout of n µs:
- Write
TIMER1_CONTROL = 0. This step is not optional:0xc1written over a fired timer does not start it again. - Write
TIMER1_LOAD = n. - Write
TIMER1_CONTROL = 0xc1. When the count ends, IRQ 6 becomes pending; a test image readTIMER1_CONTROLas0xc3then. - Wait for interrupt, then write
TIMER1_CONTROL = 0and acknowledge IRQ 6.
The timer keeps counting while the CPU waits, so it ends the wait even with IRQ masked in the CPSR. n is the programmed interval, not a bound on the elapsed time: measured waits overrun it by about 1 µs, and it is no use as a delay below about 7 µs.