Skip to content

Commit 0fe5b5a

Browse files
committed
idk if FTC etc are accessible + more pm.h stuff
1 parent a2fa91b commit 0fe5b5a

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

hardware/Timers.md

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
- [Programmable timers][]
1111
- [Programmable timer configuration][]
1212
- [Programmable timer interrupts][]
13+
- [Enabling and pausing programmable timers][]
1314

1415
[Oscillators]: #oscillators
1516
[OSC1]: #osc1
@@ -21,6 +22,7 @@
2122
[Programmable timers]: #programmable-timers
2223
[Programmable timer configuration]: #programmable-timer-configuration
2324
[Programmable timer interrupts]: #programmable-timer-interrupts
25+
[Enabling and pausing programmable timers]: #[enabling-and-pausing-programmable-timers]
2426

2527
[sleep]: Standby.md#sleep
2628

@@ -169,6 +171,8 @@ In previous documentation and code, this timer has been known in the community a
169171

170172
16-bit timer comprised of PTM4 as the lower order 8 bits and PTM5 as the higher order 8 bits. That is, `PTM5:PTM4` or given PTM5 is 0x10 and PTM4 is 0xf3, the value is 0x10f3.
171173

174+
For information on using PTM4-5 for audio, see [Audio / Sound](cpu/Sound.md).
175+
172176
In previous documentation and code, this timer has been known in the community as the "timer 3".
173177

174178
### Programmable timer configuration
@@ -199,7 +203,7 @@ After this you configure the division ratio (prescale), reload data (preset), an
199203

200204
The prescale along with the clock source determines how quickly the counter decrements. Refer to the table below:
201205

202-
| Prescale | fOSC1 / div = Hz | OSC3 / div = Hz |
206+
| Prescale | fOSC1 / div = Hz | fOSC3 / div = Hz |
203207
| -------- | ------------------- | -------------------- |
204208
| 0 | 32768 / 1 = 32768 | 4M / 2 = 2M |
205209
| 1 | 32768 / 2 = 16384 | 4M / 8 = 500k |
@@ -246,41 +250,48 @@ The scale registers are constructed as `PRPRTy:PSTy:PRPRTx:PSTx` where each PST
246250

247251
### Programmable timer interrupts
248252

249-
There are two interrupts for each timer: the underflow and the compare data interrupts. Underflow occurs the tick after a count reaches 0, causing it to preset. The compare data interrupt occurs when the count is equal to the value stored in the relevant CDR register.
253+
There are two potential interrupts for each timer: the underflow and the compare data interrupts. Underflow occurs the tick after a count reaches 0, causing it to preset. The compare data interrupt occurs when the count is equal to the value stored in the relevant CDR register.
250254

251-
Although all of these interrupts exist and can be accessed by reading the count or factor flag directely, not all of them are mapped to ROM locations (that is, there's no means to make them jump to software code automatically).
255+
Although all of these interrupts can exist, not all of them are known to be mapped. The following table lists which ones are known to be accessible.
252256

253257
| Timer interrupt | Factor | Enable | Priority | Software entry address |
254258
| ---------------- | ------ | ------ | -------- | ---------------------- |
255259
| PTM0 underflow | FTU0 | ETU0 | PPT0-1 | $2126 |
256-
| PTM0 CDR match | FTC0 | ETC0 | n/a | n/a |
257260
| PTM1 underflow | FTU1 | ETU1 | PPT0-1 | $2120 |
258-
| PTM1 CDR match | FTC1 | ETC1 | n/a | n/a |
259261
| PTM2 underflow | FTU2 | ETU2 | PPT2-3 | $211a |
260-
| PTM2 CDR match | FTC2 | ETC2 | n/a | n/a |
261262
| PTM3 underflow | FTU3 | ETU3 | PPT2-3 | $2114 |
262-
| PTM3 CDR match | FTC3 | ETC3 | n/a | n/a |
263-
| PTM4 underflow | FTU4 | ETU4 | n/a | n/a |
264-
| PTM4 CDR match | FTC4 | ETC4 | n/a | n/a |
265263
| PTM5 underflow | FTU5 | ETU5 | PPT4-5 | $212c |
266264
| PTM5 CDR match | FTC5 | ETC5 | PPT4-5 | $2132 |
267265
| PTM0-1 underflow | FTU1 | ETU1 | PPT0-1 | $2120 |
268-
| PTM0-1 CDR match | FTC1 | ETC1 | n/a | n/a |
269266
| PTM2-3 underflow | FTU3 | ETU3 | PPT2-3 | $2114 |
270-
| PTM2-3 CDR match | FTC3 | ETC3 | n/a | n/a |
271267
| PTM4-5 underflow | FTU5 | ETU5 | PPT4-5 | $212c |
272268
| PTM4-5 CDR match | FTC5 | ETC5 | PPT4-5 | $2132 |
273269

270+
With pm.h, the factor flags are all in IRQ_ACT1, the enable flags in IRQ_ENA1, and the priority flags in IRQ_PRI1.
271+
272+
| Timer | Underflow flag | CDR flag | Priority macro |
273+
| ------ | --------------- | --------------- | -------------- |
274+
| PTM0 | IRQ1_TIM1_LO_UF | n/a | PRI_TIM1 |
275+
| PTM1 | IRQ1_TIM1_HI_UF | n/a | PRI_TIM1 |
276+
| PTM2 | IRQ1_TIM2_LO_UF | n/a | PRI_TIM2 |
277+
| PTM3 | IRQ1_TIM2_HI_UF | n/a | PRI_TIM2 |
278+
| PTM5 | IRQ1_TIM3_HI_UF | IRQ1_TIM3_PIVOT | PRI_TIM3 |
279+
| PTM0-1 | IRQ1_TIM1_HI_UF | n/a | PRI_TIM1 |
280+
| PTM2-3 | IRQ1_TIM2_HI_UF | n/a | PRI_TIM2 |
281+
| PTM4-5 | IRQ1_TIM3_HI_UF | IRQ1_TIM3_PIVOT | PRI_TIM3 |
282+
274283
For more information about how interrupts work, see [Interrupts](cpu/Interrupts.md).
275-
For information on using PTM4-5 for audio, see [Audio / Sound](cpu/Sound.md).
276284

277285
### Enabling and pausing programmable timers
278286

279287
In order to turn a timer on, the following must be done, where x is some timer index (use 0 for PTM0-1, etc):
280288

281289
* CKSEL*x* should already be set to 0 by default, do not change it
290+
* In pm.h, this is bit 0 in TMR*a*\_CTRL_*hl* registers.
282291
* Set PRPRT*x* register to 1
292+
* As mentioned in the configuration section, in pm.h these are contained in the TMR*a*_SCALE registers as bit 7 and 3.
283293
* Set PTRUN*x* register to 1
294+
* In pm.h, this is bit 2 in TMR*a*\_CTRL_*hl* registers.
284295

285296
To pause the timer, reset PTRUN*x* register to 0. The timer will decrement once more before pausing.
286297
To resume the timer, set PTRUN*x* register back to 1.

0 commit comments

Comments
 (0)