In development. It changes without notice.
Topic
Clock Chip Driver
The BM8563 clock chip.
It keeps the date and the time through a sleep or a supply that is cut, on the Core2 v1.3, the CoreInk, the CoreS3 SE, the M5StickC Plus 1.1, the M5StickC Plus2 and the M5StickC Plus SE. The driver finds it, and reads and writes the time and the date; what trust a reading has is decided in Clock & Time Zone.
- See also
- Clock & Time Zone, Clock Chip Back End
Files | |
| file | src/ |
| BM8563 / PCF8563 I2C real-time-clock driver. | |
| file | src/ |
| Pure register-image transforms for the BM8563 curated accessors. | |
| file | src/ |
| Pure BCD / bit-field codec helpers for the BM8563 / PCF8563 RTC. | |
| file | src/ |
| BM8563 / PCF8563 RTC register map (Kleidos subset). | |
| file | src/ |
| Chip-level real-time-clock driver contract. | |
| file | src/ |
| RTC_CNTL introspection registration + soc-header offset cross-check. | |
| file | src/ |
| Registration hook for the SoC RTC_CNTL introspection table. | |
| file | src/ |
| RTC driver factory — probes the internal I2C bus for a supported RTC. | |
Classes | |
| class | kleidos:: |
| BM8563 / PCF8563 clock-chip driver, for the boards that carry one: Core2 v1.3, CoreInk, CoreS3 SE, M5StickC Plus 1.1, M5StickC Plus2 and M5StickC Plus SE. More about kleidos:: | |
| class | kleidos:: |
| The contract every real-time-clock chip driver implements. More about kleidos:: | |
Functions | |
| constexpr std::array< uint8_t, kAlarmRegCount > | kleidos:: |
| Assemble the 0x09..0x0C alarm register image from an RtcAlarm. | |
| constexpr RtcAlarm | kleidos:: |
| Parse a 0x09..0x0C alarm register image into an RtcAlarm. | |
| constexpr uint8_t | kleidos:: |
| Build the 0x0E timer-control byte for a countdown source. | |
| constexpr bool | kleidos:: |
| Decode the 0x0E timer-control byte into a running/ | |
| constexpr uint8_t | kleidos:: |
| Build the 0x0D CLKOUT-control byte for a CLKOUT setting. | |
| constexpr RtcClockOut | kleidos:: |
| Decode the 0x0D CLKOUT-control byte into a CLKOUT setting. | |
| constexpr bool | kleidos:: |
| Decode the VL_seconds register (0x02) into a clock-integrity verdict. | |
| constexpr uint8_t | kleidos:: |
| Decode a packed BCD byte (two 4-bit decimal nibbles) to a plain value. | |
| constexpr uint8_t | kleidos:: |
| Encode a plain 0..99 value to a packed BCD byte. | |
| constexpr bool | kleidos:: |
| True when the VL_seconds register (0x02) reports lost clock integrity. VL (bit7) is set on power-on / low-supply; the calendar is unreliable. | |
| constexpr uint8_t | kleidos:: |
| Build an alarm value register byte: BCD payload plus the active-low alarm-enable (AE) bit7 — clear enables the field, set disables it. | |
| constexpr bool | kleidos:: |
| Read the active-low alarm-enable (AE) bit of an alarm value register. | |
| constexpr uint32_t | kleidos:: |
| Decode the CLKOUT FD[1:0] output-frequency code to Hz. | |
| constexpr uint32_t | kleidos:: |
| Decode the countdown-timer TD[1:0] source-clock code to Hz x100. Scaled by 100 so the 1/60 Hz code stays integral (returns 1). | |
| IRtc * | kleidos:: |
| Constructs and initializes the RTC driver for address, returning a ready singleton or nullptr if the chip is absent. The instance lives in static storage; callers must not delete it. | |
Variables | |
| constexpr std::size_t | kleidos:: |
| Number of contiguous alarm value registers (0x09..0x0C). | |
| constexpr uint8_t | kleidos:: |
| constexpr uint8_t | kleidos:: |
| Number of CLKOUT / countdown-timer source-select codes (2-bit field mask). | |
| constexpr auto | kleidos:: |
| CLKOUT FD[1:0] output frequencies in Hz (datasheet Table 20), index = code. | |
| constexpr auto | kleidos:: |
| constexpr uint8_t | kleidos:: |
| Control/ | |
| constexpr uint8_t | kleidos:: |
| Control/ | |
| constexpr uint8_t | kleidos:: |
| Seconds (BCD, low 7 bits; bit7 = VL). | |
| constexpr uint8_t | kleidos:: |
| Day-of-month (BCD, low 6 bits). | |
| constexpr uint8_t | kleidos:: |
| Minute alarm (bit7 AE_M + BCD minute); 0x09..0x0C alarm block base. | |
| constexpr uint8_t | kleidos:: |
| Hour alarm (bit7 AE_H + BCD hour). | |
| constexpr uint8_t | kleidos:: |
| Day alarm (bit7 AE_D + BCD day-of-month). | |
| constexpr uint8_t | kleidos:: |
| Weekday alarm (bit7 AE_W + weekday 0..6). | |
| constexpr uint8_t | kleidos:: |
| CLKOUT control (bit7 FE + FD[1:0] frequency select). | |
| constexpr uint8_t | kleidos:: |
| Timer control register (bit7 TE + TD[1:0] source). | |
| constexpr uint8_t | kleidos:: |
| Countdown-timer reload/read value (8-bit). | |
| constexpr uint8_t | kleidos:: |
| Mask for the seconds value (BCD, low 7 bits). | |
| constexpr uint8_t | kleidos:: |
| VL (bit7 of VL_seconds): clock integrity lost. | |
| constexpr uint8_t | kleidos:: |
| Mask for the minutes value (BCD, low 7 bits). | |
| constexpr uint8_t | kleidos:: |
| Mask for the hours value (BCD, low 6 bits). | |
| constexpr uint8_t | kleidos:: |
| Mask for the day-of-month value (BCD, low 6 bits). | |
| constexpr uint8_t | kleidos:: |
| Mask for the month value (BCD, low 5 bits). | |
| constexpr uint8_t | kleidos:: |
| Mask for the weekday value (0..6, low 3 bits). | |
| constexpr uint8_t | kleidos:: |
| Century bit in the month register (1 == 1900s, 0 == 2000s). | |
| constexpr uint8_t | kleidos:: |
| AF (bit3): alarm flag; write 0 to clear. | |
| constexpr uint8_t | kleidos:: |
| TF (bit2): timer flag; write 0 to clear. | |
| constexpr uint8_t | kleidos:: |
| AIE (bit1): alarm-interrupt enable. | |
| constexpr uint8_t | kleidos:: |
| TIE (bit0): timer-interrupt enable. | |
| constexpr uint8_t | kleidos:: |
| FE (bit7): CLKOUT pin output enable. | |
| constexpr uint8_t | kleidos:: |
| TE (bit7): countdown-timer enable. | |
| constexpr uint8_t | kleidos:: |
| FD/TD 2-bit frequency/ | |
| constexpr uint8_t | kleidos:: |
| Timer source code: 1/60 Hz (1 pulse per minute). | |
| constexpr uint16_t | kleidos:: |
| Base year when the century bit is set. | |
| constexpr uint16_t | kleidos:: |
| Base year when the century bit is clear. | |
| constexpr uint16_t | kleidos:: |
| Inclusive lower bound for set-year validation. | |
| constexpr uint16_t | kleidos:: |
| Inclusive upper bound for set-year validation. | |
Function Documentation
alarmField() #
Build an alarm value register byte: BCD payload plus the active-low alarm-enable (AE) bit7 — clear enables the field, set disables it.
- Parameters
-
Name Meaning bcdValue BCD alarm payload (bits6..0). enabled True to enable the field (AE = 0), false to disable (AE = 1).
- Returns
- Alarm register byte with AE applied.
alarmFieldEnabled() #
Read the active-low alarm-enable (AE) bit of an alarm value register.
- Parameters
-
Name Meaning reg Raw alarm value register byte.
- Returns
- True when AE (bit7) is clear, i.e. the field participates.
assembleAlarm() #
Assemble the 0x09..0x0C alarm register image from an RtcAlarm.
Each field is BCD-encoded and tagged with the active-low AE bit: an enabled field clears AE (participates in the match), a disabled field sets AE (wildcard).
- Parameters
-
Name Direction Meaning alarm in Alarm match specification.
- Returns
- Register image, index 0 = minute (0x09) .. 3 = weekday (0x0C).
bcdToByte() #
Decode a packed BCD byte (two 4-bit decimal nibbles) to a plain value.
- Parameters
-
Name Meaning value BCD-encoded byte (e.g. 0x59).
- Returns
- Decimal value (e.g. 59).
byteToBcd() #
Encode a plain 0..99 value to a packed BCD byte.
- Parameters
-
Name Meaning value Decimal value (e.g. 59).
- Returns
- BCD-encoded byte (e.g. 0x59).
clkoutFreqHz() #
Decode the CLKOUT FD[1:0] output-frequency code to Hz.
- Parameters
-
Name Meaning fdBits 2-bit FD field (0..3); higher bits are ignored.
- Returns
- Output frequency in Hz (32768 / 1024 / 32 / 1).
clockIntegrityLost() #
True when the VL_seconds register (0x02) reports lost clock integrity. VL (bit7) is set on power-on / low-supply; the calendar is unreliable.
- Parameters
-
Name Meaning vlSecondsReg Raw VL_seconds register byte.
- Returns
- True if bit7 (VL) is set.
clockIntegrityValid() #
Decode the VL_seconds register (0x02) into a clock-integrity verdict.
- Parameters
-
Name Direction Meaning vlSecondsReg in Raw VL_seconds register byte.
- Returns
- True when clock integrity is intact (VL clear).
clockOutValue() #
Build the 0x0D CLKOUT-control byte for a CLKOUT setting.
Off disables the pin (FE = 0, whole byte 0). Otherwise sets FE (bit7) and the FD[1:0] frequency code (datasheet Table 20: 0b00 = 32768 Hz .. 0b11 = 1 Hz).
- Parameters
-
Name Direction Meaning freq in Desired CLKOUT frequency, or RtcClockOut:: Off to disable.
- Returns
- CLKOUT-control register value (0, or FE | FD).
createRtc() #
Constructs and initializes the RTC driver for address, returning a ready singleton or nullptr if the chip is absent. The instance lives in static storage; callers must not delete it.
The one chip it knows is the NXP PCF8563-compatible BM8563 (address 0x51).
- Parameters
-
Name Direction Meaning address in I2C address of the RTC chip.
- Returns
- Pointer to the singleton RTC driver, or nullptr.
- See also
- Bm8563
parseAlarm() #
Parse a 0x09..0x0C alarm register image into an RtcAlarm.
Masks each register to its value field, BCD-decodes it, and reads the active-low AE bit into the corresponding *Enabled flag.
- Parameters
-
Name Direction Meaning regs in Register image, index 0 = minute (0x09) .. 3 = weekday (0x0C).
- Returns
- Decoded alarm match specification.
parseClockOut() #
Decode the 0x0D CLKOUT-control byte into a CLKOUT setting.
Inverse of clockOutValue — a clear FE (bit7) means the pin is disabled (Off) regardless of the FD bits; a set FE decodes the FD[1:0] frequency code (datasheet Table 20: 0b00 = 32768 Hz .. 0b11 = 1 Hz).
- Parameters
-
Name Direction Meaning clkoutControlReg in Raw CLKOUT-control register byte.
- Returns
- Decoded CLKOUT frequency, or Off when FE is clear.
timerControlValue() #
Build the 0x0E timer-control byte for a countdown source.
Sets TE (bit7, arm) and the TD[1:0] source code. The enum order matches the datasheet TD codes (Hz4096 = 0b00 .. Hz1Over60 = 0b11).
- Parameters
-
Name Direction Meaning src in Countdown-timer source frequency.
- Returns
- Timer-control register value (TE | TD).
timerRunning() #
Decode the 0x0E timer-control byte into a running/
Reports the TE (bit7) countdown-timer-enable bit; the TD[1:0] source code below it is irrelevant to whether the timer is armed.
- Parameters
-
Name Direction Meaning timerControlReg in Raw timer-control register byte.
- Returns
- True when TE is set (the countdown is armed).
timerSourceHzTimes100() #
Decode the countdown-timer TD[1:0] source-clock code to Hz x100. Scaled by 100 so the 1/60 Hz code stays integral (returns 1).
- Parameters
-
Name Meaning tdBits 2-bit TD field (0..3); higher bits are ignored.
- Returns
- Source rate x100 (409600 / 6400 / 100 / 1).
Variable Documentation
kFieldFlagBit7 #
bit7 of VL_seconds (0x02): clock-integrity-lost flag (VL). Also the AE alarm-enable bit position (active-low) in the alarm value registers.
kTimerSourceHzTimes100 #
Countdown-timer TD[1:0] source rates x100 (datasheet Table 6), index = code. Scaled by 100 so the 1/60 Hz code stays integral: (1/60) * 100 = 1.