#include <string.h>
#include <time.h>
#include "pico/stdlib.h"
#include "pico/cyw43_arch.h"
#include "lwip/dns.h"
#include "lwip/pbuf.h"
#include "lwip/udp.h"
Go to the source code of this file.
◆ NTP_DELTA
#define NTP_DELTA 2208988800 |
Definition at line 17 of file ntp.h.
◆ NTP_MSG_LEN
Definition at line 15 of file ntp.h.
◆ NTP_PORT
Definition at line 16 of file ntp.h.
◆ NTP_RESEND_TIME
#define NTP_RESEND_TIME (10 * 1000) |
Definition at line 19 of file ntp.h.
◆ NTP_SERVER
#define NTP_SERVER "pool.ntp.org" |
Definition at line 14 of file ntp.h.
◆ NTP_TEST_TIME
#define NTP_TEST_TIME (30 * 1000) |
Definition at line 18 of file ntp.h.
◆ NTP_T
NTP struct.
Struct for the NTP state.
◆ ntp_deinit()
NTP deinit.
Function de-initializes the NTP.
Definition at line 114 of file ntp.c.
volatile struct tm * utc
UTC time struct.
References utc.
Referenced by main().
◆ ntp_dns_found()
static void ntp_dns_found |
( |
const char * |
hostname, |
|
|
const ip_addr_t * |
ipaddr, |
|
|
void * |
arg |
|
) |
| |
|
static |
NTP DNS found.
Function handles the NTP DNS found.
- Parameters
-
hostname | hostname |
ipaddr | IP address |
arg | argument |
◆ ntp_failed_handler()
static int64_t ntp_failed_handler |
( |
alarm_id_t |
id, |
|
|
void * |
user_data |
|
) |
| |
|
static |
NTP failed handler.
NTP DNS found.
Function handles the NTP failed handler.
- Parameters
-
id | alarm ID |
user_data | user data |
- Returns
- : time
Function handles the NTP DNS found.
- Parameters
-
hostname | hostname |
ipaddr | IP address |
arg | argument |
◆ ntp_init()
static NTP_T* ntp_init |
( |
void |
| ) |
|
|
static |
NTP init.
Function initializes the NTP.
- Returns
- : NTP state
◆ ntp_recv()
static void ntp_recv |
( |
void * |
arg, |
|
|
struct udp_pcb * |
pcb, |
|
|
struct pbuf * |
p, |
|
|
const ip_addr_t * |
addr, |
|
|
u16_t |
port |
|
) |
| |
|
static |
NTP recv.
Function receives the NTP response.
- Parameters
-
arg | argument |
pcb | UDP PCB |
p | pbuf |
addr | IP address |
port | port |
◆ ntp_request()
static void ntp_request |
( |
NTP_T * |
state | ) |
|
|
static |
NTP request.
Function sends the NTP request.
- Parameters
-
◆ ntp_result()
static void ntp_result |
( |
NTP_T * |
state, |
|
|
int |
status, |
|
|
time_t * |
result |
|
) |
| |
|
static |
NTP result.
Function handles the NTP result.
- Parameters
-
state | NTP state |
status | status |
result | result |
◆ ntp_update_time()
void ntp_update_time |
( |
void |
| ) |
|
NTP update time.
Function updates the NTP time.
Definition at line 123 of file ntp.c.
131 cyw43_arch_lwip_begin();
133 cyw43_arch_lwip_end();
138 else if (err != ERR_INPROGRESS)
140 printf(
"DNS request failed\n");
static void ntp_result(NTP_T *state, int status, time_t *result)
static int64_t ntp_failed_handler(alarm_id_t id, void *user_data)
static void ntp_dns_found(const char *hostname, const ip_addr_t *ipaddr, void *arg)
static NTP_T * ntp_init(void)
static void ntp_request(NTP_T *state)
ip_addr_t ntp_server_address
absolute_time_t ntp_test_time
alarm_id_t ntp_resend_alarm
References NTP_T_::dns_request_sent, ntp_dns_found(), ntp_failed_handler(), ntp_init(), ntp_request(), NTP_T_::ntp_resend_alarm, NTP_RESEND_TIME, ntp_result(), NTP_SERVER, NTP_T_::ntp_server_address, and NTP_T_::ntp_test_time.
◆ current_utc
volatile struct tm* current_utc |
|
extern |
UTC time struct.
Struct for the last checked UTC time.
Definition at line 14 of file ntp.c.
Referenced by ntp_result().
◆ utc