diff options
author | Daniel Friesel <daniel.friesel@uos.de> | 2020-08-12 14:23:36 +0200 |
---|---|---|
committer | Daniel Friesel <daniel.friesel@uos.de> | 2020-08-12 14:23:36 +0200 |
commit | 129b53ec9fc934a5cd66ab9ad25c81e058264321 (patch) | |
tree | 313879089dde7d147a3a0a64bf36ff80c0f33d56 /include/arch/stm32f446re-nucleo/driver | |
parent | 23f7b0e4ed05685e89c5c1d8d92556106b0845ff (diff) |
stm32f446re: Add counter
Diffstat (limited to 'include/arch/stm32f446re-nucleo/driver')
-rw-r--r-- | include/arch/stm32f446re-nucleo/driver/counter.h | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/include/arch/stm32f446re-nucleo/driver/counter.h b/include/arch/stm32f446re-nucleo/driver/counter.h new file mode 100644 index 0000000..6cb329e --- /dev/null +++ b/include/arch/stm32f446re-nucleo/driver/counter.h @@ -0,0 +1,35 @@ +#ifndef COUNTER_H +#define COUNTER_H + +#include <libopencm3/stm32/timer.h> + +#include "arch.h" + +typedef uint32_t counter_value_t; +typedef uint32_t counter_overflow_t; + +class Counter { + private: + Counter(const Counter ©); + + public: + counter_value_t value; + volatile counter_overflow_t overflow; + + Counter() : overflow(0) {} + + inline void start() { + overflow = 0; + timer_set_counter(TIM2, 0); + timer_enable_counter(TIM2); + } + + inline void stop() { + timer_disable_counter(TIM2); + value = timer_get_counter(TIM2); + } +}; + +extern Counter counter; + +#endif |