Loading...
Searching...
No Matches
sntp.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2016 Luminița Lăzărescu <cluminita.lazarescu@gmail.com>
3 * SPDX-FileCopyrightText: 2017 Freie Universität Berlin
4 * SPDX-License-Identifier: LGPL-2.1-only
5 */
6
7#pragma once
8
25
26#include <stdint.h>
27#include <time.h>
28
29#include "net/ntp_packet.h"
30#include "net/sock/udp.h"
31#include "ztimer64.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) + \
64}
65
66#ifdef __cplusplus
67}
68#endif
69
#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:51
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 ztimer64_now()
struct _sock_tl_ep sock_udp_ep_t
An end point for a UDP sock object.
Definition udp.h:292
#define US_PER_SEC
The number of microseconds per second.
Definition time_units.h:81
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.
ztimer 64bit API