13#ifndef ZEPHYR_INCLUDE_DRIVERS_RTC_H_
14#define ZEPHYR_INCLUDE_DRIVERS_RTC_H_
39#define RTC_ALARM_TIME_MASK_SECOND BIT(0)
40#define RTC_ALARM_TIME_MASK_MINUTE BIT(1)
41#define RTC_ALARM_TIME_MASK_HOUR BIT(2)
42#define RTC_ALARM_TIME_MASK_MONTHDAY BIT(3)
43#define RTC_ALARM_TIME_MASK_MONTH BIT(4)
44#define RTC_ALARM_TIME_MASK_YEAR BIT(5)
45#define RTC_ALARM_TIME_MASK_WEEKDAY BIT(6)
46#define RTC_ALARM_TIME_MASK_YEARDAY BIT(7)
47#define RTC_ALARM_TIME_MASK_NSEC BIT(8)
103typedef int (*rtc_api_set_time)(
const struct device *dev,
const struct rtc_time *timeptr);
109typedef int (*rtc_api_get_time)(
const struct device *dev,
struct rtc_time *timeptr);
115typedef int (*rtc_api_alarm_get_supported_fields)(
const struct device *dev,
uint16_t id,
136typedef int (*rtc_api_alarm_is_pending)(
const struct device *dev,
uint16_t id);
142typedef int (*rtc_api_alarm_set_callback)(
const struct device *dev,
uint16_t id,
149typedef int (*rtc_api_update_set_callback)(
const struct device *dev,
156typedef int (*rtc_api_set_calibration)(
const struct device *dev,
int32_t calibration);
162typedef int (*rtc_api_get_calibration)(
const struct device *dev,
int32_t *calibration);
167__subsystem
struct rtc_driver_api {
168 rtc_api_set_time set_time;
169 rtc_api_get_time get_time;
170#if defined(CONFIG_RTC_ALARM) || defined(__DOXYGEN__)
171 rtc_api_alarm_get_supported_fields alarm_get_supported_fields;
172 rtc_api_alarm_set_time alarm_set_time;
173 rtc_api_alarm_get_time alarm_get_time;
174 rtc_api_alarm_is_pending alarm_is_pending;
175 rtc_api_alarm_set_callback alarm_set_callback;
177#if defined(CONFIG_RTC_UPDATE) || defined(__DOXYGEN__)
178 rtc_api_update_set_callback update_set_callback;
180#if defined(CONFIG_RTC_CALIBRATION) || defined(__DOXYGEN__)
181 rtc_api_set_calibration set_calibration;
182 rtc_api_get_calibration get_calibration;
200static inline int z_impl_rtc_set_time(
const struct device *dev,
const struct rtc_time *timeptr)
217static inline int z_impl_rtc_get_time(
const struct device *dev,
struct rtc_time *timeptr)
226#if defined(CONFIG_RTC_ALARM) || defined(__DOXYGEN__)
245static inline int z_impl_rtc_alarm_get_supported_fields(
const struct device *dev,
uint16_t id,
248 if (
DEVICE_API_GET(rtc, dev)->alarm_get_supported_fields == NULL) {
252 return DEVICE_API_GET(rtc, dev)->alarm_get_supported_fields(dev,
id, mask);
288 return DEVICE_API_GET(rtc, dev)->alarm_set_time(dev,
id, mask, timeptr);
316 return DEVICE_API_GET(rtc, dev)->alarm_get_time(dev,
id, mask, timeptr);
336static inline int z_impl_rtc_alarm_is_pending(
const struct device *dev,
uint16_t id)
374static inline int z_impl_rtc_alarm_set_callback(
const struct device *dev,
uint16_t id,
381 return DEVICE_API_GET(rtc, dev)->alarm_set_callback(dev,
id, callback, user_data);
393#if defined(CONFIG_RTC_UPDATE) || defined(__DOXYGEN__)
417static inline int z_impl_rtc_update_set_callback(
const struct device *dev,
424 return DEVICE_API_GET(rtc, dev)->update_set_callback(dev, callback, user_data);
436#if defined(CONFIG_RTC_CALIBRATION) || defined(__DOXYGEN__)
458static inline int z_impl_rtc_set_calibration(
const struct device *dev,
int32_t calibration)
464 return DEVICE_API_GET(rtc, dev)->set_calibration(dev, calibration);
479static inline int z_impl_rtc_get_calibration(
const struct device *dev,
int32_t *calibration)
485 return DEVICE_API_GET(rtc, dev)->get_calibration(dev, calibration);
509 return (
struct tm *)timeptr;
521 __ASSERT_NO_MSG(frequency > 0);
523 return (
int32_t)((1000000000000000000LL / frequency) - 1000000000);
538#include <zephyr/syscalls/rtc.h>
#define DEVICE_API_GET(_class, _dev)
Expands to the pointer of a device's API for a given class.
Definition device.h:1221
int rtc_set_calibration(const struct device *dev, int32_t calibration)
API for setting RTC calibration.
int rtc_alarm_set_time(const struct device *dev, uint16_t id, uint16_t mask, const struct rtc_time *timeptr)
API for setting RTC alarm time.
int rtc_get_time(const struct device *dev, struct rtc_time *timeptr)
API for getting RTC time.
int rtc_set_time(const struct device *dev, const struct rtc_time *timeptr)
API for setting RTC time.
int rtc_alarm_is_pending(const struct device *dev, uint16_t id)
API for testing if RTC alarm is pending.
int rtc_alarm_get_supported_fields(const struct device *dev, uint16_t id, uint16_t *mask)
API for getting the supported fields of the RTC alarm time.
int rtc_alarm_set_callback(const struct device *dev, uint16_t id, rtc_alarm_callback callback, void *user_data)
API for setting alarm callback.
void(* rtc_alarm_callback)(const struct device *dev, uint16_t id, void *user_data)
RTC alarm triggered callback.
Definition rtc.h:91
void(* rtc_update_callback)(const struct device *dev, void *user_data)
RTC update event callback.
Definition rtc.h:81
int rtc_get_calibration(const struct device *dev, int32_t *calibration)
API for getting RTC calibration.
static struct tm * rtc_time_to_tm(struct rtc_time *timeptr)
Convenience function for safely casting a rtc_time pointer to a tm pointer.
Definition rtc.h:507
int rtc_alarm_get_time(const struct device *dev, uint16_t id, uint16_t *mask, struct rtc_time *timeptr)
API for getting RTC alarm time.
static int32_t rtc_calibration_from_frequency(uint32_t frequency)
Determine required calibration to 1 Hertz from frequency.
Definition rtc.h:519
int rtc_update_set_callback(const struct device *dev, rtc_update_callback callback, void *user_data)
API for setting update callback.
#define ENOSYS
Function not implemented.
Definition errno.h:82
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__INT32_TYPE__ int32_t
Definition stdint.h:74
__UINT16_TYPE__ uint16_t
Definition stdint.h:89
Runtime device structure (in ROM) per driver instance.
Definition device.h:411
Structure for storing date and time values with sub-second precision.
Definition rtc.h:61
int tm_yday
Day of the year [0, 365] (Unknown = -1)
Definition rtc.h:69
int tm_nsec
Nanoseconds [0, 999999999] (Unknown = 0)
Definition rtc.h:71
int tm_min
Minutes [0, 59].
Definition rtc.h:63
int tm_mon
Month [0, 11].
Definition rtc.h:66
int tm_isdst
Daylight saving time flag [-1] (Unknown = -1)
Definition rtc.h:70
int tm_wday
Day of the week [0, 6] (Sunday = 0) (Unknown = -1)
Definition rtc.h:68
int tm_year
Year - 1900.
Definition rtc.h:67
int tm_sec
Seconds [0, 59].
Definition rtc.h:62
int tm_hour
Hours [0, 23].
Definition rtc.h:64
int tm_mday
Day of the month [1, 31].
Definition rtc.h:65