天嵌 ARM开发社区

 找回密码
 注册
查看: 1994|回复: 2

关于RTC驱动测试程序的问题?

[复制链接]
鬼鬼一哈 发表于 2011-3-29 14:02:37 | 显示全部楼层 |阅读模式
struct  rtc_time  rtc_tm;
    rtc_fd =  : : open("/dev/rtc0", 0);    //天嵌自带的驱动rtc0设备
    if (rtc_fd < 0)
      {
           perror("open RTC device !");
           exit(1);
      }
    rtc_tm.tm_year = 2012;
    rtc_tm.tm_mon =  12;
    rtc_tm.tm_mday = 12;
    rtc_tm.tm_hour = 12;
    rtc_tm.tm_min =  12;
    rtc_tm.tm_sec =  12;

    int retval ;
    retval = ioctl(rtc_fd, RTC_SET_TIME, &rtc_tm);  //返回值是-1为什么错误?为什么设置失败?
    printf("RTC_SET: %d\n", retval);            
    while(rtc_flag != 0)
    {   
        retval = ioctl(rtc_fd, RTC_RD_TIME, &rtc_tm);   
        if (retval > 0)
          {
             printf("Current RTC date/time is %d-%d-%d, %02d:%02d:%02d.\n", rtc_tm.tm_year, rtc_tm.tm_mon,rtc_tm.tm_mday,rtc_tm.tm_hour, rtc_tm.tm_min, rtc_tm.tm_sec);
          }
      else
         {
            perror("read RTC device failed !");
            exit(1);
         }
        sleep(1);
    }
}
 楼主| 鬼鬼一哈 发表于 2011-10-29 10:51:13 | 显示全部楼层
retval = ioctl(rtc_fd, RTC_SET_TIME, &rtc_tm);  为什么错误?哪位大哥知道?
回复

使用道具 举报

 楼主| 鬼鬼一哈 发表于 2011-10-29 10:56:31 | 显示全部楼层
用 retval = write(rtc_fd,&rtc_tm,sizeof(rtc_tm));也不行。。。。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

i.MX8系列ARM cortex A53 M4 工控板上一条 /1 下一条

Archiver|手机版|小黑屋|天嵌 嵌入式开发社区 ( 粤ICP备11094220号-2 )

GMT+8, 2025-6-21 20:35 , Processed in 2.037583 second(s), 20 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表