[apps] Add a macro to define separate dump functions
@@ -63,3 +63,20 @@ static inline void mempool_wfi() { asm volatile("wfi"); }
// If core_id equals -1, wake up all cores.
static inline void wake_up(uint32_t core_id) { wake_up_reg = core_id; }
static inline void wake_up_all() { wake_up((uint32_t)-1); }
+
+// Dump a value via CSR
+// This is only supported in simulation and an experimental feature. All writes
+// to unimplemented CSR registers will be dumped by Snitch. This can be
+// exploited to quickly print measurement values from all cores simultaneously
+// without the hassle of printf. To specify multiple metrics, different CSRs can
+// be used.
+// The macro will define a function that will then always print via the same
+// CSR. E.g., `dump(errors, 8)` will define a function with the following
+// signature: `dump_errors(uint32_t val)`, which will print the given value via
+// the 8th register.
+// Alternatively, the `write_csr(reg, val)` macro can be used directly.
+#define dump(name, reg) \
+ static \
+ __attribute__((always_inline)) inline void dump_##name(uint32_t val) { \
+ asm volatile("csrw " #reg ", %0" ::"rK"(val)); \
+ }
