tinydtls
0.8.6
Main Page
Related Pages
Modules
Data Structures
Files
File List
Globals
dtls_time.c
Go to the documentation of this file.
1
/*******************************************************************************
2
*
3
* Copyright (c) 2011, 2012, 2013, 2014, 2015 Olaf Bergmann (TZI) and others.
4
* All rights reserved. This program and the accompanying materials
5
* are made available under the terms of the Eclipse Public License v1.0
6
* and Eclipse Distribution License v. 1.0 which accompanies this distribution.
7
*
8
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
9
* and the Eclipse Distribution License is available at
10
* http://www.eclipse.org/org/documents/edl-v10.php.
11
*
12
* Contributors:
13
* Olaf Bergmann - initial API and implementation
14
*
15
*******************************************************************************/
16
22
#include "
tinydtls.h
"
23
#include "
dtls_time.h
"
24
25
#ifdef WITH_CONTIKI
26
clock_time_t
dtls_clock_offset
;
27
28
void
29
dtls_clock_init
(
void
) {
30
clock_init();
31
dtls_clock_offset
= clock_time();
32
}
33
34
void
35
dtls_ticks
(
dtls_tick_t
*t) {
36
*t = clock_time();
37
}
38
39
#else
/* WITH_CONTIKI */
40
41
time_t
dtls_clock_offset
;
42
43
void
44
dtls_clock_init
(
void
) {
45
#ifdef HAVE_TIME_H
46
dtls_clock_offset
= time(NULL);
47
#else
48
# ifdef __GNUC__
49
/* Issue a warning when using gcc. Other prepropressors do
50
* not seem to have a similar feature. */
51
# warning "cannot initialize clock"
52
# endif
53
dtls_clock_offset
= 0;
54
#endif
55
}
56
57
void
dtls_ticks
(
dtls_tick_t
*t) {
58
#ifdef HAVE_SYS_TIME_H
59
struct
timeval tv;
60
gettimeofday(&tv, NULL);
61
*t = (tv.tv_sec -
dtls_clock_offset
) *
DTLS_TICKS_PER_SECOND
62
+ (tv.tv_usec *
DTLS_TICKS_PER_SECOND
/ 1000000);
63
#else
64
#error "clock not implemented"
65
#endif
66
}
67
68
#endif
/* WITH_CONTIKI */
69
70
tinydtls.h
public tinydtls API
dtls_clock_init
void dtls_clock_init(void)
Definition:
dtls_time.c:44
dtls_tick_t
clock_time_t dtls_tick_t
Definition:
dtls_time.h:49
DTLS_TICKS_PER_SECOND
#define DTLS_TICKS_PER_SECOND
Definition:
dtls_time.h:52
clock_time_t
uint32_t clock_time_t
Definition:
dtls_time.h:46
dtls_time.h
Clock Handling.
dtls_clock_offset
time_t dtls_clock_offset
Definition:
dtls_time.c:41
dtls_ticks
void dtls_ticks(dtls_tick_t *t)
Definition:
dtls_time.c:57
Generated on Thu Oct 31 2019 17:28:28 for tinydtls by
1.8.11