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