picow-http 0.12.1-4-g9d4fd13
HTTP server for the Raspberry Pi PicoW
ntp.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2022 Geoff Simmons <geoff@simmons.de>
3 *
4 * SPDX-License-Identifier: BSD-2-Clause
5 * See LICENSE
6 */
7
8#include "pico/time.h"
9
85#ifndef _NTP_H
86#define _NTP_H
87
88#include <stdbool.h>
89
103#ifndef NTP_DEFAULT_SERVERS
104#define NTP_DEFAULT_SERVERS \
105 "0.slimhazard.pool.ntp.org 1.slimhazard.pool.ntp.org " \
106 "2.slimhazard.pool.ntp.org 3.slimhazard.pool.ntp.org"
107#endif
108
117#ifndef NTP_DEFAULT_RESPONSE_TMO_S
118#define NTP_DEFAULT_RESPONSE_TMO_S (15)
119#endif
120
133#ifndef NTP_DEFAULT_RETRY_INTVL_S
134#define NTP_DEFAULT_RETRY_INTVL_S (15)
135#endif
136
146#ifndef NTP_DEFAULT_DNS_TMO_S
147#define NTP_DEFAULT_DNS_TMO_S (10)
148#endif
149
164#ifndef NTP_DEFAULT_REFRESH_INTVL_S
165#define NTP_DEFAULT_REFRESH_INTVL_S (30000)
166#endif
167
174struct ntp_cfg {
179 const char *servers;
190 unsigned dns_tmo_s;
199};
200
213static const char *wday_name[] = {
214 "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat",
215};
216
232static const char *month_name[] = {
233 "Jan", "Feb", "Mar", "Apr", "May", "Jun",
234 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
235};
236
237void time_init(struct ntp_cfg *cfg);
238void time_fini(void);
239
247bool rtc_synced(void);
248
276static inline struct ntp_cfg
278{
279 return (struct ntp_cfg) {
281 .response_tmo_s = NTP_DEFAULT_RESPONSE_TMO_S,
282 .retry_intvl_s = NTP_DEFAULT_RETRY_INTVL_S,
283 .dns_tmo_s = NTP_DEFAULT_DNS_TMO_S,
284 .refresh_intvl_s = NTP_DEFAULT_REFRESH_INTVL_S,
285 };
286}
287
288#endif /* _NTP_H */
bool rtc_synced(void)
Return true if the RTC has been synchronized.
#define NTP_DEFAULT_DNS_TMO_S
Default timeout for DNS resolution of the NTP server hostname.
Definition: ntp.h:147
#define NTP_DEFAULT_REFRESH_INTVL_S
Default interval for NTP refresh requests.
Definition: ntp.h:165
#define NTP_DEFAULT_RESPONSE_TMO_S
Default NTP response timeout.
Definition: ntp.h:118
static struct ntp_cfg ntp_default_cfg(void)
Get the NTP default configuration.
Definition: ntp.h:277
#define NTP_DEFAULT_SERVERS
Default NTP server addresses.
Definition: ntp.h:104
#define NTP_DEFAULT_RETRY_INTVL_S
Default NTP retry interval.
Definition: ntp.h:134
static const char * wday_name[]
Weekday name abbreviations.
Definition: ntp.h:213
static const char * month_name[]
Month name abbreviations.
Definition: ntp.h:232
NTP configuration.
Definition: ntp.h:174
unsigned response_tmo_s
Definition: ntp.h:181
const char * servers
Definition: ntp.h:179
unsigned dns_tmo_s
Definition: ntp.h:190
unsigned retry_intvl_s
Definition: ntp.h:186
unsigned refresh_intvl_s
Definition: ntp.h:198