Convert a time in nanoseconds into a number of iterations
#include <time.h> unsigned long nanospin_ns_to_count( unsigned long nsec );
libc
Use the -l c option to qcc to link against this library. This library is usually included automatically.
The nanospin_ns_to_count() function converts the number of nanoseconds specified in nsec into an iteration count suitable for nanospin_count().
The nanospin*() functions are designed for use with hardware that requires short time delays between accesses. You should use them to delay only for times less than a few milliseconds. For longer delays, use the POSIX timer_*() functions. |
The first time that you call nanospin_ns_to_count(), the C library invokes nanospin_calibrate() with an argument of 0 (interrupts enabled), if you haven't invoked it directly first.
The amount of time to busy-wait, or -1 if an error occurred (errno is set).
Busy-wait for at least one nanosecond:
#include <time.h> #include <sys/syspage.h> unsigned long time = 1; … /* Wake up the hardware, then wait for it to be ready. */ /* The C library invokes nanospin_calibrate if it hasn't already been called. */ nanospin_count( nanospin_ns_to_count( time ) ); /* Use the hardware. */ …
Safety: | |
---|---|
Cancellation point | No |
Interrupt handler | Read the Caveats |
Signal handler | Yes |
Thread | Yes |
You should use busy-waiting only when absolutely necessary for accessing hardware.
It isn't safe to call this function in an interrupt handler if nanospin_calibrate() hasn't been called yet.
nanospin(), nanospin_calibrate(), nanospin_count(), nanospin_ns(), timer_create()