3 ~32kHz internal RC clock
5 Can be between 22 and 42 kHz
7 ## Main Oscillator / MAINCK
11 16 MHz, based on external Xtal
15 cf `PMC_PLLR` register
17 96 MHz (MAINCK * 12 / 2)
19 ## Master Clock MCK, Processor Clock PCK, USB clock UDPCK
21 cf `common_arm/clocks.c`
23 cf `PMC_MCKR` and `PMC_SCER` registers
25 * MCK starts with RC slow clock (22 to 42 kHz).
26 * Then MCK configured from PLL: 48 MHz (PLL / 2)
30 PCK can be disabled to enter idle mode, but on Proxmark3 it's always on, so PCK is also 48 MHz.
32 USB need to be clocked at 48 MHz from the PLL, so PLL / 2 (cf `CKGR_PLLR`).
39 Distribute MCK/PCK? clock to Parallel I/O controller, ADC, SPI, Synchronous Serial controller, PWM controller, USB.
43 Activate PCK0 pin as clock output, based on PLL / 4 = 24 MHz, for the FPGA.
45 ## 1 kHz RTC: TickCount functions
49 cf `PMC_MCFR` and `RTTC_RTMR` registers for configuration, `RTTC_RTVR` register for reading value.
53 * 1 kHz, 32b (49 days), if used with 16b: 65s
54 * Configured at boot (or TIA) with `StartTickCount()`
55 * Time events with `GetTickCount()`/`GetTickCountDeltaDelta()`, see example
56 * Coarse, based on the ~32kHz RC slow clock with some adjustment factor computed by TIA
57 * Maybe 2.5% error, can increase if temperature conditions change and no TIA is recomputed
58 * If TimingIntervalAcquisition() is called later, StartTickCount() is called again and RTC is reset
63 uint32_t ti = GetTickCount();
65 uint32_t delta = GetTickCountDelta(ti);
70 * cheap random for nonces, e.g. `prng_successor(GetTickCount(), 32)`
71 * rough timing of some operations, only for informative purposes
73 * USB connection speed measure
75 ## Occasional PWM timer
77 * `void SpinDelayUs(int us)`
78 * `void SpinDelay(int ms)` based on SpinDelayUs
79 * `void SpinDelayUsPrecision(int us)`
81 Busy wait based on 46.875 kHz PWM Channel 0
83 * 21.3 us precision and maximum 1.39 s
84 * *Precision* variant: 0.7 us precision and maximum 43 ms
86 ## Occasional TC0+TC1 / CountUS functions
92 * `void StartCountUS(void)`
93 * `uint32_t RAMFUNC GetCountUS(void)`
95 Use two chained timers TC0 and TC1.
96 TC0 runs at 1.5 MHz and TC1 is clocked when TC0 reaches 0xC000.
98 Maximal value: 0x7fffffff = 2147 s
100 Can't be used at the same time as CountSspClk or Ticks functions.
102 ## Occasional TC0+TC1+TC2 SSP_CLK from FPGA / CountSspClk functions
106 About 1 cycle of 13.56 MHz? precision
108 * `void StartCountSspClk(void)`
109 * `void ResetSspClk(void)`
110 * `uint32_t RAMFUNC GetCountSspClk(void)`
111 * `uint32_t RAMFUNC GetCountSspClkDelta(uint32_t start)` <= **TODO** could be used more often
113 Use two chained timers TC0 and TC1.
114 TC0 runs at SSP_CLK from FPGA (13.56 MHz?) and TC1 is clocked when TC0 loops.
118 * for iso14443 commands to count field cycles
119 * Also usable with FPGA in LF mode ?? cf `armsrc/legicrfsim.c` SSP Clock is clocked by the FPGA at 212 kHz (sub-carrier frequency)
121 Can't be used at the same time as CountUS or Ticks functions.
123 ## Occasional TC0+TC1 / Ticks functions
129 * `void StartTicks(void)`
130 * `uint32_t GetTicks(void)` <= **TODO** why no GetTicksDelta ?
131 * `void WaitTicks(uint32_t ticks)`
132 * `void WaitUS(uint32_t us)`
133 * `void WaitMS(uint32_t ms)`
134 * `void StopTicks(void)` <= **TODO** why a stop for this timer and not for CountUS / CountSspClk ?
136 Use two chained timers TC0 and TC1.
137 TC0 runs at 1.5 MHz and TC1 is clocked when TC0 loops.
139 Maximal value: 0xffffffff = 2863 s (but don't use high value with WaitTicks else you'll trigger WDT)
143 * Timer for bitbanging, or LF stuff when you need a very precise timer
145 Can't be used at the same time as CountUS or CountSspClk functions.