From 8153696309a72ee551a37b17e4eb8ddcda62d0de Mon Sep 17 00:00:00 2001 From: BlackMark Date: Sat, 3 Aug 2019 18:45:51 +0200 Subject: [PATCH] Fixed flushing not blocking correctly --- hardware.hpp | 16 +++++++++++++--- hardware0.hpp | 10 ++++++++-- hardware1.hpp | 10 ++++++++-- 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/hardware.hpp b/hardware.hpp index aef1724..86b9f0b 100644 --- a/hardware.hpp +++ b/hardware.hpp @@ -64,14 +64,24 @@ class Hardware { return *Registers::IO_REG; } - static bool txActive() FORCE_INLINE + static bool txEmpty() FORCE_INLINE { - return !(*Registers::CTRL_STAT_REG_A & (1 << CtrlFlagsA::DATA_REG_EMPTY)); + return *Registers::CTRL_STAT_REG_A & (1 << CtrlFlagsA::DATA_REG_EMPTY); + } + + static bool txComplete() FORCE_INLINE + { + return *Registers::CTRL_STAT_REG_A & (1 << CtrlFlagsA::TRANSMIT_COMPLETE); + } + + static void clearTxComplete() FORCE_INLINE + { + *Registers::CTRL_STAT_REG_A |= (1 << CtrlFlagsA::TRANSMIT_COMPLETE); } static void txByteBlocking(const typename cfg::data_t &byte) FORCE_INLINE { - while (txActive()) + while (!txEmpty()) ; *Registers::IO_REG = byte; diff --git a/hardware0.hpp b/hardware0.hpp index 7c36201..2ca13aa 100644 --- a/hardware0.hpp +++ b/hardware0.hpp @@ -107,8 +107,11 @@ class Hardware0 { static void flushTx() FORCE_INLINE { - while (HardwareImpl::txActive()) + while (!HardwareImpl::txEmpty()) ; + while (!HardwareImpl::txComplete()) + ; + HardwareImpl::clearTxComplete(); } private: @@ -174,8 +177,11 @@ class Hardware0 { { while (sm_txBuf.head != sm_txBuf.tail) ; - while (HardwareImpl::txActive()) + while (!HardwareImpl::txEmpty()) ; + while (!HardwareImpl::txComplete()) + ; + HardwareImpl::clearTxComplete(); } private: diff --git a/hardware1.hpp b/hardware1.hpp index 06deeaf..185b24f 100644 --- a/hardware1.hpp +++ b/hardware1.hpp @@ -111,8 +111,11 @@ class Hardware1 { static void flushTx() FORCE_INLINE { - while (HardwareImpl::txActive()) + while (!HardwareImpl::txEmpty()) ; + while (!HardwareImpl::txComplete()) + ; + HardwareImpl::clearTxComplete(); } private: @@ -178,8 +181,11 @@ class Hardware1 { { while (sm_txBuf.head != sm_txBuf.tail) ; - while (HardwareImpl::txActive()) + while (!HardwareImpl::txEmpty()) ; + while (!HardwareImpl::txComplete()) + ; + HardwareImpl::clearTxComplete(); } private: