Loading...
Searching...
No Matches
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
34extern "C" {
35#endif
36
46int sntp_sync(sock_udp_ep_t *server, uint32_t timeout);
47
53int64_t sntp_get_offset(void);
54
60static 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 */
#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
static uint64_t sntp_get_unix_usec(void)
Get time in microseconds from 1970-01-01 00:00:00 UTC.
Definition sntp.h:60
int sntp_sync(sock_udp_ep_t *server, uint32_t timeout)
Synchronize with time server.
int64_t sntp_get_offset(void)
Get real time offset from system time as returned by xtimer_now64()
#define US_PER_SEC
The number of microseconds per second.
Definition time_units.h:85
static uint64_t xtimer_now_usec64(void)
get the current system time in microseconds since start
NTP packet definitions.
UDP sock definitions.
Common IP-based transport layer end point.
Definition sock.h:215
xtimer interface definitions