Implemented interrupt driven rx for uart0

This commit is contained in:
BlackMark 2019-08-02 17:38:00 +02:00
parent efe1446907
commit 16f4be8c6c

View File

@ -103,7 +103,10 @@ class Hardware0 {
HardwareImpl::txByteBlocking(byte);
}
static data_t rxByte() FORCE_INLINE {}
static bool rxByte(data_t &byte) FORCE_INLINE
{
return false;
}
static data_t peek() FORCE_INLINE {}
@ -139,7 +142,18 @@ class Hardware0<mode, cfg, Driven::INTERRUPT> {
HardwareImpl::enableDataRegEmptyInt();
}
static data_t rxByte() FORCE_INLINE {}
static bool rxByte(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];
sm_rxBuf.tail = tmpTail;
return true;
}
static data_t peek() FORCE_INLINE {}
@ -148,12 +162,19 @@ class Hardware0<mode, cfg, Driven::INTERRUPT> {
detail::ControlFlagsC0, cfg, mode, Driven::INTERRUPT>;
static constexpr auto TX_BUFFER_SIZE = 16;
static constexpr auto RX_BUFFER_SIZE = 16;
static volatile detail::RingBuffer<data_t, TX_BUFFER_SIZE> sm_txBuf;
static volatile detail::RingBuffer<data_t, RX_BUFFER_SIZE> sm_rxBuf;
static void rxIntHandler()
{
// TODO
uint8_t tmpHead = (sm_rxBuf.head + 1) % RX_BUFFER_SIZE;
if (tmpHead != sm_rxBuf.tail) {
sm_rxBuf.head = tmpHead;
sm_rxBuf.buf[tmpHead] = HardwareImpl::rxByteInterrupt();
}
}
static void dataRegEmptyIntHandler() FORCE_INLINE
@ -177,6 +198,11 @@ volatile detail::RingBuffer<typename Hardware0<mode, cfg, Driven::INTERRUPT>::da
Hardware0<mode, cfg, Driven::INTERRUPT>::TX_BUFFER_SIZE>
Hardware0<mode, cfg, Driven::INTERRUPT>::sm_txBuf = {0, 0, {0}};
template <Mode mode, class cfg>
volatile detail::RingBuffer<typename Hardware0<mode, cfg, Driven::INTERRUPT>::data_t,
Hardware0<mode, cfg, Driven::INTERRUPT>::RX_BUFFER_SIZE>
Hardware0<mode, cfg, Driven::INTERRUPT>::sm_rxBuf = {0, 0, {0}};
} // namespace uart
#undef FORCE_INLINE