coap_time.h
Go to the documentation of this file.
/*
* coap_time.h -- Clock Handling
*
* Copyright (C) 2010-2013 Olaf Bergmann <bergmann@tzi.org>
*
* This file is part of the CoAP library libcoap. Please see README for terms
* of use.
*/
#ifndef _COAP_TIME_H_
#define _COAP_TIME_H_
#ifdef WITH_LWIP
#include <stdint.h>
#include <lwip/sys.h>
/* lwIP provides ms in sys_now */
#define COAP_TICKS_PER_SECOND 1000
typedef uint32_t coap_tick_t;
typedef uint32_t coap_time_t;
typedef int32_t coap_tick_diff_t;
static inline void coap_ticks_impl(coap_tick_t *t) {
*t = sys_now();
}
static inline void coap_clock_init_impl(void) {
}
#define coap_clock_init coap_clock_init_impl
#define coap_ticks coap_ticks_impl
static inline coap_time_t coap_ticks_to_rt(coap_tick_t t) {
return t / COAP_TICKS_PER_SECOND;
}
#endif
#ifdef WITH_CONTIKI
#include "clock.h"
typedef clock_time_t coap_tick_t;
typedef clock_time_t coap_time_t;
typedef int coap_tick_diff_t;
#define COAP_TICKS_PER_SECOND CLOCK_SECOND
static inline void coap_clock_init(void) {
clock_init();
}
static inline void coap_ticks(coap_tick_t *t) {
*t = clock_time();
}
static inline coap_time_t coap_ticks_to_rt(coap_tick_t t) {
return t / COAP_TICKS_PER_SECOND;
}
#endif /* WITH_CONTIKI */
#ifdef WITH_POSIX
typedef unsigned long coap_tick_t;
typedef time_t coap_time_t;
typedef long coap_tick_diff_t;
#define COAP_TICKS_PER_SECOND 1000
void coap_clock_init(void);
void coap_ticks(coap_tick_t *t);
coap_time_t coap_ticks_to_rt(coap_tick_t t);
#endif /* WITH_POSIX */
static inline int coap_time_lt(coap_tick_t a, coap_tick_t b) {
return ((coap_tick_diff_t)(a - b)) < 0;
}
static inline int coap_time_le(coap_tick_t a, coap_tick_t b) {
return a == b || coap_time_lt(a,b);
}
#endif /* _COAP_TIME_H_ */
coap_clock_init
void coap_clock_init(void)
Initializes the internal clock.
Definition: coap_time.c:27
coap_ticks_to_rt
coap_time_t coap_ticks_to_rt(coap_tick_t t)
Helper function that converts coap ticks to wallclock time.
Definition: coap_time.c:82
coap_tick_t
unsigned long coap_tick_t
This data type represents internal timer ticks with COAP_TICKS_PER_SECOND resolution.
Definition: coap_time.h:84
COAP_TICKS_PER_SECOND
#define COAP_TICKS_PER_SECOND
Use ms resolution on POSIX systems.
Definition: coap_time.h:99
coap_tick_diff_t
long coap_tick_diff_t
This data type is used to represent the difference between two clock_tick_t values.
Definition: coap_time.h:96
coap_time_t
time_t coap_time_t
CoAP time in seconds since epoch.
Definition: coap_time.h:89
coap_ticks
void coap_ticks(coap_tick_t *t)
Sets t to the internal time with COAP_TICKS_PER_SECOND resolution.
Definition: coap_time.c:49
coap_time_le
static int coap_time_le(coap_tick_t a, coap_tick_t b)
Returns 1 if and only if a is less than or equal b where less is defined on a signed data type...
Definition: coap_time.h:136
coap_time_lt
static int coap_time_lt(coap_tick_t a, coap_tick_t b)
Returns 1 if and only if a is less than b where less is defined on a signed data type.
Definition: coap_time.h:128