2017-05-24 11:04:19 +00:00
|
|
|
#ifndef MM_CLOCK_H
|
|
|
|
#define MM_CLOCK_H
|
2017-04-10 12:11:06 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* machinarium.
|
|
|
|
*
|
|
|
|
* cooperative multitasking engine.
|
|
|
|
*/
|
|
|
|
|
2017-05-24 11:04:19 +00:00
|
|
|
typedef struct mm_clock mm_clock_t;
|
2017-04-10 12:11:06 +00:00
|
|
|
|
2017-05-24 11:04:19 +00:00
|
|
|
struct mm_clock
|
|
|
|
{
|
2017-04-20 11:56:47 +00:00
|
|
|
uint64_t time;
|
2017-08-11 15:32:58 +00:00
|
|
|
uint64_t time_us;
|
2017-04-10 12:11:06 +00:00
|
|
|
mm_buf_t timers;
|
|
|
|
int timers_count;
|
|
|
|
int timers_seq;
|
|
|
|
};
|
|
|
|
|
|
|
|
void mm_clock_init(mm_clock_t*);
|
|
|
|
void mm_clock_free(mm_clock_t*);
|
2017-04-10 12:55:59 +00:00
|
|
|
void mm_clock_update(mm_clock_t*);
|
2017-04-10 12:41:14 +00:00
|
|
|
int mm_clock_step(mm_clock_t*);
|
2017-04-10 12:11:06 +00:00
|
|
|
int mm_clock_timer_add(mm_clock_t*, mm_timer_t*);
|
|
|
|
int mm_clock_timer_del(mm_clock_t*, mm_timer_t*);
|
2017-04-10 15:07:14 +00:00
|
|
|
|
2017-04-10 12:11:06 +00:00
|
|
|
mm_timer_t*
|
|
|
|
mm_clock_timer_min(mm_clock_t*);
|
|
|
|
|
2017-04-10 15:07:14 +00:00
|
|
|
static inline void
|
2017-05-26 10:12:58 +00:00
|
|
|
mm_timer_start(mm_clock_t *clock, mm_timer_t *timer)
|
2017-04-12 12:16:01 +00:00
|
|
|
{
|
|
|
|
mm_clock_timer_add(clock, timer);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
mm_timer_stop(mm_timer_t *timer)
|
|
|
|
{
|
2017-04-10 15:07:14 +00:00
|
|
|
if (! timer->active)
|
|
|
|
return;
|
|
|
|
mm_clock_timer_del(timer->clock, timer);
|
|
|
|
}
|
|
|
|
|
2017-05-24 11:04:19 +00:00
|
|
|
#endif /* MM_CLOCK_H */
|