[riot-devel] vtimer_usleep_until or similar

Martine Lenders authmillenon at gmail.com
Tue Oct 21 16:08:10 CEST 2014


Hi,

2014-10-21 15:41 GMT+02:00 Daniel Amkær Sørensen <daniel.amkaer at gmail.com>:

> Thanks for the quick response.
>
> I have some input. I'm looking for the functionality which the FreeRTOS
> function implements. FreeRTOS calculates the time to sleep based on the
> previous waking time, and updates the pointed variable accordingly.
>
> "Pointer to a variable that holds the time at which the task was last
> unblocked. The variable must be initialised with the current time prior to
> its first use (see the example below). Following this the variable is
> automatically updated within vTaskDelayUntil()."
>
> This ensures that one call to the function each loop makes the function
> run with a chosen frequency.
>

You would achieve the same in RIOT with somthing like

while (!stop_cond) {
    vtimer_usleep(utime_increment);
    function_call(args);
}

For more precise cycles vtimer isn't the right tool anyways. If it needs to
be threaded it's a little bit more complicated. Have a look at
vtimer_set_wakeup():

static char RUN_STACK[KERNEL_CONF_STACKSIZE_DEFAULT];

void *run(void *run_args)
{
    (void)run_args;

    while (1) {
        function_call(args);

        thread_sleep();
    }

    return NULL;
}

int main(void)
{
    vtimer_t timer;
    timex_t inc = timex_set(0, utime_increment);
    kernel_pid_t pid = thread_create(RUN_STACK,
                                     KERNEL_CONF_STACKTEST_DEFAULT,
                                     PRIORITY_MAIN - 1,
                                     CREATE_SLEEPING | CREATE_STACKTEST,
                                     run, NULL, "runner");

    while (1) {
        vtimer_set_wakeup(&timer, inc, pid);
        vtimer_sleep(inc);
    }
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/devel/attachments/20141021/74863117/attachment.html>


More information about the devel mailing list