diff options
Diffstat (limited to 'include/arch/rm46l8lp/driver/counter.h')
-rw-r--r-- | include/arch/rm46l8lp/driver/counter.h | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/include/arch/rm46l8lp/driver/counter.h b/include/arch/rm46l8lp/driver/counter.h new file mode 100644 index 0000000..ee4b595 --- /dev/null +++ b/include/arch/rm46l8lp/driver/counter.h @@ -0,0 +1,40 @@ +/* + * Copyright 2020 Daniel Friesel + * + * SPDX-License-Identifier: BSD-2-Clause + */ +#ifndef COUNTER_H +#define COUNTER_H + +#include "rti.h" +#include <stdint.h> + +typedef uint32_t counter_value_t; +typedef uint32_t counter_overflow_t; + +class Counter { + private: + Counter(const Counter ©); + + public: + uint32_t value; + uint32_t overflow; + + Counter() : overflow(0) {} + + inline void start() { + rtiREG1->CNT[0].UCx = 0; + rtiREG1->CNT[0].FRCx = 0; + rtiREG1->GCTRL |= ((uint32)1 << (rtiCOUNTER_BLOCK0 & 3)); + } + + inline void stop() { + rtiREG1->GCTRL &= ~(uint32)((uint32)1 << (rtiCOUNTER_BLOCK0 & 3)); + overflow = rtiREG1->CNT[0].FRCx; + value = rtiREG1->CNT[0].UCx; + } +}; + +extern Counter counter; + +#endif |