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 
10 #pragma once
11 
29 #include <stdint.h>
30 #include <time.h>
31 
32 #include "net/ntp_packet.h"
33 #include "net/sock/udp.h"
34 #include "ztimer64.h"
35 
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39 
49 int sntp_sync(sock_udp_ep_t *server, uint32_t timeout);
50 
56 int64_t sntp_get_offset(void);
57 
63 static inline uint64_t sntp_get_unix_usec(void)
64 {
65  return (uint64_t)(sntp_get_offset() - (NTP_UNIX_OFFSET * US_PER_SEC) + \
67 }
68 
69 #ifdef __cplusplus
70 }
71 #endif
72 
#define NTP_UNIX_OFFSET
Offset in seconds of NTP timestamp (seconds from 1900-01-01 00:00:00 UTC) to UNIX timestamp (seconds ...
Definition: ntp_packet.h:54
static uint64_t sntp_get_unix_usec(void)
Get time in microseconds from 1970-01-01 00:00:00 UTC.
Definition: sntp.h:63
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 ztimer64_now()
#define US_PER_SEC
The number of microseconds per second.
Definition: time_units.h:84
uint64_t ztimer64_now(ztimer64_clock_t *clock)
Get the current time from a clock.
ztimer64_clock_t *const ZTIMER64_USEC
Default ztimer microsecond clock.
NTP packet definitions.
UDP sock definitions.
Common IP-based transport layer end point.
Definition: sock.h:214
ztimer 64bit API