Implemented interrupt driven rx for uart1
This commit is contained in:
parent
b90da9bd9c
commit
efe1446907
@ -45,6 +45,11 @@ class Hardware {
|
|||||||
*Registers::CTRL_STAT_REG_C = controlRegC;
|
*Registers::CTRL_STAT_REG_C = controlRegC;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static typename cfg::data_t rxByteInterrupt() FORCE_INLINE
|
||||||
|
{
|
||||||
|
return *Registers::IO_REG;
|
||||||
|
}
|
||||||
|
|
||||||
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 (!(*Registers::CTRL_STAT_REG_A & (1 << CtrlFlagsA::DATA_REG_EMPTY)))
|
||||||
|
@ -107,7 +107,10 @@ class Hardware1 {
|
|||||||
HardwareImpl::txByteBlocking(byte);
|
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 {}
|
static data_t peek() FORCE_INLINE {}
|
||||||
|
|
||||||
@ -143,7 +146,18 @@ class Hardware1<mode, cfg, Driven::INTERRUPT> {
|
|||||||
HardwareImpl::enableDataRegEmptyInt();
|
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 {}
|
static data_t peek() FORCE_INLINE {}
|
||||||
|
|
||||||
@ -152,12 +166,19 @@ class Hardware1<mode, cfg, Driven::INTERRUPT> {
|
|||||||
detail::ControlFlagsC1, cfg, mode, Driven::INTERRUPT>;
|
detail::ControlFlagsC1, cfg, mode, Driven::INTERRUPT>;
|
||||||
|
|
||||||
static constexpr auto TX_BUFFER_SIZE = 16;
|
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, TX_BUFFER_SIZE> sm_txBuf;
|
||||||
|
static volatile detail::RingBuffer<data_t, RX_BUFFER_SIZE> sm_rxBuf;
|
||||||
|
|
||||||
static void rxIntHandler()
|
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
|
static void dataRegEmptyIntHandler() FORCE_INLINE
|
||||||
@ -181,6 +202,11 @@ volatile detail::RingBuffer<typename Hardware1<mode, cfg, Driven::INTERRUPT>::da
|
|||||||
Hardware1<mode, cfg, Driven::INTERRUPT>::TX_BUFFER_SIZE>
|
Hardware1<mode, cfg, Driven::INTERRUPT>::TX_BUFFER_SIZE>
|
||||||
Hardware1<mode, cfg, Driven::INTERRUPT>::sm_txBuf = {0, 0, {0}};
|
Hardware1<mode, cfg, Driven::INTERRUPT>::sm_txBuf = {0, 0, {0}};
|
||||||
|
|
||||||
|
template <Mode mode, class cfg>
|
||||||
|
volatile detail::RingBuffer<typename Hardware1<mode, cfg, Driven::INTERRUPT>::data_t,
|
||||||
|
Hardware1<mode, cfg, Driven::INTERRUPT>::RX_BUFFER_SIZE>
|
||||||
|
Hardware1<mode, cfg, Driven::INTERRUPT>::sm_rxBuf = {0, 0, {0}};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
} // namespace uart
|
} // namespace uart
|
||||||
|
4
uart.hpp
4
uart.hpp
@ -40,9 +40,9 @@ class Uart {
|
|||||||
Driver::txByte(byte);
|
Driver::txByte(byte);
|
||||||
}
|
}
|
||||||
|
|
||||||
static typename Driver::data_t rxByte()
|
static bool rxByte(typename Driver::data_t &byte)
|
||||||
{
|
{
|
||||||
return Driver::rxByte();
|
return Driver::rxByte(byte);
|
||||||
}
|
}
|
||||||
|
|
||||||
static typename Driver::data_t peek()
|
static typename Driver::data_t peek()
|
||||||
|
Loading…
Reference in New Issue
Block a user