NetBurner 3.5.7
PDF Version
TickTimeout Class Reference

Timeout helper that converts a relative tick duration into an absolute expiration point. More...

#include <nbrtos.h>

Public Member Functions

 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.
 

Friends

void OSTimeWaitUntil (uint32_t systemTickValue)
 Delay the calling task until the system TimeTick reaches the specified value.
 

Detailed Description

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
TickTimeout timeout(5 * TICKS_PER_SECOND); // 5-second overall budget
uint8_t err = sem1.Pend(timeout);
if (err == OS_NO_ERR)
err = sem2.Pend(timeout); // Uses remaining time from the same 5 s window
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) // operator bool() returns true while not expired
{
void *msg = myQueue.Pend(timeout);
if (msg) ProcessMessage(msg);
}

Constructor & Destructor Documentation

◆ TickTimeout()

TickTimeout::TickTimeout ( uint32_t timeout)
inline

Construct the TickTimeout with a relative duration.

Parameters
timeoutDuration in system ticks. A value of 0 means wait forever (no expiration). The maximum usable value is INT32_MAX.

Member Function Documentation

◆ expired()

bool TickTimeout::expired ( ) const
inline

Check whether the timeout has expired.

Return values
trueThe timeout duration has elapsed.
falseThe 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
trueThe timeout is still valid (has not expired).
falseThe timeout has expired.

◆ SetUntil()

void TickTimeout::SetUntil ( uint32_t when)
inline

Set an absolute TimeTick expiration value directly.

Parameters
whenThe 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.

Friends And Related Symbol Documentation

◆ 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
systemTickValueThe absolute system TimeTick value to wait for.
See also
OSTimeDly(), OSChangeTaskDly()

Expand for Example Usage

Examples

Periodic 60-Second Task
uint32_t Now = TimeTick;
while (1)
{
Now += 60 * TICKS_PER_SECOND;
// Runs every 60 seconds with consistent spacing
}
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: