Chinaunix首页 | 论坛 | 博客
  • 博客访问: 4235937
  • 博文数量: 1148
  • 博客积分: 25453
  • 博客等级: 上将
  • 技术积分: 11949
  • 用 户 组: 普通用户
  • 注册时间: 2010-05-06 21:14
文章分类

全部博文(1148)

文章存档

2012年(15)

2011年(1078)

2010年(58)

分类: LINUX

2011-12-12 15:34:41

找的一些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\n",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时间






















阅读(1876) | 评论(0) | 转发(3) |
给主人留下些什么吧!~~