Skip to content

Commit

Permalink
add IRAM_ATTR for esp-idf targets
Browse files Browse the repository at this point in the history
  • Loading branch information
ardnew committed Jan 20, 2024
1 parent 7a586de commit 7c61f9e
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/cronos.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,24 @@ class ticker {
public:
#if defined(ESP_PLATFORM)
#include <esp_timer.h> // 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)
// It's likely there are many generic platforms that will have ARDUINO
// defined. So be sure to check it last (but before the default C++
// implementation).
#include <Arduino.h> // 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;
Expand All @@ -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()));
}
};
Expand Down

0 comments on commit 7c61f9e

Please sign in to comment.