#ifndef __TIME_H #define __TIME_H #include #define M41T82_ADDR 0xD0 #define SECONDS_TO_DAY 86400 // ñêîëüêî ñåêóíä â äíå #define HOURS_TO_DAY 24 // ÷àñîâ â äíå #define SECONDS_TO_HOUR 3600 // ñêîëüêî ñåêóíä â ÷àñå #define SECONDS_TO_MIN 60 // ñêîëüêî ñåêóíä â ìèíóòå #define YEAR_START 1970 // Ýïîõà þíèêñ #define MONTH_DECEMBER 12 // äåêàáðü #define SNTP_UPDATE_DELAY 64000 typedef enum { NON_LEAP = 0x00, LEAP = 0x01 }leap_year_t; typedef uint32_t time_t; typedef struct{ uint8_t Day; uint8_t Month; uint16_t Year; }DataRTC_typeDef; typedef struct{ uint8_t mSec; uint8_t Sec; uint8_t Min; uint8_t Hour; }TimeRTC_typeDef; typedef struct{ _Bool WDT: 1; uint8_t ALR: 2; _Bool BAT_LOW: 1; _Bool TMR: 1; _Bool OSC_FAIL: 1; }FlagsRTC_typeDef; typedef struct{ // _Bool Enable; // int8_t timeZone; int8_t Correction; DataRTC_typeDef Data; TimeRTC_typeDef Time; FlagsRTC_typeDef Flags; }RealTimeClock_typeDef; void clock_init(void); int32_t time_to_unix(RealTimeClock_typeDef *t); void unix_to_time(RealTimeClock_typeDef *t, int32_t secsarg); void set_system_time_NTP(uint32_t sec); void get_system_time_NTP(int32_t *sec, uint32_t *msec); uint8_t SetDisable_RTC(void); uint8_t SetEnable_RTC(void); uint8_t isEnable_RTC(void); void ClearBitHT_RTC(void); uint8_t SetCurrent_RTC(RealTimeClock_typeDef *ptrClock); uint8_t GetCurrent_RTC(RealTimeClock_typeDef *ptrClock); void GetCorrection_RTC(RealTimeClock_typeDef *ptrClock); void SetCorrection_RTC(RealTimeClock_typeDef *ptrClock, int8_t corr); #endif /* __TIME_H */