OpenMPTL - ARM Cortex (common)
C++ Microprocessor Template Library
dwt.hpp
Go to the documentation of this file.
1 /*
2  * OpenMPTL - C++ Microprocessor Template Library
3  *
4  * Copyright (C) 2012-2017 Axel Burri <axel@tty0.ch>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 #ifndef ARM_CORTEX_COMMON_DWT_HPP_INCLUDED
22 #define ARM_CORTEX_COMMON_DWT_HPP_INCLUDED
23 
24 #include "reg/dwt.hpp"
25 #include "reg/debug.hpp"
26 
27 namespace mptl {
28 
29 class dwt
30 {
31 public:
32 
33  static void enable(void) {
35  }
36 
37  static void disable(void) {
39  }
40 
41  static void cycle_counter_enable(void) {
42  DWT::CYCCNT::store(0); // reset counter
43  DWT::CTRL::set(1); // enable counter
44  }
45 
47  return DWT::CYCCNT::load();
48  }
49 };
50 
51 
52 /**
53  * Cycle counter: Count processor clock cycles
54  */
56 {
57  using value_type = decltype(dwt::cycle_counter_load());
58 
59  value_type value;
60 
61 public:
62 
63  cycle_counter(void) : value(0) {
64  dwt::enable();
66  }
67 
69  dwt::disable();
70  }
71 
72  void start(void) {
73  value = dwt::cycle_counter_load();
74  }
75 
76  void stop(void) {
77  value = dwt::cycle_counter_load() - value;
78  }
79 
80  value_type get(void) {
81  return value;
82  }
83 };
84 
85 } // namespace mptl
86 
87 #endif // ARM_CORTEX_COMMON_DWT_HPP_INCLUDED
cycle_counter(void)
Definition: dwt.hpp:63
static void enable(void)
Definition: dwt.hpp:33
Definition: dwt.hpp:29
~cycle_counter(void)
Definition: dwt.hpp:68
void stop(void)
Definition: dwt.hpp:76
static DWT::CYCCNT::value_type cycle_counter_load(void)
Definition: dwt.hpp:46
static __always_inline Tp load(void)
static void disable(void)
Definition: dwt.hpp:37
static void cycle_counter_enable(void)
Definition: dwt.hpp:41
static __always_inline void set(void)
void start(void)
Definition: dwt.hpp:72
static __always_inline void store(Tp const value)
Cycle counter: Count processor clock cycles.
Definition: dwt.hpp:55