3#if defined(ROO_TESTING)
5#include "roo_testing/system/timer.h"
7inline static int64_t __uptime() {
return system_time_get_micros(); }
9inline static void __delayMicros(int64_t micros) {
10 system_time_delay_micros(micros);
20int64_t esp_timer_get_time();
23inline static IRAM_ATTR int64_t __uptime() {
return esp_timer_get_time(); }
25#define ROO_TIME_UPTIME_MONOTONE 1
27inline static void __delayMicros(int64_t micros) {
30 }
else if (micros < 2000) {
31 delayMicroseconds(micros);
34 delayMicroseconds(micros % 1000);
38#elif defined(ESP_PLATFORM)
41#include <freertos/FreeRTOS.h>
42#include <freertos/task.h>
43#include <rom/ets_sys.h>
46int64_t esp_timer_get_time();
49inline static IRAM_ATTR int64_t __uptime() {
return esp_timer_get_time(); }
51#define ROO_TIME_UPTIME_MONOTONE 1
53inline static void __delayMicros(int64_t micros) {
56 }
else if (micros < 2000) {
59 vTaskDelay(pdMS_TO_TICKS(micros / 1000));
60 ets_delay_us(micros % 1000);
68inline static int64_t __uptime() {
return micros(); }
70inline static void __delayMicros(int64_t micros) {
73 }
else if (micros < 2000) {
74 delayMicroseconds(micros);
77 delayMicroseconds(micros % 1000);
81#elif defined(__linux__)
86inline static int64_t __uptime() {
87 auto now = std::chrono::high_resolution_clock::now();
88 return std::chrono::duration_cast<std::chrono::microseconds>(
89 now.time_since_epoch())
93inline static void __delayMicros(int64_t micros) {
94 std::this_thread::sleep_for(std::chrono::microseconds(micros));
105#ifndef ROO_TIME_UPTIME_MONOTONE
106#define ROO_TIME_UPTIME_MONOTONE 0
109#if ROO_TIME_UPTIME_MONOTONE
121 int64_t now = __uptime() +
offset;
Represents an amount of time (e.g. 5s, 10min).
constexpr int64_t inMicros() const
Returns duration in microseconds.
Represents an instant relative to process/boot start time.
Uptime()
Constructs zero uptime value.
static const Uptime Now()
Returns current monotonic process uptime.
Umbrella header for the roo_time module.
void DelayUntil(Uptime deadline)
Delays execution until deadline.
static int64_t last_reading
void Delay(Duration duration)
Delays execution for duration.