diff options
author | Daniel Friesel <derf@finalrewind.org> | 2019-03-04 15:31:21 +0100 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2019-03-04 15:31:21 +0100 |
commit | f0c087f4ab3cae2d8da65cf51bb5b0e69fe72a76 (patch) | |
tree | d25c48766a295311c1f451dd26f5626d842c1ddb /include | |
parent | 6fd09b2bb22f70b429b53a1205ced2487324fdd4 (diff) |
counter: Provide typedefs fore value/overflow type
Diffstat (limited to 'include')
-rw-r--r-- | include/arch/arduino-nano/driver/counter.h | 3 | ||||
-rw-r--r-- | include/arch/esp8266/driver/counter.h | 13 | ||||
-rw-r--r-- | include/arch/msp430fr5969lp/driver/counter.h | 3 | ||||
-rw-r--r-- | include/arch/msp430fr5994lp/driver/counter.h | 3 | ||||
-rw-r--r-- | include/arch/posix/driver/counter.h | 3 |
5 files changed, 21 insertions, 4 deletions
diff --git a/include/arch/arduino-nano/driver/counter.h b/include/arch/arduino-nano/driver/counter.h index 9105219..43ddd15 100644 --- a/include/arch/arduino-nano/driver/counter.h +++ b/include/arch/arduino-nano/driver/counter.h @@ -1,6 +1,9 @@ #include <avr/io.h> #include <avr/interrupt.h> +typedef counter_value_t uint16_t; +typedef counter_overflowed_t uint8_t; + class Counter { private: Counter(const Counter ©); 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; } } }; diff --git a/include/arch/msp430fr5969lp/driver/counter.h b/include/arch/msp430fr5969lp/driver/counter.h index e7f0507..501808b 100644 --- a/include/arch/msp430fr5969lp/driver/counter.h +++ b/include/arch/msp430fr5969lp/driver/counter.h @@ -1,6 +1,9 @@ #include <msp430.h> #include <stdint.h> +typedef counter_value_t uint16_t; +typedef counter_overflowed_t uint8_t; + class Counter { private: Counter(const Counter ©); diff --git a/include/arch/msp430fr5994lp/driver/counter.h b/include/arch/msp430fr5994lp/driver/counter.h index e7f0507..21c5ec5 100644 --- a/include/arch/msp430fr5994lp/driver/counter.h +++ b/include/arch/msp430fr5994lp/driver/counter.h @@ -1,6 +1,9 @@ #include <msp430.h> #include <stdint.h> +typedef uint16_t counter_value_t; +typedef uint8_t counter_overflowed_t; + class Counter { private: Counter(const Counter ©); diff --git a/include/arch/posix/driver/counter.h b/include/arch/posix/driver/counter.h index 6390d14..4f575a8 100644 --- a/include/arch/posix/driver/counter.h +++ b/include/arch/posix/driver/counter.h @@ -1,6 +1,9 @@ #include <stdint.h> #include <time.h> +typedef uint64_t counter_value_t; +typedef uint8_t counter_overflowed_t; + class Counter { private: Counter(const Counter ©); |