Clocks, Name, Synopsis – Comtrol eCos User Manual
Page 61: Description, Clock resolutions and ticks

Clocks
Name
cyg_clock_create, cyg_clock_delete, cyg_clock_to_counter,
cyg_clock_set_resolution, cyg_clock_get_resolution, cyg_real_time_clock,
cyg_current_time
— Provide system clocks
Synopsis
#include
<
cyg/kernel/kapi.h
>
void cyg_clock_create(cyg_resolution_t resolution, cyg_handle_t* handle, cyg_clock*
clock);
void cyg_clock_delete(cyg_handle_t clock);
void cyg_clock_to_counter(cyg_handle_t clock, cyg_handle_t* counter);
void cyg_clock_set_resolution(cyg_handle_t clock, cyg_resolution_t resolution);
cyg_resolution_t cyg_clock_get_resolution(cyg_handle_t clock);
cyg_handle_t cyg_real_time_clock(void);
cyg_tick_count_t cyg_current_time(void);
Description
In the eCos kernel clock objects are a special form of
objects. They are attached to a specific type of
hardware, clocks that generate ticks at very specific time intervals, whereas counters can be used with any event
source.
In a default configuration the kernel provides a single clock instance, the real-time clock. This gets used for times-
licing and for operations that involve a timeout, for example
cyg_semaphore_timed_wait
. If this functionality is
not required it can be removed from the system using the configuration option
CYGVAR_KERNEL_COUNTERS_CLOCK
.
Otherwise the real-time clock can be accessed by a call to
cyg_real_time_clock
, allowing applications to attach
alarms, and the current counter value can be obtained using
cyg_current_time
.
Applications
can
create
and
destroy
additional
clocks
if
desired,
using
cyg_clock_create
and
cyg_clock_delete
. The first argument to
cyg_clock_create
specifies the
this clock will run at. The
second argument is used to return a handle for this clock object, and the third argument provides the kernel with
the memory needed to hold this object. This clock will not actually tick by itself. Instead it is the responsibility of
application code to initialize a suitable hardware timer to generate interrupts at the appropriate frequency, install
an interrupt handler for this, and call
cyg_counter_tick
from inside the DSR. Associated with each clock is a
kernel counter, a handle for which can be obtained using
cyg_clock_to_counter
.
Clock Resolutions and Ticks
At the kernel level all clock-related operations including delays, timeouts and alarms work in units of clock ticks,
rather than in units of seconds or milliseconds. If the calling code, whether the application or some other package,
needs to operate using units such as milliseconds then it has to convert from these units to clock ticks.
61