Search code examples
ctimercontikicontiki-process

Contiki timer without pausing the process


is there a way for wait that a timer expire without pausing the process? If we use

 PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));

we pause the process. Suppose we want continue to do other stuff and when the timer expires check if the value of a function has changed.

If it is not possible, may I have to start a new process that just wait?

Thank you.


Solution

  • No, there isn't - that's a fundamental consequence of how event timers work. Contiki multithreading / multiprocessing is cooperative - processes have to voluntarily pause execution to let other processes run. Since event timers are managed by another (system) process, if your process never gives up execution, the timer process never gets to run. Hence, your process will never get the timer event back.

    Sounds like event timer might not be the best option for you. You can use rtimer instead:

    rtimer_clock_t end = RTIMER_NOW() + RTIMER_SECOND;
    while(RTIMER_CLOCK_LT(RTIMER_NOW(), end)) {
       /* do stuff */
    }
    

    Remember to poke watchdog timer occasionally - if your process will be stuck doing things for a couple of seconds (not recommended anyway), the watchdog will expire.