From d80c71b8d9dbf9accc346983f9b1b762c6506a59 Mon Sep 17 00:00:00 2001 From: Mathieu Carbou Date: Sun, 27 Oct 2024 01:30:23 +0200 Subject: [PATCH 1/2] fix(sntp): Lock / Unlock LWIP if CONFIG_LWIP_TCPIP_CORE_LOCKING is set Fixes: https://github.com/espressif/arduino-esp32/issues/10526 --- cores/esp32/esp32-hal-time.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/cores/esp32/esp32-hal-time.c b/cores/esp32/esp32-hal-time.c index 23bd3bf9e99..607379f626b 100644 --- a/cores/esp32/esp32-hal-time.c +++ b/cores/esp32/esp32-hal-time.c @@ -17,6 +17,10 @@ //#include "tcpip_adapter.h" #include "esp_netif.h" +#ifdef CONFIG_LWIP_TCPIP_CORE_LOCKING + #include "lwip/priv/tcpip_priv.h" +#endif + static void setTimeZone(long offset, int daylight) { char cst[17] = {0}; char cdt[17] = "DST"; @@ -50,11 +54,23 @@ void configTime(long gmtOffset_sec, int daylightOffset_sec, const char *server1, if (sntp_enabled()) { sntp_stop(); } + +#ifdef CONFIG_LWIP_TCPIP_CORE_LOCKING + if (!sys_thread_tcpip(LWIP_CORE_LOCK_QUERY_HOLDER)) + LOCK_TCPIP_CORE(); +#endif + sntp_setoperatingmode(SNTP_OPMODE_POLL); sntp_setservername(0, (char *)server1); sntp_setservername(1, (char *)server2); sntp_setservername(2, (char *)server3); sntp_init(); + +#ifdef CONFIG_LWIP_TCPIP_CORE_LOCKING + if (sys_thread_tcpip(LWIP_CORE_LOCK_QUERY_HOLDER)) + UNLOCK_TCPIP_CORE(); +#endif + setTimeZone(-gmtOffset_sec, daylightOffset_sec); } @@ -68,11 +84,23 @@ void configTzTime(const char *tz, const char *server1, const char *server2, cons if (sntp_enabled()) { sntp_stop(); } + +#ifdef CONFIG_LWIP_TCPIP_CORE_LOCKING + if (!sys_thread_tcpip(LWIP_CORE_LOCK_QUERY_HOLDER)) + LOCK_TCPIP_CORE(); +#endif + sntp_setoperatingmode(SNTP_OPMODE_POLL); sntp_setservername(0, (char *)server1); sntp_setservername(1, (char *)server2); sntp_setservername(2, (char *)server3); sntp_init(); + +#ifdef CONFIG_LWIP_TCPIP_CORE_LOCKING + if (sys_thread_tcpip(LWIP_CORE_LOCK_QUERY_HOLDER)) + UNLOCK_TCPIP_CORE(); +#endif + setenv("TZ", tz, 1); tzset(); } From b746f090322256c53bd06d81f53e5cb375f178d6 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci-lite[bot]" <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> Date: Tue, 29 Oct 2024 10:19:53 +0000 Subject: [PATCH 2/2] ci(pre-commit): Apply automatic fixes --- cores/esp32/esp32-hal-time.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/cores/esp32/esp32-hal-time.c b/cores/esp32/esp32-hal-time.c index 607379f626b..25c060eabdd 100644 --- a/cores/esp32/esp32-hal-time.c +++ b/cores/esp32/esp32-hal-time.c @@ -18,7 +18,7 @@ #include "esp_netif.h" #ifdef CONFIG_LWIP_TCPIP_CORE_LOCKING - #include "lwip/priv/tcpip_priv.h" +#include "lwip/priv/tcpip_priv.h" #endif static void setTimeZone(long offset, int daylight) { @@ -56,8 +56,9 @@ void configTime(long gmtOffset_sec, int daylightOffset_sec, const char *server1, } #ifdef CONFIG_LWIP_TCPIP_CORE_LOCKING - if (!sys_thread_tcpip(LWIP_CORE_LOCK_QUERY_HOLDER)) + if (!sys_thread_tcpip(LWIP_CORE_LOCK_QUERY_HOLDER)) { LOCK_TCPIP_CORE(); + } #endif sntp_setoperatingmode(SNTP_OPMODE_POLL); @@ -67,8 +68,9 @@ void configTime(long gmtOffset_sec, int daylightOffset_sec, const char *server1, sntp_init(); #ifdef CONFIG_LWIP_TCPIP_CORE_LOCKING - if (sys_thread_tcpip(LWIP_CORE_LOCK_QUERY_HOLDER)) + if (sys_thread_tcpip(LWIP_CORE_LOCK_QUERY_HOLDER)) { UNLOCK_TCPIP_CORE(); + } #endif setTimeZone(-gmtOffset_sec, daylightOffset_sec); @@ -86,8 +88,9 @@ void configTzTime(const char *tz, const char *server1, const char *server2, cons } #ifdef CONFIG_LWIP_TCPIP_CORE_LOCKING - if (!sys_thread_tcpip(LWIP_CORE_LOCK_QUERY_HOLDER)) + if (!sys_thread_tcpip(LWIP_CORE_LOCK_QUERY_HOLDER)) { LOCK_TCPIP_CORE(); + } #endif sntp_setoperatingmode(SNTP_OPMODE_POLL); @@ -97,8 +100,9 @@ void configTzTime(const char *tz, const char *server1, const char *server2, cons sntp_init(); #ifdef CONFIG_LWIP_TCPIP_CORE_LOCKING - if (sys_thread_tcpip(LWIP_CORE_LOCK_QUERY_HOLDER)) + if (sys_thread_tcpip(LWIP_CORE_LOCK_QUERY_HOLDER)) { UNLOCK_TCPIP_CORE(); + } #endif setenv("TZ", tz, 1);