Expand serial support in DUE/AVR hals exploiting the templated MarlinSerial classes (#11988)

This commit is contained in:
Eduardo José Tagle 2018-10-03 02:47:27 -03:00 committed by Scott Lahteine
parent f6f2246f59
commit d6955f25b2
14 changed files with 661 additions and 558 deletions

View file

@ -79,16 +79,32 @@ typedef int8_t pin_t;
//extern uint8_t MCUSR; //extern uint8_t MCUSR;
#define NUM_SERIAL 1 // Serial ports
#ifdef USBCON #ifdef USBCON
#if ENABLED(BLUETOOTH) #if ENABLED(BLUETOOTH)
#define MYSERIAL0 bluetoothSerial #define MYSERIAL0 bluetoothSerial
#else #else
#define MYSERIAL0 Serial #define MYSERIAL0 Serial
#endif #endif
#define NUM_SERIAL 1
#else #else
#define MYSERIAL0 customizedSerial #if !WITHIN(SERIAL_PORT, -1, 3)
#error "SERIAL_PORT must be from -1 to 3"
#endif
#define MYSERIAL0 customizedSerial1
#ifdef SERIAL_PORT_2
#if !WITHIN(SERIAL_PORT_2, -1, 3)
#error "SERIAL_PORT_2 must be from -1 to 3"
#elif SERIAL_PORT_2 == SERIAL_PORT
#error "SERIAL_PORT_2 must be different than SERIAL_PORT"
#endif
#define NUM_SERIAL 2
#define MYSERIAL1 customizedSerial2
#else
#define NUM_SERIAL 1
#endif
#endif #endif
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------

View file

@ -705,18 +705,37 @@
// Hookup ISR handlers // Hookup ISR handlers
ISR(SERIAL_REGNAME(USART,SERIAL_PORT,_RX_vect)) { ISR(SERIAL_REGNAME(USART,SERIAL_PORT,_RX_vect)) {
MarlinSerial<MarlinSerialCfg>::store_rxd_char(); MarlinSerial<MarlinSerialCfg1>::store_rxd_char();
} }
ISR(SERIAL_REGNAME(USART,SERIAL_PORT,_UDRE_vect)) { ISR(SERIAL_REGNAME(USART,SERIAL_PORT,_UDRE_vect)) {
MarlinSerial<MarlinSerialCfg>::_tx_udr_empty_irq(); MarlinSerial<MarlinSerialCfg1>::_tx_udr_empty_irq();
} }
// Preinstantiate // Preinstantiate
template class MarlinSerial<MarlinSerialCfg>; template class MarlinSerial<MarlinSerialCfg1>;
// Instantiate // Instantiate
MarlinSerial<MarlinSerialCfg> customizedSerial; MarlinSerial<MarlinSerialCfg1> customizedSerial1;
#ifdef SERIAL_PORT_2
// Hookup ISR handlers
ISR(SERIAL_REGNAME(USART,SERIAL_PORT_2,_RX_vect)) {
MarlinSerial<MarlinSerialCfg2>::store_rxd_char();
}
ISR(SERIAL_REGNAME(USART,SERIAL_PORT_2,_UDRE_vect)) {
MarlinSerial<MarlinSerialCfg2>::_tx_udr_empty_irq();
}
// Preinstantiate
template class MarlinSerial<MarlinSerialCfg2>;
// Instantiate
MarlinSerial<MarlinSerialCfg2> customizedSerial2;
#endif
#endif // !USBCON && (UBRRH || UBRR0H || UBRR1H || UBRR2H || UBRR3H) #endif // !USBCON && (UBRRH || UBRR0H || UBRR1H || UBRR2H || UBRR3H)

View file

@ -256,7 +256,7 @@
}; };
// Serial port configuration // Serial port configuration
struct MarlinSerialCfg { struct MarlinSerialCfg1 {
static constexpr int PORT = SERIAL_PORT; static constexpr int PORT = SERIAL_PORT;
static constexpr unsigned int RX_SIZE = RX_BUFFER_SIZE; static constexpr unsigned int RX_SIZE = RX_BUFFER_SIZE;
static constexpr unsigned int TX_SIZE = TX_BUFFER_SIZE; static constexpr unsigned int TX_SIZE = TX_BUFFER_SIZE;
@ -268,7 +268,27 @@
static constexpr bool MAX_RX_QUEUED = bSERIAL_STATS_MAX_RX_QUEUED; static constexpr bool MAX_RX_QUEUED = bSERIAL_STATS_MAX_RX_QUEUED;
}; };
extern MarlinSerial<MarlinSerialCfg> customizedSerial; extern MarlinSerial<MarlinSerialCfg1> customizedSerial1;
#ifdef SERIAL_PORT_2
// Serial port configuration
struct MarlinSerialCfg2 {
static constexpr int PORT = SERIAL_PORT_2;
static constexpr unsigned int RX_SIZE = RX_BUFFER_SIZE;
static constexpr unsigned int TX_SIZE = TX_BUFFER_SIZE;
static constexpr bool XONOFF = bSERIAL_XON_XOFF;
static constexpr bool EMERGENCYPARSER = bEMERGENCY_PARSER;
static constexpr bool DROPPED_RX = bSERIAL_STATS_DROPPED_RX;
static constexpr bool RX_OVERRUNS = bSERIAL_STATS_RX_BUFFER_OVERRUNS;
static constexpr bool RX_FRAMING_ERRORS = bSERIAL_STATS_RX_FRAMING_ERRORS;
static constexpr bool MAX_RX_QUEUED = bSERIAL_STATS_MAX_RX_QUEUED;
};
extern MarlinSerial<MarlinSerialCfg2> customizedSerial2;
#endif
#endif // !USBCON #endif // !USBCON

