Skip to content

Commit

Permalink
GetTimerPeriod and associated test.
Browse files Browse the repository at this point in the history
  • Loading branch information
mattheweshleman committed Oct 16, 2024
1 parent 1aaa466 commit 6244432
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
31 changes: 25 additions & 6 deletions include/FakeTimers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class FakeTimers
void operator=(FakeTimers const &x) = delete;

/**
* Create a timer. Modeled after FreeRTOS xTimerCreate
* Create a timer.
* @param timerName - a string
* @param period - time period in milliseconds for this timer
* @param behavior - single shot or repeating?
Expand All @@ -76,6 +76,7 @@ class FakeTimers
* Zero (0) means an error, for example, the
* period must be modulo the configured sys tick
* period.
* @note: Reference FreeRTOS xTimerCreate
*/
TimerHandle TimerCreate(
const char * timerName,
Expand Down Expand Up @@ -182,21 +183,22 @@ class FakeTimers
}

/**
* re-starts a timer that was previously created with TimerCreate() API function.
* Modeled after FreeRTOS xTimerReset.
* Re-starts a timer that was previously created with TimerCreate() API function.
* @param handle
* @return
* @note: Reference FreeRTOS xTimerReset
*/
bool TimerReset(TimerHandle handle)
{
return TimerStart(handle);
}

/**
* Modeled after FreeRTOS xTimerChangePeriod
* Change a timer's period setting.
* @param handle
* @param newPeriod
* @return: true: changed ok. false: some error.
* @note: Reference FreeRTOS xTimerChangePeriod
*/
bool TimerChangePeriod(TimerHandle handle, TimerDuration newPeriod)
{
Expand Down Expand Up @@ -225,9 +227,10 @@ class FakeTimers
}

/**
* Similar to FreeRTOS pvTimerGetTimerID
* Get the timer's user context.
* @param handle
* @return: the user context provided when the timer was created
* @note: Reference FreeRTOS pvTimerGetTimerID
*/
UserContext GetTimerContext(TimerHandle handle) const
{
Expand All @@ -239,9 +242,10 @@ class FakeTimers
}

/**
* Similar to FreeRTOS pcTimerGetName
* Get the timer's name.
* @param handle
* @return the timer name provided when created.
* @note: Reference FreeRTOS pcTimerGetName
*/
const char * GetTimerName(TimerHandle handle) const
{
Expand All @@ -252,6 +256,21 @@ class FakeTimers
return timer.name;
}

/**
* Get the timer's period setting.
* @param handle
* @return
* @note: Reference FreeRTOS xTimerGetPeriod
*/
TimerDuration GetTimerPeriod(TimerHandle handle) const
{
const Timer& timer = mTimers.at(handle - 1);
assert(timer.handle == handle);
assert(timer.allocated);

return timer.period;
}

/**
* Check if a timer is currently active or not
* @param handle - the timer handle
Expand Down
7 changes: 7 additions & 0 deletions tests/FakeTimersTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,13 @@ TEST(FakeTimersTests, access_timer_name_via_handle)
STRCMP_EQUAL("TEST", name);
}

TEST(FakeTimersTests, access_timer_period_via_handle)
{
auto handle = Create(1s);
auto period = mUnderTest->GetTimerPeriod(handle);
CHECK_TRUE(1s == period);
}

TEST(FakeTimersTests, is_timer_active_method_works_as_expected)
{
auto handle = Create();
Expand Down

0 comments on commit 6244432

Please sign in to comment.