天嵌 ARM开发社区

 找回密码
 注册
查看: 2459|回复: 1

RTC应用程序问题

[复制链接]
lovelogan 发表于 2010-9-29 18:41:43 | 显示全部楼层 |阅读模式
我写了下面的程序测试RTC但是编译后执行的时候出现了RTC_AIE_ON ioctl: Invalid argument的错误,
驱动程序使用的是内核自带的。我在驱动程序中明明看到了RTC_AIE_ON 这个命令,怎么还出错。
#include <stdio.h>
#include <linux/rtc.h>
#include <sys/ioctl.h>
#include <sys/time.h>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>

int main(void)
{
        int i, fd, retval, irqcount = 0;
        unsigned long tmp, data;
        struct rtc_time rtc_tm;

        fd = open("/dev/rtc0", O_RDONLY);
        if (fd ==-1)
        {
                perror("/dev/rtc0");
                exit(errno);
        }

        /* Read the RTC time/date */
        retval = ioctl(fd, RTC_RD_TIME, &rtc_tm);
        if (retval == -1)
        {
                perror("RTC_RD_TIME ioctl");
                exit(errno);
        }

        fprintf(stderr, "Current RTC date/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);


        /* Read the current alarm settings */
        retval = ioctl(fd, RTC_ALM_READ, &rtc_tm);
        if (retval == -1) {
                perror("RTC_ALM_READ ioctl");
                exit(errno);
        }

        fprintf(stderr, "Alarm time now set to %02d:%02d:%02d.\n",
                rtc_tm.tm_hour, rtc_tm.tm_min, rtc_tm.tm_sec);

        /* Enable alarm interrupts */
        retval = ioctl(fd,RTC_AIE_ON);
        if (retval == -1) {
                perror("RTC_AIE_ON ioctl");
                exit(errno);
        }

        fprintf(stderr, "Waiting 5 seconds for alarm...");
        fflush(stderr);
        /* This blocks until the alarm ring causes an interrupt */
        retval = read(fd, &data, sizeof(unsigned long));
        if (retval == -1) {
                perror("read");
                exit(errno);
        }
        irqcount++;
        fprintf(stderr, " okay. Alarm rang.\n");

        /* Disable alarm interrupts */
        retval = ioctl(fd, RTC_AIE_OFF, 0);
        if (retval == -1) {
                perror("RTC_AIE_OFF ioctl");
                exit(errno);
        }

        close(fd);

        return 0;
}
天嵌_support1 发表于 2010-10-7 16:23:57 | 显示全部楼层
1# lovelogan


你直接调用驱动中定义的变量当然不可以阿
要不你在自己的运用程序里定义了。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

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

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

GMT+8, 2024-9-27 23:30 , Processed in 1.034219 second(s), 18 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2020, Tencent Cloud.

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