|
@@ -73,6 +73,7 @@
|
|
// is the index of the location from which to read.
|
|
// is the index of the location from which to read.
|
|
#define RX_BUFFER_SIZE 128
|
|
#define RX_BUFFER_SIZE 128
|
|
|
|
|
|
|
|
+extern int selectedSerialPort;
|
|
|
|
|
|
struct ring_buffer
|
|
struct ring_buffer
|
|
{
|
|
{
|
|
@@ -110,24 +111,48 @@ class MarlinSerial //: public Stream
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
- FORCE_INLINE void checkRx(void)
|
|
+ void checkRx(void)
|
|
{
|
|
{
|
|
- if((M_UCSRxA & (1<<M_RXCx)) != 0) {
|
|
+ if (selectedSerialPort == 0) {
|
|
- // Test for a framing error.
|
|
+ if((M_UCSRxA & (1<<M_RXCx)) != 0) {
|
|
- if (M_UCSRxA & (1<<M_FEx)) {
|
|
+ // Test for a framing error.
|
|
- // Characters received with the framing errors will be ignored.
|
|
+ if (M_UCSRxA & (1<<M_FEx)) {
|
|
- // The temporary variable "c" was made volatile, so the compiler does not optimize this out.
|
|
+ // Characters received with the framing errors will be ignored.
|
|
- volatile unsigned char c = M_UDRx;
|
|
+ // The temporary variable "c" was made volatile, so the compiler does not optimize this out.
|
|
- } else {
|
|
+ volatile unsigned char c = M_UDRx;
|
|
- unsigned char c = M_UDRx;
|
|
+ } else {
|
|
- int i = (unsigned int)(rx_buffer.head + 1) % RX_BUFFER_SIZE;
|
|
+ unsigned char c = M_UDRx;
|
|
- // if we should be storing the received character into the location
|
|
+ int i = (unsigned int)(rx_buffer.head + 1) % RX_BUFFER_SIZE;
|
|
- // just before the tail (meaning that the head would advance to the
|
|
+ // if we should be storing the received character into the location
|
|
- // current location of the tail), we're about to overflow the buffer
|
|
+ // just before the tail (meaning that the head would advance to the
|
|
- // and so we don't write the character or advance the head.
|
|
+ // current location of the tail), we're about to overflow the buffer
|
|
- if (i != rx_buffer.tail) {
|
|
+ // and so we don't write the character or advance the head.
|
|
- rx_buffer.buffer[rx_buffer.head] = c;
|
|
+ if (i != rx_buffer.tail) {
|
|
- rx_buffer.head = i;
|
|
+ rx_buffer.buffer[rx_buffer.head] = c;
|
|
|
|
+ rx_buffer.head = i;
|
|
|
|
+ }
|
|
|
|
+ selectedSerialPort = 0;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } else if(selectedSerialPort == 1) {
|
|
|
|
+ if((UCSR2A & (1<<RXC2)) != 0) {
|
|
|
|
+ // Test for a framing error.
|
|
|
|
+ if (UCSR2A & (1<<FE2)) {
|
|
|
|
+ // Characters received with the framing errors will be ignored.
|
|
|
|
+ // The temporary variable "c" was made volatile, so the compiler does not optimize this out.
|
|
|
|
+ volatile unsigned char c = UDR2;
|
|
|
|
+ } else {
|
|
|
|
+ unsigned char c = UDR2;
|
|
|
|
+ int i = (unsigned int)(rx_buffer.head + 1) % RX_BUFFER_SIZE;
|
|
|
|
+ // if we should be storing the received character into the location
|
|
|
|
+ // just before the tail (meaning that the head would advance to the
|
|
|
|
+ // current location of the tail), we're about to overflow the buffer
|
|
|
|
+ // and so we don't write the character or advance the head.
|
|
|
|
+ if (i != rx_buffer.tail) {
|
|
|
|
+ rx_buffer.buffer[rx_buffer.head] = c;
|
|
|
|
+ rx_buffer.head = i;
|
|
|
|
+ }
|
|
|
|
+ selectedSerialPort = 1;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|