summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2019-03-04 15:30:14 +0100
committerDaniel Friesel <derf@finalrewind.org>2019-03-04 15:30:14 +0100
commit6fd09b2bb22f70b429b53a1205ced2487324fdd4 (patch)
treefa0d18411964dc1bee1fdc7c80e5b94c8c2bee21
parent618972e944942d7c3b4dac1f7c769608ea1d897c (diff)
ptalog: Support different logging types
-rw-r--r--include/object/ptalog.h42
1 files changed, 40 insertions, 2 deletions
diff --git a/include/object/ptalog.h b/include/object/ptalog.h
index f53dcc5..8ae43d1 100644
--- a/include/object/ptalog.h
+++ b/include/object/ptalog.h
@@ -4,21 +4,41 @@
#include <stdlib.h>
#include "driver/stdout.h"
+#ifdef PTALOG_GPIO
+#include "driver/gpio.h"
+#endif
+
+#ifdef PTALOG_TIMING
+#include "driver/counter.h"
+#endif
+
class PTALog {
public:
typedef struct {
uint8_t transition_id;
+#ifdef PTALOG_TIMING
+ counter_value_t timer;
+ counter_overflow_t overflow;
+#endif
} log_entry;
- log_entry log[32];
+ int const max_entry = 15;
+
+ log_entry log[16];
uint8_t log_index;
+#ifdef PTALOG_GPIO
PTALog(uint8_t pin_number) : log_index(0), sync_pin(pin_number) {}
+#else
+ PTALog(uint8_t pin_number) : log_index(0) {}
+#endif
inline void passTransition(uint8_t transition_id)
{
log[log_index].transition_id = transition_id;
- log_index++;
+ if (log_index < max_entry) {
+ log_index++;
+ }
}
inline void reset()
@@ -29,7 +49,9 @@ class PTALog {
inline void startBenchmark(uint8_t id)
{
kout << "[PTA] benchmark start, id=" << dec << id << endl;
+#ifdef PTALOG_GPIO
gpio.output(sync_pin);
+#endif
}
inline void stopBenchmark()
@@ -41,7 +63,11 @@ class PTALog {
{
kout << "[PTA] trace, count=" << dec << log_index << endl;
for (uint8_t i = 0; i < log_index; i++) {
+#ifdef PTALOG_TIMING
+ kout << "[PTA] transition=" << log[i].transition_id << endl;
+#else
kout << "[PTA] transition=" << log[i].transition_id << endl;
+#endif
}
}
@@ -50,14 +76,26 @@ class PTALog {
gpio.write(sync_pin, 1);
}
+#ifdef PTALOG_TIMING
+ inline void stopTransition(Counter& counter)
+#else
inline void stopTransition()
+#endif
{
+#ifdef PTALOG_GPIO
gpio.write(sync_pin, 0);
+#endif
+#ifdef PTALOG_TIMING
+ log[log_index - 1].timer = counter.value;
+ log[log_index - 1].overflow = counter.overflow;
+#endif
}
private:
PTALog(const PTALog& copy);
+#ifdef PTALOG_GPIO
uint8_t sync_pin;
+#endif
};
#endif