Updated: April 19, 2023 |
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 number of iterations to busy-wait for, 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. */ unsigned long count = nanospin_ns_to_count( time ); if ( count != -1UL ) { nanospin_count( count ); } else { /* Check errno and handle error here somehow */ } /* Use the hardware. */ …
Safety: | |
---|---|
Cancellation point | No |
Interrupt handler | Yes |
Signal handler | Yes |
Thread | Yes |
You should use busy-waiting only when absolutely necessary for accessing hardware.