idfxx 1.0.0
Modern C++23 components for ESP-IDF
Loading...
Searching...
No Matches
chrono.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2// Copyright 2026 Chris Leishman
3
4#pragma once
5
20#include <chrono>
21#include <freertos/FreeRTOS.h>
22#include <freertos/task.h>
23
27namespace idfxx::chrono {
28
32template<class Rep, class Period>
33[[nodiscard]] constexpr TickType_t ticks(const std::chrono::duration<Rep, Period>& d) {
34 return pdMS_TO_TICKS(std::chrono::ceil<std::chrono::milliseconds>(d).count());
35}
36
44struct tick_clock {
45 using rep = TickType_t;
46 using period = std::ratio<1, configTICK_RATE_HZ>;
47 using duration = std::chrono::duration<rep, period>;
48 using time_point = std::chrono::time_point<tick_clock>;
49 static constexpr bool is_steady = true;
50
56
62};
63
// end of idfxx_core_chrono // end of idfxx_core
66
67} // namespace idfxx::chrono
constexpr TickType_t ticks(const std::chrono::duration< Rep, Period > &d)
Converts a std::chrono duration to TickType_t ticks.
Definition chrono.hpp:33
ESP-IDF C++ chrono utilities.
Definition chrono.hpp:27
Steady clock based on FreeRTOS tick count.
Definition chrono.hpp:44
std::chrono::time_point< tick_clock > time_point
Definition chrono.hpp:48
static time_point now() noexcept
Returns the current tick count as a time_point.
Definition chrono.hpp:55
static constexpr bool is_steady
Definition chrono.hpp:49
static time_point now_from_isr() noexcept
Returns the current tick count as a time_point from ISR context.
Definition chrono.hpp:61
std::chrono::duration< rep, period > duration
Definition chrono.hpp:47
std::ratio< 1, configTICK_RATE_HZ > period
Definition chrono.hpp:46