Skip to content

Commit

Permalink
dtls_time: migrate to ztimer_msec
Browse files Browse the repository at this point in the history
  • Loading branch information
fjmolinas committed Feb 2, 2022
1 parent 8660e46 commit d4ac77b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
6 changes: 3 additions & 3 deletions dtls_time.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ dtls_tick_t dtls_clock_offset;

void
dtls_clock_init(void) {
dtls_clock_offset = xtimer_now64().ticks64;
dtls_clock_offset = ztimer_now(ZTIMER_MSEC);
}

void
dtls_ticks(dtls_tick_t *t) {
*t = xtimer_now64().ticks64 -dtls_clock_offset;
*t = ztimer_now(ZTIMER_MSEC) - dtls_clock_offset;
}

#endif /* RIOT_VERSION */
Expand All @@ -74,7 +74,7 @@ void dtls_ticks(dtls_tick_t *t) {
#ifdef HAVE_SYS_TIME_H
struct timeval tv;
gettimeofday(&tv, NULL);
*t = (tv.tv_sec - dtls_clock_offset) * DTLS_TICKS_PER_SECOND
*t = (tv.tv_sec - dtls_clock_offset) * DTLS_TICKS_PER_SECOND
+ (tv.tv_usec * DTLS_TICKS_PER_SECOND / 1000000);
#else
#error "clock not implemented"
Expand Down
7 changes: 4 additions & 3 deletions dtls_time.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,16 @@

#elif defined(RIOT_VERSION)

#include <xtimer.h>
#include "ztimer.h"
#include "timex.h"

/* this macro is already present on FreeBSD
which causes a redefine error otherwise */
#ifndef CLOCK_SECOND
#define CLOCK_SECOND (xtimer_ticks_from_usec64(1000000UL).ticks64)
#define CLOCK_SECOND (MS_PER_SEC)
#endif

typedef uint64_t clock_time_t;
typedef uint32_t clock_time_t;
#else /* WITH_CONTIKI || RIOT_VERSION */

#include <time.h>
Expand Down

0 comments on commit d4ac77b

Please sign in to comment.