|
ProtoCore v1.0.16
Deterministic, zero-heap network stack for embedded targets
|
I2C real-time-clock driver (DS1307 / DS3231) - a battery-backed time source. More...
#include "protocore_config.h"Go to the source code of this file.
Classes | |
| struct | RtcNs |
| Dispatch table. Addressed by offset, so the layout is asserted below. More... | |
Macros | |
| #define | RTC_REG_COUNT 7 |
Functions | |
| PROTOCORE_NS_LAYOUT (RtcNs, regs_to_epoch, epoch_to_regs, begin, read_epoch, set_epoch, time_source) | |
| proto_bool | protocore_rtc_regs_to_epoch (uint8_t *work, const uint8_t *regs, uint32_t *epoch) |
| Convert the 7 raw RTC time registers (BCD: sec, min, hour, dow, . | |
| void | protocore_rtc_epoch_to_regs (uint8_t *work, uint32_t epoch, uint8_t *regs) |
| Convert a Unix timestamp to the 7 RTC time registers (BCD, . | |
| proto_bool | protocore_rtc_begin (uint8_t *work) |
| Initialize the I2C bus for the RTC. true; with no bus seam it is a . | |
| uint32_t | protocore_rtc_read_epoch (uint8_t *work) |
| Read the current time from the RTC over I2C. | |
| proto_bool | protocore_rtc_set_epoch (uint8_t *work, uint32_t epoch) |
| Set the RTC to epoch over I2C. true if the write succeeded. | |
| void | protocore_rtc_time_source (uint8_t *work) |
| A TimeSourceFn wrapper (returns protocore_rtc_read_epoch()) to . | |
| uint8_t * | protocore_rtc_span (void) |
| The PROTOCORE_I2C_DEVICE_BORROW bytes this module's state lives in. | |
Variables | |
| PROTOCORE_NS RtcNs Rtc | PROTOCORE_UNUSED |
| Module namespace. | |
I2C real-time-clock driver (DS1307 / DS3231) - a battery-backed time source.
A DS1307 or DS3231 keeps the wall-clock time running from a coin cell when the ESP32 is off or offline. This reads it (and can set it) over I2C, and plugs into the time-source chain so protocore_time_now() - and the NTP server - can use it: GPS when locked, the RTC when GPS and the internet are gone, upstream NTP otherwise. Both chips expose the same seven BCD time registers at address 0x68, so one driver serves both. Zero heap; gated by PROTOCORE_ENABLE_RTC.
The BCD <-> Unix-epoch conversion (12/24-hour, leap years, range validation) is pure and host-tested; only the register read/write touches hardware, over the shared I2C bus owner.
work is PROTOCORE_I2C_DEVICE_BORROW bytes the CALLER took, at an address it knows. It is not held past the call, so nothing here aliases it. How those bytes are carved is this module's and is never named here.
Definition in file rtc.h.
| PROTOCORE_NS_LAYOUT | ( | RtcNs | , |
| regs_to_epoch | , | ||
| epoch_to_regs | , | ||
| begin | , | ||
| read_epoch | , | ||
| set_epoch | , | ||
| time_source | |||
| ) |
| proto_bool protocore_rtc_regs_to_epoch | ( | uint8_t * | work, |
| const uint8_t * | regs, | ||
| uint32_t * | epoch | ||
| ) |
Convert the 7 raw RTC time registers (BCD: sec, min, hour, dow, .
| work | PROTOCORE_RTC_BORROW bytes the caller took. Not held past the call. |
| regs | the 7 register bytes as read from register 0 RTC_REG_COUNT bytes |
| epoch | out: seconds since 1970-01-01 UTC |
| void protocore_rtc_epoch_to_regs | ( | uint8_t * | work, |
| uint32_t | epoch, | ||
| uint8_t * | regs | ||
| ) |
Convert a Unix timestamp to the 7 RTC time registers (BCD, .
| work | PROTOCORE_RTC_BORROW bytes the caller took. Not held past the call. |
| epoch | Epoch |
| regs | RTC_REG_COUNT bytes |
| proto_bool protocore_rtc_begin | ( | uint8_t * | work | ) |
Initialize the I2C bus for the RTC. true; with no bus seam it is a .
| work | PROTOCORE_RTC_BORROW bytes the caller took. Not held past the call. |
| uint32_t protocore_rtc_read_epoch | ( | uint8_t * | work | ) |
Read the current time from the RTC over I2C.
| work | PROTOCORE_RTC_BORROW bytes the caller took. Not held past the call. |
| proto_bool protocore_rtc_set_epoch | ( | uint8_t * | work, |
| uint32_t | epoch | ||
| ) |
Set the RTC to epoch over I2C. true if the write succeeded.
| work | PROTOCORE_RTC_BORROW bytes the caller took. Not held past the call. |
| epoch | Epoch |
| void protocore_rtc_time_source | ( | uint8_t * | work | ) |
A TimeSourceFn wrapper (returns protocore_rtc_read_epoch()) to .
| work | PROTOCORE_RTC_BORROW bytes the caller took. Not held past the call. |
| uint8_t * protocore_rtc_span | ( | void | ) |
The PROTOCORE_I2C_DEVICE_BORROW bytes this module's state lives in.
Stated beside the namespace rather than on it: an entry takes a borrow, and this is where that borrow comes from. Taken once from the end of the pool, which no mark and no release walks, so the state lasts the life of the program.
| PROTOCORE_NS RtcNs Rtc PROTOCORE_UNUSED |
Module namespace.