RTC example in Documentation/rtc.txt not working correctly

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello all, (first post here =)

I'm working with RTC these days and got to read the example provided by
    Paul Gortmaker in 1996 included in Documentation/rtc.txt

I prepared the binary with the supplied code and everything goes
 smoothly but something strange seems to happen when running: i will
 restrict the code to the scope of the problem to keep things readable
 and simple,

        // open the rtc device
        fd = open ("/dev/rtc", O_RDONLY);

        if ( fd == -1 ) {
                    perror("/dev/rtc");   // error printing
                    exit(errno);            // errno holds last error code
         }

         // to start with, some periodic interrupt with 1 sec delay,
mode RTC_UIE_ON

        // enable interrupts (unmasking i guess)
        retval = ioctl(fd, RTC_UIE_ON, 0);
        if (retval == -1){
                perror("ioctl");
                exit(errno);
         }

         fprintf(stderr,"Receiving interrupts each second .. \n");
         fflush(stderr);

        for (i=1;i<6;i++){
                    retval = read(fd, &data, sizeof(unsigned long));
                    if (retval == -1){
                            perror("read");
                            exit(errno);
                 }

                 fprintf(stderr, "%d ",i);
                 fflush(stderr);

                irqs++;
          }


The problem appears because as soon as i press enter and run the binary
my program gets an interruption, and that happens before the end of the
current second comes, so i'm supposing i'm getting the former second
interrupt which was not catched or something, could it be?

I'm also thinking that because two more things happen: if i disable
the interrupt
before enabling then i do not get that first interruption and nor do i if i
run the program again without a second expiring in the meantime. So, i
would propose to update the example so that works as it was intended
(count 5 seconds).

Adding a line like this one,

-[  ioctl(fd, RTC_UIE_OFF, 0);  ]-
    ioctl(fd, RTC_UIE_ON, 0);

solves the problem.

I'm thinking that this fearture may be architecture dependant .. well
i'm not an expert in this matter.

---------------------------------------------------------------------------------------------------
PD: i'm waiting for being included in the list, please CC any reply to
me, thank you  =)

--
Carlos Martinez Belinchon
UPM
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux