diff options
author | Daniel Friesel <derf@finalrewind.org> | 2019-01-29 11:44:00 +0100 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2019-01-29 11:44:00 +0100 |
commit | 05c4a7af8fadf4be8bdb794fc0335e113c134d14 (patch) | |
tree | f47191b8c240b9c428ae8c657d863d075e88961f /include/arch | |
parent | 974f1a7eb28f56221f53cedb87b505bafa02d8a5 (diff) |
add primitive esp8266 counter
Diffstat (limited to 'include/arch')
-rw-r--r-- | include/arch/esp8266/driver/counter.h | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/include/arch/esp8266/driver/counter.h b/include/arch/esp8266/driver/counter.h new file mode 100644 index 0000000..754f4d6 --- /dev/null +++ b/include/arch/esp8266/driver/counter.h @@ -0,0 +1,36 @@ +#ifndef COUNTER_H +#define COUNTER_H + +extern "C" { +#include "osapi.h" +#include "user_interface.h" +} +#include "c_types.h" + +class Counter { + private: + Counter(const Counter ©); + uint32_t start_cycles; + + public: + Counter() : start_cycles(0) {} + uint32_t overflowed; + + inline void start() { + asm volatile ("esync; rsr %0,ccount":"=a" (start_cycles)); + } + + inline uint32_t stop() { + uint32_t stop_cycles; + asm volatile ("esync; rsr %0,ccount":"=a" (stop_cycles)); + if (stop_cycles > start_cycles) { + return stop_cycles - start_cycles; + } else { + return 0; + } + } +}; + +extern Counter counter; + +#endif |