From 61f4d2dc0e672f2c26bc964a27789cfd4fb81b88 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Thu, 21 Jul 2022 12:49:26 +0200 Subject: tc1796 is a proper arch now --- include/arch/tc1796-triboard/driver/counter.h | 41 +++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 include/arch/tc1796-triboard/driver/counter.h (limited to 'include/arch/tc1796-triboard/driver/counter.h') diff --git a/include/arch/tc1796-triboard/driver/counter.h b/include/arch/tc1796-triboard/driver/counter.h new file mode 100644 index 0000000..38d039e --- /dev/null +++ b/include/arch/tc1796-triboard/driver/counter.h @@ -0,0 +1,41 @@ +/* + * Copyright 2022 Daniel Friesel + * + * SPDX-License-Identifier: BSD-2-Clause + */ +#ifndef COUNTER_H +#define COUNTER_H + +#define STM_TIM0 (*(volatile unsigned int*)0xf0000210) +#define STM_CAP (*(volatile unsigned int*)0xf000022c) + +typedef unsigned int counter_value_t; +typedef unsigned int counter_overflow_t; + +class Counter { + private: + Counter(const Counter ©); + unsigned long long startvalue, stopvalue; + + public: + counter_value_t value; + counter_overflow_t overflow; + + Counter() : overflow(0) {} + + inline void start() { + startvalue = STM_TIM0; + startvalue += (unsigned long long)STM_CAP << 32; + } + + inline void stop() { + stopvalue = STM_TIM0; + stopvalue += (unsigned long long)STM_CAP << 32; + value = (stopvalue - startvalue) & 0xffffffff; + overflow = (unsigned long long)(stopvalue - startvalue) >> 32; + } +}; + +extern Counter counter; + +#endif -- cgit v1.2.3