zoukankan      html  css  js  c++  java
  • 应用程序 /dev/rtc 编程 获取时间 2011-12-13 01:01:06【转】

    本文转载自:http://blog.chinaunix.net/uid-16785183-id-3040310.html

    分类:

    原文地址:应用程序 /dev/rtc 编程 获取时间 作者:yuweixian4230

    找的一些rtc资料:
     
     
     
    ubuntu10.10 /dev/rtc
    功能: 简单操作,打开/dev/rtc, 然后获取 时间信息
     
    在busybox源码src/include/rtc.h 和 linux /usr/include/linux/rtc.h有如下定义数据结构:
    1. struct rtc_time {
    2.         int tm_sec;
    3.         int tm_min;
    4.         int tm_hour;
    5.         int tm_mday;
    6.         int tm_mon;
    7.         int tm_year;
    8.         int tm_wday;
    9.         int tm_yday;
    10.         int tm_isdst;
    11. };
     
    ioctl命令
     
    1. #define RTC_AIE_ON   打开alarm中断
    2. #define RTC_AIE_OFF   关闭 alarm中断
    3. #define RTC_UIE_ON    打开update类型的中断
    4. #define RTC_UIE_OFF   关闭
    5. #define RTC_PIE_ON    打开周期性中断
    6. #define RTC_PIE_OFF   关闭
    7. #define RTC_WIE_ON    
    8. #define RTC_WIE_OFF
    9. #define RTC_ALM_SET     设置alarm的时间
    10. #define RTC_ALM_READ     读取alarm的时间
    11. #define RTC_RD_TIME   读取当前的rtc时间
    12. #define RTC_SET_TIME   设置当前的rtc时间
    13. #define RTC_IRQP_READ  读取当前周期性中断的频率
    14. #define RTC_IRQP_SET   设置当前周期性中断的频率
    15. #define RTC_EPOCH_READ
     

    附件源码: rtc.rar   将rar修改为 tar.bz2
     
    1. #include <stdio.h>//printf funciton
    2. #include <stdlib.h>//EXIT_FAILURE
    3. #include <linux/rtc.h> //usr/include/linux/rtc.h struct rtc_time
    4. #include <fcntl.h> //O_RDONLY open close funciton
    5. #include <sys/ioctl.h> //ioctl funciton /usr/include/sys/ioctl
    6. int main(int argc,char *argv[])
    7. {
    8.     int retval,fd;
    9.     struct rtc_time rtc_tm;
    10.     fd=open("/dev/rtc",O_RDONLY);    
    11.     if(fd==-1)
    12.     {
    13.         perror("error open /dev/rtc");
    14.         exit(EXIT_FAILURE);
    15.     }
    16.     retval=ioctl(fd,RTC_RD_TIME,&rtc_tm);
    17.     if(retval==-1)
    18.     {
    19.         perror("error RTC_RD_TIME ioctl");
    20.         exit(EXIT_FAILURE);
    21.     }
    22.     printf("sec=%d,min=%d,hour=%d ",rtc_tm.tm_sec,rtc_tm.tm_min,rtc_tm.tm_hour);
    23.     close(fd);
    24.     exit(EXIT_SUCCESS);
    25. }
     
    1. ywx@ywx:~/desktop/module/rtc$ sudo ./rtc
    2. [sudo] password for ywx: 
    3. sec=53,min=29,hour=1
    一篇网上的代码:设置rtc时间
     
  • 相关阅读:
    [leetcode]Valid Number
    [leetcode]Edit Distance
    [leetcode]Decode Ways
    [leetcode]Maximum Depth of Binary Tree
    [topcoder]BadNeighbors
    [topcoder]ZigZag
    [leetcode]Subsets II
    [leetcode]Merge Sorted Array
    [leetcode]Binary Tree Maximum Path Sum
    hdu 2964 Prime Bases(简单数学题)
  • 原文地址:https://www.cnblogs.com/zzb-Dream-90Time/p/7580471.html
Copyright © 2011-2022 走看看