#include #include #include #include #include struct MyStruct { char *str; struct UCTimer timer; }; void t1_cb(struct UCTimers *timers, struct UCTimer *timer) { TRACEF("T1 expired\n"); } void t2_cb(struct UCTimers *timers, struct UCTimer *timer) { TRACEF("T2 expired\n"); } void mystruct_cb(struct UCTimers *timers, struct UCTimer *timer) { struct MyStruct *mystruct = CONTAINER_OF(timer, struct MyStruct, timer); TRACEF("MyStruct timer: %s\n", mystruct->str); uc_timer_add(timers, timer, 1, 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 = { .str = "Hello", .timer = { .callback = mystruct_cb, }, }; 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); for(;;) { struct timeval now; gettimeofday(&now, NULL); uc_timers_run(&timers, &now); #ifndef FULL_SPEED usleep(1000); #endif } return 0; }