[Previous] [Contents] [Next]

nanospin_ns_to_count()

Busy-wait without blocking for a number of iterations

Synopsis:

#include <time.h>

unsigned long nanospin_ns_to_count( 
                 unsigned long nsec );

Library:

libc

Description:

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.

Returns:

The amount of time to busy-wait, or -1 if an error occurred (errno is set).

Errors:

ENOSYS
This system's startup-* program didn't initialize the timing information necessary to use nanospin_ns_to_count().

Examples:

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. */
...

Classification:

QNX 6

Safety:
Cancellation point No
Interrupt handler Read the Caveats
Signal handler Yes
Thread Yes

Caveats:

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.

See also:

nanospin(), nanospin_calibrate(), nanospin_count(), nanospin_ns()


[Previous] [Contents] [Next]