Implemented peeking with and without data for interrupt and blocking mode

This commit is contained in:
BlackMark 2019-08-02 18:20:06 +02:00
parent 95963295e2
commit a3d76a138d
4 changed files with 67 additions and 7 deletions

View File

@ -73,6 +73,15 @@ class Hardware {
*Registers::IO_REG = byte;
}
static bool peekBlocking() FORCE_INLINE
{
if (*Registers::CTRL_STAT_REG_A & (1 << CtrlFlagsA::RECEIVE_COMPLETE)) {
return true;
}
return false;
}
static void enableDataRegEmptyInt() FORCE_INLINE
{
*Registers::CTRL_STAT_REG_B |= (1 << CtrlFlagsB::DATA_REG_EMPTY_INT_ENABLE);

View File

@ -101,7 +101,17 @@ class Hardware0 {
return HardwareImpl::rxByteBlocking(byte);
}
static data_t peek() FORCE_INLINE {}
static bool peek(data_t &byte) FORCE_INLINE
{
static_cast<void>(byte);
static_assert(driven == Driven::BLOCKING, "Peek with data is not supported in blocking mode");
return false;
}
static bool peek() FORCE_INLINE
{
return HardwareImpl::peekBlocking();
}
private:
using HardwareImpl = detail::Hardware<detail::Registers0, detail::ControlFlagsA0, detail::ControlFlagsB0,
@ -140,14 +150,27 @@ class Hardware0<mode, cfg, Driven::INTERRUPT> {
return false;
uint8_t tmpTail = (sm_rxBuf.tail + 1) % RX_BUFFER_SIZE;
byte = sm_rxBuf.buf[tmpTail];
sm_rxBuf.tail = tmpTail;
return true;
}
static data_t peek() FORCE_INLINE {}
static bool peek(data_t &byte) FORCE_INLINE
{
if (sm_rxBuf.head == sm_rxBuf.tail)
return false;
uint8_t tmpTail = (sm_rxBuf.tail + 1) % RX_BUFFER_SIZE;
byte = sm_rxBuf.buf[tmpTail];
return true;
}
static bool peek() FORCE_INLINE
{
return (sm_rxBuf.head != sm_rxBuf.tail);
}
private:
using HardwareImpl = detail::Hardware<detail::Registers0, detail::ControlFlagsA0, detail::ControlFlagsB0,

View File

@ -105,7 +105,17 @@ class Hardware1 {
return HardwareImpl::rxByteBlocking(byte);
}
static data_t peek() FORCE_INLINE {}
static bool peek(data_t &byte) FORCE_INLINE
{
static_cast<void>(byte);
static_assert(driven != Driven::BLOCKING, "Peek with data is not supported in blocking mode");
return false;
}
static bool peek() FORCE_INLINE
{
return HardwareImpl::peekBlocking();
}
private:
using HardwareImpl = detail::Hardware<detail::Registers1, detail::ControlFlagsA1, detail::ControlFlagsB1,
@ -144,14 +154,27 @@ class Hardware1<mode, cfg, Driven::INTERRUPT> {
return false;
uint8_t tmpTail = (sm_rxBuf.tail + 1) % RX_BUFFER_SIZE;
byte = sm_rxBuf.buf[tmpTail];
sm_rxBuf.tail = tmpTail;
return true;
}
static data_t peek() FORCE_INLINE {}
static bool peek(data_t &byte) FORCE_INLINE
{
if (sm_rxBuf.head == sm_rxBuf.tail)
return false;
uint8_t tmpTail = (sm_rxBuf.tail + 1) % RX_BUFFER_SIZE;
byte = sm_rxBuf.buf[tmpTail];
return true;
}
static bool peek() FORCE_INLINE
{
return (sm_rxBuf.head != sm_rxBuf.tail);
}
private:
using HardwareImpl = detail::Hardware<detail::Registers1, detail::ControlFlagsA1, detail::ControlFlagsB1,

View File

@ -45,7 +45,12 @@ class Uart {
return Driver::rxByte(byte);
}
static typename Driver::data_t peek()
static bool peek(typename Driver::data_t &byte)
{
return Driver::peek(byte);
}
static bool peek()
{
return Driver::peek();
}