From e141ef35b9a93ed174f206bf8cdae0c34c0a7fd2 Mon Sep 17 00:00:00 2001
From: Karl Palsson <karlp@etactica.com>
Date: Mon, 20 Sep 2021 17:05:26 +0000
Subject: cortex-debug: add blocking ITM helpers.

Sometimes you really would like to slow things down to get trace out.
---
 cortex_m/debug.h | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/cortex_m/debug.h b/cortex_m/debug.h
index 5375e70..8134829 100644
--- a/cortex_m/debug.h
+++ b/cortex_m/debug.h
@@ -18,6 +18,32 @@ struct ITM_reg_t {
     volatile uint32_t TCR;
     uint32_t _reserved4[76];
     volatile uint32_t LSR;
+
+    // FIXME - only supports first 32 stimulus ports
+    void stim_blocking(unsigned stim, uint8_t data) {
+	    if (!(this->TER[0] & (1<<stim))) {
+		    return;
+	    }
+	    while (!(this->STIM[stim].u8 & 1))
+		    ;
+	    this->STIM[stim].u8 = data;
+    }
+    void stim_blocking(unsigned stim, uint16_t data) {
+	    if (!(this->TER[0] & (1<<stim))) {
+		    return;
+	    }
+	    while (!(this->STIM[stim].u16 & 1))
+		    ;
+	    this->STIM[stim].u16 = data;
+    }
+    void stim_blocking(unsigned stim, uint32_t data) {
+	    if (!(this->TER[0] & (1<<stim))) {
+		    return;
+	    }
+	    while (!(this->STIM[stim].u32 & 1))
+		    ;
+	    this->STIM[stim].u32 = data;
+    }
 };
 
 struct DWT_reg_t {
-- 
cgit v1.2.3