1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// Pure RTC_B prescaler-tick math for the `rtc` module.
//
// Like `rtc_alarm.rs`, this file is intentionally dependency-free (pure
// `core` integer arithmetic, no PAC/HAL types) so the exact same source can
// be `include!`d by the host-side test crate in `unit_tests/`. The
// `rtc::Rtc` tick methods are a thin wrapper over these conversions — a
// regression here (a rate mapped to the wrong prescaler, an off-by-one
// interval code, a wrong period) fails the host tests without a board on
// the desk. Do not add external `use`s. (Regular `//` comments, not `//!`,
// so the file can be `include!`d mid-crate.)
//
// # The hardware's prescaler chain (SLAU367P, "RTC_B Operation")
//
// In calendar mode the RTC_B divider chain is hardwired: **RT0PS** divides
// the 32768 Hz crystal and **RT1PS** divides RT0PS's /256 output (128 Hz);
// RT1PS's own /128 output is the calendar's 1 Hz. The chain cannot be
// re-sourced or re-cascaded on this part — what *is* programmable is one
// interrupt tap per prescaler: the 3-bit `RTxIP` field picks a divide of
// that prescaler's input clock (`/2, /4, … /256` for `IP = 0..7`, TI's
// `RT0IP__2`..`RT0IP__256` constants), and `RTxPSIFG` latches at that rate,
// firing the shared `RTC` vector when `RTxPSIE` is set.
//
// Two taps, sixteen rates, all powers of two:
//
// - RT0PS (input 32768 Hz): 16384, 8192, 4096, 2048, 1024, 512, 256, 128 Hz
// - RT1PS (input 128 Hz): 64, 32, 16, 8, 4, 2, 1, 0.5 Hz
//
// The two banks chain seamlessly — RT1PS at `IP = n` runs 256× slower than
// RT0PS at the same `n` — so a single ordered enum covers the full range,
// with the discriminant encoding everything: bit 3 picks the prescaler,
// bits 2:0 are the `RTxIP` code, and the frequency is
// `32768 >> (discriminant + 1)` (in half-hertz units so 0.5 Hz stays
// integral).
/// A periodic tick rate available from the RTC_B prescaler chain — sixteen
/// power-of-two rates from 16.384 kHz down to one tick every two seconds,
/// crystal-accurate and alive in LPM3 (the prescalers run off ACLK's LFXT
/// like the calendar itself).
///
/// The first eight rates come from prescaler RT0PS (RTCIV slot `0x08`), the
/// last eight from RT1PS (slot `0x0A`); the two are independent, so one of
/// each bank can run concurrently.