View file

@ -29,6 +29,7 @@
// Includes // Includes
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
#include "../../inc/MarlinConfig.h"
#include "HAL.h" #include "HAL.h"
#include <Wire.h> #include <Wire.h>

View file

@ -41,9 +41,25 @@
#include "watchdog_Due.h" #include "watchdog_Due.h"
#include "HAL_timers_Due.h" #include "HAL_timers_Due.h"
#define NUM_SERIAL 1 // Serial ports
// Required before the include or compilation fails #if !WITHIN(SERIAL_PORT, -1, 3)
#define MYSERIAL0 customizedSerial #error "SERIAL_PORT must be from -1 to 3"
#endif
// MYSERIAL0 required before MarlinSerial includes!
#define MYSERIAL0 customizedSerial1
#ifdef SERIAL_PORT_2
#if !WITHIN(SERIAL_PORT_2, -1, 3)
#error "SERIAL_PORT_2 must be from -1 to 3"
#elif SERIAL_PORT_2 == SERIAL_PORT
#error "SERIAL_PORT_2 must be different than SERIAL_PORT"
#endif
#define NUM_SERIAL 2
#define MYSERIAL1 customizedSerial2
#else
#define NUM_SERIAL 1
#endif
#include "MarlinSerial_Due.h" #include "MarlinSerial_Due.h"
#include "MarlinSerialUSB_Due.h" #include "MarlinSerialUSB_Due.h"

View file

@ -31,7 +31,7 @@
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
// Includes // Includes
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
#include "../../inc/MarlinConfig.h"
#include "HAL.h" #include "HAL.h"
#include "HAL_timers_Due.h" #include "HAL_timers_Due.h"

View file

@ -32,6 +32,7 @@
*/ */
#ifdef ARDUINO_ARCH_SAM #ifdef ARDUINO_ARCH_SAM
#include "../../inc/MarlinConfig.h"
#include "HAL.h" #include "HAL.h"
#include "InterruptVectors_Due.h" #include "InterruptVectors_Due.h"

View file

@ -285,7 +285,7 @@ void MarlinSerialUSB::printFloat(double number, uint8_t digits) {
} }
// Preinstantiate // Preinstantiate
MarlinSerialUSB customizedSerial; MarlinSerialUSB customizedSerial1;
#endif // SERIAL_PORT == -1 #endif // SERIAL_PORT == -1

View file

@ -89,7 +89,7 @@ private:
static void printFloat(double, uint8_t); static void printFloat(double, uint8_t);
}; };
extern MarlinSerialUSB customizedSerial; extern MarlinSerialUSB customizedSerial1;
#endif // SERIAL_PORT == -1 #endif // SERIAL_PORT == -1
#endif // MARLINSERIAL_DUE_H #endif // MARLINSERIAL_DUE_H

View file

