Page 1 of 1
nanosecond timer
Posted: Fri Aug 28, 2009 10:48 pm
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
Posted: Sun Aug 30, 2009 6:00 am
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
Posted: Sun Aug 30, 2009 4:27 pm
by dhouston
That's well outside my skillset
so any help will be greatly appreciated.
Posted: Sun Aug 30, 2009 6:28 pm
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)
Posted: Wed Sep 02, 2009 2:13 pm
by dhouston
apifunctions.txt in the compilers directory lists nanosleep - perhaps it might be recognized.
Re: nanosecond timer
Posted: Sun Sep 13, 2009 1:30 pm
by walker
at least to have a working example
:
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
Re: nanosecond timer
Posted: Sun Sep 13, 2009 2:01 pm
by dhouston
walker wrote:at least to have a working example
:
Thank you.
Re: nanosecond timer
Posted: Sun Sep 13, 2009 4:43 pm
by walker
you're welcome
removed a typo in the example ...