Files
SC-F001/main/rtc.h
Thaddeus Hughes ff1ea6615c Many things, including a log timing report in the test
Timing report:

I (52322) LOG_TEST: === WRITE TIMING REPORT ===
I (52322) LOG_TEST:   Iterations:       200
I (52322) LOG_TEST:   Payload size:     39 bytes
I (52322) LOG_TEST:   Min:              49960 us
I (52332) LOG_TEST:   Max:              54476 us
I (52332) LOG_TEST:   Avg:              50005 us
I (52342) LOG_TEST:   Sector crossings: 2 (max 49983 us)
I (52342) LOG_TEST:   WDT margin:       4.9s (WDT=5s, worst=54476us)
I (52352) LOG_TEST: ===========================

so a write takes up to 54ms - not negligible!
2026-03-12 19:58:39 -05:00

58 lines
1.5 KiB
C

/*
* system.h
*
* Public system services:
* • Battery charge-state machine
* • Inactivity / deep-sleep handling
* • RTC time & alarm
*
* All implementation lives in system.c
*/
#ifndef MAIN_RTC_H_
#define MAIN_RTC_H_
#include "driver/gpio.h"
#include "esp_sleep.h"
#include "esp_timer.h"
#include "esp_err.h"
#include <time.h>
#define POWER_INACTIVITY_TIMEOUT_MS 180000
/* -------------------------------------------------------------------------- */
/* Public API */
/* -------------------------------------------------------------------------- */
esp_err_t rtc_xtal_init();
bool rtc_is_set();
void rtc_check_shutdown_timer();
void rtc_reset_shutdown_timer(); // reset shutoff timer
void soft_idle_enter(void);
void soft_idle_exit(void);
bool soft_idle_is_active(void);
bool soft_idle_button_raw(void); /* direct GPIO read, no I2C */
/*void adjust_rtc_hour(char *key, int8_t dir);
void adjust_rtc_min(char *key, int8_t dir);*/
int64_t rtc_get_s (void);
int64_t rtc_get_ms(void);
void rtc_set_s(int64_t);
void rtc_save_time(void); // No-op: time is always live via rtc_get_s()
void rtc_restore_time(void); // Re-syncs stdlib clock on boot; emits TIME log marker
void rtc_schedule_next_alarm(void);
int64_t rtc_get_next_alarm_s();
bool rtc_alarm_tripped();
void rtc_print_debug(void); // Dump full RTC state to stdout (UART)
/* -------------------------------------------------------------------------- */
#endif /* MAIN_RTC_H_ */