2 * This file is part of Cleanflight.
4 * Cleanflight is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * Cleanflight is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
27 // time difference, 32 bits always sufficient
28 typedef int32_t timeDelta_t
;
30 typedef uint32_t timeMs_t
;
33 typedef uint64_t timeUs_t
;
34 #define TIMEUS_MAX UINT64_MAX
36 typedef uint32_t timeUs_t
;
37 #define TIMEUS_MAX UINT32_MAX
40 static inline timeDelta_t
cmpTimeUs(timeUs_t a
, timeUs_t b
) { return (timeDelta_t
)(a
- b
); }
42 #define FORMATTED_DATE_TIME_BUFSIZE 30
46 typedef struct timeConfig_s
{
47 int16_t tz_offsetMinutes
; // Offset from UTC in minutes, might be positive or negative
50 PG_DECLARE(timeConfig_t
, timeConfig
);
52 // Milliseconds since Jan 1 1970
53 typedef int64_t rtcTime_t
;
55 rtcTime_t
rtcTimeMake(int32_t secs
, uint16_t millis
);
56 int32_t rtcTimeGetSeconds(rtcTime_t
*t
);
57 uint16_t rtcTimeGetMillis(rtcTime_t
*t
);
59 typedef struct _dateTime_s
{
76 // buf must be at least FORMATTED_DATE_TIME_BUFSIZE
77 bool dateTimeFormatUTC(char *buf
, dateTime_t
*dt
);
78 bool dateTimeFormatLocal(char *buf
, dateTime_t
*dt
);
79 bool dateTimeFormatLocalShort(char *buf
, dateTime_t
*dt
);
81 void dateTimeUTCToLocal(dateTime_t
*utcDateTime
, dateTime_t
*localDateTime
);
82 // dateTimeSplitFormatted splits a formatted date into its date
83 // and time parts. Note that the string pointed by formatted will
84 // be modifed and will become invalid after calling this function.
85 bool dateTimeSplitFormatted(char *formatted
, char **date
, char **time
);
87 bool rtcHasTime(void);
89 bool rtcGet(rtcTime_t
*t
);
90 bool rtcSet(rtcTime_t
*t
);
92 bool rtcGetDateTime(dateTime_t
*dt
);
93 bool rtcSetDateTime(dateTime_t
*dt
);