Fixed blocking on full rx buffer and implemented support for ATmega328P

This commit is contained in:
BlackMark 2019-08-14 18:58:21 +02:00
parent 8d028aa635
commit e326e40b38
5 changed files with 18 additions and 9 deletions

View File

@ -220,7 +220,7 @@ class Hardware {
uint8_t interruptVal = 0; uint8_t interruptVal = 0;
if (driven == Driven::INTERRUPT) if (driven == Driven::INTERRUPT)
interruptVal |= (1 << CtrlFlagsB::DATA_REG_EMPTY_INT_ENABLE) | (1 << CtrlFlagsB::RX_INT_ENABLE); interruptVal = (1 << CtrlFlagsB::RX_INT_ENABLE);
return interruptVal; return interruptVal;
} }

View File

@ -5,7 +5,12 @@
namespace uart { namespace uart {
namespace detail { namespace detail {
#if defined(__AVR_ATmega1284P__) #if defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega328P__)
#if defined(__AVR_ATmega328P__)
#define USART0_RX_vect USART_RX_vect
#define USART0_UDRE_vect USART_UDRE_vect
#endif
void (*fnRx0IntHandler)() = nullptr; void (*fnRx0IntHandler)() = nullptr;
void (*fnDataReg0EmptyIntHandler)() = nullptr; void (*fnDataReg0EmptyIntHandler)() = nullptr;

View File

@ -15,7 +15,7 @@ namespace uart {
namespace detail { namespace detail {
#if defined(__AVR_ATmega1284P__) #if defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega328P__)
/* /*
The following works in avr-gcc 5.4.0, but is not legal C++, because ptr's are not legal constexpr's The following works in avr-gcc 5.4.0, but is not legal C++, because ptr's are not legal constexpr's
@ -213,11 +213,15 @@ class Hardware0<cfg, Driven::INTERRUPT, mode> {
static void rxIntHandler() static void rxIntHandler()
{ {
auto data = HardwareImpl::rxByteInterrupt();
uint8_t tmpHead = (sm_rxBuf.head + 1) % RX_BUFFER_SIZE; uint8_t tmpHead = (sm_rxBuf.head + 1) % RX_BUFFER_SIZE;
if (tmpHead != sm_rxBuf.tail) { if (tmpHead != sm_rxBuf.tail) {
sm_rxBuf.head = tmpHead; sm_rxBuf.head = tmpHead;
sm_rxBuf.buf[tmpHead] = HardwareImpl::rxByteInterrupt(); sm_rxBuf.buf[tmpHead] = data;
} else {
// TODO: Handle overflow
} }
} }

View File

@ -22,8 +22,6 @@ ISR(USART1_UDRE_vect)
fnDataReg1EmptyIntHandler(); fnDataReg1EmptyIntHandler();
} }
#else
#error "This chip is not supported"
#endif #endif
} // namespace detail } // namespace detail

View File

@ -84,8 +84,6 @@ extern void (*fnDataReg1EmptyIntHandler)();
#define HAS_UART1 #define HAS_UART1
#else
#error "This chip is not supported"
#endif #endif
} // namespace detail } // namespace detail
@ -217,11 +215,15 @@ class Hardware1<cfg, Driven::INTERRUPT, mode> {
static void rxIntHandler() static void rxIntHandler()
{ {
auto data = HardwareImpl::rxByteInterrupt();
uint8_t tmpHead = (sm_rxBuf.head + 1) % RX_BUFFER_SIZE; uint8_t tmpHead = (sm_rxBuf.head + 1) % RX_BUFFER_SIZE;
if (tmpHead != sm_rxBuf.tail) { if (tmpHead != sm_rxBuf.tail) {
sm_rxBuf.head = tmpHead; sm_rxBuf.head = tmpHead;
sm_rxBuf.buf[tmpHead] = HardwareImpl::rxByteInterrupt(); sm_rxBuf.buf[tmpHead] = data;
} else {
// TODO: Handle overflow
} }
} }