tinydtls  0.8.6
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
27 
28 void
29 dtls_clock_init(void) {
30  clock_init();
31  dtls_clock_offset = clock_time();
32 }
33 
34 void
36  *t = clock_time();
37 }
38 
39 #else /* WITH_CONTIKI */
40 
42 
43 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
54 #endif
55 }
56 
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 
public tinydtls API
void dtls_clock_init(void)
Definition: dtls_time.c:44
clock_time_t dtls_tick_t
Definition: dtls_time.h:49
#define DTLS_TICKS_PER_SECOND
Definition: dtls_time.h:52
uint32_t clock_time_t
Definition: dtls_time.h:46
Clock Handling.
time_t dtls_clock_offset
Definition: dtls_time.c:41
void dtls_ticks(dtls_tick_t *t)
Definition: dtls_time.c:57