36#ifndef PROTOCORE_CLOCK_H
37#define PROTOCORE_CLOCK_H
55 static uint32_t div = 1;
127 static uint32_t div = 1;
139 _pc_micros_div_ref() = (ticks_per_second >= 1000000u) ? (ticks_per_second / 1000000u) : 1u;
214 if (budget_us && lat > budget_us)
251 return ESP.getCycleCount();
253 const uint32_t host_fallback_mhz = 240;
265 return cpu_mhz ? (uint32_t)(((uint64_t)delta_cycles * 1000u) / cpu_mhz) : 0u;
void pc_lat_end(pc_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...
pc_clock_fn & _pc_clock_fn_ref()
pc_clock_fn & _pc_micros_fn_ref()
void pc_set_clock(pc_clock_fn fn, uint32_t ticks_per_second)
Install a custom clock running at ticks_per_second; the library divides it down to its internal 1000 ...
uint32_t pc_lat_begin(void)
Start of a measured span: capture the current microsecond time.
uint32_t(* pc_clock_fn)(void)
User clock: returns a free-running monotonic tick count.
void pcdelay(uint32_t ms)
Block for at least ms milliseconds - the library's single delay primitive.
uint32_t pc_lat_avg_us(const pc_latency_stat *s)
Mean latency (us) over the recorded samples, 0 if none.
uint32_t pc_cycles(void)
Free-running CPU cycle count. ISR-safe. On ARDUINO/ESP32 this is the hardware cycle counter (CCOUNT);...
uint32_t & _pc_micros_div_ref()
void pc_lat_reset(pc_latency_stat *s)
Zero a stat (min seeded high so the first sample sets it).
uint32_t pc_millis(void)
The library's monotonic time at 1000 Hz (milliseconds).
uint32_t & _pc_clock_div_ref()
uint32_t pc_cycles_to_ns(uint32_t delta_cycles, uint32_t cpu_mhz)
Convert a cycle-count delta to nanoseconds at cpu_mhz (the running CPU frequency, e....
void pc_set_micros_clock(pc_clock_fn fn, uint32_t ticks_per_second)
Install a custom microsecond clock running at ticks_per_second; the library divides it down to 1 MHz....
uint32_t pc_micros(void)
Monotonic microseconds - the high-resolution time base for ISR timestamps and sub-millisecond latency...
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