Sign in Join

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

Mailing lists / fpc-pascal / 2007-11

fpnanosleep (again)

6 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

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

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

Reply by email

John Coppens
to John Coppens
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

Reply by email

John Coppens
to John Coppens: Hi all. I need a small delay in my program, which bitbangs an i2c interface connected to…
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

Reply by email

Rainer Stratmann
to John Coppens: Hi all. I need a small delay in my program, which bitbangs an i2c interface connected to…

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

John Coppens wrote 16 lines
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 - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply by email