From 10cc269d9dd45b606bbc8a6b1a6672d256743bde Mon Sep 17 00:00:00 2001 From: Ken Van Hoeylandt Date: Fri, 2 Jan 2026 20:16:43 +0100 Subject: [PATCH] Fixes --- .../Include/Tactility/Semaphore.h | 8 ++++-- Tests/TactilityFreeRtos/TimerTest.cpp | 26 +++++++++---------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/TactilityFreeRtos/Include/Tactility/Semaphore.h b/TactilityFreeRtos/Include/Tactility/Semaphore.h index 8dc0bc9b..64b25773 100644 --- a/TactilityFreeRtos/Include/Tactility/Semaphore.h +++ b/TactilityFreeRtos/Include/Tactility/Semaphore.h @@ -24,8 +24,12 @@ class Semaphore final : public Lock { assert(initialAvailable <= maxCount); if (maxCount == 1U) { - assert(initialAvailable == maxCount); // TODO: Consider supporting this deviation - return xSemaphoreCreateBinary(); + auto result = xSemaphoreCreateBinary(); + if (initialAvailable != 0U) { + auto give_result = xSemaphoreGive(result); + assert(give_result == pdPASS); + } + return result; } else { return xSemaphoreCreateCounting(maxCount, initialAvailable); } diff --git a/Tests/TactilityFreeRtos/TimerTest.cpp b/Tests/TactilityFreeRtos/TimerTest.cpp index 1c3caf82..4c5ec7f1 100644 --- a/Tests/TactilityFreeRtos/TimerTest.cpp +++ b/Tests/TactilityFreeRtos/TimerTest.cpp @@ -5,13 +5,13 @@ using namespace tt; TEST_CASE("TimerType::Periodic timers can be stopped and restarted") { int counter = 0; - auto* timer = new Timer(Timer::Type::Periodic, [&counter]() { counter++; }); - timer->start(1); + auto* timer = new Timer(Timer::Type::Periodic, 1, [&counter] { counter++; }); + CHECK_EQ(timer->start(), true); kernel::delayTicks(10); - timer->stop(); - timer->start(1); + CHECK_EQ(timer->stop(), true); + CHECK_EQ(timer->start(), true); kernel::delayTicks(10); - timer->stop(); + CHECK_EQ(timer->stop(), true); delete timer; CHECK_GE(counter, 2); @@ -20,10 +20,10 @@ TEST_CASE("TimerType::Periodic timers can be stopped and restarted") { TEST_CASE("TimerType::Periodic calls the callback periodically") { int ticks_to_run = 10; int counter = 0; - auto* timer = new Timer(Timer::Type::Periodic, [&counter]() { counter++; }); - timer->start(1); + auto* timer = new Timer(Timer::Type::Periodic, 1, [&counter] { counter++; }); + CHECK_EQ(timer->start(), true); kernel::delayTicks(ticks_to_run); - timer->stop(); + CHECK_EQ(timer->stop(), true); delete timer; CHECK_EQ(counter, ticks_to_run); @@ -31,13 +31,13 @@ TEST_CASE("TimerType::Periodic calls the callback periodically") { TEST_CASE("restarting TimerType::Once timers calls the callback again") { int counter = 0; - auto* timer = new Timer(Timer::Type::Once, [&counter]() { counter++; }); - timer->start(1); + auto* timer = new Timer(Timer::Type::Once, 1, [&counter] { counter++; }); + CHECK_EQ(timer->start(), true); kernel::delayTicks(10); - timer->stop(); - timer->start(1); + CHECK_EQ(timer->stop(), true); + CHECK_EQ(timer->start(), true); kernel::delayTicks(10); - timer->stop(); + CHECK_EQ(timer->stop(), true); delete timer; CHECK_EQ(counter, 2);