Convert a time in nanoseconds into a number of iterations
#include <time.h> unsigned long nanospin_ns_to_count( unsigned long nsec );
- The number of nanoseconds that you want to convert.
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 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).
- A too-high rate of interrupts occurred during the calibration routine.
- This system's startup-* program didn't initialize the timing information necessary to use nanospin_ns_to_count().
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. */ …
|Interrupt handler||Read the Caveats|
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.