Xenomai API
2.6.5
|
Clocks and timers services. More...
Functions | |
int | clock_getres (clockid_t clock_id, struct timespec *res) |
Get the resolution of the specified clock. More... | |
int | clock_gettime (clockid_t clock_id, struct timespec *tp) |
Read the specified clock. More... | |
int | clock_settime (clockid_t clock_id, const struct timespec *tp) |
Set the specified clock. More... | |
int | clock_nanosleep (clockid_t clock_id, int flags, const struct timespec *rqtp, struct timespec *rmtp) |
Sleep some amount of time. More... | |
int | nanosleep (const struct timespec *rqtp, struct timespec *rmtp) |
Sleep some amount of time. More... | |
int | timer_create (clockid_t clockid, const struct sigevent *__restrict__ evp, timer_t *__restrict__ timerid) |
Create a timer object. More... | |
int | timer_delete (timer_t timerid) |
Delete a timer object. More... | |
int | timer_settime (timer_t timerid, int flags, const struct itimerspec *__restrict__ value, struct itimerspec *__restrict__ ovalue) |
Start or stop a timer. More... | |
int | timer_gettime (timer_t timerid, struct itimerspec *value) |
Get timer next expiration date and reload value. More... | |
int | timer_getoverrun (timer_t timerid) |
Get expiration overruns count since the most recent timer expiration signal delivery. More... | |
Clocks and timers services.
Xenomai POSIX skin supports two clocks:
CLOCK_REALTIME maps to the nucleus system clock, keeping time as the amount of time since the Epoch, with a resolution of one system clock tick.
CLOCK_MONOTONIC maps to an architecture-dependent high resolution counter, so is suitable for measuring short time intervals. However, when used for sleeping (with clock_nanosleep()), the CLOCK_MONOTONIC clock has a resolution of one system clock tick, like the CLOCK_REALTIME clock.
Timer objects may be created with the timer_create() service using either of the two clocks, but the resolution of these timers is one system clock tick, as is the case for clock_nanosleep().
int clock_getres | ( | clockid_t | clock_id, |
struct timespec * | res | ||
) |
Get the resolution of the specified clock.
This service returns, at the address res, if it is not NULL, the resolution of the clock clock_id.
For both CLOCK_REALTIME and CLOCK_MONOTONIC, this resolution is the duration of one system clock tick. No other clock is supported.
clock_id | clock identifier, either CLOCK_REALTIME or CLOCK_MONOTONIC; |
res | the address where the resolution of the specified clock will be stored on success. |
0 | on success; |
-1 | with errno set if:
|
int clock_gettime | ( | clockid_t | clock_id, |
struct timespec * | tp | ||
) |
Read the specified clock.
This service returns, at the address tp the current value of the clock clock_id. If clock_id is:
clock_id | clock identifier, either CLOCK_REALTIME, CLOCK_MONOTONIC, or CLOCK_HOST_REALTIME; |
tp | the address where the value of the specified clock will be stored. |
0 | on success; |
-1 | with errno set if:
|
References xntbase_get_time().
int clock_nanosleep | ( | clockid_t | clock_id, |
int | flags, | ||
const struct timespec * | rqtp, | ||
struct timespec * | rmtp | ||
) |
Sleep some amount of time.
This service suspends the calling thread until the wakeup time specified by rqtp, or a signal is delivered to the caller. If the flag TIMER_ABSTIME is set in the flags argument, the wakeup time is specified as an absolute value of the clock clock_id. If the flag TIMER_ABSTIME is not set, the wakeup time is specified as a time interval.
If this service is interrupted by a signal, the flag TIMER_ABSTIME is not set, and rmtp is not NULL, the time remaining until the specified wakeup time is returned at the address rmtp.
The resolution of this service is one system clock tick.
clock_id | clock identifier, either CLOCK_REALTIME or CLOCK_MONOTONIC. |
flags | one of:
|
rqtp | address of the wakeup time. |
rmtp | address where the remaining time before wakeup will be stored if the service is interrupted by a signal. |
References XNBREAK, XNDELAY, and xnpod_suspend_thread().
Referenced by nanosleep().
int clock_settime | ( | clockid_t | clock_id, |
const struct timespec * | tp | ||
) |
Set the specified clock.
This allow setting the CLOCK_REALTIME clock.
clock_id | the id of the clock to be set, only CLOCK_REALTIME is supported. |
tp | the address of a struct timespec specifying the new date. |
0 | on success; |
-1 | with errno set if:
|
References xntbase_adjust_time(), and xntbase_get_time().
int nanosleep | ( | const struct timespec * | rqtp, |
struct timespec * | rmtp | ||
) |
Sleep some amount of time.
This service suspends the calling thread until the wakeup time specified by rqtp, or a signal is delivered. The wakeup time is specified as a time interval.
If this service is interrupted by a signal and rmtp is not NULL, the time remaining until the specified wakeup time is returned at the address rmtp.
The resolution of this service is one system clock tick.
rqtp | address of the wakeup time. |
rmtp | address where the remaining time before wakeup will be stored if the service is interrupted by a signal. |
0 | on success; |
-1 | with errno set if:
|
References clock_nanosleep().
int timer_create | ( | clockid_t | clockid, |
const struct sigevent *__restrict__ | evp, | ||
timer_t *__restrict__ | timerid | ||
) |
Create a timer object.
This service creates a time object using the clock clockid.
If evp is not NULL, it describes the notification mechanism used on timer expiration. Only notification via signal delivery is supported (member sigev_notify of evp set to SIGEV_SIGNAL). The signal will be sent to the thread starting the timer with the timer_settime() service. If evp is NULL, the SIGALRM signal will be used.
Note that signals sent to user-space threads will cause them to switch to secondary mode.
If this service succeeds, an identifier for the created timer is returned at the address timerid. The timer is unarmed until started with the timer_settime() service.
clockid | clock used as a timing base; |
evp | description of the asynchronous notification to occur when the timer expires; |
timerid | address where the identifier of the created timer will be stored on success. |
0 | on success; |
-1 | with errno set if:
|
References xntimer_init().
int timer_delete | ( | timer_t | timerid | ) |
Delete a timer object.
This service deletes the timer timerid.
timerid | identifier of the timer to be removed; |
0 | on success; |
-1 | with errno set if:
|
int timer_getoverrun | ( | timer_t | timerid | ) |
Get expiration overruns count since the most recent timer expiration signal delivery.
This service returns timerid expiration overruns count since the most recent timer expiration signal delivery. If this count is more than DELAYTIMER_MAX expirations, DELAYTIMER_MAX is returned.
timerid | Timer identifier. |
int timer_gettime | ( | timer_t | timerid, |
struct itimerspec * | value | ||
) |
Get timer next expiration date and reload value.
This service stores, at the address value, the expiration date (member it_value) and reload value (member it_interval) of the timer timerid. The values are returned as time intervals, and as multiples of the system clock tick duration (see note in section Clocks and timers services for details on the duration of the system clock tick). If the timer was not started, the returned members it_value and it_interval of value are zero.
timerid | timer identifier; |
value | address where the timer expiration date and reload value are stored on success. |
0 | on success; |
-1 | with errno set if:
|
int timer_settime | ( | timer_t | timerid, |
int | flags, | ||
const struct itimerspec *__restrict__ | value, | ||
struct itimerspec *__restrict__ | ovalue | ||
) |
Start or stop a timer.
This service sets a timer expiration date and reload value of the timer timerid. If ovalue is not NULL, the current expiration date and reload value are stored at the address ovalue as with timer_gettime().
If the member it_value of the itimerspec structure at value is zero, the timer is stopped, otherwise the timer is started. If the member it_interval is not zero, the timer is periodic. The current thread must be a POSIX skin thread (created with pthread_create()) and will be notified via signal of timer expirations. Note that these notifications will cause user-space threads to switch to secondary mode.
When starting the timer, if flags is TIMER_ABSTIME, the expiration value is interpreted as an absolute date of the clock passed to the timer_create() service. Otherwise, the expiration value is interpreted as a time interval.
Expiration date and reload value are rounded to an integer count of system clock ticks (see note in section Clocks and timers services for details on the duration of the system tick).
timerid | identifier of the timer to be started or stopped; |
flags | one of 0 or TIMER_ABSTIME; |
value | address where the specified timer expiration date and reload value are read; |
ovalue | address where the specified timer previous expiration date and reload value are stored if not NULL. |
0 | on success; |
-1 | with errno set if:
|
References xntimer_start(), and xntimer_stop().