zephyr/subsys/net/lib/config/init_clock_sntp.c
Kumar Gala a1b77fd589 zephyr: replace zephyr integer types with C99 types
git grep -l 'u\(8\|16\|32\|64\)_t' | \
		xargs sed -i "s/u\(8\|16\|32\|64\)_t/uint\1_t/g"
	git grep -l 's\(8\|16\|32\|64\)_t' | \
		xargs sed -i "s/s\(8\|16\|32\|64\)_t/int\1_t/g"

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-06-08 08:23:57 -05:00

32 lines
668 B
C

/*
* Copyright (c) 2019 Linaro Limited
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <logging/log.h>
LOG_MODULE_DECLARE(net_config, CONFIG_NET_CONFIG_LOG_LEVEL);
#include <errno.h>
#include <net/sntp.h>
#include <posix/time.h>
int net_init_clock_via_sntp(void)
{
struct sntp_time ts;
struct timespec tspec;
int res = sntp_simple(CONFIG_NET_CONFIG_SNTP_INIT_SERVER,
CONFIG_NET_CONFIG_SNTP_INIT_TIMEOUT, &ts);
if (res < 0) {
LOG_ERR("Cannot set time using SNTP");
return res;
}
tspec.tv_sec = ts.seconds;
tspec.tv_nsec = ((uint64_t)ts.fraction * (1000 * 1000 * 1000)) >> 32;
res = clock_settime(CLOCK_REALTIME, &tspec);
return 0;
}