Added basic structure to support interrupt driven operation

This commit is contained in:
2019-08-02 12:08:16 +02:00
parent a13a1ca9ab
commit 3aeb43ee1e
3 changed files with 152 additions and 7 deletions

View File

@@ -59,6 +59,28 @@ constexpr int operator<<(const int &lhs, const ControlFlagsB0 &rhs) { return lhs
constexpr int operator<<(const int &lhs, const ControlFlagsC0 &rhs) { return lhs << static_cast<int>(rhs); }
// clang-format on
static void (*fnDataReg0EmptyIntHandler)() = nullptr;
static void (*fnRx0IntHandler)() = nullptr;
static void (*fnTx0IntHandler)() = nullptr;
ISR(USART0_UDRE_vect)
{
if (fnDataReg0EmptyIntHandler)
fnDataReg0EmptyIntHandler();
}
ISR(USART0_RX_vect)
{
if (fnRx0IntHandler)
fnRx0IntHandler();
}
ISR(USART0_TX_vect)
{
if (fnTx0IntHandler)
fnTx0IntHandler();
}
#else
#error "This chip is not supported"
#endif
@@ -78,7 +100,7 @@ class Hardware0 {
static void txByte(data_t byte) FORCE_INLINE
{
HardwareImpl::txByte(byte);
HardwareImpl::txByteBlocking(byte);
}
static data_t rxByte() FORCE_INLINE {}
@@ -87,7 +109,51 @@ class Hardware0 {
private:
using HardwareImpl = detail::Hardware<detail::Registers0, detail::ControlFlagsA0, detail::ControlFlagsB0,
detail::ControlFlagsC0, cfg, mode>;
detail::ControlFlagsC0, cfg, mode, driven>;
};
template <Mode mode, class cfg>
class Hardware0<mode, cfg, Driven::INTERRUPT> {
public:
using data_t = typename cfg::data_t;
static constexpr auto DATA_BITS = cfg::DATA_BITS;
static void init() FORCE_INLINE
{
detail::fnDataReg0EmptyIntHandler = dataRegEmptyIntHandler;
detail::fnRx0IntHandler = rxIntHandler;
detail::fnTx0IntHandler = txIntHandler;
HardwareImpl::init();
}
static void txByte(data_t byte) FORCE_INLINE
{
HardwareImpl::txByteBlocking(byte);
}
static data_t rxByte() FORCE_INLINE {}
static data_t peek() FORCE_INLINE {}
private:
using HardwareImpl = detail::Hardware<detail::Registers0, detail::ControlFlagsA0, detail::ControlFlagsB0,
detail::ControlFlagsC0, cfg, mode, Driven::INTERRUPT>;
static void dataRegEmptyIntHandler()
{
// TODO
}
static void rxIntHandler()
{
// TODO
}
static void txIntHandler()
{
// TODO
}
};
} // namespace uart