@ -29,30 +29,27 @@
#include "../../inc/MarlinConfig.h" #include "../../inc/MarlinConfig.h"
// If not using the USB port as serial port #include "MarlinSerial_Due.h"
#if SERIAL_PORT >= 0 #include "InterruptVectors_Due.h"
#include "../../Marlin.h"
#include "MarlinSerial_Due.h" template<typename Cfg> typename MarlinSerial<Cfg>::ring_buffer_r MarlinSerial<Cfg>::rx_buffer = { 0 };
#include "InterruptVectors_Due.h" template<typename Cfg> typename MarlinSerial<Cfg>::ring_buffer_t MarlinSerial<Cfg>::tx_buffer = { 0 };
#include "../../Marlin.h" template<typename Cfg> bool MarlinSerial<Cfg>::_written = false;
template<typename Cfg> uint8_t MarlinSerial<Cfg>::xon_xoff_state = MarlinSerial<Cfg>::XON_XOFF_CHAR_SENT | MarlinSerial<Cfg>::XON_CHAR;
template<typename Cfg> uint8_t MarlinSerial<Cfg>::rx_dropped_bytes = 0;
template<typename Cfg> uint8_t MarlinSerial<Cfg>::rx_buffer_overruns = 0;
template<typename Cfg> uint8_t MarlinSerial<Cfg>::rx_framing_errors = 0;
template<typename Cfg> typename MarlinSerial<Cfg>::ring_buffer_pos_t MarlinSerial<Cfg>::rx_max_enqueued = 0;
template<typename Cfg> typename MarlinSerial<Cfg>::ring_buffer_r MarlinSerial<Cfg>::rx_buffer = { 0 }; // A SW memory barrier, to ensure GCC does not overoptimize loops
template<typename Cfg> typename MarlinSerial<Cfg>::ring_buffer_t MarlinSerial<Cfg>::tx_buffer = { 0 }; #define sw_barrier() asm volatile("": : :"memory");
template<typename Cfg> bool MarlinSerial<Cfg>::_written = false;
template<typename Cfg> uint8_t MarlinSerial<Cfg>::xon_xoff_state = MarlinSerial<Cfg>::XON_XOFF_CHAR_SENT | MarlinSerial<Cfg>::XON_CHAR;
template<typename Cfg> uint8_t MarlinSerial<Cfg>::rx_dropped_bytes = 0;
template<typename Cfg> uint8_t MarlinSerial<Cfg>::rx_buffer_overruns = 0;
template<typename Cfg> uint8_t MarlinSerial<Cfg>::rx_framing_errors = 0;
template<typename Cfg> typename MarlinSerial<Cfg>::ring_buffer_pos_t MarlinSerial<Cfg>::rx_max_enqueued = 0;
// A SW memory barrier, to ensure GCC does not overoptimize loops #include "../../feature/emergency_parser.h"
#define sw_barrier() asm volatile("": : :"memory");
#include "../../feature/emergency_parser.h" // (called with RX interrupts disabled)
template<typename Cfg>
// (called with RX interrupts disabled) FORCE_INLINE void MarlinSerial<Cfg>::store_rxd_char() {
template<typename Cfg>
FORCE_INLINE void MarlinSerial<Cfg>::store_rxd_char() {
static EmergencyParser::State emergency_state; // = EP_RESET static EmergencyParser::State emergency_state; // = EP_RESET
@ -178,10 +175,10 @@
// Store the new head value // Store the new head value
rx_buffer.head = h; rx_buffer.head = h;
} }
template<typename Cfg> template<typename Cfg>
FORCE_INLINE void MarlinSerial<Cfg>::_tx_thr_empty_irq(void) { FORCE_INLINE void MarlinSerial<Cfg>::_tx_thr_empty_irq(void) {
if (Cfg::TX_SIZE > 0) { if (Cfg::TX_SIZE > 0) {
// Read positions // Read positions
uint8_t t = tx_buffer.tail; uint8_t t = tx_buffer.tail;
@ -221,10 +218,10 @@
// Disable interrupts if there is nothing to transmit following this byte // Disable interrupts if there is nothing to transmit following this byte
if (h == t) HWUART->UART_IDR = UART_IDR_TXRDY; if (h == t) HWUART->UART_IDR = UART_IDR_TXRDY;
} }
} }
template<typename Cfg> template<typename Cfg>
void MarlinSerial<Cfg>::UART_ISR(void) { void MarlinSerial<Cfg>::UART_ISR(void) {
const uint32_t status = HWUART->UART_SR; const uint32_t status = HWUART->UART_SR;
// Data received? // Data received?
@ -244,11 +241,11 @@
// TODO: error reporting outside ISR // TODO: error reporting outside ISR
HWUART->UART_CR = UART_CR_RSTSTA; HWUART->UART_CR = UART_CR_RSTSTA;
} }
} }
// Public Methods // Public Methods
template<typename Cfg> template<typename Cfg>
void MarlinSerial<Cfg>::begin(const long baud_setting) { void MarlinSerial<Cfg>::begin(const long baud_setting) {
// Disable UART interrupt in NVIC // Disable UART interrupt in NVIC
NVIC_DisableIRQ( HWUART_IRQ ); NVIC_DisableIRQ( HWUART_IRQ );
@ -295,10 +292,10 @@
HWUART->UART_CR = UART_CR_RXEN | UART_CR_TXEN; HWUART->UART_CR = UART_CR_RXEN | UART_CR_TXEN;
if (Cfg::TX_SIZE > 0) _written = false; if (Cfg::TX_SIZE > 0) _written = false;
} }
template<typename Cfg> template<typename Cfg>
void MarlinSerial<Cfg>::end() { void MarlinSerial<Cfg>::end() {
// Disable UART interrupt in NVIC // Disable UART interrupt in NVIC
NVIC_DisableIRQ( HWUART_IRQ ); NVIC_DisableIRQ( HWUART_IRQ );
@ -308,16 +305,16 @@
__ISB(); __ISB();
pmc_disable_periph_clk( HWUART_IRQ_ID ); pmc_disable_periph_clk( HWUART_IRQ_ID );
} }
template<typename Cfg> template<typename Cfg>
int MarlinSerial<Cfg>::peek(void) { int MarlinSerial<Cfg>::peek(void) {
const int v = rx_buffer.head == rx_buffer.tail ? -1 : rx_buffer.buffer[rx_buffer.tail]; const int v = rx_buffer.head == rx_buffer.tail ? -1 : rx_buffer.buffer[rx_buffer.tail];
return v; return v;
} }
template<typename Cfg> template<typename Cfg>
int MarlinSerial<Cfg>::read(void) { int MarlinSerial<Cfg>::read(void) {
const ring_buffer_pos_t h = rx_buffer.head; const ring_buffer_pos_t h = rx_buffer.head;
ring_buffer_pos_t t = rx_buffer.tail; ring_buffer_pos_t t = rx_buffer.tail;
@ -354,16 +351,16 @@
} }
return v; return v;
} }
template<typename Cfg> template<typename Cfg>
typename MarlinSerial<Cfg>::ring_buffer_pos_t MarlinSerial<Cfg>::available(void) { typename MarlinSerial<Cfg>::ring_buffer_pos_t MarlinSerial<Cfg>::available(void) {
const ring_buffer_pos_t h = rx_buffer.head, t = rx_buffer.tail; const ring_buffer_pos_t h = rx_buffer.head, t = rx_buffer.tail;
return (ring_buffer_pos_t)(Cfg::RX_SIZE + h - t) & (Cfg::RX_SIZE - 1); return (ring_buffer_pos_t)(Cfg::RX_SIZE + h - t) & (Cfg::RX_SIZE - 1);
} }
template<typename Cfg> template<typename Cfg>
void MarlinSerial<Cfg>::flush(void) { void MarlinSerial<Cfg>::flush(void) {
rx_buffer.tail = rx_buffer.head; rx_buffer.tail = rx_buffer.head;
if (Cfg::XONOFF) { if (Cfg::XONOFF) {
@ -382,10 +379,10 @@
} }
} }
} }
} }
template<typename Cfg> template<typename Cfg>
void MarlinSerial<Cfg>::write(const uint8_t c) { void MarlinSerial<Cfg>::write(const uint8_t c) {
_written = true; _written = true;
if (Cfg::TX_SIZE == 0) { if (Cfg::TX_SIZE == 0) {
@ -431,10 +428,10 @@
// Enable TX isr - Non atomic, but it will eventually enable TX isr // Enable TX isr - Non atomic, but it will eventually enable TX isr
HWUART->UART_IER = UART_IER_TXRDY; HWUART->UART_IER = UART_IER_TXRDY;
} }
} }
template<typename Cfg> template<typename Cfg>
void MarlinSerial<Cfg>::flushTX(void) { void MarlinSerial<Cfg>::flushTX(void) {
// TX // TX
if (Cfg::TX_SIZE == 0) { if (Cfg::TX_SIZE == 0) {
@ -474,34 +471,34 @@
// At this point nothing is queued anymore (DRIE is disabled) and // At this point nothing is queued anymore (DRIE is disabled) and
// the hardware finished transmission (TXC is set). // the hardware finished transmission (TXC is set).
} }
} }
/** /**
* Imports from print.h * Imports from print.h
*/ */
template<typename Cfg> template<typename Cfg>
void MarlinSerial<Cfg>::print(char c, int base) { void MarlinSerial<Cfg>::print(char c, int base) {
print((long)c, base); print((long)c, base);
} }
template<typename Cfg> template<typename Cfg>
void MarlinSerial<Cfg>::print(unsigned char b, int base) { void MarlinSerial<Cfg>::print(unsigned char b, int base) {
print((unsigned long)b, base); print((unsigned long)b, base);
} }
template<typename Cfg> template<typename Cfg>
void MarlinSerial<Cfg>::print(int n, int base) { void MarlinSerial<Cfg>::print(int n, int base) {
print((long)n, base); print((long)n, base);
} }
template<typename Cfg> template<typename Cfg>
void MarlinSerial<Cfg>::print(unsigned int n, int base) { void MarlinSerial<Cfg>::print(unsigned int n, int base) {
print((unsigned long)n, base); print((unsigned long)n, base);
} }
template<typename Cfg> template<typename Cfg>
void MarlinSerial<Cfg>::print(long n, int base) { void MarlinSerial<Cfg>::print(long n, int base) {
if (base == 0) write(n); if (base == 0) write(n);
else if (base == 10) { else if (base == 10) {
if (n < 0) { print('-'); n = -n; } if (n < 0) { print('-'); n = -n; }
@ -509,82 +506,82 @@
} }
else else
printNumber(n, base); printNumber(n, base);
} }
template<typename Cfg> template<typename Cfg>
void MarlinSerial<Cfg>::print(unsigned long n, int base) { void MarlinSerial<Cfg>::print(unsigned long n, int base) {
if (base == 0) write(n); if (base == 0) write(n);
else printNumber(n, base); else printNumber(n, base);
} }
template<typename Cfg> template<typename Cfg>
void MarlinSerial<Cfg>::print(double n, int digits) { void MarlinSerial<Cfg>::print(double n, int digits) {
printFloat(n, digits); printFloat(n, digits);
} }
template<typename Cfg> template<typename Cfg>
void MarlinSerial<Cfg>::println(void) { void MarlinSerial<Cfg>::println(void) {
print('\r'); print('\r');
print('\n'); print('\n');
} }
template<typename Cfg> template<typename Cfg>
void MarlinSerial<Cfg>::println(const String& s) { void MarlinSerial<Cfg>::println(const String& s) {
print(s); print(s);
println(); println();
} }
template<typename Cfg> template<typename Cfg>
void MarlinSerial<Cfg>::println(const char c[]) { void MarlinSerial<Cfg>::println(const char c[]) {
print(c); print(c);
println(); println();
} }
template<typename Cfg> template<typename Cfg>
void MarlinSerial<Cfg>::println(char c, int base) { void MarlinSerial<Cfg>::println(char c, int base) {
print(c, base); print(c, base);
println(); println();
} }
template<typename Cfg> template<typename Cfg>
void MarlinSerial<Cfg>::println(unsigned char b, int base) { void MarlinSerial<Cfg>::println(unsigned char b, int base) {
print(b, base); print(b, base);
println(); println();
} }
template<typename Cfg> template<typename Cfg>
void MarlinSerial<Cfg>::println(int n, int base) { void MarlinSerial<Cfg>::println(int n, int base) {
print(n, base); print(n, base);
println(); println();
} }
template<typename Cfg> template<typename Cfg>
void MarlinSerial<Cfg>::println(unsigned int n, int base) { void MarlinSerial<Cfg>::println(unsigned int n, int base) {
print(n, base); print(n, base);
println(); println();
} }
template<typename Cfg> template<typename Cfg>
void MarlinSerial<Cfg>::println(long n, int base) { void MarlinSerial<Cfg>::println(long n, int base) {
print(n, base); print(n, base);
println(); println();
} }
template<typename Cfg> template<typename Cfg>
void MarlinSerial<Cfg>::println(unsigned long n, int base) { void MarlinSerial<Cfg>::println(unsigned long n, int base) {
print(n, base); print(n, base);
println(); println();
} }
template<typename Cfg> template<typename Cfg>
void MarlinSerial<Cfg>::println(double n, int digits) { void MarlinSerial<Cfg>::println(double n, int digits) {
print(n, digits); print(n, digits);
println(); println();
} }
// Private Methods // Private Methods
template<typename Cfg> template<typename Cfg>
void MarlinSerial<Cfg>::printNumber(unsigned long n, uint8_t base) { void MarlinSerial<Cfg>::printNumber(unsigned long n, uint8_t base) {
if (n) { if (n) {
unsigned char buf[8 * sizeof(long)]; // Enough space for base 2 unsigned char buf[8 * sizeof(long)]; // Enough space for base 2
int8_t i = 0; int8_t i = 0;
@ -597,10 +594,10 @@
} }
else else
print('0'); print('0');
} }
template<typename Cfg> template<typename Cfg>
void MarlinSerial<Cfg>::printFloat(double number, uint8_t digits) { void MarlinSerial<Cfg>::printFloat(double number, uint8_t digits) {
// Handle negative numbers // Handle negative numbers
if (number < 0.0) { if (number < 0.0) {
print('-'); print('-');
@ -628,13 +625,26 @@
remainder -= toPrint; remainder -= toPrint;
} }
} }
} }
// If not using the USB port as serial port
#if SERIAL_PORT >= 0
// Preinstantiate // Preinstantiate
template class MarlinSerial<MarlinSerialCfg>; template class MarlinSerial<MarlinSerialCfg1>;
// Instantiate // Instantiate
MarlinSerial<MarlinSerialCfg> customizedSerial; MarlinSerial<MarlinSerialCfg1> customizedSerial1;
#endif
#ifdef SERIAL_PORT_2
// Preinstantiate
template class MarlinSerial<MarlinSerialCfg2>;
// Instantiate
MarlinSerial<MarlinSerialCfg2> customizedSerial2;
#endif #endif

