RTOS Wrapper
API reference
Loading...
Searching...
No Matches
Utility.h
Go to the documentation of this file.
1#pragma once
7#include <stdint.h>
8#include <functional>
9#include "OsUtility.h"
10
11// `enum time_unit_t` is declared in OsUtility.h (must be visible to its
12// C-facing function declarations); included transitively above.
13
25template <typename Func, typename T>
26static inline bool TestLogicWithTimeout(Func func, T expected, uint32_t timeoutMsec, uint32_t checkIntervalMs)
27{
28 uint32_t start = os_get_elapsed_time_msec();
29 while ((os_get_elapsed_time_msec() - start) < timeoutMsec) {
30 if (func() == expected) {
31 return true;
32 }
33 os_delay_msec(static_cast<uint16_t>(checkIntervalMs));
34 }
35 return false;
36}
37
C-facing helper functions for delays, cycle counters, and creation of RTOS handles (queues,...
uint32_t os_get_elapsed_time_msec()
Retrieves the elapsed time in milliseconds.
Definition OsUtility.cpp:65
void os_delay_msec(uint16_t msec)
Delays execution for the specified number of milliseconds.
Definition OsUtility.cpp:28
static bool TestLogicWithTimeout(Func func, T expected, uint32_t timeoutMsec, uint32_t checkIntervalMs)
Helper to repeatedly check a condition until timeout.
Definition Utility.h:26