mirror of
https://github.com/obgm/libcoap.git
synced 2026-11-09 18:32:53 +03:00
New data_type coap_time_diff_t and functions coap_time_lt(), coap_time_le()
for time stamps with wrapping
This commit is contained in:
1 parent
80b9a5f82f
commit
3f3c8dc63f
1 file changed
+24
+24
@@ -28,6 +28,13 @@
|
||||
|
||||
typedef clock_time_t coap_tick_t;
|
||||
|
||||
/**
|
||||
* This data type is used to represent the difference between two
|
||||
* clock_tick_t values. This data type must have the same size in
|
||||
* memory as coap_tick_t to allow wrapping.
|
||||
*/
|
||||
typedef int coap_tick_diff_t;
|
||||
|
||||
#define COAP_TICKS_PER_SECOND CLOCK_SECOND
|
||||
|
||||
/** Set at startup to initialize the internal clock (time in seconds). */
|
||||
@@ -51,6 +58,13 @@ contiki_ticks_impl(coap_tick_t *t) {
|
||||
#else /* WITH_CONTIKI */
|
||||
typedef unsigned int coap_tick_t;
|
||||
|
||||
/**
|
||||
* This data type is used to represent the difference between two
|
||||
* clock_tick_t values. This data type must have the same size in
|
||||
* memory as coap_tick_t to allow wrapping.
|
||||
*/
|
||||
typedef int coap_tick_diff_t;
|
||||
|
||||
#define COAP_TICKS_PER_SECOND 1024
|
||||
|
||||
/** Set at startup to initialize the internal clock (time in seconds). */
|
||||
@@ -89,6 +103,16 @@ coap_ticks_impl(coap_tick_t *t) {
|
||||
#define coap_ticks coap_ticks_impl
|
||||
#endif /* coap_ticks */
|
||||
|
||||
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_ */
|
||||
Reference in new issue
Block a user