From 7c61f9e1359e85e5c8086b64789293197f10f323 Mon Sep 17 00:00:00 2001 From: ardnew Date: Sat, 20 Jan 2024 15:08:55 -0600 Subject: [PATCH] add IRAM_ATTR for esp-idf targets --- src/cronos.hpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/cronos.hpp b/src/cronos.hpp index 6e6f5ff..afbaae9 100644 --- a/src/cronos.hpp +++ b/src/cronos.hpp @@ -10,7 +10,8 @@ class ticker { public: #if defined(ESP_PLATFORM) #include // ESP32 (FreeRTOS) ticks are in microseconds. - static constexpr auto count = esp_timer_get_time; +#define fastcode IRAM_ATTR /* __attribute__((section(".iram1.text"))) */ + static constexpr auto fastcode count = esp_timer_get_time; using period = std::micro; #elif defined(ARDUINO) @@ -18,13 +19,15 @@ class ticker { // defined. So be sure to check it last (but before the default C++ // implementation). #include // Arduino ticks are in milliseconds. - static constexpr auto count = millis; +#define fastcode + static constexpr auto fastcode count = millis; using period = std::milli; #else +#define fastcode // C++17 allows constexpr with lambda functions (instead of masquerading // around as a functor). - static constexpr auto count = []() { + static constexpr auto fastcode count = []() { return std::chrono::steady_clock::now().time_since_epoch().count(); }; using period = std::chrono::steady_clock::period; @@ -41,7 +44,7 @@ class ticker { // // For unhandled platforms, the default implementation returns current tick // count using std::chrono::steady_clock (C++11). - static auto now() noexcept -> time_point { + static auto fastcode now() noexcept -> time_point { return time_point(duration(count())); } };