![]() |
![]() |
![]() |
Calibrate before calling nanospin*()
#include <time.h> int nanospin_calibrate( int disable );
libc
The nanospin_calibrate() function performs the calibration function for the nanospin()* family of delay functions. The first time nanospin(), nanospin_ns(), or nanospin_ns_to_count() are called, the C library invokes nanospin_calibrate(), unless the user calls it directly first. Therefore, if you don't directly invoke nanospin_calibrate(), the first nanospin*() call in a process will have an overly long delay. To avoid this delay, call nanospin_calibrate() before calling nanospin*().
The parameter disable can take the value 0 or 1.
Interrupts occurring during nanospin_calibrate() can throw off its timings. If disable is 0 (zero), you can prevent this situation by:
If disable is 1 (one), the code disables interrupts around the calibration loop(s). The calling thread is still responsible for obtaining I/O privilege before calling nanospin_calibrate().
Busy-wait for 100 nanoseconds:
#include <time.h> #include <sys/syspage.h> int disable = 0; unsigned long time = 100; ... /* Wake up the hardware, then wait for it to be ready. */ if ( (nanospin_calibrate( disable )) == EOK ) nanospin_count( nanospin_ns_to_count( time ) ); else printf ("Didn't calibrate successfully.\n"); /* Use the hardware. */ ...
Safety: | |
---|---|
Cancellation point | No |
Interrupt handler | No |
Signal handler | Yes |
Thread | Yes |
nanospin(), nanospin_count(), nanospin_ns(), nanospin_ns_to_count()
![]() |
![]() |
![]() |