Lydia - Printhead
Loading...
Searching...
No Matches
Timer< max_tasks, time_func > Class Template Reference

#include <xtimer.h>

Classes

struct  task
 

Public Types

typedef bool(* handler_t) (void *opaque)
 

Public Member Functions

bool at (unsigned long time, handler_t h, void *opaque=NULL)
 
bool every (unsigned long interval, handler_t h, void *opaque=NULL)
 
bool in (unsigned long delay, handler_t h, void *opaque=NULL)
 
void tick ()
 
void tick (unsigned long t)
 

Private Member Functions

struct taskadd_task (unsigned long start, unsigned long expires, handler_t h, void *opaque, bool repeat=0)
 
struct tasknext_task_slot ()
 
void remove (struct task *task)
 

Private Attributes

struct Timer::task tasks [max_tasks]
 

Detailed Description

template<size_t max_tasks = TIMER_MAX_TASKS, unsigned long(*)() time_func = millis>
class Timer< max_tasks, time_func >

Definition at line 20 of file xtimer.h.

Member Typedef Documentation

◆ handler_t

template<size_t max_tasks = TIMER_MAX_TASKS, unsigned long(*)() time_func = millis>
typedef bool(* Timer< max_tasks, time_func >::handler_t) (void *opaque)

Definition at line 23 of file xtimer.h.

Member Function Documentation

◆ add_task()

template<size_t max_tasks = TIMER_MAX_TASKS, unsigned long(*)() time_func = millis>
struct task * Timer< max_tasks, time_func >::add_task ( unsigned long start,
unsigned long expires,
handler_t h,
void * opaque,
bool repeat = 0 )
inlineprivate

Definition at line 110 of file xtimer.h.

112 {
113 struct task *const slot = next_task_slot();
114
115 if (!slot){
116 return NULL;
117 }
118
119 slot->handler = h;
120 slot->opaque = opaque;
121 slot->start = start;
122 slot->expires = expires;
123 slot->repeat = repeat;
124
125 return slot;
126 }
Definition xtimer.h:21
struct task * next_task_slot()
Definition xtimer.h:97

◆ at()

template<size_t max_tasks = TIMER_MAX_TASKS, unsigned long(*)() time_func = millis>
bool Timer< max_tasks, time_func >::at ( unsigned long time,
handler_t h,
void * opaque = NULL )
inline

Definition at line 33 of file xtimer.h.

34 {
35 const unsigned long now = time_func();
36 return add_task(now, time - now, h, opaque);
37 }
struct task * add_task(unsigned long start, unsigned long expires, handler_t h, void *opaque, bool repeat=0)
Definition xtimer.h:110

◆ every()

template<size_t max_tasks = TIMER_MAX_TASKS, unsigned long(*)() time_func = millis>
bool Timer< max_tasks, time_func >::every ( unsigned long interval,
handler_t h,
void * opaque = NULL )
inline

Definition at line 41 of file xtimer.h.

42 {
43 return add_task(time_func(), interval, h, opaque, interval);
44 }

◆ in()

template<size_t max_tasks = TIMER_MAX_TASKS, unsigned long(*)() time_func = millis>
bool Timer< max_tasks, time_func >::in ( unsigned long delay,
handler_t h,
void * opaque = NULL )
inline

Definition at line 26 of file xtimer.h.

27 {
28 return add_task(time_func(), delay, h, opaque);
29 }

◆ next_task_slot()

template<size_t max_tasks = TIMER_MAX_TASKS, unsigned long(*)() time_func = millis>
struct task * Timer< max_tasks, time_func >::next_task_slot ( )
inlineprivate

Definition at line 97 of file xtimer.h.

98 {
99 for (size_t i = 0; i < max_tasks; ++i)
100 {
101 struct task *const slot = &tasks[i];
102 if (slot->handler == NULL)
103 return slot;
104 }
105
106 return NULL;
107 }
struct Timer::task tasks[max_tasks]

◆ remove()

template<size_t max_tasks = TIMER_MAX_TASKS, unsigned long(*)() time_func = millis>
void Timer< max_tasks, time_func >::remove ( struct task * task)
inlineprivate

Definition at line 87 of file xtimer.h.

88 {
89 task->handler = NULL;
90 task->opaque = NULL;
91 task->start = 0;
92 task->expires = 0;
93 task->repeat = 0;
94 }

◆ tick() [1/2]

template<size_t max_tasks = TIMER_MAX_TASKS, unsigned long(*)() time_func = millis>
void Timer< max_tasks, time_func >::tick ( )
inline

Definition at line 49 of file xtimer.h.

50 {
51 tick(time_func());
52 }
void tick()
Definition xtimer.h:49

◆ tick() [2/2]

template<size_t max_tasks = TIMER_MAX_TASKS, unsigned long(*)() time_func = millis>
void Timer< max_tasks, time_func >::tick ( unsigned long t)
inline

Definition at line 56 of file xtimer.h.

57 {
58 for (size_t i = 0; i < max_tasks; ++i)
59 {
60 struct task *const task = &tasks[i];
61 const unsigned long duration = t - task->start;
62
63 if (task->handler && duration >= task->expires)
64 {
65 task->repeat = task->handler(task->opaque) && task->repeat;
66
67 if (task->repeat)
68 task->start = t;
69 else
70 remove(task);
71 }else{
72 }
73 }
74 }
void remove(struct task *task)
Definition xtimer.h:87

Member Data Documentation

◆ tasks

template<size_t max_tasks = TIMER_MAX_TASKS, unsigned long(*)() time_func = millis>
struct Timer::task Timer< max_tasks, time_func >::tasks[max_tasks]
private

The documentation for this class was generated from the following file: