Contiki-NG provides a set of timer libraries that are used both by applications and by the OS itself. The timer libraries contain functionality for checking if a time period has passed, waking up the system from low power mode at scheduled times, and real-time tasks scheduling.
All the timers build on the clock module, in charge of basic system time:
1. timer: a simple timer, without built-in notification (caller must check if expired). Safe from interrupt.
2. stimer: same as timer, but in seconds and with significantly longer wrapping period. Safe from interrupt.
3. etimer: schedules events to Contiki-NG processes. Unsafe from interrupt.
4. ctimer: schedules calls to a callback function. Unsafe from interrupt.
5. rtimer: real-time task scheduling, with execution from ISR. Safe from interrupt.
Code:
File location -> contiki-Ng/os/sys
#include "sys/timer.h"
static struct timer rxtimer;
void init(void) {
timer_set(&rxtimer, CLOCK_SECOND / 2);
}
interrupt(UART1RX_VECTOR)
uart1_rx_interrupt(void)
{
if(timer_expired(&rxtimer)) {
/* Timeout */
...
}
timer_restart(&rxtimer);
...
}