From f0c087f4ab3cae2d8da65cf51bb5b0e69fe72a76 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Mon, 4 Mar 2019 15:31:21 +0100 Subject: counter: Provide typedefs fore value/overflow type --- include/arch/esp8266/driver/counter.h | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'include/arch/esp8266/driver/counter.h') diff --git a/include/arch/esp8266/driver/counter.h b/include/arch/esp8266/driver/counter.h index 754f4d6..42f6f14 100644 --- a/include/arch/esp8266/driver/counter.h +++ b/include/arch/esp8266/driver/counter.h @@ -7,26 +7,31 @@ extern "C" { } #include "c_types.h" +typedef counter_value_t uint32_t; +typedef counter_overflowed_t uint32_t; + class Counter { private: Counter(const Counter ©); uint32_t start_cycles; public: - Counter() : start_cycles(0) {} + uint32_t value; uint32_t overflowed; + Counter() : start_cycles(0), value(0), overflowed(0) {} + inline void start() { asm volatile ("esync; rsr %0,ccount":"=a" (start_cycles)); } - inline uint32_t stop() { + inline void stop() { uint32_t stop_cycles; asm volatile ("esync; rsr %0,ccount":"=a" (stop_cycles)); if (stop_cycles > start_cycles) { - return stop_cycles - start_cycles; + value = stop_cycles - start_cycles; } else { - return 0; + overflowed = 1; } } }; -- cgit v1.2.3