XTOS / OPEN SOURCE REAL-TIME SYSTEMOPEN SOURCE · VERSION 0.9.0 · BUILD FROM SOURCE
libxtos-signalxtos_signal_validate_timestamps

xtos_signal_validate_timestamps

Checks nanosecond timestamp ordering and adjacent intervals, then writes validation statistics.

On this page

Declaration

c
#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

ParameterTypeDescription
timestamps_nsconst uint64_t *Non-NULL timestamp array with at least count entries, in nanoseconds.
countsize_tElement count, greater than zero.
sample_rate_hzuint32_tSampling rate in Hz, greater than zero.
tolerance_nsuint64_tAllowed absolute interval error in nanoseconds.
resultstruct xtos_signal_validation *Non-NULL caller-provided output structure.

Output fields

FieldTypeMeaning
expected_interval_nsuint64_tExpected adjacent interval derived from the sample rate, in nanoseconds.
min_interval_nsuint64_tMinimum positive adjacent interval, in nanoseconds; remains UINT64_MAX when no positive interval exists.
max_interval_nsuint64_tMaximum positive adjacent interval, in nanoseconds; is 0 when no positive interval exists.
interval_anomaliessize_tNumber of positive intervals whose error exceeds tolerance_ns.
timestamp_anomaliessize_tNumber 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

errnoCondition
EINVALThe 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.