IDF release/v4.0 08219f3cf

This commit is contained in:
me-no-dev
2020-01-25 14:51:58 +00:00
parent 8c723be135
commit 41ba143063
858 changed files with 37940 additions and 49396 deletions

View File

@ -1,7 +1,7 @@
/*
* coap_time.h -- Clock Handling
*
* Copyright (C) 2010-2013 Olaf Bergmann <bergmann@tzi.org>
* Copyright (C) 2010-2019 Olaf Bergmann <bergmann@tzi.org>
*
* This file is part of the CoAP library libcoap. Please see README for terms
* of use.
@ -12,8 +12,8 @@
* @brief Clock Handling
*/
#ifndef _COAP_TIME_H_
#define _COAP_TIME_H_
#ifndef COAP_TIME_H_
#define COAP_TIME_H_
/**
* @defgroup clock Clock Handling
@ -21,7 +21,7 @@
* @{
*/
#ifdef WITH_LWIP
#if defined(WITH_LWIP)
#include <stdint.h>
#include <lwip/sys.h>
@ -33,22 +33,22 @@ 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) {
COAP_STATIC_INLINE void coap_ticks_impl(coap_tick_t *t) {
*t = sys_now();
}
static inline void coap_clock_init_impl(void) {
COAP_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) {
COAP_STATIC_INLINE coap_time_t coap_ticks_to_rt(coap_tick_t t) {
return t / COAP_TICKS_PER_SECOND;
}
#endif
#ifdef WITH_CONTIKI
#elif defined(WITH_CONTIKI)
#include "clock.h"
typedef clock_time_t coap_tick_t;
@ -63,25 +63,26 @@ typedef int coap_tick_diff_t;
#define COAP_TICKS_PER_SECOND CLOCK_SECOND
static inline void coap_clock_init(void) {
COAP_STATIC_INLINE void coap_clock_init(void) {
clock_init();
}
static inline void coap_ticks(coap_tick_t *t) {
COAP_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) {
COAP_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
#else
#include <stdint.h>
/**
* This data type represents internal timer ticks with COAP_TICKS_PER_SECOND
* resolution.
*/
typedef unsigned long coap_tick_t;
typedef uint64_t coap_tick_t;
/**
* CoAP time in seconds since epoch.
@ -93,10 +94,10 @@ typedef time_t coap_time_t;
* values. This data type must have the same size in memory as coap_tick_t to
* allow wrapping.
*/
typedef long coap_tick_diff_t;
typedef int64_t coap_tick_diff_t;
/** Use ms resolution on POSIX systems */
#define COAP_TICKS_PER_SECOND 1000
#define COAP_TICKS_PER_SECOND ((coap_tick_t)(1000U))
/**
* Initializes the internal clock.
@ -119,13 +120,32 @@ void coap_ticks(coap_tick_t *t);
* point (seconds since epoch on POSIX).
*/
coap_time_t coap_ticks_to_rt(coap_tick_t t);
#endif /* WITH_POSIX */
/**
* Helper function that converts coap ticks to POSIX wallclock time in us.
*
* @param t Internal system ticks.
*
* @return The number of seconds that has passed since a specific reference
* point (seconds since epoch on POSIX).
*/
uint64_t coap_ticks_to_rt_us(coap_tick_t t);
/**
* Helper function that converts POSIX wallclock time in us to coap ticks.
*
* @param t POSIX time is us
*
* @return coap ticks
*/
coap_tick_t coap_ticks_from_rt_us(uint64_t t);
#endif
/**
* Returns @c 1 if and only if @p a is less than @p b where less is defined on a
* signed data type.
*/
static inline int coap_time_lt(coap_tick_t a, coap_tick_t b) {
COAP_STATIC_INLINE int coap_time_lt(coap_tick_t a, coap_tick_t b) {
return ((coap_tick_diff_t)(a - b)) < 0;
}
@ -133,10 +153,10 @@ static inline int coap_time_lt(coap_tick_t a, coap_tick_t b) {
* Returns @c 1 if and only if @p a is less than or equal @p b where less is
* defined on a signed data type.
*/
static inline int coap_time_le(coap_tick_t a, coap_tick_t b) {
COAP_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_ */
#endif /* COAP_TIME_H_ */