From 7fe2812f7f619404f8b0fd428f9a6b28b7f9c3f6 Mon Sep 17 00:00:00 2001 From: "Dirk O. Kaar" <19971886+dok-net@users.noreply.github.com> Date: Wed, 11 Sep 2019 13:29:53 +0200 Subject: [PATCH] Inline ESP::getCycleCount() to make it safe to call from ISRs (#3165) * Inline ESP::getCycleCount() to make it safe to call from ISRs * Attribute IRAM_ATTR ISR-safe function in addition to inlining. --- cores/esp32/Esp.cpp | 7 ------- cores/esp32/Esp.h | 9 ++++++++- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/cores/esp32/Esp.cpp b/cores/esp32/Esp.cpp index 8df9514e..54451127 100644 --- a/cores/esp32/Esp.cpp +++ b/cores/esp32/Esp.cpp @@ -92,13 +92,6 @@ void EspClass::deepSleep(uint32_t time_us) esp_deep_sleep(time_us); } -uint32_t EspClass::getCycleCount() -{ - uint32_t ccount; - __asm__ __volatile__("esync; rsr %0,ccount":"=a" (ccount)); - return ccount; -} - void EspClass::restart(void) { esp_restart(); diff --git a/cores/esp32/Esp.h b/cores/esp32/Esp.h index 9acb6665..2580eecf 100644 --- a/cores/esp32/Esp.h +++ b/cores/esp32/Esp.h @@ -76,7 +76,7 @@ public: uint8_t getChipRevision(); uint32_t getCpuFreqMHz(){ return getCpuFrequencyMhz(); } - uint32_t getCycleCount(); + inline uint32_t getCycleCount() __attribute__((always_inline)); const char * getSdkVersion(); void deepSleep(uint32_t time_us); @@ -101,6 +101,13 @@ public: }; +uint32_t IRAM_ATTR EspClass::getCycleCount() +{ + uint32_t ccount; + __asm__ __volatile__("esync; rsr %0,ccount":"=a" (ccount)); + return ccount; +} + extern EspClass ESP; #endif //ESP_H