我正在尝试在 Linux 设备上配置 RTC 警报。我使用了RTC 文档中的一个示例:
    int retval
    struct rtc_time rtc_tm;
    /* .... */
    /* Read the RTC time/date */
    retval = ioctl(fd, RTC_RD_TIME, &rtc_tm);
    if (retval == -1) {
       exit(errno);
    }
    /* Set the alarm to 5 sec in the future, and check for rollover */
    rtc_tm.tm_sec += 5;
    if (rtc_tm.tm_sec >= 60) {
         rtc_tm.tm_sec %= 60;
         rtc_tm.tm_min++;
    }
    if (rtc_tm.tm_min == 60) {
         rtc_tm.tm_min = 0;
         rtc_tm.tm_hour++;
    }
    if (rtc_tm.tm_hour == 24)
         rtc_tm.tm_hour = 0;
    retval = ioctl(fd, RTC_ALM_SET, &rtc_tm);
    if (retval == -1) {
        exit(errno);
}
此代码片段使用绝对时间(从纪元开始),它对我不起作用。我认为这是由于硬件中的错误,但经过一些看似随机的时间后,警报确实触发了。我设法找到的唯一其他文档是rtc.cc中的评论:
 case RTC_ALM_SET: /* Store a time into the alarm */
 {
      /*
       * This expects a struct rtc_time. Writing 0xff means
       * "don't care" or "match all". Only the tm_hour,
       * tm_min and tm_sec are used.
       */
仅使用小时、分钟和秒这一事实表明时间与调用 ioctl 的时刻相关。
传递给 ioctl(fd, RTC_ALM_SET, &rtc_tm) 的时间应该是相对的还是绝对的?