oveRTOS C API
Embedded RTOS framework — build system, configuration, and portable C API
Loading...
Searching...
No Matches
Macros | Functions
Time

High-resolution timestamps and blocking delay utilities. More...

Collaboration diagram for Time:

Macros

#define OVE_NS(n)   ((uint64_t)(n))
 
#define OVE_US(n)   ((uint64_t)(n) * 1000ULL)
 
#define OVE_MS(n)   ((uint64_t)(n) * 1000000ULL)
 
#define OVE_SEC(n)   ((uint64_t)(n) * 1000000000ULL)
 
#define OVE_MIN(n)   (OVE_SEC(n) * 60ULL)
 

Functions

int ove_time_get_us (uint64_t *out)
 Get the current monotonic time in microseconds.
 
int ove_time_get_ns (uint64_t *out)
 Get the current monotonic time in nanoseconds.
 
void ove_time_delay_ms (uint32_t ms)
 Block the calling task for at least ms milliseconds.
 
void ove_time_delay_us (uint32_t us)
 Block the calling task for at least us microseconds.
 
static uint64_t ove_time_now_steady_ns (void)
 Get the current monotonic time in nanoseconds (value-return form).
 
static uint64_t ove_time_deadline_to_timeout_ns (uint64_t deadline_ns)
 Convert a steady-clock deadline to a duration suitable for the existing timeout_ns-taking APIs.
 

Detailed Description

High-resolution timestamps and blocking delay utilities.

Provides monotonic time queries at microsecond and nanosecond resolution, as well as blocking delay functions for both millisecond and microsecond granularities.

Timestamp values are monotonically non-decreasing from an arbitrary epoch (typically system boot). The actual resolution is backend-dependent and may be coarser than the unit implies on some platforms.

Note
Requires CONFIG_OVE_TIME.

Function Documentation

◆ ove_time_get_us()

int ove_time_get_us ( uint64_t *  out)

Get the current monotonic time in microseconds.

Reads the system timer and writes the elapsed microseconds since an arbitrary epoch (typically boot) to out.

Parameters
[out]outReceives the current timestamp in microseconds.
Returns
OVE_OK on success, negative error code on failure.
Note
Requires CONFIG_OVE_TIME.

◆ ove_time_get_ns()

int ove_time_get_ns ( uint64_t *  out)

Get the current monotonic time in nanoseconds.

Reads the system timer and writes the elapsed nanoseconds since an arbitrary epoch (typically boot) to out. Actual nanosecond resolution depends on the hardware timer; values may be rounded to the nearest tick.

Parameters
[out]outReceives the current timestamp in nanoseconds.
Returns
OVE_OK on success, negative error code on failure.
Note
Requires CONFIG_OVE_TIME.

◆ ove_time_delay_ms()

void ove_time_delay_ms ( uint32_t  ms)

Block the calling task for at least ms milliseconds.

Suspends the current task for a minimum of ms milliseconds. The actual sleep duration may be longer due to scheduling granularity and system load. Passing 0 yields the CPU to any equal or higher-priority task.

Parameters
[in]msMinimum delay in milliseconds.
Note
Requires CONFIG_OVE_TIME. Must not be called from an ISR.

◆ ove_time_delay_us()

void ove_time_delay_us ( uint32_t  us)

Block the calling task for at least us microseconds.

Suspends the current task for a minimum of us microseconds. For very short delays the implementation may busy-wait rather than yield, depending on the RTOS tick resolution.

Parameters
[in]usMinimum delay in microseconds.
Note
Requires CONFIG_OVE_TIME. Must not be called from an ISR.

◆ ove_time_now_steady_ns()

static uint64_t ove_time_now_steady_ns ( void  )
inlinestatic

Get the current monotonic time in nanoseconds (value-return form).

Convenience wrapper over ove_time_get_ns with a friendlier signature. Failure paths return 0; on every backend supported today the underlying call cannot fail in practice.

Returns
Monotonic timestamp in nanoseconds since an arbitrary epoch.

◆ ove_time_deadline_to_timeout_ns()

static uint64_t ove_time_deadline_to_timeout_ns ( uint64_t  deadline_ns)
inlinestatic

Convert a steady-clock deadline to a duration suitable for the existing timeout_ns-taking APIs.

If deadline_ns is in the past relative to ove_time_now_steady_ns, returns 0 (the caller should not block). The OVE_WAIT_FOREVER sentinel is preserved verbatim so _until shims can pass it straight through without altering the indefinite-block semantics.

Parameters
[in]deadline_nsAbsolute deadline in nanoseconds from the same epoch as ove_time_now_steady_ns.
Returns
Nanoseconds remaining until the deadline, 0 if the deadline has passed, or OVE_WAIT_FOREVER if deadline_ns is the sentinel.