SysTimer

Offers a timer which signals timeout via input ready state of sys_iochannel_t.  This allows you to handle timers like any other io-device.

You need to include “C-kern/api/time/timevalue.h” before you can use the interface.

Summary
SysTimerOffers a timer which signals timeout via input ready state of sys_iochannel_t.
CopyrightThis program is free software.
Files
C-kern/api/time/systimer.hHeader file SysTimer.
C-kern/platform/Linux/time/systimer.cLinux implementation file SysTimer Linux.
Types
systimer_tExports systimer_t as alias for sys_iochannel_t.
Functions
test
unittest_time_systimerUnittest for systimer_t.
systimer_tImplements system timer to measure periods of time.
lifetime
systimer_FREEStatic initializer.
init_systimerAllocates a new system timer.
free_systimerFrees any resources associated with the timer.
measure
start_systimerThis function starts (arms) a one shot timer.
startinterval_systimerThis function starts (arms) a periodic timer.
stop_systimerStops a timer.
wait
wait_systimerWaits until timer expires.
query
remainingtime_systimerReturns the remaining time until the timer expires the next time.
expirationcount_systimerReturns the number of times the timer has expired.

Copyright

This program is free software.  You can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.

Author

© 2011 Jörg Seebohn

Files

C-kern/api/time/systimer.h

Header file SysTimer.

C-kern/platform/Linux/time/systimer.c

Linux implementation file SysTimer Linux.

Types

systimer_t

typedef sys_iochannel_t systimer_t

Exports systimer_t as alias for sys_iochannel_t.

Functions

test

unittest_time_systimer

int unittest_time_systimer(void)

Unittest for systimer_t.

systimer_t

typedef sys_iochannel_t systimer_t

Implements system timer to measure periods of time.

Summary
lifetime
systimer_FREEStatic initializer.
init_systimerAllocates a new system timer.
free_systimerFrees any resources associated with the timer.
measure
start_systimerThis function starts (arms) a one shot timer.
startinterval_systimerThis function starts (arms) a periodic timer.
stop_systimerStops a timer.
wait
wait_systimerWaits until timer expires.
query
remainingtime_systimerReturns the remaining time until the timer expires the next time.
expirationcount_systimerReturns the number of times the timer has expired.

lifetime

systimer_FREE

#define systimer_FREE sys_iochannel_FREE

Static initializer.

init_systimer

int init_systimer(/*out*/systimer_t *timer,
sysclock_e clock_type)

Allocates a new system timer.  See sysclock_e for the different clocks the timer can use to measure time.

free_systimer

int free_systimer(systimer_t *timer)

Frees any resources associated with the timer.  If the timer is running it will be stopped.

measure

start_systimer

int start_systimer(systimer_t timer,
struct timevalue_t *relative_time)

This function starts (arms) a one shot timer.  The started timer fires (expires) only once after relative_time seconds (+nanoseconds).  After the timer has expired it is stopped.

startinterval_systimer

int startinterval_systimer(systimer_t timer,
struct timevalue_t *interval_time)

This function starts (arms) a periodic timer.  The started timer fires (expires) at regular intervals after interval_time seconds (+nanoseconds).  After the timer has expired it is restarted with interval_time.

stop_systimer

int stop_systimer(systimer_t timer)

Stops a timer.  If a timer is stopped the remaining time and the expiration count are reset to 0.

wait

wait_systimer

int wait_systimer(systimer_t timer)

Waits until timer expires.  It returns EINVAL if a stopped timer is waited for.  After a successfull call to this function calling expirationcount_systimer will return a value != 0.  If the timer has already expired (expirationcount_systimer return != 0) calling this function has no effect.  It will return immediately.

Event

The timer is also a file descriptor.  If the timer expires this is signaled as file descriptor being readable.

query

remainingtime_systimer

int remainingtime_systimer(systimer_t timer,
struct timevalue_t *remaining_time)

Returns the remaining time until the timer expires the next time.  This value is a relative time value.

expirationcount_systimer

int expirationcount_systimer(systimer_t timer,
/*out*/uint64_t *expiration_count)

Returns the number of times the timer has expired.  After reading it is reset to 0.  If timer which is not an interval timer expires only once and after that it is considered stopped.

#define sys_iochannel_t int
Choose Posix file descriptor type.
Offers a timer which signals timeout via input ready state of sys_iochannel_t.
Linux specific implementation of SysTimer.
typedef sys_iochannel_t systimer_t
Exports systimer_t as alias for sys_iochannel_t.
int unittest_time_systimer(void)
Unittest for systimer_t.
#define systimer_FREE sys_iochannel_FREE
Static initializer.
int init_systimer(/*out*/systimer_t *timer,
sysclock_e clock_type)
Allocates a new system timer.
int free_systimer(systimer_t *timer)
Frees any resources associated with the timer.
int start_systimer(systimer_t timer,
struct timevalue_t *relative_time)
This function starts (arms) a one shot timer.
int startinterval_systimer(systimer_t timer,
struct timevalue_t *interval_time)
This function starts (arms) a periodic timer.
int stop_systimer(systimer_t timer)
Stops a timer.
int wait_systimer(systimer_t timer)
Waits until timer expires.
int remainingtime_systimer(systimer_t timer,
struct timevalue_t *remaining_time)
Returns the remaining time until the timer expires the next time.
int expirationcount_systimer(systimer_t timer,
/*out*/uint64_t *expiration_count)
Returns the number of times the timer has expired.
This value selects the clock type.
Close