Is there a way to do set a timer without having to put it inside a process in the Contiki OS?

421 views Asked by At

Is it possible to do what the code below does without any process? I need a timeout without surrounding it with Contiki process. Is this possible?

#include "sys/etimer.h"

PROCESS_THREAD(example_process, ev, data)
{
    static struct etimer et;
    PROCESS_BEGIN();

    /* Delay 1 second */
    etimer_set(&et, CLOCK_SECOND);

    while(1) {
        PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));

        /* Reset the etimer to trig again in 1 second */
        etimer_reset(&et);
        /* ... */
    }
    PROCESS_END();
}
1

There are 1 answers

3
kfx On

You can use callback timers:

struct ctimer my_timer;

static void
callback_function(void *data)
{
  ctimer_set(&my_timer, CLOCK_SECOND, callback_function, NULL);
}

To get the timer started the first time, call ctimer_set(&my_timer, CLOCK_SECOND, callback_function, NULL); from some initialization code. It does not have to be within a process handler function.