xtos_ signal_ validate_ timestamps
Checks nanosecond timestamp ordering and adjacent intervals, then writes validation statistics.
On this page
Declaration
#include <xtos/signal.h>
int xtos_signal_validate_timestamps(const uint64_t *timestamps_ns,
size_t count,
uint32_t sample_rate_hz,
uint64_t tolerance_ns,
struct xtos_signal_validation *result);Parameters
| Parameter | Type | Description |
|---|---|---|
| timestamps_ns | const uint64_t * | Non-NULL timestamp array with at least count entries, in nanoseconds. |
| count | size_t | Element count, greater than zero. |
| sample_rate_hz | uint32_t | Sampling rate in Hz, greater than zero. |
| tolerance_ns | uint64_t | Allowed absolute interval error in nanoseconds. |
| result | struct xtos_signal_validation * | Non-NULL caller-provided output structure. |
Output fields
| Field | Type | Meaning |
|---|---|---|
| expected_interval_ns | uint64_t | Expected adjacent interval derived from the sample rate, in nanoseconds. |
| min_interval_ns | uint64_t | Minimum positive adjacent interval, in nanoseconds; remains UINT64_MAX when no positive interval exists. |
| max_interval_ns | uint64_t | Maximum positive adjacent interval, in nanoseconds; is 0 when no positive interval exists. |
| interval_anomalies | size_t | Number of positive intervals whose error exceeds tolerance_ns. |
| timestamp_anomalies | size_t | Number of adjacent timestamps that repeat or decrease. |
Return value
Returns 0 with no detected anomaly, 1 when an interval or ordering anomaly is detected, and -1 for invalid arguments.
Errors
| errno | Condition |
|---|---|
| EINVAL | The array or result is NULL, count is zero, or sample rate is zero. |
Notes
- The expected interval uses llround(1000000000.0 / sample_rate_hz); uint64 inputs have no NaN/Inf case to check.
- Result fields are initialized for valid arguments; both interval extrema are 0 when count=1. When count>1 and every adjacent timestamp repeats or decreases, no forward interval is recorded, so min_interval_ns remains UINT64_MAX and max_interval_ns is 0.
- The function reads but does not modify the input or allocate memory; the caller owns result.
Example
Source
This reference describes headers and implementation at OpenXTOS commit dd313955ad57542bcd2af8827157d1bbd0cf5e83.