From 8db3c25349eb5dcbc840f621d96c5b1552d413cc Mon Sep 17 00:00:00 2001 From: Mathieu Carbou Date: Sat, 26 Oct 2024 13:37:09 +0200 Subject: [PATCH] Bugfix:Crash with "Required to lock TCPIP core functionality!)" because of Arduino Core 3.1.0 RC2 bug See: https://github.com/espressif/arduino-esp32/issues/10526 --- .clang-format | 8 +++++++- src/MycilaNTP.cpp | 36 ++++++++++++++++++++++++++---------- src/MycilaNTP.h | 10 +++++----- 3 files changed, 38 insertions(+), 16 deletions(-) diff --git a/.clang-format b/.clang-format index a0498d9..63f29c0 100644 --- a/.clang-format +++ b/.clang-format @@ -2,15 +2,21 @@ Language: Cpp BasedOnStyle: LLVM AccessModifierOffset: -2 +AlignConsecutiveMacros: true +AllowAllArgumentsOnNextLine: false +AllowAllParametersOfDeclarationOnNextLine: false AllowShortIfStatementsOnASingleLine: false +AllowShortLambdasOnASingleLine: Inline +BinPackArguments: false ColumnLimit: 0 ContinuationIndentWidth: 2 FixNamespaceComments: false IndentAccessModifiers: true IndentCaseLabels: true +IndentPPDirectives: BeforeHash IndentWidth: 2 NamespaceIndentation: All PointerAlignment: Left ReferenceAlignment: Left TabWidth: 2 -UseTab: Never \ No newline at end of file +UseTab: Never diff --git a/src/MycilaNTP.cpp b/src/MycilaNTP.cpp index 91e0862..3ad57af 100644 --- a/src/MycilaNTP.cpp +++ b/src/MycilaNTP.cpp @@ -8,18 +8,22 @@ #include #include +#ifdef CONFIG_LWIP_TCPIP_CORE_LOCKING + #include "lwip/priv/tcpip_priv.h" +#endif + #ifdef MYCILA_LOGGER_SUPPORT -#include + #include extern Mycila::Logger logger; -#define LOGD(tag, format, ...) logger.debug(tag, format, ##__VA_ARGS__) -#define LOGI(tag, format, ...) logger.info(tag, format, ##__VA_ARGS__) -#define LOGW(tag, format, ...) logger.warn(tag, format, ##__VA_ARGS__) -#define LOGE(tag, format, ...) logger.error(tag, format, ##__VA_ARGS__) + #define LOGD(tag, format, ...) logger.debug(tag, format, ##__VA_ARGS__) + #define LOGI(tag, format, ...) logger.info(tag, format, ##__VA_ARGS__) + #define LOGW(tag, format, ...) logger.warn(tag, format, ##__VA_ARGS__) + #define LOGE(tag, format, ...) logger.error(tag, format, ##__VA_ARGS__) #else -#define LOGD(tag, format, ...) ESP_LOGD(tag, format, ##__VA_ARGS__) -#define LOGI(tag, format, ...) ESP_LOGI(tag, format, ##__VA_ARGS__) -#define LOGW(tag, format, ...) ESP_LOGW(tag, format, ##__VA_ARGS__) -#define LOGE(tag, format, ...) ESP_LOGE(tag, format, ##__VA_ARGS__) + #define LOGD(tag, format, ...) ESP_LOGD(tag, format, ##__VA_ARGS__) + #define LOGI(tag, format, ...) ESP_LOGI(tag, format, ##__VA_ARGS__) + #define LOGW(tag, format, ...) ESP_LOGW(tag, format, ##__VA_ARGS__) + #define LOGE(tag, format, ...) ESP_LOGE(tag, format, ##__VA_ARGS__) #endif #define TAG "NTP" @@ -63,7 +67,18 @@ bool Mycila::NTPClass::sync(const char* server, const uint8_t retryInterval) { _server = server; _ticker.detach(); +#ifdef CONFIG_LWIP_TCPIP_CORE_LOCKING + if (!sys_thread_tcpip(LWIP_CORE_LOCK_QUERY_HOLDER)) + LOCK_TCPIP_CORE(); +#endif + configTime(0, 0, _server.c_str()); + +#ifdef CONFIG_LWIP_TCPIP_CORE_LOCKING + if (sys_thread_tcpip(LWIP_CORE_LOCK_QUERY_HOLDER)) + UNLOCK_TCPIP_CORE(); +#endif + if (!_spec.isEmpty()) { setenv("TZ", _spec.c_str(), 1); tzset(); @@ -75,7 +90,8 @@ bool Mycila::NTPClass::sync(const char* server, const uint8_t retryInterval) { if (!_synced) { LOGI(TAG, "Syncing time with %s", _server.c_str()); _ticker.attach( - retryInterval, +[](NTPClass* instance) { + retryInterval, + +[](NTPClass* instance) { // Serial.println("NTP Tick"); if (!instance->_synced) { struct tm timeInfo; diff --git a/src/MycilaNTP.h b/src/MycilaNTP.h index e492302..d120655 100644 --- a/src/MycilaNTP.h +++ b/src/MycilaNTP.h @@ -11,16 +11,16 @@ #include #ifdef MYCILA_JSON_SUPPORT -#include + #include #endif -#define MYCILA_NTP_VERSION "5.0.0" -#define MYCILA_NTP_VERSION_MAJOR 5 -#define MYCILA_NTP_VERSION_MINOR 0 +#define MYCILA_NTP_VERSION "5.0.0" +#define MYCILA_NTP_VERSION_MAJOR 5 +#define MYCILA_NTP_VERSION_MINOR 0 #define MYCILA_NTP_VERSION_REVISION 0 #ifndef MYCILA_NTP_RETRY_INTERVAL -#define MYCILA_NTP_RETRY_INTERVAL 2 + #define MYCILA_NTP_RETRY_INTERVAL 2 #endif namespace Mycila {