nanospin_ns_to_count()

Преобразовать время в наносекундах в число итераций

Прототип:

#include <time.h>
unsigned long nanospin_ns_to_count( unsigned long nsec );

Аргументы:

nsec
The number of nanoseconds that you want to convert.

Библиотека:

libc

Описание:

The nanospin_ns_to_count() function converts the number of nanoseconds specified in nsec into an iteration count suitable for nanospin_count().


Note: 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.

Если возникла ошибка функция возвращает -1, код ошибки записывается в errno.

Коды ошибок:

EINTR
A too-high rate of interrupts occurred during the calibration routine.
ENOSYS
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. */
...

Классификация:

ЗОСРВ «Нейтрино»

Точка остановки потока
Нет
Обработчик прерываний
Смотри ниже
Обработчик сигналов
Да
В потоке
Да

Предостережения:

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()




Предыдущий раздел: Описание API системной библиотеки