fpnanosleep (again)

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

fpnanosleep (again)

John Coppens
Hi all.

I need a small delay in my program, which bitbangs an i2c interface
connected to the parallel port. This is mainly for educational purposes,
so please don't question the wiseness of this decision.

Is there any simple way (short of writing a kernel module) of delaying
less than the HZ value? Weirdly, fpNanosleep seems to delay 8.3 ms
minimally (weird, 'cause that's less than the HZ value).

I'm using a 2.6 kernel.

John
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: fpnanosleep (again)

John Coppens
On Wed, 7 Nov 2007 19:27:39 -0300
John Coppens <[hidden email]> wrote:

> Is there any simple way (short of writing a kernel module) of delaying
> less than the HZ value? Weirdly, fpNanosleep seems to delay 8.3 ms
> minimally (weird, 'cause that's less than the HZ value).

Just an extra note: delay(1) seems to delay 4.1 ms, so it _does_ seem to
be possible to do less than 8.3?

John
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: fpnanosleep (again)

John Coppens
In reply to this post by John Coppens
On Wed, 7 Nov 2007 19:27:39 -0300
John Coppens <[hidden email]> wrote:

> Is there any simple way (short of writing a kernel module) of delaying
> less than the HZ value?

Very unelegant, but it works:

procedure usleep(time: longint);
var
  tv: timeval;
  tz: timezone;
  diff,
  ref: clong;
begin
  fpGetTimeOfDay(@tv, @tz);
  ref := tv.tv_usec;
  repeat
    fpGetTimeOfDay(@tv, @tz);
    diff := tv.tv_usec - ref;
    if diff < 0 then
      diff := diff + 1000000;
  until diff > time;
end;

in case someone is interested.

John
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: fpnanosleep (again)

Rainer Stratmann
In reply to this post by John Coppens
If you know the Processor Speed (MHz) then there is an assembler command which
reads the cpu cycles (for example a 1MHz Processor has 1.000.000
cycles/second) so you can do it in this way.

http://en.wikipedia.org/wiki/RDTSC

Rainer


Am Mittwoch, 7. November 2007 23:27 schrieb John Coppens:

> Hi all.
>
> I need a small delay in my program, which bitbangs an i2c interface
> connected to the parallel port. This is mainly for educational purposes,
> so please don't question the wiseness of this decision.
>
> Is there any simple way (short of writing a kernel module) of delaying
> less than the HZ value? Weirdly, fpNanosleep seems to delay 8.3 ms
> minimally (weird, 'cause that's less than the HZ value).
>
> I'm using a 2.6 kernel.
>
> John
> _______________________________________________
> fpc-pascal maillist  -  [hidden email]
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: fpnanosleep (again)

John Coppens
On Thu, 8 Nov 2007 13:43:48 +0100
Rainer Stratmann <[hidden email]> wrote:

> http://en.wikipedia.org/wiki/RDTSC

Interesting... I'm guessing gettimeofday would use this register to
obtain the hi-res time it provides - does it?

Thanks
John
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: fpnanosleep (again)

Micha Nelissen
In reply to this post by John Coppens
John Coppens wrote:
> Just an extra note: delay(1) seems to delay 4.1 ms, so it _does_ seem to
> be possible to do less than 8.3?

You wait till the next tick that is after the requested delay. So it's
never a HZ multiple or so.

Micha
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal