source: S-port/trunk/Core/Inc/Time.h

Last change on this file was 1, checked in by AlexLir, 3 years ago
File size: 1.6 KB
Line 
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
15typedef enum {
16 NON_LEAP = 0x00,
17 LEAP = 0x01
18}leap_year_t;
19
20typedef uint32_t time_t;
21
22typedef struct{
23 uint8_t Day;
24 uint8_t Month;
25 uint16_t Year;
26}DataRTC_typeDef;
27
28typedef struct{
29 uint8_t mSec;
30 uint8_t Sec;
31 uint8_t Min;
32 uint8_t Hour;
33}TimeRTC_typeDef;
34
35typedef 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
43typedef 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
52void clock_init(void);
53int32_t time_to_unix(RealTimeClock_typeDef *t);
54void unix_to_time(RealTimeClock_typeDef *t, int32_t secsarg);
55
56void set_system_time_NTP(uint32_t sec);
57void get_system_time_NTP(int32_t *sec, uint32_t *msec);
58
59uint8_t SetDisable_RTC(void);
60uint8_t SetEnable_RTC(void);
61uint8_t isEnable_RTC(void);
62void ClearBitHT_RTC(void);
63uint8_t SetCurrent_RTC(RealTimeClock_typeDef *ptrClock);
64uint8_t GetCurrent_RTC(RealTimeClock_typeDef *ptrClock);
65void GetCorrection_RTC(RealTimeClock_typeDef *ptrClock);
66void SetCorrection_RTC(RealTimeClock_typeDef *ptrClock, int8_t corr);
67
68#endif /* __TIME_H */
Note: See TracBrowser for help on using the repository browser.