PFW-1428 Enable UART1 receiver when the MMU is ready to process incoming messages
parent
144725ab11
commit
21a3ceb2b2
|
|
@ -66,20 +66,23 @@ public:
|
||||||
/// blocks until the TX buffer was successfully transmitted
|
/// blocks until the TX buffer was successfully transmitted
|
||||||
void Flush();
|
void Flush();
|
||||||
|
|
||||||
|
/// Enable the RX receiver
|
||||||
|
__attribute__((always_inline)) inline void rx_enable() { husart->UCSRxB |= (1 << RXEN1); };
|
||||||
|
|
||||||
/// Initializes USART interface
|
/// Initializes USART interface
|
||||||
__attribute__((always_inline)) inline void Init(USART_InitTypeDef *const conf) {
|
__attribute__((always_inline)) inline void Init(USART_InitTypeDef *const conf) {
|
||||||
gpio::Init(conf->rx_pin, gpio::GPIO_InitTypeDef(gpio::Mode::input, gpio::Level::low));
|
gpio::Init(conf->rx_pin, gpio::GPIO_InitTypeDef(gpio::Mode::input, gpio::Level::low));
|
||||||
gpio::Init(conf->tx_pin, gpio::GPIO_InitTypeDef(gpio::Mode::output, gpio::Level::low));
|
gpio::Init(conf->tx_pin, gpio::GPIO_InitTypeDef(gpio::Mode::output, gpio::Level::low));
|
||||||
husart->UBRRx = UART_BAUD_SELECT(conf->baudrate, F_CPU);
|
husart->UBRRx = UART_BAUD_SELECT(conf->baudrate, F_CPU);
|
||||||
husart->UCSRxA |= (1 << 1); // Set double baudrate setting. Clear all other status bits/flags
|
husart->UCSRxA |= (1 << U2X1); // Set double baudrate setting. Clear all other status bits/flags
|
||||||
// husart->UCSRxC |= (1 << 3); // 2 stop bits. Preserve data size setting
|
// husart->UCSRxC |= (1 << 3); // 2 stop bits. Preserve data size setting
|
||||||
husart->UCSRxD = 0; // disable hardware flow control. Few avr MCUs have this feature, but this register is reserved on all AVR devices with USART, so we can disable it without consequences.
|
husart->UCSRxD = 0; // disable hardware flow control. Few avr MCUs have this feature, but this register is reserved on all AVR devices with USART, so we can disable it without consequences.
|
||||||
husart->UCSRxB = (1 << 3) | (1 << 4) | (1 << 7); // Turn on the transmission and reception circuitry and enable the RX interrupt
|
husart->UCSRxB = (1 << TXEN1) | (1 << RXCIE1); // Turn on the transmission and reception circuitry and enable the RX interrupt
|
||||||
}
|
}
|
||||||
|
|
||||||
/// implementation of the receive ISR's body
|
/// implementation of the receive ISR's body
|
||||||
__attribute__((always_inline)) inline void ISR_RX() {
|
__attribute__((always_inline)) inline void ISR_RX() {
|
||||||
if (husart->UCSRxA & (1 << 4)) {
|
if (husart->UCSRxA & (1 << FE1)) {
|
||||||
(void)husart->UDRx;
|
(void)husart->UDRx;
|
||||||
} else {
|
} else {
|
||||||
rx_buf.push((uint8_t)husart->UDRx);
|
rx_buf.push((uint8_t)husart->UDRx);
|
||||||
|
|
@ -94,10 +97,10 @@ public:
|
||||||
// clear the TXC bit -- "can be cleared by writing a one to its bit
|
// clear the TXC bit -- "can be cleared by writing a one to its bit
|
||||||
// location". This makes sure flush() won't return until the bytes
|
// location". This makes sure flush() won't return until the bytes
|
||||||
// actually got written
|
// actually got written
|
||||||
husart->UCSRxA |= (1 << 6);
|
husart->UCSRxA |= (1 << TXC1);
|
||||||
|
|
||||||
if (tx_buf.empty())
|
if (tx_buf.empty())
|
||||||
husart->UCSRxB &= ~(1 << 5); // disable UDRE interrupt
|
husart->UCSRxB &= ~(1 << UDRIE1); // disable UDRE interrupt
|
||||||
}
|
}
|
||||||
|
|
||||||
USART(USART_TypeDef *husart)
|
USART(USART_TypeDef *husart)
|
||||||
|
|
|
||||||
|
|
@ -123,9 +123,7 @@ static void setup2() {
|
||||||
if (logic::hwSanity.Error() != ErrorCode::OK) {
|
if (logic::hwSanity.Error() != ErrorCode::OK) {
|
||||||
// forward the issue to the logic startup handler.
|
// forward the issue to the logic startup handler.
|
||||||
logic::noCommand.SetInitError(logic::hwSanity.Error());
|
logic::noCommand.SetInitError(logic::hwSanity.Error());
|
||||||
return;
|
} else {
|
||||||
}
|
|
||||||
|
|
||||||
// Idler and Selector decide whether homing is possible/safe
|
// Idler and Selector decide whether homing is possible/safe
|
||||||
mi::idler.Init();
|
mi::idler.Init();
|
||||||
ms::selector.Init();
|
ms::selector.Init();
|
||||||
|
|
@ -136,6 +134,10 @@ static void setup2() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Finally, enable RX receiver to start talking to the printer
|
||||||
|
hu::usart1.rx_enable();
|
||||||
|
}
|
||||||
|
|
||||||
void Panic(ErrorCode ec) {
|
void Panic(ErrorCode ec) {
|
||||||
application.Panic(ec);
|
application.Panic(ec);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue