Kleidos API Search

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/drivers/rtc/bm8563.h
BM8563 / PCF8563 I2C real-time-clock driver.
file src/drivers/rtc/bm8563_accessors.h
Pure register-image transforms for the BM8563 curated accessors.
file src/drivers/rtc/bm8563_codec.h
Pure BCD / bit-field codec helpers for the BM8563 / PCF8563 RTC.
file src/drivers/rtc/bm8563_regs.h
BM8563 / PCF8563 RTC register map (Kleidos subset).
file src/drivers/rtc/i_rtc.h
Chip-level real-time-clock driver contract.
file src/drivers/rtc/rtc_cntl_introspection.cpp
RTC_CNTL introspection registration + soc-header offset cross-check.
file src/drivers/rtc/rtc_cntl_introspection.h
Registration hook for the SoC RTC_CNTL introspection table.
file src/drivers/rtc/rtc_factory.cpp
RTC driver factory — probes the internal I2C bus for a supported RTC.

Classes

class kleidos::drivers::rtc::Bm8563
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::drivers::rtc::Bm8563
class kleidos::drivers::rtc::IRtc
The contract every real-time-clock chip driver implements. More about kleidos::drivers::rtc::IRtc

Functions

constexpr std::array< uint8_t, kAlarmRegCount >kleidos::drivers::rtc::accessors::assembleAlarm (const RtcAlarm &alarm)
Assemble the 0x09..0x0C alarm register image from an RtcAlarm.
constexpr RtcAlarmkleidos::drivers::rtc::accessors::parseAlarm (const std::array< uint8_t, kAlarmRegCount > &regs)
Parse a 0x09..0x0C alarm register image into an RtcAlarm.
constexpr uint8_tkleidos::drivers::rtc::accessors::timerControlValue (RtcTimerSource src)
Build the 0x0E timer-control byte for a countdown source.
constexpr boolkleidos::drivers::rtc::accessors::timerRunning (uint8_t timerControlReg)
Decode the 0x0E timer-control byte into a running/stopped verdict.
constexpr uint8_tkleidos::drivers::rtc::accessors::clockOutValue (RtcClockOut freq)
Build the 0x0D CLKOUT-control byte for a CLKOUT setting.
constexpr RtcClockOutkleidos::drivers::rtc::accessors::parseClockOut (uint8_t clkoutControlReg)
Decode the 0x0D CLKOUT-control byte into a CLKOUT setting.
constexpr boolkleidos::drivers::rtc::accessors::clockIntegrityValid (uint8_t vlSecondsReg)
Decode the VL_seconds register (0x02) into a clock-integrity verdict.
constexpr uint8_tkleidos::drivers::rtc::codec::bcdToByte (uint8_t value)
Decode a packed BCD byte (two 4-bit decimal nibbles) to a plain value.
constexpr uint8_tkleidos::drivers::rtc::codec::byteToBcd (uint8_t value)
Encode a plain 0..99 value to a packed BCD byte.
constexpr boolkleidos::drivers::rtc::codec::clockIntegrityLost (uint8_t vlSecondsReg)
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_tkleidos::drivers::rtc::codec::alarmField (uint8_t bcdValue, bool enabled)
Build an alarm value register byte: BCD payload plus the active-low alarm-enable (AE) bit7 — clear enables the field, set disables it.
constexpr boolkleidos::drivers::rtc::codec::alarmFieldEnabled (uint8_t reg)
Read the active-low alarm-enable (AE) bit of an alarm value register.
constexpr uint32_tkleidos::drivers::rtc::codec::clkoutFreqHz (uint8_t fdBits)
Decode the CLKOUT FD[1:0] output-frequency code to Hz.
constexpr uint32_tkleidos::drivers::rtc::codec::timerSourceHzTimes100 (uint8_t tdBits)
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::drivers::rtc::createRtc (uint8_t address)
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_tkleidos::drivers::rtc::accessors::kAlarmRegCount
Number of contiguous alarm value registers (0x09..0x0C).
constexpr uint8_tkleidos::drivers::rtc::codec::kFieldFlagBit7
constexpr uint8_tkleidos::drivers::rtc::codec::kSourceCodeMask
Number of CLKOUT / countdown-timer source-select codes (2-bit field mask).
constexpr autokleidos::drivers::rtc::codec::kClkoutFreqHz
CLKOUT FD[1:0] output frequencies in Hz (datasheet Table 20), index = code.
constexpr autokleidos::drivers::rtc::codec::kTimerSourceHzTimes100
constexpr uint8_tkleidos::drivers::rtc::bm8563::kRegControlStatus1
Control/status 1 register.
constexpr uint8_tkleidos::drivers::rtc::bm8563::kRegControlStatus2
Control/status 2: alarm/timer interrupt enables + flags.
constexpr uint8_tkleidos::drivers::rtc::bm8563::kRegSeconds
Seconds (BCD, low 7 bits; bit7 = VL).
constexpr uint8_tkleidos::drivers::rtc::bm8563::kRegDay
Day-of-month (BCD, low 6 bits).
constexpr uint8_tkleidos::drivers::rtc::bm8563::kRegMinuteAlarm
Minute alarm (bit7 AE_M + BCD minute); 0x09..0x0C alarm block base.
constexpr uint8_tkleidos::drivers::rtc::bm8563::kRegHourAlarm
Hour alarm (bit7 AE_H + BCD hour).
constexpr uint8_tkleidos::drivers::rtc::bm8563::kRegDayAlarm
Day alarm (bit7 AE_D + BCD day-of-month).
constexpr uint8_tkleidos::drivers::rtc::bm8563::kRegWeekdayAlarm
Weekday alarm (bit7 AE_W + weekday 0..6).
constexpr uint8_tkleidos::drivers::rtc::bm8563::kRegClkoutControl
CLKOUT control (bit7 FE + FD[1:0] frequency select).
constexpr uint8_tkleidos::drivers::rtc::bm8563::kRegTimerControl
Timer control register (bit7 TE + TD[1:0] source).
constexpr uint8_tkleidos::drivers::rtc::bm8563::kRegTimer
Countdown-timer reload/read value (8-bit).
constexpr uint8_tkleidos::drivers::rtc::bm8563::kSecondsMask
Mask for the seconds value (BCD, low 7 bits).
constexpr uint8_tkleidos::drivers::rtc::bm8563::kVlFlagMask
VL (bit7 of VL_seconds): clock integrity lost.
constexpr uint8_tkleidos::drivers::rtc::bm8563::kMinutesMask
Mask for the minutes value (BCD, low 7 bits).
constexpr uint8_tkleidos::drivers::rtc::bm8563::kHoursMask
Mask for the hours value (BCD, low 6 bits).
constexpr uint8_tkleidos::drivers::rtc::bm8563::kDayMask
Mask for the day-of-month value (BCD, low 6 bits).
constexpr uint8_tkleidos::drivers::rtc::bm8563::kMonthMask
Mask for the month value (BCD, low 5 bits).
constexpr uint8_tkleidos::drivers::rtc::bm8563::kWeekdayMask
Mask for the weekday value (0..6, low 3 bits).
constexpr uint8_tkleidos::drivers::rtc::bm8563::kCenturyMask
Century bit in the month register (1 == 1900s, 0 == 2000s).
constexpr uint8_tkleidos::drivers::rtc::bm8563::kControl2AlarmFlag
AF (bit3): alarm flag; write 0 to clear.
constexpr uint8_tkleidos::drivers::rtc::bm8563::kControl2TimerFlag
TF (bit2): timer flag; write 0 to clear.
constexpr uint8_tkleidos::drivers::rtc::bm8563::kControl2AlarmIntEnable
AIE (bit1): alarm-interrupt enable.
constexpr uint8_tkleidos::drivers::rtc::bm8563::kControl2TimerIntEnable
TIE (bit0): timer-interrupt enable.
constexpr uint8_tkleidos::drivers::rtc::bm8563::kClkoutEnable
FE (bit7): CLKOUT pin output enable.
constexpr uint8_tkleidos::drivers::rtc::bm8563::kTimerEnable
TE (bit7): countdown-timer enable.
constexpr uint8_tkleidos::drivers::rtc::bm8563::kFrequencyCodeMask
FD/TD 2-bit frequency/source select mask.
constexpr uint8_tkleidos::drivers::rtc::bm8563::kTimerClockHzOneSixtieth
Timer source code: 1/60 Hz (1 pulse per minute).
constexpr uint16_tkleidos::drivers::rtc::bm8563::kCenturyBase1900
Base year when the century bit is set.
constexpr uint16_tkleidos::drivers::rtc::bm8563::kCenturyBase2000
Base year when the century bit is clear.
constexpr uint16_tkleidos::drivers::rtc::bm8563::kMinimumYear
Inclusive lower bound for set-year validation.
constexpr uint16_tkleidos::drivers::rtc::bm8563::kMaximumYear
Inclusive upper bound for set-year validation.

Back to the top

Function Documentation

alarmField() #

uint8_t kleidos::drivers::rtc::codec::alarmField(uint8_t bcdValue, bool enabled)
constexpr

Build an alarm value register byte: BCD payload plus the active-low alarm-enable (AE) bit7 — clear enables the field, set disables it.

Parameters
NameMeaning
bcdValueBCD alarm payload (bits6..0).
enabledTrue to enable the field (AE = 0), false to disable (AE = 1).
Returns
Alarm register byte with AE applied.

alarmFieldEnabled() #

bool kleidos::drivers::rtc::codec::alarmFieldEnabled(uint8_t reg)
constexpr

Read the active-low alarm-enable (AE) bit of an alarm value register.

Parameters
NameMeaning
regRaw alarm value register byte.
Returns
True when AE (bit7) is clear, i.e. the field participates.

assembleAlarm() #

std::array< uint8_t, kAlarmRegCount > kleidos::drivers::rtc::accessors::assembleAlarm(const RtcAlarm & alarm)
constexpr

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
NameDirectionMeaning
alarminAlarm match specification.
Returns
Register image, index 0 = minute (0x09) .. 3 = weekday (0x0C).

bcdToByte() #

uint8_t kleidos::drivers::rtc::codec::bcdToByte(uint8_t value)
constexpr

