Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2003-04

RTC with Free Pascal

9 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Christophe Espern

Hello

I'd like to use RTC (Real Time Clock) with FPC under Linux.

Is it possible ?

I found a file named rtc.txt in the Documentation directory of the Kernel source (/usr/linux/Documentation). There is a simple C example. Is it possible to write this kind of things in Pascal ?

Cheers,

Christophe

Save Our Software - Sauvez le droit d'auteur ! Comprendre / Agir : http://eucd.info

Reply by email

Jonas Maebe
to Christophe Espern
Christophe Espern wrote
I found a file named rtc.txt in the Documentation directory of the Kernel source (/usr/linux/Documentation). There is a simple C example. Is it possible to write this kind of things in Pascal ?

Yes, they are simply reading from a device (which is done exactly the same as reading from a file, also in Pascal) and using some ioctl's (which is available in the linux unit).

Jonas

Reply by email

Christophe Espern
to Jonas Maebe
Jonas Maebe wrote
Yes, they are simply reading from a device (which is done exactly the same as reading from a file, also in Pascal) and using some ioctl's (which is available in the linux unit).

Yes but the rtc.h has some constants which seems not available under FPC. For example :

#define RTC_UIE_ON _IO('p', 0x03) /* Update int. enable on #define RTC_UIE_OFF _IO('p', 0x04) /* ... off

I don't know what means the _IO functions and the "p" param. h2pas can convert this h file.

As I like danger I try with only the hexa values (ie:$03) for and it fails

Here is the ugly code :)

program testrtc;
uses Sysutils,Linux;
var
   retval:boolean;
   i, irqcount:integer;
   tmp, data :longint;
   fd:integer;
begin
  fd:=fileopen ('/dev/rtc', fmOpenRead);
if (fd=-1) then begin
	writeln(stderr,'/dev/rtc');
	exit;
end;
retval:= ioctl(fd,$03, 0);
if (retval = false) then begin
	writeln('error open');
	exit;
end;
retval:= ioctl(fd,$04, 0);
if (retval=false) then  begin
	writeln('error close');
	exit;
 end;
fileclose(fd);
end.
Moreover what about sched_set_scheduler under FPC ? Does someone try to use it ? Cheers, Christophe

Reply by email

Jonas Maebe
to Christophe Espern
Christophe Espern wrote 5 lines
retval:= ioctl(fd,$03, 0); if (retval = false) then begin writeln('error open'); exit; end;

ioctl returns true on success. Note to Michael: my version of units.pdf (April 19, 2002) states that ioctl is a procedure instead of a function. Has this already been corrected?

Jonas

Reply by email

Christophe Espern
to Jonas Maebe

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;
;
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

Reply by email

Lee, John

Re clock resolution, why not use eg Thomas Schatzl's cpu unit (or some of its code) for the timing.
http://members.yline.com/~tom_at_work/index.html

Regards John

Earlier message 58 lines
-----Original Message----- From: Anton Tichawa Sent: Wednesday, April 16, 2003 19:08 To: Subject: Re: [fpc-pascal]RTC with Free Pascal Hello, Crhistophe! > Hello > > I'd like to use RTC (Real Time Clock) with FPC under Linux. > > Is it possible ? > > I found a file named rtc.txt in the Documentation directory of the > Kernel source (/usr/linux/Documentation). There is a simple C example. > Is it possible to write this kind of things in Pascal ? I didn't find rtc.txt on my local hard disk, but I have written a unit, times.pas, that does real-time stuff, using linux system calls. It implements real time stamps and a sceleton timer interrupt handler. That allows profiling, multi-tasking and other intelligent behaviour. Not understanding the linux documentation, I have to use monitor protection. Then there's day times, leap years, (currently only) gregorian date-to-integer mapping with ISO conforming date strings. Shall I post the file(s) to the list or to your email address, Christophe? A serious question: The resolution on linux is still as high as 10 ms. Can any one tell me where to change that big, big constant to e. g. 10 ns, because also cpus were slower by a factor of 1e6 when these 10 ms were chosen. Thanx, Anton Tichawa. ---------- "Adas Methode war, wie sich zeigen wird, Tagträume in offenbar korrekte Berechnungen einzuweben." Doris Langley Moore: Ada, Countess of Lovelace (London 1977). ---------- Ing. Anton Tichawa Volkertstrasse 19 / 20 A-1020 Wien phone: +43 1 218 97 59 mobil: +43 664 52 07 907; currently n/a email: ----------

Reply by email

Anton Tichawa
to Christophe Espern: Hello I'd like to use RTC (Real Time Clock) with FPC under Linux. Is it possible ? I…

Hello, Crhistophe!

Show quoted text 9 lines
Hello I'd like to use RTC (Real Time Clock) with FPC under Linux. Is it possible ? I found a file named rtc.txt in the Documentation directory of the Kernel source (/usr/linux/Documentation). There is a simple C example. Is it possible to write this kind of things in Pascal ?

I didn't find rtc.txt on my local hard disk, but I have written a unit, times.pas, that does real-time stuff, using linux system calls.

It implements real time stamps and a sceleton timer interrupt handler. That allows profiling, multi-tasking and other intelligent behaviour. Not understanding the linux documentation, I have to use monitor protection. Then there's day times, leap years, (currently only) gregorian date-to-integer mapping with ISO conforming date strings.

Shall I post the file(s) to the list or to your email address, Christophe?

A serious question: The resolution on linux is still as high as 10 ms. Can any one tell me where to change that big, big constant to e. g. 10 ns, because also cpus were slower by a factor of 1e6 when these 10 ms were chosen.

Thanx,

Anton Tichawa.

----------

"Adas Methode war, wie sich zeigen wird, Tagträume in offenbar korrekte Berechnungen einzuweben."

Doris Langley Moore: Ada, Countess of Lovelace (London 1977).

----------

Ing. Anton Tichawa
Volkertstrasse 19 / 20
A-1020 Wien
phone: +43 1 218 97 59
mobil: +43 664 52 07 907; currently n/a
email:

----------

Reply by email

Christophe Espern
to Anton Tichawa: Hello, Crhistophe! I didn't find rtc.txt on my local hard disk, but I have written a unit,
Anton Tichawa wrote
I didn't find rtc.txt on my local hard disk, but I have written a unit, times.pas, that does real-time stuff, using linux system calls.

Here is an online version :

http://public.planetmirror.com/pub/slackware/slackware-7.1/docs/linux-2.2.16/rtc.txt

Shall I post the file(s) to the list or to your email address, Christophe?

The list may be interested I think :)

A serious question: The resolution on linux is still as high as 10 ms. Can any one tell me where to change that big, big constant to e. g. 10 ns, because also cpus were slower by a factor of 1e6 when these 10 ms were chosen.

By using RTC I think you avoid this. I must perform tests with threading and take a look to the sched_set_scheduler() for that.

Cheers,

Christophe

Reply by email