summaryrefslogtreecommitdiff
path: root/include/arch
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2019-01-29 11:44:00 +0100
committerDaniel Friesel <derf@finalrewind.org>2019-01-29 11:44:00 +0100
commit05c4a7af8fadf4be8bdb794fc0335e113c134d14 (patch)
treef47191b8c240b9c428ae8c657d863d075e88961f /include/arch
parent974f1a7eb28f56221f53cedb87b505bafa02d8a5 (diff)
add primitive esp8266 counter
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