View file

@ -31,8 +31,6 @@
#include "../shared/MarlinSerial.h" #include "../shared/MarlinSerial.h"
#if SERIAL_PORT >= 0
#include <WString.h> #include <WString.h>
#define DEC 10 #define DEC 10
@ -161,8 +159,10 @@ private:
static void printFloat(double, uint8_t); static void printFloat(double, uint8_t);
}; };
// Serial port configuration #if SERIAL_PORT >= 0
struct MarlinSerialCfg {
// Serial port configuration
struct MarlinSerialCfg1 {
static constexpr int PORT = SERIAL_PORT; static constexpr int PORT = SERIAL_PORT;
static constexpr unsigned int RX_SIZE = RX_BUFFER_SIZE; static constexpr unsigned int RX_SIZE = RX_BUFFER_SIZE;
static constexpr unsigned int TX_SIZE = TX_BUFFER_SIZE; static constexpr unsigned int TX_SIZE = TX_BUFFER_SIZE;
@ -172,10 +172,29 @@ struct MarlinSerialCfg {
static constexpr bool RX_OVERRUNS = bSERIAL_STATS_RX_BUFFER_OVERRUNS; static constexpr bool RX_OVERRUNS = bSERIAL_STATS_RX_BUFFER_OVERRUNS;
static constexpr bool RX_FRAMING_ERRORS = bSERIAL_STATS_RX_FRAMING_ERRORS; static constexpr bool RX_FRAMING_ERRORS = bSERIAL_STATS_RX_FRAMING_ERRORS;
static constexpr bool MAX_RX_QUEUED = bSERIAL_STATS_MAX_RX_QUEUED; static constexpr bool MAX_RX_QUEUED = bSERIAL_STATS_MAX_RX_QUEUED;
}; };
extern MarlinSerial<MarlinSerialCfg> customizedSerial; extern MarlinSerial<MarlinSerialCfg1> customizedSerial1;
#endif // SERIAL_PORT >= 0 #endif // SERIAL_PORT >= 0
#ifdef SERIAL_PORT_2
// Serial port configuration
struct MarlinSerialCfg2 {
static constexpr int PORT = SERIAL_PORT_2;
static constexpr unsigned int RX_SIZE = RX_BUFFER_SIZE;
static constexpr unsigned int TX_SIZE = TX_BUFFER_SIZE;
static constexpr bool XONOFF = bSERIAL_XON_XOFF;
static constexpr bool EMERGENCYPARSER = bEMERGENCY_PARSER;
static constexpr bool DROPPED_RX = bSERIAL_STATS_DROPPED_RX;
static constexpr bool RX_OVERRUNS = bSERIAL_STATS_RX_BUFFER_OVERRUNS;
static constexpr bool RX_FRAMING_ERRORS = bSERIAL_STATS_RX_FRAMING_ERRORS;
static constexpr bool MAX_RX_QUEUED = bSERIAL_STATS_MAX_RX_QUEUED;
};
extern MarlinSerial<MarlinSerialCfg2> customizedSerial2;
#endif
#endif // MARLINSERIAL_DUE_H #endif // MARLINSERIAL_DUE_H

View file

@ -27,6 +27,7 @@
#ifdef ARDUINO_ARCH_SAM #ifdef ARDUINO_ARCH_SAM
#include "../../inc/MarlinConfig.h"
#include "HAL.h" #include "HAL.h"
#include "HAL_timers_Due.h" #include "HAL_timers_Due.h"

View file

@ -60,19 +60,19 @@ void GcodeSuite::M111() {
SERIAL_ECHOPGM(MSG_DEBUG_OFF); SERIAL_ECHOPGM(MSG_DEBUG_OFF);
#if !defined(__AVR__) || !defined(USBCON) #if !defined(__AVR__) || !defined(USBCON)
#if ENABLED(SERIAL_STATS_RX_BUFFER_OVERRUNS) #if ENABLED(SERIAL_STATS_RX_BUFFER_OVERRUNS)
SERIAL_ECHOPAIR("\nBuffer Overruns: ", customizedSerial.buffer_overruns()); SERIAL_ECHOPAIR("\nBuffer Overruns: ", MYSERIAL0.buffer_overruns());
#endif #endif
#if ENABLED(SERIAL_STATS_RX_FRAMING_ERRORS) #if ENABLED(SERIAL_STATS_RX_FRAMING_ERRORS)
SERIAL_ECHOPAIR("\nFraming Errors: ", customizedSerial.framing_errors()); SERIAL_ECHOPAIR("\nFraming Errors: ", MYSERIAL0.framing_errors());
#endif #endif
#if ENABLED(SERIAL_STATS_DROPPED_RX) #if ENABLED(SERIAL_STATS_DROPPED_RX)
SERIAL_ECHOPAIR("\nDropped bytes: ", customizedSerial.dropped()); SERIAL_ECHOPAIR("\nDropped bytes: ", MYSERIAL0.dropped());
#endif #endif
#if ENABLED(SERIAL_STATS_MAX_RX_QUEUED) #if ENABLED(SERIAL_STATS_MAX_RX_QUEUED)
SERIAL_ECHOPAIR("\nMax RX Queue Size: ", customizedSerial.rxMaxEnqueued()); SERIAL_ECHOPAIR("\nMax RX Queue Size: ", MYSERIAL0.rxMaxEnqueued());
#endif #endif
#endif // !defined(__AVR__) || !defined(USBCON) #endif // !defined(__AVR__) || !defined(USBCON)
} }

View file

@ -562,11 +562,11 @@ void advance_command_queue() {
#if !defined(__AVR__) || !defined(USBCON) #if !defined(__AVR__) || !defined(USBCON)
#if ENABLED(SERIAL_STATS_DROPPED_RX) #if ENABLED(SERIAL_STATS_DROPPED_RX)
SERIAL_ECHOLNPAIR("Dropped bytes: ", customizedSerial.dropped()); SERIAL_ECHOLNPAIR("Dropped bytes: ", MYSERIAL0.dropped());
#endif #endif
#if ENABLED(SERIAL_STATS_MAX_RX_QUEUED) #if ENABLED(SERIAL_STATS_MAX_RX_QUEUED)
SERIAL_ECHOLNPAIR("Max RX Queue Size: ", customizedSerial.rxMaxEnqueued()); SERIAL_ECHOLNPAIR("Max RX Queue Size: ", MYSERIAL0.rxMaxEnqueued());
#endif #endif
#endif // !defined(__AVR__) || !defined(USBCON) #endif // !defined(__AVR__) || !defined(USBCON)