From 3918cb633b88bd2e4f11af56bdac33fce6e45b05 Mon Sep 17 00:00:00 2001 From: Wu Jian Gang Date: Thu, 3 May 2018 14:53:35 +0800 Subject: [PATCH] feat(lwip): Integrate sntp with newlib time --- components/lwip/Kconfig | 5 +++++ components/lwip/include/lwip/port/arch/cc.h | 2 ++ components/lwip/include/lwip/port/lwipopts.h | 21 +++++++++++++++----- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/components/lwip/Kconfig b/components/lwip/Kconfig index 9bc032ca..7119a53e 100755 --- a/components/lwip/Kconfig +++ b/components/lwip/Kconfig @@ -174,6 +174,11 @@ config LWIP_IP6_DEBUG depends on LWIP_DEBUG default n +config LWIP_SNTP_DEBUG + bool "Enable debugging for SNTP." + depends on LWIP_DEBUG + default n + config LWIP_SO_REUSE bool "Enable SO_REUSEADDR option" default n diff --git a/components/lwip/include/lwip/port/arch/cc.h b/components/lwip/include/lwip/port/arch/cc.h index d97e8563..a54d6fd9 100644 --- a/components/lwip/include/lwip/port/arch/cc.h +++ b/components/lwip/include/lwip/port/arch/cc.h @@ -86,4 +86,6 @@ typedef int sys_prot_t; #define LWIP_PLATFORM_HTONS(_n) ((u16_t)((((_n) & 0xff) << 8) | (((_n) >> 8) & 0xff))) #define LWIP_PLATFORM_HTONL(_n) ((u32_t)( (((_n) & 0xff) << 24) | (((_n) & 0xff00) << 8) | (((_n) >> 8) & 0xff00) | (((_n) >> 24) & 0xff) )) +#define LWIP_TIMEVAL_PRIVATE 0 + #endif /* __ARCH_CC_H__ */ diff --git a/components/lwip/include/lwip/port/lwipopts.h b/components/lwip/include/lwip/port/lwipopts.h index 8a94994c..bb0a9bea 100644 --- a/components/lwip/include/lwip/port/lwipopts.h +++ b/components/lwip/include/lwip/port/lwipopts.h @@ -711,11 +711,14 @@ extern void vPortFree(void *pv, const char * file, unsigned line); #define SNTP_SERVER_DNS 1 -#ifndef sntp_time_t -typedef long sntp_time_t; -#endif -extern void sntp_set_system_time(sntp_time_t GMT_Time); -#define SNTP_SET_SYSTEM_TIME sntp_set_system_time +#include + +#define SNTP_SET_SYSTEM_TIME_US(sec, us) \ + do { \ + struct timeval tv = { .tv_sec = sec, .tv_usec = us }; \ + settimeofday(&tv, NULL); \ + } while (0); + /* ---------------------------------- ----- Multicast/IGMP options ----- @@ -2134,6 +2137,14 @@ extern void sntp_set_system_time(sntp_time_t GMT_Time); #if CONFIG_LWIP_IP6_DEBUG #define IP6_DEBUG LWIP_DBG_ON #endif + +/** + * SNTP_DEBUG: Enable debugging for SNTP. + */ +#if CONFIG_LWIP_SNTP_DEBUG +#define SNTP_DEBUG LWIP_DBG_ON +#endif + /** * @} */