主题 : 使用mini2440  rtc时间中的周信息 复制链接 | 浏览器收藏 | 打印
级别: 新手上路
UID: 11434
精华: 0
发帖: 19
金钱: 115 两
威望: 35 点
综合积分: 38 分
注册时间: 2009-12-07
最后登录: 2016-08-24
楼主  发表于: 2010-04-13 12:49

 使用mini2440  rtc时间中的周信息

最近在做mini2440的开发,需要使用rtc提供的时间信息,特别是周信息,使用ret=ioctl(fd, RTC_RD_TIME, (unsigned long)timep);
读取到的时间信息中不含有周信息,
timep->tm_wday+=1;
打印出来后tm_wday始终为零,查询过rtc.c驱动程序
case RTC_RD_TIME: /* Read the time/date from RTC */
{
  memset(&wtime, 0, sizeof(struct rtc_time));
  rtc_get_rtc_time(&wtime);
  break;
}
case RTC_SET_TIME: /* Set the RTC */
{
  struct rtc_time rtc_tm;
  unsigned char mon, day, hrs, min, sec, leap_yr;
  unsigned char save_control, save_freq_select;
  unsigned int yrs;
#ifdef CONFIG_MACH_DECSTATION
  unsigned int real_yrs;
#endif
  if (!capable(CAP_SYS_TIME))
   return -EACCES;
  if (copy_from_user(&rtc_tm, (struct rtc_time __user *)arg,
       sizeof(struct rtc_time)))
   return -EFAULT;
  yrs = rtc_tm.tm_year + 1900;
  mon = rtc_tm.tm_mon + 1;   /* tm_mon starts at zero */
  day = rtc_tm.tm_mday;
  hrs = rtc_tm.tm_hour;
  min = rtc_tm.tm_min;
  sec = rtc_tm.tm_sec;
设置时间的case RTC_SET_TIME中就没有周信息的设置,

同时读取实时时钟的rtc_get_rtc_time(&wtime);中也没有返回周信息。

在开发板的串口上输入命令date或者是hwclock -r都能将时间信息中的周信息打印出来,不知道它们的处理办法是什么?不知道哪位达人能够给点提示,多谢!
*無鈳取玳
级别: 论坛版主
UID: 27
精华: 12
发帖: 5398
金钱: 40120 两
威望: 17929 点
综合积分: 11036 分
注册时间: 2008-01-16
最后登录: 2014-11-22
1楼  发表于: 2010-04-13 13:23

 Re:使用mini2440 rtc时间中的周信息

你可以用strace这个工具来跟踪date或者hwclock运行过程中的系统调用(即与硬件驱动的交互)。
用法参考http://www.ibm.com/developerworks/cn/linux/l-tsl/

我以前交叉编译了一个可以在开发板上运行的strace, 在这里
http://www.aiothome.net/read.php?tid=3739#12801
"If you have an apple and I have an apple and we exchange apples, then you and I will
still each have one apple. But if you have an idea and I have an idea and we exchange
these ideas, then each of us will have two ideas."
级别: 新手上路
UID: 11434
精华: 0
发帖: 19
金钱: 115 两
威望: 35 点
综合积分: 38 分
注册时间: 2009-12-07
最后登录: 2016-08-24
2楼  发表于: 2010-04-13 13:54

 Re:使用mini2440 rtc时间中的周信息

呵呵,多谢版主了,我的linux版本是2.6.13的,不知道能不能用,看看先!
*無鈳取玳
级别: 论坛版主
UID: 27
精华: 12
发帖: 5398
金钱: 40120 两
威望: 17929 点
综合积分: 11036 分
注册时间: 2008-01-16
最后登录: 2014-11-22
3楼  发表于: 2010-04-13 14:23

 回 2楼(flyingdonkey) 的帖子

我编译的strace只能在EABI的内核上跑,在友善之臂提供的2.6.13内核上是不能运行的。你需要用光盘上和2.6.13配套的交叉编译器(3.4.1?)重新编译一遍。
"If you have an apple and I have an apple and we exchange apples, then you and I will
still each have one apple. But if you have an idea and I have an idea and we exchange
these ideas, then each of us will have two ideas."
级别: 新手上路
UID: 11434
精华: 0
发帖: 19
金钱: 115 两
威望: 35 点
综合积分: 38 分
注册时间: 2009-12-07
最后登录: 2016-08-24
4楼  发表于: 2010-04-13 15:55

 Re:使用mini2440 rtc时间中的周信息

新编译strace,在友善之臂提供的2.6.13内核能够运行的。使用2.6.13配套的交叉编译器(3.4.1)重新编译的。我已经下载到开发板上使用了。 strace-sbin_4.5.15.tar.gz (10 K) 下载次数:1
级别: 新手上路
UID: 11434
精华: 0
发帖: 19
金钱: 115 两
威望: 35 点
综合积分: 38 分
注册时间: 2009-12-07
最后登录: 2016-08-24
5楼  发表于: 2010-04-13 16:46

 Re:使用mini2440 rtc时间中的周信息

使用strace跟踪hwclock的结果,版主帮我分析一下
execve("/sbin/hwclock", ["hwclock"], [/* 9 vars */]) = 0
uname({sys="Linux", node="FriendlyARM", ...}) = 0
fcntl64(0, F_GETFD)                     = 0
fcntl64(1, F_GETFD)                     = 0
fcntl64(2, F_GETFD)                     = 0
geteuid32()                             = 0
getuid32()                              = 0
getegid32()                             = 0
getgid32()                              = 0
brk(0)                                  = 0x2cb000
brk(0x2cc000)                           = 0x2cc000
getuid32()                              = 0
getgid32()                              = 0
setgid32(0)                             = 0
setuid32(0)                             = 0
open("/var/lib/hwclock/adjtime", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory)
open("/dev/rtc", O_RDONLY|O_LARGEFILE)  = -1 ENOENT (No such file or directory)
open("/dev/misc/rtc", O_RDONLY|O_LARGEFILE) = 3
ioctl(3, RTC_RD_TIME, {tm_sec=29, tm_min=38, tm_hour=16, tm_mday=13, tm_mon=3, tm_year=110, ...}) = 0
close(3)                                = 0
open("/etc/localtime", O_RDONLY)        = -1 ENOENT (No such file or directory)
fstat64(1, {st_mode=S_IFCHR|0600, st_rdev=makedev(5, 1), ...}) = 0
ioctl(1, SNDCTL_TMR_TIMEBASE or TCGETS, {B115200 opost isig icanon echo ...}) = 0
old_mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x40000000
write(1, "Tue Apr 13 16:38:29 2010  0.0000"..., 43Tue Apr 13 16:38:29 2010  0.000000 seconds
) = 43
munmap(0x400000, 4096)                = 0
exit_group(0)                           = ?
Process 377 detached

前边这种使用ioctl(3, RTC_RD_TIME, {tm_sec=29, tm_min=38, tm_hour=16, tm_mday=13, tm_mon=3, tm_year=110, ...}) = 0
和我使用的办法一样,没有得到周信息,后面这两行
fstat64(1, {st_mode=S_IFCHR|0600, st_rdev=makedev(5, 1), ...}) = 0
ioctl(1, SNDCTL_TMR_TIMEBASE or TCGETS, {B115200 opost isig icanon echo ...}) = 0
old_mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x40000000
好像比较有用,希望楼主帮忙看看,谢谢!
级别: 新手上路
UID: 11434
精华: 0
发帖: 19
金钱: 115 两
威望: 35 点
综合积分: 38 分
注册时间: 2009-12-07
最后登录: 2016-08-24
6楼  发表于: 2010-04-14 15:54
算了,网上找了一个由年月日推算周的公式,自己计算了,呵呵
*無鈳取玳
级别: 论坛版主
UID: 27
精华: 12
发帖: 5398
金钱: 40120 两
威望: 17929 点
综合积分: 11036 分
注册时间: 2008-01-16
最后登录: 2014-11-22
7楼  发表于: 2010-04-14 15:57

 回 6楼(flyingdonkey) 的帖子

事实上,hwclock也是这样做的。你看到的
ioctl(1, SNDCTL_TMR_TIMEBASE or TCGETS, {B115200 opost isig icanon echo ...}) = 0
old_mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x40000000
只是它用来向标准输出输出信息的
"If you have an apple and I have an apple and we exchange apples, then you and I will
still each have one apple. But if you have an idea and I have an idea and we exchange
these ideas, then each of us will have two ideas."