This PR adds native APIs for getting and setting real-time, either formatted as a timestamp or a struct rtc_time formatted datetime, abstracting both conversions between the two time formats, and the interactions with the underlying hardware which will be used to keep time.
The API
/** Get universal coordinated time timestamp */
int sys_time_get_timestamp(int64_t *timestamp);
/** Set universal coordinated time timestamp */
int sys_time_set_timestamp(const int64_t *timestamp);
/** Get universal coordinated time datetime */
int sys_time_get_datetime(struct rtc_time *datetime);
/** Set universal coordinated time datetime */
int sys_time_set_datetime(const struct rtc_time *datetime);
/** Convert universal coordinated time datetime to timestamp */
int sys_time_datetime_to_timestamp(int64_t *timestamp, const struct rtc_time *datetime);
/** Convert universal coordinated time timestamp to datetime */
int sys_time_timestamp_to_datetime(struct rtc_time *datetime, const int64_t *timestamp);
The timestamp is a UTC timestamp, stored in an int64_t. Datetime (clock+calendar) formatted time is stored in a struct rtc_time, which is 1-1 mapped to the struct tm.
Hardware support
RTC
This PR currently supports using an RTC as time provider. The RTC to use is designated using a DTS chosen node
/ {
chosen {
zephyr,rtc = &rtc;
};
};
Counter (In progress)
This PR will be expanded to support using a low power counter as a time provider, using the counter.h API to configure it, and the retained_mem.h to store the offset between the counter value and the timestamp. Chosen nodes will be used to designate both the retained mem area, and the counter to use:
Introduction
This PR adds native APIs for getting and setting real-time, either formatted as a timestamp or a
struct rtc_time
formatted datetime, abstracting both conversions between the two time formats, and the interactions with the underlying hardware which will be used to keep time.The API
The timestamp is a UTC timestamp, stored in an
int64_t
. Datetime (clock+calendar) formatted time is stored in astruct rtc_time
, which is 1-1 mapped to thestruct tm
.Hardware support
RTC
This PR currently supports using an RTC as time provider. The RTC to use is designated using a DTS chosen node
Counter (In progress)
This PR will be expanded to support using a low power counter as a time provider, using the
counter.h
API to configure it, and theretained_mem.h
to store the offset between the counter value and the timestamp. Chosen nodes will be used to designate both the retained mem area, and the counter to use:fixes: #35333