Added flushing of transmit buffer

This commit is contained in:
BlackMark 2019-08-03 17:52:28 +02:00
parent b6c1c3b51b
commit 9f9f7a8de5
4 changed files with 39 additions and 1 deletions

View File

@ -64,9 +64,14 @@ class Hardware {
return *Registers::IO_REG; 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 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; *Registers::IO_REG = byte;

View File

@ -105,6 +105,12 @@ class Hardware0 {
return HardwareImpl::peekBlocking(); return HardwareImpl::peekBlocking();
} }
static void flushTx() FORCE_INLINE
{
while (HardwareImpl::txActive())
;
}
private: private:
using HardwareImpl = detail::Hardware<detail::Registers0, detail::ControlFlagsA0, detail::ControlFlagsB0, using HardwareImpl = detail::Hardware<detail::Registers0, detail::ControlFlagsA0, detail::ControlFlagsB0,
detail::ControlFlagsC0, cfg, mode, driven>; detail::ControlFlagsC0, cfg, mode, driven>;
@ -164,6 +170,14 @@ class Hardware0<mode, cfg, Driven::INTERRUPT> {
return (sm_rxBuf.head != sm_rxBuf.tail); return (sm_rxBuf.head != sm_rxBuf.tail);
} }
static void flushTx() FORCE_INLINE
{
while (sm_txBuf.head != sm_txBuf.tail)
;
while (HardwareImpl::txActive())
;
}
private: private:
using HardwareImpl = detail::Hardware<detail::Registers0, detail::ControlFlagsA0, detail::ControlFlagsB0, using HardwareImpl = detail::Hardware<detail::Registers0, detail::ControlFlagsA0, detail::ControlFlagsB0,
detail::ControlFlagsC0, cfg, mode, Driven::INTERRUPT>; detail::ControlFlagsC0, cfg, mode, Driven::INTERRUPT>;

View File

@ -109,6 +109,12 @@ class Hardware1 {
return HardwareImpl::peekBlocking(); return HardwareImpl::peekBlocking();
} }
static void flushTx() FORCE_INLINE
{
while (HardwareImpl::txActive())
;
}
private: private:
using HardwareImpl = detail::Hardware<detail::Registers1, detail::ControlFlagsA1, detail::ControlFlagsB1, using HardwareImpl = detail::Hardware<detail::Registers1, detail::ControlFlagsA1, detail::ControlFlagsB1,
detail::ControlFlagsC1, cfg, mode, driven>; detail::ControlFlagsC1, cfg, mode, driven>;
@ -168,6 +174,14 @@ class Hardware1<mode, cfg, Driven::INTERRUPT> {
return (sm_rxBuf.head != sm_rxBuf.tail); return (sm_rxBuf.head != sm_rxBuf.tail);
} }
static void flushTx() FORCE_INLINE
{
while (sm_txBuf.head != sm_txBuf.tail)
;
while (HardwareImpl::txActive())
;
}
private: private:
using HardwareImpl = detail::Hardware<detail::Registers1, detail::ControlFlagsA1, detail::ControlFlagsB1, using HardwareImpl = detail::Hardware<detail::Registers1, detail::ControlFlagsA1, detail::ControlFlagsB1,
detail::ControlFlagsC1, cfg, mode, Driven::INTERRUPT>; detail::ControlFlagsC1, cfg, mode, Driven::INTERRUPT>;

View File

@ -88,6 +88,11 @@ class Uart {
return Driver::peek(); return Driver::peek();
} }
static void flushTx()
{
Driver::flushTx();
}
static void txString(const char *str) static void txString(const char *str)
{ {
static_assert(Driver::DATA_BITS == DataBits::EIGHT, "Strings are only supported with 8 data bits"); static_assert(Driver::DATA_BITS == DataBits::EIGHT, "Strings are only supported with 8 data bits");