blob: 805aef95a506ceb6f7ac6f22155961cc59820ab1 [file] [log] [blame]
#include <stdio.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/rtc.h>
int main() {
int rtc_fd = open("/dev/rtc0", O_RDWR);
if (rtc_fd == -1) {
perror("open");
return 1;
}
struct rtc_time rtc_tm;
struct rtc_wkalrm rtc_alarm;
int flags;
// ......
if (ioctl(rtc_fd, RTC_RD_TIME, &rtc_alarm.time) == -1) {
perror("ioctl RTC_RD_TIME");
close(rtc_fd);
return 1;
}
// ......
printf("Current RTC time: %d-%d-%d %02d:%02d:%02d\n",
rtc_alarm.time.tm_year, rtc_alarm.time.tm_mon, rtc_alarm.time.tm_mday, rtc_alarm.time.tm_hour, rtc_alarm.time.tm_min, rtc_alarm.time.tm_sec);
// .. RTC ...
rtc_alarm.time.tm_sec = rtc_tm.tm_sec + 10; // 10 .......
rtc_alarm.enabled = 1;
if (ioctl(rtc_fd, RTC_WKALM_SET, &rtc_alarm) == -1) {
perror("ioctl RTC_WKALM_SET1");
close(rtc_fd);
return 1;
}
if (ioctl(rtc_fd, RTC_AIE_ON) == -1) {
perror("ioctl RTC_AIE_ON");
close(rtc_fd);
return 1;
}
printf("RTC alarm set for 10 seconds from now1\n");
#if 0
rtc_alarm.time.tm_sec = rtc_tm.tm_sec + 10; // 10 .......
rtc_alarm.enabled = 0;
if (ioctl(rtc_fd, RTC_WKALM_SET, &rtc_alarm) == -1) {
perror("ioctl RTC_WKALM_SET2");
close(rtc_fd);
return 1;
}
if (ioctl(rtc_fd, RTC_AIE_OFF) == -1) {
perror("ioctl RTC_AIE_OFF");
close(rtc_fd);
return 1;
}
printf("RTC alarm disable2\n");
#endif
close(rtc_fd);
return 0;
}