From 9f9f7a8de591b09708ac81b0d41ffb2ef57f53bf Mon Sep 17 00:00:00 2001 From: BlackMark Date: Sat, 3 Aug 2019 17:52:28 +0200 Subject: [PATCH] Added flushing of transmit buffer --- hardware.hpp | 7 ++++++- hardware0.hpp | 14 ++++++++++++++ hardware1.hpp | 14 ++++++++++++++ uart.hpp | 5 +++++ 4 files changed, 39 insertions(+), 1 deletion(-) diff --git a/hardware.hpp b/hardware.hpp index 37100a0..aef1724 100644 --- a/hardware.hpp +++ b/hardware.hpp @@ -64,9 +64,14 @@ class Hardware { return *Registers::IO_REG; } + static bool txActive() FORCE_INLINE + { + return !(*Registers::CTRL_STAT_REG_A & (1 << CtrlFlagsA::DATA_REG_EMPTY)); + } + static void txByteBlocking(const typename cfg::data_t &byte) FORCE_INLINE { - while (!(*Registers::CTRL_STAT_REG_A & (1 << CtrlFlagsA::DATA_REG_EMPTY))) + while (txActive()) ; *Registers::IO_REG = byte; diff --git a/hardware0.hpp b/hardware0.hpp index 8ce0629..7c36201 100644 --- a/hardware0.hpp +++ b/hardware0.hpp @@ -105,6 +105,12 @@ class Hardware0 { return HardwareImpl::peekBlocking(); } + static void flushTx() FORCE_INLINE + { + while (HardwareImpl::txActive()) + ; + } + private: using HardwareImpl = detail::Hardware; @@ -164,6 +170,14 @@ class Hardware0 { return (sm_rxBuf.head != sm_rxBuf.tail); } + static void flushTx() FORCE_INLINE + { + while (sm_txBuf.head != sm_txBuf.tail) + ; + while (HardwareImpl::txActive()) + ; + } + private: using HardwareImpl = detail::Hardware; diff --git a/hardware1.hpp b/hardware1.hpp index 5528b32..06deeaf 100644 --- a/hardware1.hpp +++ b/hardware1.hpp @@ -109,6 +109,12 @@ class Hardware1 { return HardwareImpl::peekBlocking(); } + static void flushTx() FORCE_INLINE + { + while (HardwareImpl::txActive()) + ; + } + private: using HardwareImpl = detail::Hardware; @@ -168,6 +174,14 @@ class Hardware1 { return (sm_rxBuf.head != sm_rxBuf.tail); } + static void flushTx() FORCE_INLINE + { + while (sm_txBuf.head != sm_txBuf.tail) + ; + while (HardwareImpl::txActive()) + ; + } + private: using HardwareImpl = detail::Hardware; diff --git a/uart.hpp b/uart.hpp index e87124d..91326ab 100644 --- a/uart.hpp +++ b/uart.hpp @@ -88,6 +88,11 @@ class Uart { return Driver::peek(); } + static void flushTx() + { + Driver::flushTx(); + } + static void txString(const char *str) { static_assert(Driver::DATA_BITS == DataBits::EIGHT, "Strings are only supported with 8 data bits");