debug.h
1 /*
2  * EEZ PSU Firmware
3  * Copyright (C) 2015-present, Envox d.o.o.
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9 
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14 
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #pragma once
20 
21 #if CONF_DEBUG || CONF_DEBUG_LATEST
22 
23 #ifdef EEZ_PSU_ARDUINO
24 #pragma GCC diagnostic ignored "-Wwrite-strings"
25 #endif
26 
27 namespace eez {
28 namespace psu {
30 namespace debug {
31 
32 void tick(uint32_t tickCount);
33 
34 void Trace(const char *format, ...);
35 
36 }
37 }
38 } // namespace eez::psu::debug
39 
40 
41 #define DebugTrace(message) debug::Trace(PSTR(message))
42 #define DebugTraceF(format, ...) debug::Trace(PSTR(format), __VA_ARGS__)
43 
44 #else // NO DEBUG
45 
46 #define DebugTrace(...) 0
47 #define DebugTraceF(...) 0
48 
49 #endif
50 
51 
52 #if CONF_DEBUG
53 
54 namespace eez {
55 namespace psu {
56 namespace debug {
57 
59 public:
60  DebugVariable(const char *name);
61 
62  const char *name();
63 
64  virtual void tick1secPeriod() = 0;
65  virtual void tick10secPeriod() = 0;
66  virtual void dump(char *buffer) = 0;
67 
68 private:
69  const char *m_name;
70 };
71 
73 public:
74  DebugValueVariable(const char *name);
75 
76  void set(uint32_t value) { m_value = value; }
77 
78  void tick1secPeriod();
79  void tick10secPeriod();
80  void dump(char *buffer);
81 
82 private:
83  uint32_t m_value;
84 };
85 
87 public:
89 
90  void tick(uint32_t duration);
91  void tickPeriod();
92 
93  void dump(char *buffer);
94 
95 private:
96  uint32_t m_lastTickCount;
97 
98  uint32_t m_min;
99  uint32_t m_max;
100  uint32_t m_total;
101  uint32_t m_count;
102 
103  uint32_t m_minLast;
104  uint32_t m_maxLast;
105  uint32_t m_avgLast;
106 
107 };
108 
110 public:
111  DebugDurationVariable(const char *name);
112 
113  void start();
114  void finish();
115  void tick(uint32_t tickCount);
116 
117  void tick1secPeriod();
118  void tick10secPeriod();
119  void dump(char *buffer);
120 
121 private:
122  uint32_t m_lastTickCount;
123 
124  DebugDurationForPeriod duration1sec;
125  DebugDurationForPeriod duration10sec;
126 
127  uint32_t m_minTotal;
128  uint32_t m_maxTotal;
129 };
130 
132 public:
134 
135  void inc();
136  void tickPeriod();
137  void dump(char *buffer);
138 
139 private:
140  uint32_t m_counter;
141  uint32_t m_lastCounter;
142 };
143 
145 public:
146  DebugCounterVariable(const char *name);
147 
148  void inc();
149 
150  void tick1secPeriod();
151  void tick10secPeriod();
152  void dump(char *buffer);
153 
154 private:
155  DebugCounterForPeriod counter1sec;
156  DebugCounterForPeriod counter10sec;
157 
158  uint32_t m_totalCounter;
159 };
160 
161 extern DebugValueVariable g_uDac[2];
162 extern DebugValueVariable g_uMon[2];
163 extern DebugValueVariable g_uMonDac[2];
164 extern DebugValueVariable g_iDac[2];
165 extern DebugValueVariable g_iMon[2];
166 extern DebugValueVariable g_iMonDac[2];
167 
168 extern DebugDurationVariable g_mainLoopDuration;
169 #if CONF_DEBUG_VARIABLES
170 extern DebugDurationVariable g_listTickDuration;
171 #endif
172 extern DebugCounterVariable g_adcCounter;
173 
174 extern bool g_debugWatchdog;
175 
176 void dumpVariables(char *buffer);
177 
178 }
179 }
180 } // namespace eez::psu::debug
181 
182 #endif
Namespace for the everything from the EEZ.
Definition: actions.cpp:41
Definition: debug.h:58