[fpc-pascal]RTC with Free Pascal

Christophe Espern cespern at free.fr
Wed Apr 16 17:45:56 CEST 2003


Hello,

Here is the new basic code which works :)

I'm going to rewrite the whole C demo and I will post it here

program testrtc;

uses Sysutils,Linux;


{$PACKRECORDS C}

  type
     rtc_time = record
          tm_sec : longint;
          tm_min : longint;
          tm_hour : longint;
          tm_mday : longint;
          tm_mon : longint;
          tm_year : longint;
          tm_wday : longint;
          tm_yday : longint;
          tm_isdst : longint;
       end;



var
   retval:boolean;
   i, irqcount:integer;
   tmp, data :longint;
   fd:integer;
   rtime:rtc_time;
   w:word;
   p:^longint;
begin
  
  fd:=fdopen ('/dev/rtc', Open_Rdonly);

if (fd=-1) then begin
	writeln(stderr,'/dev/rtc');
	exit;
end;

p:=@data;
   
retval:= ioctl(fd,(ord('p') shl 8)+3,0);
if (retval = false) then begin
	writeln(stderr,LinuxError);
	exit;
end;


writeln('Counting 5 update (1/sec) interrupts from reading /dev/rtc');
flush(stderr);

for i:=1 to 5  do begin
   try
      fdread(fd, data,sizeof(longint));
   except
      exit;
   end;
   writeln(stderr,i);
   flush(stderr);
   inc(irqcount);
end;


retval:= ioctl(fd,(ord('p') shl 8)+4, 0);
if (retval=false) then  begin
	writeln(LinuxError);
	exit;
 end;

fdclose(fd);   
end.

Cheers,

Christophe







More information about the fpc-pascal mailing list