More timers example

This commit is contained in:
Nils O. Selåsdal
2013-02-20 20:47:04 +01:00
parent d6faa0a3e2
commit a413572f3c
+24 -5
View File
@@ -20,34 +20,53 @@ void t2_cb(struct UCTimers *timers, struct UCTimer *timer)
TRACEF("T2 expired\n");
}
void mystruct_cb(struct UCTimers *timers, struct UCTimer *timer)
void mystruct1_cb(struct UCTimers *timers, struct UCTimer *timer)
{
struct MyStruct *mystruct = CONTAINER_OF(timer, struct MyStruct, timer);
TRACEF("MyStruct timer: %s\n", mystruct->str);
TRACEF("MyStruct1 timer: %s\n", mystruct->str);
uc_timer_add(timers, timer, 1, 0);
}
void mystruct2_cb(struct UCTimers *timers, struct UCTimer *timer)
{
struct MyStruct *mystruct = timer->cookie_ptr;
TRACEF("MyStruct2 timer: %s\n", mystruct->str);
uc_timer_add(timers, timer, 5, 0);
}
int main(int argc, char *argv[])
{
struct UCTimers timers;
struct UCTimer t1 = {
.callback = t1_cb,
};
struct UCTimer t2 = {
.callback = t2_cb,
};
struct MyStruct my_struct = {
struct MyStruct my_struct1 = {
.str = "Hello",
.timer = {
.callback = mystruct_cb,
.callback = mystruct1_cb,
},
};
struct MyStruct my_struct2 = {
.str = "Hello again",
.timer = {
.callback = mystruct2_cb,
.cookie_ptr = &my_struct2,
},
};
uc_timers_init(&timers);
uc_timer_add(&timers, &t1, 2, 0);
uc_timer_add(&timers, &t2, 5, 0);
uc_timer_add(&timers, &my_struct.timer, 10, 0);
uc_timer_add(&timers, &my_struct1.timer, 10, 0);
uc_timer_add(&timers, &my_struct2.timer, 10, 0);
for(;;) {
struct timeval now;