From 7d2d7532522971bcdd6f018469d2e8b16b8160c0 Mon Sep 17 00:00:00 2001 From: Verkehrsrot Date: Tue, 23 Jul 2019 17:53:20 +0200 Subject: [PATCH] bugfixing mutex lock --- src/display.cpp | 10 ++++++---- src/irqhandler.cpp | 11 ++++++----- src/timesync.cpp | 2 +- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/display.cpp b/src/display.cpp index 260686fe..632e0ee8 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -62,8 +62,9 @@ void DisplayKey(const uint8_t *key, uint8_t len, bool lsb) { void init_display(const char *Productname, const char *Version) { // block i2c bus access - if (I2C_MUTEX_LOCK()) { - + if (!I2C_MUTEX_LOCK()) + ESP_LOGW(TAG, "[%0.3f] i2c mutex lock failed", millis() / 1000.0); + else { // show startup screen uint8_t buf[32]; u8x8.begin(); @@ -141,8 +142,9 @@ void refreshTheDisplay(bool nextPage) { myTZ.toLocal(now()); // note: call now() here *before* locking mutex! // block i2c bus access - if (I2C_MUTEX_LOCK()) { - + if (!I2C_MUTEX_LOCK()) + ESP_LOGW(TAG, "[%0.3f] i2c mutex lock failed", millis() / 1000.0); + else { // set display on/off according to current device configuration if (DisplayIsOn != cfg.screenon) { DisplayIsOn = cfg.screenon; diff --git a/src/irqhandler.cpp b/src/irqhandler.cpp index f95f6fe9..1ecfa59f 100644 --- a/src/irqhandler.cpp +++ b/src/irqhandler.cpp @@ -120,12 +120,13 @@ void IRAM_ATTR GpsIRQ() { #endif int mask_user_IRQ() { - // begin of time critical section: lock I2C bus to ensure accurate timing - if (I2C_MUTEX_LOCK()) { + if (!I2C_MUTEX_LOCK()) { + ESP_LOGW(TAG, "[%0.3f] i2c mutex lock failed", millis() / 1000.0); + return 0; // failure + } else { xTaskNotify(irqHandlerTask, MASK_IRQ, eSetBits); - return 0; - } else - return 1; // failure + return 1; // success + } } int unmask_user_IRQ() { diff --git a/src/timesync.cpp b/src/timesync.cpp index 42cdecd9..ec85370b 100644 --- a/src/timesync.cpp +++ b/src/timesync.cpp @@ -113,7 +113,7 @@ void process_timesync_req(void *taskparameter) { // begin of time critical section: lock app irq's and I2C bus if (!mask_user_IRQ()) { ESP_LOGW(TAG, - "[%0.3f] Timesync handshake error: irq / i2c masking failed", + "[%0.3f] Timesync handshake error: irq masking failed", millis() / 1000.0); goto finish; // failure }