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/peripheral/uart.cc b/motors/peripheral/uart.cc
index a901483..70eadf1 100644
--- a/motors/peripheral/uart.cc
+++ b/motors/peripheral/uart.cc
@@ -64,8 +64,8 @@
uart_.Initialize(baud_rate);
}
-void InterruptBufferedUart::Write(gsl::span<char> data,
- const DisableInterrupts &disable_interrupts) {
+void InterruptBufferedUart::Write(gsl::span<char> data) {
+ DisableInterrupts disable_interrupts;
uart_.EnableTransmitInterrupt();
static_assert(buffer_.size() >= 8,
"Need enough space to not turn the interrupt off each time");
@@ -73,6 +73,7 @@
const int bytes_written = buffer_.PushSpan(data);
data = data.subspan(bytes_written);
WriteCharacters(data.empty(), disable_interrupts);
+ ReenableInterrupts{&disable_interrupts};
}
}