程序获取rtc时间

strace hwclock看到ioctl调用  

读取rtc时间

    int fd;
    struct rtc_time rtc_tm;
    int ret;

    fd = open("/dev/rtc0", O_RDONLY, 0);

    // the ioctl command RTC_RD_TIME is used to read the current timer.
    // about the detail ioctl command, refer to section 3
    ret = ioctl(fd, RTC_RD_TIME, &rtc_tm);

    ::close(fd);

读取系统时间
    QDateTime datetime = QDateTime::currentDateTime();
    QDate sysdate = datetime.date();
    QDate hwdate(rtc_tm.tm_year+1900, rtc_tm.tm_mon+1, rtc_tm.tm_mday);

    qDebug()<    if(sysdate!=hwdate)

 

 

http://www.uclinux.org/pub/uClinux/ports/blackfin/docs/Device%20Driver%20Integration%20Notes%20and%20Tests/RTC_device_driver.txt

http://download.analog.com/27516/trackeritem/1/2/4/1247/rtc_test.c

你可能感兴趣的:(程序获取rtc时间)