Chinaunix首页 | 论坛 | 博客
  • 博客访问: 798725
  • 博文数量: 124
  • 博客积分: 1927
  • 博客等级: 上尉
  • 技术积分: 932
  • 用 户 组: 普通用户
  • 注册时间: 2010-08-31 14:06
文章分类

全部博文(124)

文章存档

2018年(5)

2017年(2)

2016年(6)

2015年(4)

2014年(24)

2013年(7)

2012年(11)

2011年(13)

2010年(52)

我的朋友

分类: LINUX

2010-08-31 16:12:18

   这两天调试了AT91RM9200+pcf8563在linux2.6.20下的驱动,记录一下我的调试过程以及调试心得,呵呵
     在linux2.6.20/drivers/rtc目录下面已经有了pcf8563的驱动程序,通过make menuconfig配置一下就可以了。
     问题出来了“This chip cannot be reliably autodetected”这是源码中的注释,不能自动检测,实际上确实如此,怎么解决这个问题呢?google.....
     搜索很久终于看到有个牛人的解决方法:
     static unsigned short normal_i2c[] = { I2C_CLIENT_END };
     修改为
     static unsigned short normal_i2c[] = { 0x51,I2C_CLIENT_END };
     增加pcf8563的设备地址,编译运行,内核终于找到pcf8563了,:)
     你可以顺便看一下其他rtc的驱动,确实这个地方有个设备地址的,不知道为什么当时pcf8563不加这个地址,还写了那么一个注释,奇怪啊。。暂时不关心。继续。。。。
     接下来就是系统时钟和硬件时钟同步的问题了,date用来设置系统时钟,hwclock用来同步系统时钟和硬件时钟,比如:
     >date 2008.5.24-13:16:25    设置系统时间
     >hwclock -w         把设置的时间,保存到rtc中
     刚开始我的系统中没有hwclock命令,可以重新编译一下busybox,重新生成。
     还有一个小问题,hwclock所操作的设备名是RTC,而pcf8563自动挂载的是rtc0。如果不解决这个问题,hwclock是没办法读写pcf8563的。
     这有两个解决方法:
     方法一:修改busybox的源码,把rtc全部修改为rtc0
     方法二:>mknod /dev/rtc c 254 0
          >mknod /dev/rtc0 c 254 0
            建立两个设备rtc 和 rtc0
     最后写一个小的测试程序吧,呵呵
#include
#include
#include
#include
#include
#include
#include
#include
#include
int main(int argc, char **argv)
{
int ret, fd;
struct rtc_time rtc_tm;

fd = open("/dev/rtc0", O_RDWR);
if (fd < 0) {
   printf( "Fail to open PCF8563!\n" );
   exit(1);
}

ret=ioctl(fd, RTC_RD_TIME, &rtc_tm);
if (ret < 0) {
   printf( "Fail to read_time!\n" );
}
printf("\n\nRead PCF8563 time is %d-%d-%d, %02d:%02d:%02d.\n",rtc_tm.tm_mday, rtc_tm.tm_mon + 1, rtc_tm.tm_year + 1900,rtc_tm.tm_hour, rtc_tm.tm_min, rtc_tm.tm_sec);

close(fd);
return 0;
}
阅读(3254) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2010-09-02 08:15:45

Download More than 1000 free IT eBooks: http://free-ebooks.appspot.com