Fix uart interrupt printing when the buffer fills up
It almost managed to block the print until there was space in the
buffer, except it ended up blocking out interrupts so it just
deadlocked.
Change-Id: Ifa3ae0cd6bef22cc8521c9bd866a30f62cfbc76d
diff --git a/motors/util.h b/motors/util.h
index 110caed..0056089 100644
--- a/motors/util.h
+++ b/motors/util.h
@@ -240,6 +240,19 @@
DisableInterrupts &operator=(const DisableInterrupts &) = delete;
};
+class ReenableInterrupts {
+ public:
+ ReenableInterrupts(DisableInterrupts *) {
+ __enable_irq();
+ // Because we're on a Cortex-M4, we don't need an ISB here to ensure
+ // interrupts are processed.
+ }
+ ~ReenableInterrupts() { __disable_irq(); }
+
+ ReenableInterrupts(const ReenableInterrupts &) = delete;
+ ReenableInterrupts &operator=(const ReenableInterrupts &) = delete;
+};
+
// constexpr log base 2, which fails to compile for non-power-of-2 inputs.
// This is a silly implementation to use at runtime.
template<typename T>