Decode a packed BCD byte (two 4-bit decimal nibbles) to a plain value.

Parameters
NameMeaning
valueBCD-encoded byte (e.g. 0x59).
Returns
Decimal value (e.g. 59).

byteToBcd() #

uint8_t kleidos::drivers::rtc::codec::byteToBcd(uint8_t value)
constexpr

Encode a plain 0..99 value to a packed BCD byte.

Parameters
NameMeaning
valueDecimal value (e.g. 59).
Returns
BCD-encoded byte (e.g. 0x59).

clkoutFreqHz() #

uint32_t kleidos::drivers::rtc::codec::clkoutFreqHz(uint8_t fdBits)
constexpr

Decode the CLKOUT FD[1:0] output-frequency code to Hz.

Parameters
NameMeaning
fdBits2-bit FD field (0..3); higher bits are ignored.
Returns
Output frequency in Hz (32768 / 1024 / 32 / 1).

clockIntegrityLost() #

bool kleidos::drivers::rtc::codec::clockIntegrityLost(uint8_t vlSecondsReg)
constexpr

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
NameMeaning
vlSecondsRegRaw VL_seconds register byte.
Returns
True if bit7 (VL) is set.

clockIntegrityValid() #

bool kleidos::drivers::rtc::accessors::clockIntegrityValid(uint8_t vlSecondsReg)
constexpr

Decode the VL_seconds register (0x02) into a clock-integrity verdict.

Parameters
NameDirectionMeaning
vlSecondsReginRaw VL_seconds register byte.
Returns
True when clock integrity is intact (VL clear).

clockOutValue() #

uint8_t kleidos::drivers::rtc::accessors::clockOutValue(RtcClockOut freq)
constexpr

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
NameDirectionMeaning
freqinDesired CLKOUT frequency, or RtcClockOut::Off to disable.
Returns
CLKOUT-control register value (0, or FE | FD).

createRtc() #

IRtc * kleidos::drivers::rtc::createRtc(uint8_t address)

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
NameDirectionMeaning
addressinI2C address of the RTC chip.
Returns
Pointer to the singleton RTC driver, or nullptr.
See also
Bm8563

parseAlarm() #

RtcAlarm kleidos::drivers::rtc::accessors::parseAlarm(const std::array< uint8_t, kAlarmRegCount > & regs)
constexpr

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
NameDirectionMeaning
regsinRegister image, index 0 = minute (0x09) .. 3 = weekday (0x0C).
Returns
Decoded alarm match specification.

parseClockOut() #

RtcClockOut kleidos::drivers::rtc::accessors::parseClockOut(uint8_t clkoutControlReg)
constexpr

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
NameDirectionMeaning
clkoutControlReginRaw CLKOUT-control register byte.
Returns
Decoded CLKOUT frequency, or Off when FE is clear.

timerControlValue() #

uint8_t kleidos::drivers::rtc::accessors::timerControlValue(RtcTimerSource src)
constexpr

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
NameDirectionMeaning
srcinCountdown-timer source frequency.
Returns
Timer-control register value (TE | TD).

timerRunning() #

bool kleidos::drivers::rtc::accessors::timerRunning(uint8_t timerControlReg)
constexpr

Decode the 0x0E timer-control byte into a running/stopped verdict.

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
NameDirectionMeaning
timerControlReginRaw timer-control register byte.
Returns
True when TE is set (the countdown is armed).

timerSourceHzTimes100() #

uint32_t kleidos::drivers::rtc::codec::timerSourceHzTimes100(uint8_t tdBits)
constexpr

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
NameMeaning
tdBits2-bit TD field (0..3); higher bits are ignored.
Returns
Source rate x100 (409600 / 6400 / 100 / 1).

Back to the top

Variable Documentation

kFieldFlagBit7 #

uint8_t kleidos::drivers::rtc::codec::kFieldFlagBit7
constexpr

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 #

auto kleidos::drivers::rtc::codec::kTimerSourceHzTimes100
constexpr

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.

Back to the top