Open bayou9 opened 7 years ago
Sounds like the timer scheduler should fit your use-case quite well.
It is a finicky little module, that fails quite miserably unless used 100% correctly (which is why we didn't expose it completely in the API :)).
For it to function correctly, the user has to follow some rules:
timer_event_t
must be stored statically, or be malloc'd. The scheduler arranges events in a linked list, and if any of the events are corrupted or altered after being scheduled, it will break.timer_sch_schedule()
, and scheduling the same event multiple times (without the event triggering in between) will break it. timer_sch_schedule()
. If you want to reschedule your event, call timer_sch_reschedule(p_my_event, new_timestamp)
. This function can also be used instead of timer_sch_schedule()
in all occurrences, but will be slightly slower, as we look for the event in our linked list before scheduling it.Example usage:
static timer_event_t m_event;
void schedule_event()
{
m_event.timestamp = timer_now() + DELAY;
m_event.interval = 0;
m_event.cb = timer_cb_function;
timer_sch_schedule(&m_event);
}
I'm trying to push a trickle instance into the local data cache... AFTER a certain variable time T (for example, 200ms, 55 ms, 308 ms, etc )
Now clearly there are 2 ways to do it:
One is to write my own timer function that , after the desired delay T, triggers an interrupt, and in this interrupt a callback will be called upon to push my target data into the m_data_cache and then I simply forget about it because it will have a timeout (of course, provided that it hears an amount of "gossip" with the same handle for less than c times) and promptly be sent, which is exactly what I want, the minute difference of 5 or even 50 ms is of no concern to me.
But I'm rather reluctant, because I'm not sure if I would end up missing something and result in some unforeseen consequences, another reason is that the function "timer_sch_schedule" is readily available but never used, and based on its description, it is exactly what I want, and it was exactly what I went after
Problem is, it does not work. I entered error loop after either:
A. try to event_handler_push my event into the asynchronous event queue. B. finishing executing the radio_signal_callback.
A will not happen if I place a breakpoint right before it and F11 through everything, however that's when B happens, A will happen only when I let the program run on its own or press F10 instead of F11 after the breakpoint pause (right before event_handler_push(evt)), in which case I would be letting it run by itself too.
I suspect B isn't a real problem, just has something to do with time_slots.
And the code are as follows:
What would be the probable cause(s)?