From 4d31fcd6d38fb2acaf960857628047c06ae14dee Mon Sep 17 00:00:00 2001 From: Olaf Bergmann Date: Thu, 3 Feb 2022 08:26:01 +0100 Subject: [PATCH 1/2] dtls_time.c: Moved as dtls_time_posix.c to platform-specific Change-Id: Ie709f36ea7918c0267c5760c87c771600310d95f --- dtls_time.c => platform-specific/dtls_time_posix.c | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename dtls_time.c => platform-specific/dtls_time_posix.c (100%) diff --git a/dtls_time.c b/platform-specific/dtls_time_posix.c similarity index 100% rename from dtls_time.c rename to platform-specific/dtls_time_posix.c From b1ebfc63212c9199c9085fe4d594dc4f694a5f14 Mon Sep 17 00:00:00 2001 From: Olaf Bergmann Date: Thu, 3 Feb 2022 08:37:37 +0100 Subject: [PATCH 2/2] dtls_time: Moved platform-specific code to separate files Change-Id: I79d6b07be77f496f592fe53833c34666dd068d1a --- dtls_time.c | 36 +++++++++++++++++++++++ platform-specific/dtls_time_contiki.c | 31 ++++++++++++++++++++ platform-specific/dtls_time_posix.c | 41 +-------------------------- platform-specific/dtls_time_riot.c | 30 ++++++++++++++++++++ 4 files changed, 98 insertions(+), 40 deletions(-) create mode 100644 dtls_time.c create mode 100644 platform-specific/dtls_time_contiki.c create mode 100644 platform-specific/dtls_time_riot.c diff --git a/dtls_time.c b/dtls_time.c new file mode 100644 index 00000000..982f5a1d --- /dev/null +++ b/dtls_time.c @@ -0,0 +1,36 @@ +/******************************************************************************* + * + * Copyright (c) 2011-2022 Olaf Bergmann (TZI) and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and Eclipse Distribution License v. 1.0 which accompanies this distribution. + * + * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html + * and the Eclipse Distribution License is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * Contributors: + * Olaf Bergmann - initial API and implementation + * + *******************************************************************************/ + +/** + * @file dtls_time.c + * @brief Clock Handling + */ + +#include "tinydtls.h" + +#if defined (WITH_CONTIKI) +#include "platform-specific/dtls_time_contiki.c" + +#elif defined (RIOT_VERSION) +#include "platform-specific/dtls_time_riot.c" + +#elif defined (WITH_POSIX) +#include "platform-specific/dtls_time_posix.c" + +#else +#error platform specific time functions not defined + +#endif diff --git a/platform-specific/dtls_time_contiki.c b/platform-specific/dtls_time_contiki.c new file mode 100644 index 00000000..d04ca7a1 --- /dev/null +++ b/platform-specific/dtls_time_contiki.c @@ -0,0 +1,31 @@ +/******************************************************************************* + * + * Copyright (c) 2011-2022 Olaf Bergmann (TZI) and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and Eclipse Distribution License v. 1.0 which accompanies this distribution. + * + * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html + * and the Eclipse Distribution License is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * Contributors: + * Olaf Bergmann - initial API and implementation + * + *******************************************************************************/ + +#include "tinydtls.h" +#include "dtls_time.h" + +clock_time_t dtls_clock_offset; + +void +dtls_clock_init(void) { + clock_init(); + dtls_clock_offset = clock_time(); +} + +void +dtls_ticks(dtls_tick_t *t) { + *t = clock_time(); +} diff --git a/platform-specific/dtls_time_posix.c b/platform-specific/dtls_time_posix.c index 5d353b4f..eeb97f01 100644 --- a/platform-specific/dtls_time_posix.c +++ b/platform-specific/dtls_time_posix.c @@ -1,6 +1,6 @@ /******************************************************************************* * - * Copyright (c) 2011, 2012, 2013, 2014, 2015 Olaf Bergmann (TZI) and others. + * Copyright (c) 2011-2022 Olaf Bergmann (TZI) and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * and Eclipse Distribution License v. 1.0 which accompanies this distribution. @@ -14,46 +14,9 @@ * *******************************************************************************/ -/** - * @file dtls_time.c - * @brief Clock Handling - */ - #include "tinydtls.h" #include "dtls_time.h" -#ifdef WITH_CONTIKI -clock_time_t dtls_clock_offset; - -void -dtls_clock_init(void) { - clock_init(); - dtls_clock_offset = clock_time(); -} - -void -dtls_ticks(dtls_tick_t *t) { - *t = clock_time(); -} - -#endif /* WITH_CONTIKI */ - -#ifdef RIOT_VERSION -dtls_tick_t dtls_clock_offset; - -void -dtls_clock_init(void) { - dtls_clock_offset = xtimer_now64().ticks64; -} - -void -dtls_ticks(dtls_tick_t *t) { - *t = xtimer_now64().ticks64 -dtls_clock_offset; -} - -#endif /* RIOT_VERSION */ - -#ifdef WITH_POSIX time_t dtls_clock_offset; void @@ -81,6 +44,4 @@ void dtls_ticks(dtls_tick_t *t) { #endif } -#endif /* WITH_POSIX */ - diff --git a/platform-specific/dtls_time_riot.c b/platform-specific/dtls_time_riot.c new file mode 100644 index 00000000..798fd897 --- /dev/null +++ b/platform-specific/dtls_time_riot.c @@ -0,0 +1,30 @@ +/******************************************************************************* + * + * Copyright (c) 2011-2022 Olaf Bergmann (TZI) and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and Eclipse Distribution License v. 1.0 which accompanies this distribution. + * + * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html + * and the Eclipse Distribution License is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * Contributors: + * Olaf Bergmann - initial API and implementation + * + *******************************************************************************/ + +#include "tinydtls.h" +#include "dtls_time.h" + +dtls_tick_t dtls_clock_offset; + +void +dtls_clock_init(void) { + dtls_clock_offset = xtimer_now64().ticks64; +} + +void +dtls_ticks(dtls_tick_t *t) { + *t = xtimer_now64().ticks64 -dtls_clock_offset; +}