Contiki-NG
Modules | Functions

The CoAP timer API defines a common interface for CoAP timer and time functionality. More...

Modules

 CoAP timer for Contiki-NG
 This is an implementation of CoAP timer for Contiki-NG.
 

Functions

void coap_timer_stop (coap_timer_t *timer)
 Stop a pending CoAP timer. More...
 
void coap_timer_set (coap_timer_t *timer, uint64_t time)
 Set a CoAP timer to expire after the specified time. More...
 
void coap_timer_reset (coap_timer_t *timer, uint64_t time)
 Reset a CoAP timer to expire a specified time after the last expiration time. More...
 
uint64_t coap_timer_time_to_next_expiration (void)
 Get the time until next CoAP timer expires or 0 if there already exists expired timers that have not yet been processed. More...
 
int coap_timer_run (void)
 This function must be called periodically by the CoAP timer driver to process any expired CoAP timers. More...
 
void coap_timer_init (void)
 This function initializes the CoAP timer library. More...
 
static uint64_t coap_timer_uptime (void)
 Get the time since boot in milliseconds. More...
 
static uint32_t coap_timer_seconds (void)
 Get the time since boot in seconds. More...
 
static void coap_timer_set_callback (coap_timer_t *timer, void(*callback)(coap_timer_t *))
 Set a callback function to be called when a CoAP timer expires. More...
 
static void * coap_timer_get_user_data (coap_timer_t *timer)
 Get user data that has been attached to a CoAP timer. More...
 
static void coap_timer_set_user_data (coap_timer_t *timer, void *data)
 Attach user data to a CoAP timer. More...
 
static int coap_timer_expired (const coap_timer_t *timer)
 Check if a CoAP timer has expired. More...
 

Detailed Description

The CoAP timer API defines a common interface for CoAP timer and time functionality.

Function Documentation

◆ coap_timer_expired()

static int coap_timer_expired ( const coap_timer_t *  timer)
inlinestatic

Check if a CoAP timer has expired.

Parameters
timerA pointer to a CoAP timer.
Returns
Non-zero if the timer has expired, zero otherwise.

Definition at line 142 of file coap-timer.h.

References coap_timer_init(), coap_timer_reset(), coap_timer_run(), coap_timer_set(), coap_timer_stop(), coap_timer_time_to_next_expiration(), and coap_timer_uptime().

◆ coap_timer_get_user_data()

static void* coap_timer_get_user_data ( coap_timer_t *  timer)
inlinestatic

Get user data that has been attached to a CoAP timer.

Parameters
timerA pointer to a CoAP timer.
Returns
An opaque pointer to user data or NULL if no user data is attached to the timer.

Definition at line 118 of file coap-timer.h.

◆ coap_timer_init()

void coap_timer_init ( void  )

This function initializes the CoAP timer library.

It is automatically called at first use of a CoAP timer. This function is normally never called by application code.

Definition at line 176 of file coap-timer.c.

Referenced by coap_timer_expired().

◆ coap_timer_reset()

void coap_timer_reset ( coap_timer_t *  timer,
uint64_t  time 
)

Reset a CoAP timer to expire a specified time after the last expiration time.

This function sets the CoAP timer to expire the specified time after the previous expiration time. If the new expiration time has already passed, the timer will expire as soon as possible.

If the timer has not yet expired when this function is called, the time until the timer expires will be extended by the specified time.

Parameters
timerA pointer to a CoAP timer.
timeThe time after previous expiration the timer expires.

Definition at line 110 of file coap-timer.c.

Referenced by coap_timer_expired().

◆ coap_timer_run()

int coap_timer_run ( void  )

This function must be called periodically by the CoAP timer driver to process any expired CoAP timers.

This function is normally never called by application code.

Returns non-zero if it needs to run again to process more timers.

Definition at line 137 of file coap-timer.c.

References coap_timer_uptime(), and list_head().

Referenced by coap_timer_expired().

◆ coap_timer_seconds()

static uint32_t coap_timer_seconds ( void  )
inlinestatic

Get the time since boot in seconds.

Returns
The number of seconds since boot.

Definition at line 93 of file coap-timer.h.

◆ coap_timer_set()

void coap_timer_set ( coap_timer_t *  timer,
uint64_t  time 
)

Set a CoAP timer to expire after the specified time.

Parameters
timerA pointer to a CoAP timer.
timeThe time until the timer expires.

Definition at line 103 of file coap-timer.c.

References coap_timer_uptime().

Referenced by coap_timer_expired().

◆ coap_timer_set_callback()

static void coap_timer_set_callback ( coap_timer_t *  timer,
void(*)(coap_timer_t *)  callback 
)
inlinestatic

Set a callback function to be called when a CoAP timer expires.

Parameters
timerA pointer to a CoAP timer.
callbackA callback function.

Definition at line 105 of file coap-timer.h.

◆ coap_timer_set_user_data()

static void coap_timer_set_user_data ( coap_timer_t *  timer,
void *  data 
)
inlinestatic

Attach user data to a CoAP timer.

Parameters
timerA pointer to a CoAP timer.
dataAn opaque pointer to user data.

Definition at line 130 of file coap-timer.h.

◆ coap_timer_stop()

void coap_timer_stop ( coap_timer_t *  timer)

Stop a pending CoAP timer.

After this function has been called, the timer will be expired and will not call the callback function.

Parameters
timerA pointer to a CoAP timer.

Definition at line 92 of file coap-timer.c.

Referenced by coap_timer_expired().

◆ coap_timer_time_to_next_expiration()

uint64_t coap_timer_time_to_next_expiration ( void  )

Get the time until next CoAP timer expires or 0 if there already exists expired timers that have not yet been processed.

This function is normally never called by application code.

Returns the time to next CoAP timer expires or 0 if unprocessed expired timers exists. Returns a time in the future if there are no timers pending.

Definition at line 117 of file coap-timer.c.

References list_head().

Referenced by coap_timer_expired().

◆ coap_timer_uptime()

static uint64_t coap_timer_uptime ( void  )
inlinestatic

Get the time since boot in milliseconds.

Returns
The number of milliseconds since boot.

Definition at line 83 of file coap-timer.h.

Referenced by coap_timer_expired(), coap_timer_run(), and coap_timer_set().