RTC APIs

This topic provides details for the RTC APIs.

rtc_read_time

Synopsis
int rtc_read_time(struct rtc_device *rtc, struct rtc_time *tm)
Description Reads RTC time information from a specific RTC device.
Parameter
  • rtc: The target RTC device

  • tm: The location where the RTC time information is stored

Return
  • Success: 0
  • Failure: Error code

rtc_set_time

Synopsis
int rtc_set_time(struct rtc_device *rtc, struct rtc_time *tm)
Description Sets RTC time information on a specific RTC device.
Parameter
  • rtc: The target RTC device

  • tm: The location where the RTC time information is stored

Return
  • Success: 0
  • Failure: Error code

rtc_read_alarm

Synopsis
int rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm)
Description Reads alarm time from a specific RTC device.
Parameter
  • rtc: The target RTC device

  • tm: The location where the alarm time is stored

Return
  • Success: 0
  • Failure: Error code

rtc_set_alarm

Synopsis
int rtc_set_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm)
Description Sets alarm time on a specific RTC device.
Parameter
  • rtc: The target RTC device

  • tm: The location where the alarm time is stored

Return
  • Success: 0
  • Failure: Error code

rtc_read_offset

Synopsis
int rtc_read_offset(struct rtc_device *rtc, long *offset)
Description Reads the count of RTC offset in parts per billion.
Parameter
  • rtc: The target RTC device

  • offset: The offset in parts per billion

Return
  • Success: 0
  • Failure: Error code

rtc_set_offset

Synopsis
int rtc_set_offset(struct rtc_device *rtc, long offset)
Description Sets the RTC offset in parts per billion.
Parameter
  • rtc: The target RTC device

  • offset: The core calibration value used to correct the timekeeping accuracy of the RTC

Return
  • Success: 0
  • Failure: Error code

rtc_update_irq

Synopsis
void rtc_update_irq(struct rtc_device *rtc, unsigned long num, unsigned long events)
Description Clears the outdated alarms when an RTC interrupt occurs.
Parameter
  • rtc: The target RTC device

  • num: The number of the IRQ events reported (Usually only 1 event is reported.)

  • events: The mask of RTC_IRQF with one or more of RTC_PF, RTC_AF, RTC_UF

Return None

rtc_allocate_device

Synopsis
static struct rtc_device *rtc_allocate_device(void)
Description Allocates an RTC device and then initializes the RTC device.
Parameter None
Return
  • Success: The pointer of the allocated RTC device
  • Failure: NULL

dvem_rtc_allocate_device

Synopsis
struct rtc_device *devm_rtc_allocate_device(struct device *dev)
Description Allocates an RTC device with the devm method and then initializes the RTC device.
Parameter
  • dev: The parent device to which the RTC device belongs

Return
  • Success: The pointer of the allocated RTC device
  • Failure: NULL

dvem_rtc_register_device

Synopsis
#define devm_rtc_register_device(device) __devm_rtc_register_device(THIS_MODULE, device) 
int __devm_rtc_register_device(struct module *owner, struct rtc_device *rtc)
Description Registers an RTC device.
Parameter
  • owner: The module to which the RTC device belongs

  • rtc: The target RTC device to register

Return
  • Success: 0
  • Failure: Error code

dvem_rtc_device_register

Synopsis
struct rtc_device *devm_rtc_device_register(struct device *dev, const char *name, const struct rtc_class_ops *ops, struct module *owner)
Description Re-allocates an RTC device and then registers the RTC device.
Parameter
  • dev: The parent device to which the RTC device belongs

  • name: Not used.

  • ops: The operation function of the RTC device

  • owner: The module to which the RTC device belongs

Return
  • Success: The pointer of the allocated RTC device
  • Failure: Error code