Timeout helper that converts a relative tick duration into an absolute expiration point.
More...
#include <nbrtos.h>
|
| | TickTimeout (uint32_t timeout) |
| | Construct the TickTimeout with a relative duration.
|
| |
| uint32_t | val () const |
| | Get the remaining ticks until expiration, suitable for passing to RTOS wait functions.
|
| |
| bool | expired () const |
| | Check whether the timeout has expired.
|
| |
| | operator bool () const |
| | Boolean conversion: true if the timeout has NOT expired.
|
| |
| void | SetUntil (uint32_t when) |
| | Set an absolute TimeTick expiration value directly.
|
| |
|
| void | OSTimeWaitUntil (uint32_t systemTickValue) |
| | Delay the calling task until the system TimeTick reaches the specified value.
|
| |
Timeout helper that converts a relative tick duration into an absolute expiration point.
A TickTimeout captures the current TimeTick at construction and computes an absolute expiration value. It can then be passed to multiple Pend() calls in sequence, ensuring they all share the same overall timeout window rather than each restarting their own independent countdown. The class also handles 32-bit TimeTick rollover transparently.
- See also
- WAIT_FOREVER, TimeTick
Expand for Example Usage
Examples
- Sequential Pends with a Shared Timeout
uint8_t err = sem1.Pend(timeout);
err = sem2.Pend(timeout);
Timeout helper that converts a relative tick duration into an absolute expiration point.
Definition nbrtos.h:262
#define TICKS_PER_SECOND
System clock ticks per second.
Definition constants.h:49
#define OS_NO_ERR
No error.
Definition nbrtos.h:67
- Loop Until Timeout
while (timeout)
{
void *msg = myQueue.Pend(timeout);
if (msg) ProcessMessage(msg);
}
◆ TickTimeout()
| TickTimeout::TickTimeout |
( |
uint32_t | timeout | ) |
|
|
inline |
Construct the TickTimeout with a relative duration.
- Parameters
-
| timeout | Duration in system ticks. A value of 0 means wait forever (no expiration). The maximum usable value is INT32_MAX. |
◆ expired()
| bool TickTimeout::expired |
( |
| ) |
const |
|
inline |
Check whether the timeout has expired.
- Return values
-
| true | The timeout duration has elapsed. |
| false | The timeout has not yet expired (or represents "wait forever"). |
◆ operator bool()
| TickTimeout::operator bool |
( |
| ) |
const |
|
inline |
Boolean conversion: true if the timeout has NOT expired.
Designed for use in while loops and precondition checks. This is the logical inverse of expired().
- Return values
-
| true | The timeout is still valid (has not expired). |
| false | The timeout has expired. |
◆ SetUntil()
| void TickTimeout::SetUntil |
( |
uint32_t | when | ) |
|
|
inline |
Set an absolute TimeTick expiration value directly.
- Parameters
-
| when | The absolute TimeTick value at which this timeout should expire. |
◆ val()
| uint32_t TickTimeout::val |
( |
| ) |
const |
|
inline |
Get the remaining ticks until expiration, suitable for passing to RTOS wait functions.
Returns 0 if the timeout represents "wait forever", or at least 1 if the timeout has not yet expired (to avoid accidentally passing 0, which means wait forever, when the timeout is nearly exhausted).
- Returns
- Remaining ticks, or 0 for infinite wait.
◆ OSTimeWaitUntil
| void OSTimeWaitUntil |
( |
uint32_t | systemTickValue | ) |
|
|
friend |
Delay the calling task until the system TimeTick reaches the specified value.
Unlike OSTimeDly(), which delays for a relative duration, this function waits for an absolute TimeTick value. This is ideal for creating periodic tasks with consistent intervals that do not drift regardless of how long the task body takes to execute.
The number of ticks per second is defined by TICKS_PER_SECOND in <nburn_install>/nbrtos/include/constants.h (default: 20 ticks/second).
- Parameters
-
| systemTickValue | The absolute system TimeTick value to wait for. |
- See also
- OSTimeDly(), OSChangeTaskDly()
Expand for Example Usage
Examples
- Periodic 60-Second Task
while (1)
{
}
friend void OSTimeWaitUntil(uint32_t systemTickValue)
Delay the calling task until the system TimeTick reaches the specified value.
volatile tick_t TimeTick
Number of system timer ticks elapsed since system start.
The documentation for this class was generated from the following file: