File syn_timeout.h¶
FileList > src > syntropic > util > syn_timeout.h
Go to the source code of this file
Non-blocking timeout helper — tick wrap-around safe. More...
#include "../common/syn_defs.h"#include "../port/syn_port_system.h"#include <stdbool.h>
Classes¶
| Type | Name |
|---|---|
| struct | SYN_Timeout Non-blocking timeout — tick wrap-around safe. |
Public Static Functions¶
| Type | Name |
|---|---|
| uint32_t | syn_timeout_elapsed (const SYN_Timeout * to) Get the elapsed time since the timeout was started. |
| bool | syn_timeout_expired (const SYN_Timeout * to) Check if the timeout has expired. |
| bool | syn_timeout_periodic (SYN_Timeout * to) Check expiry and auto-restart if expired (periodic use). |
| uint32_t | syn_timeout_remaining (const SYN_Timeout * to) Get the remaining time until expiry. |
| void | syn_timeout_restart (SYN_Timeout * to) Restart the timeout from now with the same duration. |
| void | syn_timeout_start (SYN_Timeout * to, uint32_t duration) Start (or restart) a timeout. |
Macros¶
| Type | Name |
|---|---|
| define | PT_WAIT_TIMEOUT (pt, to) [**PT\_WAIT\_UNTIL**](syn__pt_8h.md#define-pt_wait_until)(pt, [**syn\_timeout\_expired**](syn__timeout_8h.md#function-syn_timeout_expired)(to))Block a protothread until the timeout expires. |
Detailed Description¶
The "has N ms elapsed?" pattern is used everywhere in embedded code and is easy to get wrong with tick counter wrap-around. This header provides a tiny inline API that handles it correctly.
Header-only — zero code size if unused.
** **
SYN_Timeout to;
syn_timeout_start(&to, 1000);
while (!syn_timeout_expired(&to)) {
// try something...
}
// In a protothread:
PT_WAIT_TIMEOUT(pt, &to);
Public Static Functions Documentation¶
function syn_timeout_elapsed¶
Get the elapsed time since the timeout was started.
Parameters:
toTimeout.
Returns:
Elapsed milliseconds.
function syn_timeout_expired¶
Check if the timeout has expired.
Uses unsigned subtraction, which is wrap-around safe for a single wrap of the 32-bit tick counter (~49 days at 1 kHz).
Parameters:
toTimeout to check.
Returns:
true if the timeout has expired.
function syn_timeout_periodic¶
Check expiry and auto-restart if expired (periodic use).
Useful in main loops: "every N ms, do X".
Parameters:
toTimeout.
Returns:
true if the timeout expired (and was restarted).
function syn_timeout_remaining¶
Get the remaining time until expiry.
Parameters:
toTimeout.
Returns:
Remaining milliseconds, or 0 if already expired.
function syn_timeout_restart¶
Restart the timeout from now with the same duration.
Parameters:
toTimeout.
function syn_timeout_start¶
Start (or restart) a timeout.
Parameters:
toTimeout to start.durationDuration in milliseconds.
Macro Definition Documentation¶
define PT_WAIT_TIMEOUT¶
Block a protothread until the timeout expires.
The documentation for this class was generated from the following file src/syntropic/util/syn_timeout.h