Pico Led Controller 1.0.3
A project to control LEDs using Raspberry Pi Pico W
ntp.h
Go to the documentation of this file.
1 #ifndef _NTP_H
2 #define _NTP_H
3 
4 #include <string.h>
5 #include <time.h>
6 
7 #include "pico/stdlib.h"
8 #include "pico/cyw43_arch.h"
9 
10 #include "lwip/dns.h"
11 #include "lwip/pbuf.h"
12 #include "lwip/udp.h"
13 
14 #define NTP_SERVER "pool.ntp.org"
15 #define NTP_MSG_LEN 48
16 #define NTP_PORT 123
17 #define NTP_DELTA 2208988800
18 #define NTP_TEST_TIME (30 * 1000)
19 #define NTP_RESEND_TIME (10 * 1000)
20 
24 extern volatile struct tm *utc;
25 
29 extern volatile struct tm *current_utc;
30 
34 typedef struct NTP_T_
35 {
36  ip_addr_t ntp_server_address;
38  struct udp_pcb *ntp_pcb;
39  absolute_time_t ntp_test_time;
40  alarm_id_t ntp_resend_alarm;
42 
50 static void ntp_result(NTP_T* state, int status, time_t *result);
51 
59 static int64_t ntp_failed_handler(alarm_id_t id, void *user_data);
60 
66 static void ntp_request(NTP_T *state);
67 
75 static int64_t ntp_failed_handler(alarm_id_t id, void *user_data);
76 
84 static void ntp_dns_found(const char *hostname, const ip_addr_t *ipaddr, void *arg);
85 
95 static void ntp_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *addr, u16_t port);
96 
102 static NTP_T* ntp_init(void);
103 
107 void ntp_deinit(void);
108 
112 void ntp_update_time(void);
113 
114 #endif
static void ntp_result(NTP_T *state, int status, time_t *result)
NTP result.
static int64_t ntp_failed_handler(alarm_id_t id, void *user_data)
NTP failed handler.
static void ntp_dns_found(const char *hostname, const ip_addr_t *ipaddr, void *arg)
NTP DNS found.
void ntp_deinit(void)
NTP deinit.
Definition: ntp.c:114
static void ntp_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *addr, u16_t port)
NTP recv.
volatile struct tm * current_utc
UTC time struct.
Definition: ntp.c:14
static NTP_T * ntp_init(void)
NTP init.
struct NTP_T_ NTP_T
NTP struct.
volatile struct tm * utc
UTC time struct.
Definition: ntp.c:13
static void ntp_request(NTP_T *state)
NTP request.
void ntp_update_time(void)
NTP update time.
Definition: ntp.c:123
NTP struct.
Definition: ntp.h:35
ip_addr_t ntp_server_address
Definition: ntp.h:36
absolute_time_t ntp_test_time
Definition: ntp.h:39
bool dns_request_sent
Definition: ntp.h:37
struct udp_pcb * ntp_pcb
Definition: ntp.h:38
alarm_id_t ntp_resend_alarm
Definition: ntp.h:40