Skip to content

Commit 7fe2812

Browse files
dok-netme-no-dev
authored andcommitted
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.
1 parent 9710fed commit 7fe2812

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

cores/esp32/Esp.cpp

-7
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,6 @@ void EspClass::deepSleep(uint32_t time_us)
9292
esp_deep_sleep(time_us);
9393
}
9494

95-
uint32_t EspClass::getCycleCount()
96-
{
97-
uint32_t ccount;
98-
__asm__ __volatile__("esync; rsr %0,ccount":"=a" (ccount));
99-
return ccount;
100-
}
101-
10295
void EspClass::restart(void)
10396
{
10497
esp_restart();

cores/esp32/Esp.h

+8-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class EspClass
7676

7777
uint8_t getChipRevision();
7878
uint32_t getCpuFreqMHz(){ return getCpuFrequencyMhz(); }
79-
uint32_t getCycleCount();
79+
inline uint32_t getCycleCount() __attribute__((always_inline));
8080
const char * getSdkVersion();
8181

8282
void deepSleep(uint32_t time_us);
@@ -101,6 +101,13 @@ class EspClass
101101

102102
};
103103

104+
uint32_t IRAM_ATTR EspClass::getCycleCount()
105+
{
106+
uint32_t ccount;
107+
__asm__ __volatile__("esync; rsr %0,ccount":"=a" (ccount));
108+
return ccount;
109+
}
110+
104111
extern EspClass ESP;
105112

106113
#endif //ESP_H

0 commit comments

Comments
 (0)