sntp.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2016 Luminița Lăzărescu <cluminita.lazarescu@gmail.com>
3  * Copyright (C) 2017 Freie Universität Berlin
4  *
5  * This file is subject to the terms and conditions of the GNU Lesser
6  * General Public License v2.1. See the file LICENSE in the top level
7  * directory for more details.
8  */
9 
23 #ifndef NET_SNTP_H
24 #define NET_SNTP_H
25 
26 #include <stdint.h>
27 #include <time.h>
28 
29 #include "net/ntp_packet.h"
30 #include "net/sock/udp.h"
31 #include "xtimer.h"
32 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36 
46 int sntp_sync(sock_udp_ep_t *server, uint32_t timeout);
47 
53 int64_t sntp_get_offset(void);
54 
60 static inline uint64_t sntp_get_unix_usec(void)
61 {
62  return (uint64_t)(sntp_get_offset() - (NTP_UNIX_OFFSET * US_PER_SEC) + xtimer_now_usec64());
63 }
64 
65 #ifdef __cplusplus
66 }
67 #endif
68 
69 #endif /* NET_SNTP_H */
70 
udp.h
UDP sock definitions.
sntp_get_offset
int64_t sntp_get_offset(void)
Get real time offset from system time as returned by xtimer_now64()
sntp_sync
int sntp_sync(sock_udp_ep_t *server, uint32_t timeout)
Synchronize with time server.
NTP_UNIX_OFFSET
#define NTP_UNIX_OFFSET
Offset in seconds of NTP timestamp (seconds from 1990-01-01 00:00:00 UTC) to UNIX timestamp (seconds ...
Definition: ntp_packet.h:53
_sock_tl_ep
Common IP-based transport layer end point.
Definition: sock.h:213
sntp_get_unix_usec
static uint64_t sntp_get_unix_usec(void)
Get time in microseconds from 1970-01-01 00:00:00 UTC.
Definition: sntp.h:60
xtimer_now_usec64
static uint64_t xtimer_now_usec64(void)
get the current system time in microseconds since start
ntp_packet.h
NTP packet definitions.
xtimer.h
xtimer interface definitions
US_PER_SEC
#define US_PER_SEC
The number of microseconds per second.
Definition: timex.h:34