#ifdef HAVE_TIME_H
#include <time.h>
#endif
+#ifdef HAVE_SYS_TIME_H
+#include <sys/time.h>
+#endif
#ifdef WITH_LWIP
#include <stdint.h>
typedef uint32_t coap_tick_t;
- static inline void coap_ticks_impl(coap_tick_t *t)
+ INLINE_API void coap_ticks_impl(coap_tick_t *t)
{
*t = sys_now();
}
- static inline void coap_clock_init_impl(void)
+ INLINE_API void coap_clock_init_impl(void)
{
}
/** Set at startup to initialize the internal clock (time in seconds). */
extern clock_time_t clock_offset;
- static inline void
+ INLINE_API void
contiki_clock_init_impl(void)
{
clock_init();
#define coap_clock_init contiki_clock_init_impl
- static inline void
+ INLINE_API void
contiki_ticks_impl(coap_tick_t *t)
{
*t = clock_time();
#define coap_ticks contiki_ticks_impl
#endif /* WITH_CONTIKI */
-#ifdef WITH_POSIX
+#if defined(WITH_POSIX) || defined(_WIN32)
typedef unsigned int coap_tick_t;
/**
/** Set at startup to initialize the internal clock (time in seconds). */
extern time_t clock_offset;
-#endif /* WITH_POSIX */
+#endif /* WITH_POSIX || _WIN32 */
#ifdef WITH_ARDUINO
#include "Time.h"
#endif /* WITH_ARDUINO */
#ifndef coap_clock_init
- static inline void coap_clock_init_impl(void)
+ INLINE_API void coap_clock_init_impl(void)
{
#ifdef HAVE_TIME_H
clock_offset = time(NULL);
#endif /* coap_clock_init */
#ifndef coap_ticks
- static inline void coap_ticks_impl(coap_tick_t *t)
+ INLINE_API void coap_ticks_impl(coap_tick_t *t)
{
#ifdef HAVE_SYS_TIME_H
struct timeval tv;
#endif
*t = (tv - clock_offset) * COAP_TICKS_PER_SECOND;
# else
+#ifdef HAVE_TIME_H
+ time_t tv = time(NULL);
+ *t = difftime(tv, clock_offset) * COAP_TICKS_PER_SECOND;
+#else
# error "clock not implemented"
+#endif /* HAVE_TIME_H */
# endif /* WITH_ARDUINO */
#endif /* HAVE_SYS_TIME_H */
}
* 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
+ INLINE_API
int coap_time_lt(coap_tick_t a, coap_tick_t b)
{
return ((coap_tick_diff_t)(a - b)) < 0;
* 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
+ INLINE_API
int coap_time_le(coap_tick_t a, coap_tick_t b)
{
return a == b || coap_time_lt(a, b);