38#ifndef PROTOCORE_CLOCK_H
39#define PROTOCORE_CLOCK_H
91 void (*
set_ms)(
struct ClockInternal *ctx);
92 void (*
millis)(
struct ClockInternal *ctx);
93 void (*
set_us)(
struct ClockInternal *ctx);
94 void (*
micros)(
struct ClockInternal *ctx);
95 void (*
cycles)(
struct ClockInternal *ctx);
112 protocore_platform_task_delay(ms);
155 uint32_t start = protocore_platform_micros();
156 while (protocore_platform_micros() - start < us)
204 uint32_t lat =
Clock.us - start_us;
215 if (budget_us && lat > budget_us)
256 return cpu_mhz ? (uint32_t)(((uint64_t)delta_cycles * 1000u) / cpu_mhz) : 0u;
EMBED_BEGIN_DECLS typedef uint32_t(* protocore_clock_fn)(void)
User clock: returns a free-running monotonic tick count.
EMBED_INLINE void protocore_delay_us(uint32_t us)
Install a custom microsecond clock running at ticks_per_second; the library divides it down to 1 MHz....
EMBED_INLINE uint32_t protocore_lat_avg_us(const protocore_latency_stat *s)
Mean latency (us) over the recorded samples, 0 if none.
EMBED_INLINE uint32_t protocore_cycles_to_ns(uint32_t delta_cycles, uint32_t cpu_mhz)
Free-running CPU cycle count. ISR-safe. On a part that has one this is the hardware cycle counter; on...
ServerClockNs Clock
The one symbol this module exports.
EMBED_INLINE void pcdelay(uint32_t ms)
The library's monotonic time at 1000 Hz (milliseconds).
EMBED_INLINE void protocore_lat_end(protocore_latency_stat *s, uint32_t start_us, uint32_t budget_us)
End of a span started at start_us: record its latency, counting it as over-budget when budget_us is n...
EMBED_INLINE uint32_t protocore_lat_begin(void)
Start of a measured span: capture the current microsecond time.
EMBED_INLINE void protocore_lat_reset(protocore_latency_stat *s)
Zero a stat (min seeded high so the first sample sets it).
Install a custom clock running at ticks_per_second; the library divides it down to its internal 1000 ...
uint32_t ticks_per_second
its rate, divided down to the library's
protocore_clock_fn fn
the source; NULL falls back to the platform's own
void(* set_ms)(struct ClockInternal *ctx)
void(* set_us)(struct ClockInternal *ctx)
struct ClockInternal * internal
void(* cycles)(struct ClockInternal *ctx)
void(* micros)(struct ClockInternal *ctx)
void(* millis)(struct ClockInternal *ctx)
Rolling latency statistics in microseconds: sample count, min / max / mean, and how many samples blew...
uint32_t over_budget
samples whose latency exceeded the budget