nanosecond timer

Linux specific forum
User avatar
dhouston
Enthusiast
Enthusiast
Posts: 430
Joined: Tue Aug 21, 2007 2:44 pm
Location: USA (Cincinnati)
Contact:

nanosecond timer

Post by dhouston »

Is it possible to call clock_nanosleep() from PB and, if possible, can someone more adept at C than me provide an example.

http://www.kernel.org/doc/man-pages/onl ... eep.2.html
RE-A
User
User
Posts: 39
Joined: Thu Aug 21, 2008 4:19 pm
Location: Belgium
Contact:

Post by RE-A »

This is also something on my to do list, thanks for the reminder. PB doesn't recognise this api so the only option is to create a library :?
User avatar
dhouston
Enthusiast
Enthusiast
Posts: 430
Joined: Tue Aug 21, 2007 2:44 pm
Location: USA (Cincinnati)
Contact:

Post by dhouston »

That's well outside my skillset :oops: so any help will be greatly appreciated.
Anonymous

Post by Anonymous »

first step.

don't work , but this is the good way.

Code: Select all

#CLOCK_REALTIME            = 0
#CLOCK_MONOTONIC           = 1
#CLOCK_PROCESS_CPUTIME_ID  = 2
#CLOCK_THREAD_CPUTIME_ID   = 3
#CLOCK_REALTIME_HR         = 4
#CLOCK_MONOTONIC_HR        = 5


Structure timespec 
    tv_sec.i;        /* seconds */
    tv_nsec.i;           /* nanoseconds [0 .. 999999999] */
EndStructure           


ImportC "-lrt"
clock_nanosleep(clockid.i,b.i,c.i,d.i)
EndImport


clock_nanosleep(#CLOCK_MONOTONIC,0,0,0)
User avatar
dhouston
Enthusiast
Enthusiast
Posts: 430
Joined: Tue Aug 21, 2007 2:44 pm
Location: USA (Cincinnati)
Contact:

Post by dhouston »

apifunctions.txt in the compilers directory lists nanosleep - perhaps it might be recognized.
walker
Enthusiast
Enthusiast
Posts: 634
Joined: Wed May 05, 2004 4:04 pm
Location: Germany

Re: nanosecond timer

Post by walker »

at least to have a working example :wink: :

Code: Select all

;Clock-ID's = Type of clock to use
#CLOCK_REALTIME            = 0
#CLOCK_MONOTONIC           = 1
#CLOCK_PROCESS_CPUTIME_ID  = 2
#CLOCK_THREAD_CPUTIME_ID   = 3
#CLOCK_REALTIME_HR         = 4
#CLOCK_MONOTONIC_HR        = 5

;Flags
#TIMER_ABSTIME=1; if used, the remain variable could be set to #NULL

Structure timespec
    tv_sec.i;           /* seconds */
    tv_nsec.i;         /* nanoseconds [0 .. 999999999] */
EndStructure           

; see  http://www.kernel.org/doc/man-pages/online/pages/man2/clock_nanosleep.2.html
ImportC "-lrt"
clock_nanosleep(clockid.i,flags.i,requested.i,remain.i)
EndImport

time.timespec ; requested nanosleep
rem.timespec; remaining time if interrupted

time\tv_sec=10
time\tv_nsec=666

error=clock_nanosleep(#CLOCK_MONOTONIC,0,@time,@rem) 
If error<>0
    ;interupted by signal or error occured
    Debug error
EndIf
Last edited by walker on Sun Sep 13, 2009 4:41 pm, edited 1 time in total.
User avatar
dhouston
Enthusiast
Enthusiast
Posts: 430
Joined: Tue Aug 21, 2007 2:44 pm
Location: USA (Cincinnati)
Contact:

Re: nanosecond timer

Post by dhouston »

walker wrote:at least to have a working example :wink: :
Thank you. :D
walker
Enthusiast
Enthusiast
Posts: 634
Joined: Wed May 05, 2004 4:04 pm
Location: Germany

Re: nanosecond timer

Post by walker »

you're welcome :D
removed a typo in the example ...
Post Reply