Implemented interrupt driven tx
This commit is contained in:
@@ -102,7 +102,7 @@ class Hardware1 {
|
||||
HardwareImpl::init();
|
||||
}
|
||||
|
||||
static void txByte(data_t byte) FORCE_INLINE
|
||||
static void txByte(const data_t &byte) FORCE_INLINE
|
||||
{
|
||||
HardwareImpl::txByteBlocking(byte);
|
||||
}
|
||||
@@ -131,9 +131,16 @@ class Hardware1<mode, cfg, Driven::INTERRUPT> {
|
||||
HardwareImpl::init();
|
||||
}
|
||||
|
||||
static void txByte(data_t byte) FORCE_INLINE
|
||||
static void txByte(const data_t &byte) FORCE_INLINE
|
||||
{
|
||||
HardwareImpl::txByteBlocking(byte);
|
||||
uint8_t tmpHead = (sm_txHead + 1) % TX_BUFFER_SIZE;
|
||||
while (tmpHead == sm_txTail)
|
||||
;
|
||||
|
||||
sm_txBuffer[tmpHead] = byte;
|
||||
sm_txHead = tmpHead;
|
||||
|
||||
HardwareImpl::enableDataRegEmptyInt();
|
||||
}
|
||||
|
||||
static data_t rxByte() FORCE_INLINE {}
|
||||
@@ -144,14 +151,25 @@ class Hardware1<mode, cfg, Driven::INTERRUPT> {
|
||||
using HardwareImpl = detail::Hardware<detail::Registers1, detail::ControlFlagsA1, detail::ControlFlagsB1,
|
||||
detail::ControlFlagsC1, cfg, mode, Driven::INTERRUPT>;
|
||||
|
||||
static constexpr auto TX_BUFFER_SIZE = 16;
|
||||
|
||||
static volatile uint8_t sm_txHead;
|
||||
static volatile uint8_t sm_txTail;
|
||||
static volatile data_t sm_txBuffer[TX_BUFFER_SIZE];
|
||||
|
||||
static void rxIntHandler()
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
|
||||
static void dataRegEmptyIntHandler()
|
||||
static void dataRegEmptyIntHandler() FORCE_INLINE
|
||||
{
|
||||
// TODO
|
||||
if (sm_txHead != sm_txTail) {
|
||||
uint8_t tmpTail = (sm_txTail + 1) % TX_BUFFER_SIZE;
|
||||
sm_txTail = tmpTail;
|
||||
HardwareImpl::txByteInterrupt(sm_txBuffer[tmpTail]);
|
||||
} else
|
||||
HardwareImpl::disableDataRegEmptyInt();
|
||||
}
|
||||
|
||||
static void txIntHandler()
|
||||
@@ -160,6 +178,14 @@ class Hardware1<mode, cfg, Driven::INTERRUPT> {
|
||||
}
|
||||
};
|
||||
|
||||
template <Mode mode, class cfg>
|
||||
volatile uint8_t Hardware1<mode, cfg, Driven::INTERRUPT>::sm_txHead = 0;
|
||||
template <Mode mode, class cfg>
|
||||
volatile uint8_t Hardware1<mode, cfg, Driven::INTERRUPT>::sm_txTail = 0;
|
||||
template <Mode mode, class cfg>
|
||||
volatile typename Hardware1<mode, cfg, Driven::INTERRUPT>::data_t
|
||||
Hardware1<mode, cfg, Driven::INTERRUPT>::sm_txBuffer[TX_BUFFER_SIZE];
|
||||
|
||||
#endif
|
||||
|
||||
} // namespace uart
|
||||
|
||||
Reference in New Issue
Block a user