应用程序 /dev/rtc 编程 获取时间 2011-12-13 01:01:06【转】

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

分类:

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

找的一些rtc资料:

系统时钟硬件与LINUX时间表示二 之 Linux内核对RTC的编程

S3C2440上RTC时钟驱动开发实例讲解

linux 实时时钟(RTC)驱动

linux 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. [email protected]:~/desktop/module/rtc$ sudo ./rtc
  2. [sudo] password for ywx:
  3. sec=53,min=29,hour=1

一篇网上的代码:设置rtc时间

 settime.rar

时间: 2024-08-10 12:12:25

应用程序 /dev/rtc 编程 获取时间 2011-12-13 01:01:06【转】的相关文章

【转】vc++MCF/C++/C中怎样让应用程序获得或以管理员权限运行 ,ShellExecuteEX编程 --- 获取管理员权限

ShellExecuteEX编程 --- 获取管理员权限:http://blog.csdn.net/jhui163/article/details/5873027 怎样让你的应用程序获得管理员权限:就是在运行开发工具如vc6.0 或vs2010时,要以管理员身份运行,这样你的应用程序才可以继承 http://bbs.csdn.NET/topics/390262991 解决:在vs2010等开发工具中虽然以管理员身份编译运行了程序,可以获得管理员权限,但是当单独点击Debug或release版时,

小程序 js中获取时间new date()的用法(网络复制过来自用)

js中获取时间new date()的用法 获取时间: 1 var myDate = new Date();//获取系统当前时间 获取特定格式的时间: 1 myDate.getYear(); //获取当前年份(2位) 2 myDate.getFullYear(); //获取完整的年份(4位,1970-????) 3 myDate.getMonth(); //获取当前月份(0-11,0代表1月) 4 myDate.getDate(); //获取当前日(1-31) 5 myDate.getDay();

微信小程序的按下抬起事件,下拉选择框的事件及点击确定的方法函数,获取时间的方法,省市区的方法。

抬起按下的事件: 抬起事件: bind:touchstart="nanOne"   把这条属性放到标签里就可以了 在JS中 nanOne: function () { this.setData({ nvimg: '../img/nvOne.png', }) }, 按下事件: bind:touchend="nanTwo" 把这条属性放到标签里就可以了 在JS中 nanTwo: function () { this.setData({ nvimg: '../img/nv

【转载】c/c++在windows下获取时间和计算时间差的几种方法总结

一.标准C和C++都可用 1.获取时间用time_t time( time_t * timer ),计算时间差使用double difftime( time_t timer1, time_t timer0 ). 精确到秒. 测试程序如下: #include <time.h> #include <stdio.h> int main() { time_t start ,end ; double cost; time(&start); sleep(1); time(&en

linux获取时间函数及计算时间差

参考:   http://www.cnblogs.com/krythur/archive/2013/02/25/2932647.html 第一章  获取时间函数 1. char * asctime(const struct tm * timeptr); 函数说明 asctime()将参数timeptr所指的tm结构中的信息转换成真实世界所使用的时间日期表示方法,然后将结果以字符串形态返回.此函数已经由时区转换成当地时间,字符串格式为:"Wed Jun 30 21:49:08 1993\n&quo

Delphi编程获取系统当前进程、窗口句柄、文件属性以(转)

Delphi编程获取系统当前进程.窗口句柄.文件属性以及程序运行状态. uses TLHelp32,PsAPI; (1)显示进程列表:procedure TForm1.Button2Click(Sender: TObject);var lppe: TProcessEntry32;found : boolean;Hand : THandle;P:DWORD;s:string;beginListBox1.Items.Clear ;Hand := CreateToolhelp32Snapshot(TH

c和c++在windows下获取时间和计算时间差的方法总结

c/c++在windows下获取时间和计算时间差的几种方法总结 一.标准C和C++都可用 1.获取时间用time_t time( time_t * timer ),计算时间差使用double difftime( time_t timer1, time_t timer0 ). 精确到秒. 测试程序如下: 1 #include <time.h> 2 #include <stdio.h> 3 4 int main() 5 { 6 time_t start, end; 7 double c

linux编程获取本机网络相关参数

getifaddrs()和struct ifaddrs的使用,获取本机IP 博客分类: Linux C编程 ifaddrs结构体定义如下: C代码   struct ifaddrs { struct ifaddrs  *ifa_next;    /* Next item in list */ char            *ifa_name;    /* Name of interface */ unsigned int     ifa_flags;   /* Flags from SIOCG

shell获取时间的相关命令

Linux shell获取时间和时间间隔(ms级别) 说明:在进行一些性能测试的时候,有时候我们希望能计算一个程序运行的时间,有时候可能会自己写一个shell脚本方便进行一些性能测试的控制(比如希望能运行N次取平均值等),总之,这其中有一个需求可能就是获取一个时间戳或时间差. 1. Linux shell获取时间的相关命令 time命令:获取一个程序的执行时间,可以获取到实际运行时间以及程序在用户态和内核态分别的时间,大部分的性能测试,可能只需要关注实际时间. time命令的使用就很简单了,在原