From 94d9c1d611680f6e0ff4cbd8712aea248d9e9354 Mon Sep 17 00:00:00 2001 From: Ken Van Hoeylandt Date: Fri, 2 Jan 2026 20:35:38 +0100 Subject: [PATCH] Fixes --- Drivers/BQ25896/Source/Bq25896.cpp | 4 +++- Drivers/DRV2605/Source/Drv2605.h | 1 + TactilityC/Source/tt_lock.cpp | 2 +- .../Source/kernel/critical/Critical.cpp | 4 +++- .../Include/Tactility/Dispatcher.h | 17 ++++++++++++++--- .../Include/Tactility/EventGroup.h | 2 +- TactilityFreeRtos/Include/Tactility/Thread.h | 5 +++-- .../Include/Tactility/kernel/Kernel.h | 4 ++-- Tests/TactilityCore/Main.cpp | 2 ++ Tests/TactilityFreeRtos/Main.cpp | 2 ++ 10 files changed, 32 insertions(+), 11 deletions(-) diff --git a/Drivers/BQ25896/Source/Bq25896.cpp b/Drivers/BQ25896/Source/Bq25896.cpp index 27c66d5e..020027d7 100644 --- a/Drivers/BQ25896/Source/Bq25896.cpp +++ b/Drivers/BQ25896/Source/Bq25896.cpp @@ -1,6 +1,8 @@ #include "Bq25896.h" -#define TAG "BQ27220" +#include + +constexpr auto* TAG = "BQ27220"; void Bq25896::powerOff() { TT_LOG_I(TAG, "Power off"); diff --git a/Drivers/DRV2605/Source/Drv2605.h b/Drivers/DRV2605/Source/Drv2605.h index b29461ec..781f95fb 100644 --- a/Drivers/DRV2605/Source/Drv2605.h +++ b/Drivers/DRV2605/Source/Drv2605.h @@ -1,6 +1,7 @@ #pragma once #include +#include class Drv2605 : public tt::hal::i2c::I2cDevice { diff --git a/TactilityC/Source/tt_lock.cpp b/TactilityC/Source/tt_lock.cpp index de185a92..d160275e 100644 --- a/TactilityC/Source/tt_lock.cpp +++ b/TactilityC/Source/tt_lock.cpp @@ -33,7 +33,7 @@ bool tt_lock_acquire(LockHandle handle, TickType timeout) { } void tt_lock_release(LockHandle handle) { - return HANDLE_AS_LOCK(handle)->unlock(); + HANDLE_AS_LOCK(handle)->unlock(); } void tt_lock_free(LockHandle handle) { diff --git a/TactilityCore/Source/kernel/critical/Critical.cpp b/TactilityCore/Source/kernel/critical/Critical.cpp index 3e6a97bb..f0550373 100644 --- a/TactilityCore/Source/kernel/critical/Critical.cpp +++ b/TactilityCore/Source/kernel/critical/Critical.cpp @@ -6,8 +6,10 @@ #ifdef ESP_PLATFORM static portMUX_TYPE critical_mutex; #define TT_ENTER_CRITICAL() taskENTER_CRITICAL(&critical_mutex) +#define TT_EXIT_CRITICAL() taskEXIT_CRITICAL(&critical_mutex) #else #define TT_ENTER_CRITICAL() taskENTER_CRITICAL() +#define TT_EXIT_CRITICAL() taskEXIT_CRITICAL() #endif namespace tt::kernel::critical { @@ -34,7 +36,7 @@ void exit(CriticalInfo info) { if (info.fromIsr) { taskEXIT_CRITICAL_FROM_ISR(info.isrm); } else if (info.kernelRunning) { - TT_ENTER_CRITICAL(); + TT_EXIT_CRITICAL(); } else { portENABLE_INTERRUPTS(); } diff --git a/TactilityFreeRtos/Include/Tactility/Dispatcher.h b/TactilityFreeRtos/Include/Tactility/Dispatcher.h index 071c39dd..70677860 100644 --- a/TactilityFreeRtos/Include/Tactility/Dispatcher.h +++ b/TactilityFreeRtos/Include/Tactility/Dispatcher.h @@ -37,14 +37,17 @@ private: Mutex mutex; std::queue queue = {}; EventGroup eventFlag; + bool shutdown = false; public: explicit Dispatcher() = default; ~Dispatcher() { - mutex.lock(); - mutex.unlock(); + shutdown = true; + if (mutex.lock()) { + mutex.unlock(); + } } /** @@ -62,6 +65,10 @@ public: return false; } + if (shutdown) { + return false; + } + queue.push(std::move(function)); if (queue.size() == BACKPRESSURE_WARNING_COUNT) { #ifdef ESP_PLATFORM @@ -89,6 +96,10 @@ public: return 0; } + if (shutdown) { + return 0; + } + // Mutate bool processing = true; uint32_t consumed = 0; @@ -112,7 +123,7 @@ public: #endif } - } while (processing); + } while (processing && !shutdown); return consumed; } diff --git a/TactilityFreeRtos/Include/Tactility/EventGroup.h b/TactilityFreeRtos/Include/Tactility/EventGroup.h index 3cce00ba..92146300 100644 --- a/TactilityFreeRtos/Include/Tactility/EventGroup.h +++ b/TactilityFreeRtos/Include/Tactility/EventGroup.h @@ -79,7 +79,7 @@ public: * @param[out] outError optional error output: this is set when the return value is false * @return true on success */ - uint32_t clear(uint32_t flags, uint32_t* outFlags = nullptr, Error* outError = nullptr) const { + bool clear(uint32_t flags, uint32_t* outFlags = nullptr, Error* outError = nullptr) const { if (xPortInIsrContext() == pdTRUE) { uint32_t result = xEventGroupGetBitsFromISR(handle.get()); if (xEventGroupClearBitsFromISR(handle.get(), flags) == pdFAIL) { diff --git a/TactilityFreeRtos/Include/Tactility/Thread.h b/TactilityFreeRtos/Include/Tactility/Thread.h index 6bb6e204..686bc587 100644 --- a/TactilityFreeRtos/Include/Tactility/Thread.h +++ b/TactilityFreeRtos/Include/Tactility/Thread.h @@ -88,11 +88,12 @@ private: portBASE_TYPE affinity = -1; void setState(State newState) { - // mutex.lock(); + mutex.lock(); state = newState; if (stateCallback) { stateCallback(state, stateCallbackContext); } + mutex.unlock(); } public: @@ -127,7 +128,7 @@ public: void setStackSize(size_t newStackSize) { mutex.lock(); assert(state == State::Stopped); - assert(stackSize % 4 == 0); + assert(newStackSize % 4 == 0); stackSize = newStackSize; mutex.unlock(); } diff --git a/TactilityFreeRtos/Include/Tactility/kernel/Kernel.h b/TactilityFreeRtos/Include/Tactility/kernel/Kernel.h index 2fdbc444..bdb95dad 100644 --- a/TactilityFreeRtos/Include/Tactility/kernel/Kernel.h +++ b/TactilityFreeRtos/Include/Tactility/kernel/Kernel.h @@ -35,13 +35,13 @@ constexpr TickType_t getTicks() { /** @return the amount of milliseconds that has passed in the main kernel tasks */ constexpr size_t getMillis() { - return getTicks() / portTICK_PERIOD_MS; + return getTicks() * portTICK_PERIOD_MS; } /** @return the microseconds that have passed since boot */ constexpr int64_t getMicrosSinceBoot() { #ifdef ESP_PLATFORM - return static_cast(esp_timer_get_time()); + return esp_timer_get_time(); #else timeval tv; gettimeofday(&tv, nullptr); diff --git a/Tests/TactilityCore/Main.cpp b/Tests/TactilityCore/Main.cpp index c1dd29aa..165c3d27 100644 --- a/Tests/TactilityCore/Main.cpp +++ b/Tests/TactilityCore/Main.cpp @@ -48,6 +48,8 @@ int main(int argc, char** argv) { assert(task_result == pdPASS); vTaskStartScheduler(); + + return data.result; } extern "C" { diff --git a/Tests/TactilityFreeRtos/Main.cpp b/Tests/TactilityFreeRtos/Main.cpp index c1dd29aa..165c3d27 100644 --- a/Tests/TactilityFreeRtos/Main.cpp +++ b/Tests/TactilityFreeRtos/Main.cpp @@ -48,6 +48,8 @@ int main(int argc, char** argv) { assert(task_result == pdPASS); vTaskStartScheduler(); + + return data.result; } extern "C" {