Rev | Line | |
---|
[1] | 1 | #ifndef __TIME_H
|
---|
| 2 | #define __TIME_H
|
---|
| 3 | #include <stdint.h>
|
---|
| 4 |
|
---|
| 5 | #define M41T82_ADDR 0xD0
|
---|
| 6 | #define SECONDS_TO_DAY 86400 // ñêîëüêî ñåêóíä â äíå
|
---|
| 7 | #define HOURS_TO_DAY 24 // ÷àñîâ â äíå
|
---|
| 8 | #define SECONDS_TO_HOUR 3600 // ñêîëüêî ñåêóíä â ÷àñå
|
---|
| 9 | #define SECONDS_TO_MIN 60 // ñêîëüêî ñåêóíä â ìèíóòå
|
---|
| 10 | #define YEAR_START 1970 // Ýïîõà þíèêñ
|
---|
| 11 | #define MONTH_DECEMBER 12 // äåêàáðü
|
---|
| 12 |
|
---|
| 13 | #define SNTP_UPDATE_DELAY 64000
|
---|
| 14 |
|
---|
| 15 | typedef enum {
|
---|
| 16 | NON_LEAP = 0x00,
|
---|
| 17 | LEAP = 0x01
|
---|
| 18 | }leap_year_t;
|
---|
| 19 |
|
---|
| 20 | typedef uint32_t time_t;
|
---|
| 21 |
|
---|
| 22 | typedef struct{
|
---|
| 23 | uint8_t Day;
|
---|
| 24 | uint8_t Month;
|
---|
| 25 | uint16_t Year;
|
---|
| 26 | }DataRTC_typeDef;
|
---|
| 27 |
|
---|
| 28 | typedef struct{
|
---|
| 29 | uint8_t mSec;
|
---|
| 30 | uint8_t Sec;
|
---|
| 31 | uint8_t Min;
|
---|
| 32 | uint8_t Hour;
|
---|
| 33 | }TimeRTC_typeDef;
|
---|
| 34 |
|
---|
| 35 | typedef struct{
|
---|
| 36 | _Bool WDT: 1;
|
---|
| 37 | uint8_t ALR: 2;
|
---|
| 38 | _Bool BAT_LOW: 1;
|
---|
| 39 | _Bool TMR: 1;
|
---|
| 40 | _Bool OSC_FAIL: 1;
|
---|
| 41 | }FlagsRTC_typeDef;
|
---|
| 42 |
|
---|
| 43 | typedef struct{
|
---|
| 44 | // _Bool Enable;
|
---|
| 45 | // int8_t timeZone;
|
---|
| 46 | int8_t Correction;
|
---|
| 47 | DataRTC_typeDef Data;
|
---|
| 48 | TimeRTC_typeDef Time;
|
---|
| 49 | FlagsRTC_typeDef Flags;
|
---|
| 50 | }RealTimeClock_typeDef;
|
---|
| 51 |
|
---|
| 52 | void clock_init(void);
|
---|
| 53 | int32_t time_to_unix(RealTimeClock_typeDef *t);
|
---|
| 54 | void unix_to_time(RealTimeClock_typeDef *t, int32_t secsarg);
|
---|
| 55 |
|
---|
| 56 | void set_system_time_NTP(uint32_t sec);
|
---|
| 57 | void get_system_time_NTP(int32_t *sec, uint32_t *msec);
|
---|
| 58 |
|
---|
| 59 | uint8_t SetDisable_RTC(void);
|
---|
| 60 | uint8_t SetEnable_RTC(void);
|
---|
| 61 | uint8_t isEnable_RTC(void);
|
---|
| 62 | void ClearBitHT_RTC(void);
|
---|
| 63 | uint8_t SetCurrent_RTC(RealTimeClock_typeDef *ptrClock);
|
---|
| 64 | uint8_t GetCurrent_RTC(RealTimeClock_typeDef *ptrClock);
|
---|
| 65 | void GetCorrection_RTC(RealTimeClock_typeDef *ptrClock);
|
---|
| 66 | void SetCorrection_RTC(RealTimeClock_typeDef *ptrClock, int8_t corr);
|
---|
| 67 |
|
---|
| 68 | #endif /* __TIME_H */
|
---|
Note:
See
TracBrowser
for help on using the repository browser.