![]() |
![]() |
![]() |
Busy-wait without blocking for a number of iterations
#include <time.h> unsigned long nanospin_ns_to_count( unsigned long nsec );
libc
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. They should be used only to delay for times less than a few milliseconds.
The first time nanospin_ns_to_count() is called, the C library invokes the nanospin_calibrate() function, if the user hasn't invoked it directly first.
The amount of time to busy-wait, or -1 if an error occurred (errno is set).
To 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 |
Busy-waiting should be used only when absolutely necessary for accessing hardware.
This function isn't safe to call in an interrupt handler if nanospin_calibrate() hasn't been called yet.
nanospin(), nanospin_calibrate(), nanospin_count(), nanospin_ns()
![]() |
![]() |
![]() |