diff options
| author | Kimplul <kimi.h.kuparinen@gmail.com> | 2022-04-18 21:10:57 +0300 |
|---|---|---|
| committer | Kimplul <kimi.h.kuparinen@gmail.com> | 2022-04-21 12:12:38 +0300 |
| commit | 7967a9ab13214543041e4408086668b4db8d3e62 (patch) | |
| tree | 4dab7b89bd9d5b5b8280877f9d8eb23a1edf1230 /include/apos/timer.h | |
| parent | 1ceed7525272b82c1028ebd353e65c3a63bd2714 (diff) | |
| download | kmi-7967a9ab13214543041e4408086668b4db8d3e62.tar.gz kmi-7967a9ab13214543041e4408086668b4db8d3e62.zip | |
start working on timer subsys
Diffstat (limited to 'include/apos/timer.h')
| -rw-r--r-- | include/apos/timer.h | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/include/apos/timer.h b/include/apos/timer.h new file mode 100644 index 0000000..ea5bd03 --- /dev/null +++ b/include/apos/timer.h @@ -0,0 +1,47 @@ +#ifndef APOS_TIMER_H +#define APOS_TIMER_H + +#include <apos/types.h> + +typedef size_t ticks_t; +/* whichever time unit we're dealing with */ +typedef size_t tunit_t; + +struct timer { + id_t tid; + id_t cid; + + ticks_t ticks; +}; + +void init_timer(); + +/* set up timer interrupt ticks from now */ +id_t new_rel_timer(id_t tid, ticks_t ticks); +/* set up timer interrupt at ticks (from startup I suppose) */ +id_t new_abs_timer(id_t tid, ticks_t ticks); + +struct timer *newest_timer(); +struct timer *find_timer(id_t cid); +void remove_timer(struct timer *); + +ticks_t nsecs_to_ticks(tunit_t nsecs); + +static inline ticks_t usecs_to_ticks(tunit_t usecs) +{ + return nsecs_to_ticks(usecs * 1000); +} + +static inline ticks_t msecs_to_ticks(tunit_t msecs) +{ + return usecs_to_ticks(msecs * 1000); +} + +/* TODO: likely not a problem on 64bit systems, not sure how to handle situation on + * 32bit */ +static inline ticks_t secs_to_ticks(tunit_t secs) +{ + return msecs_to_ticks(secs * 1000); +} + +#endif /* APOS_TIMER_H */ |
