Search code examples
ccontiki

Is there any function in Contiki similar to clock_gettime() from time.h?


I want to use a function similar to the clock_gettime() function from time.h to calculate the time taken in a function call. I to include time.h, but found that it does not exist in Contiki.


Solution

  • You can use the rtimer functions for this task. The clock module is not suitable, as it's not meant for real-time or high-precision time accounting.

    rtimer_clock_t start;
    start = RTIMER_NOW();
    /* ...do stuff... */
    printf("it took %u ticks to do stuff\n", RTIMER_NOW() - start);
    

    The typical duration a rtimer tick is 1/32768 seconds. If you need even greater precision, you're left with hardware-specific counters.