Name

Time conversions — Converting between clock ticks and calendar time

Synopsis

#include <cyg/clock/api.h>

Cyg_ErrNo cyg_clock_ticks_to_time(cyg_tick_count_t ticks, struct timespec *ts);

Cyg_ErrNo cyg_clock_time_to_ticks(const struct timespec *ts, cyg_tick_count_t *ticks, cyg_boolroundup);

void cyg_clock_ticks_to_reltime(cyg_tick_count_t ticks, struct timespec *ts);

Cyg_ErrNo cyg_clock_reltime_to_ticks(const struct timespec *ts, cyg_tick_count_t *ticks, cyg_boolroundup);

Description

These functions allow conversions between the 'ticks' of the clock which is driving system time, and calendar time values. These are intended to be used in conjunction with the clock identified by the clock handle returned by cyg_clock_sysclock_handle().

cyg_clock_ticks_to_time() returns what the calendar time (which is defined as relative to the Epoch 1970-01-01 00:00:00) will be when the system time clock reaches the supplied tick count. If a fine adjustment is in progress, it will be taken into account.

cyg_clock_time_to_ticks() returns what the system time clock's tick value will be when the supplied system time (which is defined as relative to the epoch 1970-01-01 00:00:00) is reached. If roundup is true, ticks will be rounded up to the next tick; if roundup is false, it will be rounded to the nearest tick. If a fine adjustment is in progress, it will be taken into account.

cyg_clock_ticks_to_reltime() returns the relative time interval (as a struct timespec) corresponding to the supplied number of ticks. Note this does not take into account any effect of fine clock adjustment.

cyg_clock_reltime_to_ticks() returns the number of ticks corresponding to the relative time interval specified in the struct timespec ts. If roundup is true, ticks will be rounded up to the next tick; if roundup is false, it will be rounded to the nearest tick. Note this does not take into account any effect of fine clock adjustment.

These functions are only provided if the configuration option CYGFUN_CLOCK_COMMON_TICK_CONVERTERS is enabled.

Return value

These functions return a standard error code, as defined in <errno.h>, or ENOERR on success. Notably cyg_clock_reltime_to_ticks() may return ERANGE for values which cannot be converted.