47 lines
1.0 KiB
C
47 lines
1.0 KiB
C
#ifndef RTC_TASK_H
|
|
#define RTC_TASK_H
|
|
|
|
#include <Arduino.h>
|
|
#include <SoftWire.h>
|
|
#include <freertos/FreeRTOS.h>
|
|
#include <freertos/task.h>
|
|
#include <freertos/semphr.h>
|
|
#include "config.h"
|
|
|
|
// RTC status
|
|
struct RTCStatus {
|
|
bool available; // DS3231 detected on I2C
|
|
bool timeSynced; // RTC has been set with valid time
|
|
uint32_t syncCount; // Number of RTC → System syncs
|
|
float temperature; // DS3231 internal temperature
|
|
};
|
|
|
|
extern RTCStatus rtcStatus;
|
|
extern SemaphoreHandle_t rtcMutex;
|
|
|
|
// Initialize DS3231 and read time
|
|
bool rtcInit();
|
|
|
|
// Read time from DS3231 → returns epoch (0 = fail)
|
|
time_t rtcReadTime();
|
|
|
|
// Write time to DS3231 from epoch
|
|
bool rtcWriteTime(time_t epoch);
|
|
|
|
// Sync: RTC → ESP32 system clock
|
|
bool rtcSyncToSystem();
|
|
|
|
// Sync: ESP32 system clock → RTC
|
|
bool rtcSyncFromSystem();
|
|
|
|
// Read DS3231 temperature (°C, ±0.25 resolution)
|
|
float rtcReadTemperature();
|
|
|
|
// RTC periodic sync task
|
|
void rtcSyncTask(void *param);
|
|
|
|
// Start RTC task
|
|
void rtcTaskInit();
|
|
|
|
#endif // RTC_TASK_H
|