Skip to content

Commit

Permalink
Bugfix:Crash with "Required to lock TCPIP core functionality!)" becau…
Browse files Browse the repository at this point in the history
…se of Arduino Core 3.1.0 RC2 bug

See: espressif/arduino-esp32#10526
  • Loading branch information
mathieucarbou committed Oct 26, 2024
1 parent 56eb7ba commit 8db3c25
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 16 deletions.
8 changes: 7 additions & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -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
UseTab: Never
36 changes: 26 additions & 10 deletions src/MycilaNTP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,22 @@
#include <Arduino.h>
#include <sys/time.h>

#ifdef CONFIG_LWIP_TCPIP_CORE_LOCKING
#include "lwip/priv/tcpip_priv.h"
#endif

#ifdef MYCILA_LOGGER_SUPPORT
#include <MycilaLogger.h>
#include <MycilaLogger.h>
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"
Expand Down Expand Up @@ -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();
Expand All @@ -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;
Expand Down
10 changes: 5 additions & 5 deletions src/MycilaNTP.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@
#include <functional>

#ifdef MYCILA_JSON_SUPPORT
#include <ArduinoJson.h>
#include <ArduinoJson.h>
#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 {
Expand Down

0 comments on commit 8db3c25

Please sign in to comment.