summaryrefslogtreecommitdiff
path: root/include/arch
diff options
context:
space:
mode:
Diffstat (limited to 'include/arch')
-rw-r--r--include/arch/esp8266/driver/counter.h36
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 &copy);
+ 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