Merge pull request #74 from XPila/MK3

setup second serial port only in case it is selected
This commit is contained in:
XPila 2017-10-24 23:21:43 +02:00 committed by GitHub
commit 5100ead22e
4 changed files with 14489 additions and 25 deletions

View File

@ -9,7 +9,7 @@
// Firmware version // Firmware version
#define FW_version "3.0.12-RC2" #define FW_version "3.0.12-RC2"
#define FW_build 103 #define FW_build 104
#define FW_version_build FW_version " b" STR(FW_build) #define FW_version_build FW_version " b" STR(FW_build)

View File

@ -23,7 +23,7 @@
#include "Marlin.h" #include "Marlin.h"
#include "MarlinSerial.h" #include "MarlinSerial.h"
int selectedSerialPort = 0; uint8_t selectedSerialPort = 0;
#ifndef AT90USB #ifndef AT90USB
// this next line disables the entire HardwareSerial.cpp, // this next line disables the entire HardwareSerial.cpp,
@ -58,23 +58,23 @@ FORCE_INLINE void store_char(unsigned char c)
// Test for a framing error. // Test for a framing error.
if (M_UCSRxA & (1<<M_FEx)) { if (M_UCSRxA & (1<<M_FEx)) {
// Characters received with the framing errors will be ignored. // Characters received with the framing errors will be ignored.
// The temporary variable "c" was made volatile, so the compiler does not optimize this out. // Dummy register read (discard)
volatile unsigned char c = M_UDRx; (void)(*(char *)M_UDRx);
} else { } else {
// Read the input register. // Read the input register.
unsigned char c = M_UDRx; unsigned char c = M_UDRx;
store_char(c); store_char(c);
} }
} }
#ifndef SNMM
SIGNAL(USART2_RX_vect) SIGNAL(USART2_RX_vect)
{ {
if (selectedSerialPort == 1) { if (selectedSerialPort == 1) {
// Test for a framing error. // Test for a framing error.
if (UCSR2A & (1<<FE2)) { if (UCSR2A & (1<<FE2)) {
// Characters received with the framing errors will be ignored. // Characters received with the framing errors will be ignored.
// The temporary variable "c" was made volatile, so the compiler does not optimize this out. // Dummy register read (discard)
volatile unsigned char c = UDR2; (void)(*(char *)UDR2);
} else { } else {
// Read the input register. // Read the input register.
unsigned char c = UDR2; unsigned char c = UDR2;
@ -84,6 +84,7 @@ FORCE_INLINE void store_char(unsigned char c)
} }
} }
#endif #endif
#endif
// Constructors //////////////////////////////////////////////////////////////// // Constructors ////////////////////////////////////////////////////////////////
@ -124,23 +125,26 @@ void MarlinSerial::begin(long baud)
sbi(M_UCSRxB, M_TXENx); sbi(M_UCSRxB, M_TXENx);
sbi(M_UCSRxB, M_RXCIEx); sbi(M_UCSRxB, M_RXCIEx);
#ifndef SNMM
// set up the second serial port
if (useU2X) {
UCSR2A = 1 << U2X2;
baud_setting = (F_CPU / 4 / baud - 1) / 2;
} else {
UCSR2A = 0;
baud_setting = (F_CPU / 8 / baud - 1) / 2;
}
// assign the baud_setting, a.k.a. ubbr (USART Baud Rate Register) if (selectedSerialPort == 1) { //set up also the second serial port
UBRR2H = baud_setting >> 8; if (useU2X) {
UBRR2L = baud_setting; UCSR2A = 1 << U2X2;
baud_setting = (F_CPU / 4 / baud - 1) / 2;
} else {
UCSR2A = 0;
baud_setting = (F_CPU / 8 / baud - 1) / 2;
}
sbi(UCSR2B, RXEN2); // assign the baud_setting, a.k.a. ubbr (USART Baud Rate Register)
sbi(UCSR2B, TXEN2); UBRR2H = baud_setting >> 8;
sbi(UCSR2B, RXCIE2); UBRR2L = baud_setting;
sbi(UCSR2B, RXEN2);
sbi(UCSR2B, TXEN2);
sbi(UCSR2B, RXCIE2);
}
#endif
} }
void MarlinSerial::end() void MarlinSerial::end()
@ -148,10 +152,12 @@ void MarlinSerial::end()
cbi(M_UCSRxB, M_RXENx); cbi(M_UCSRxB, M_RXENx);
cbi(M_UCSRxB, M_TXENx); cbi(M_UCSRxB, M_TXENx);
cbi(M_UCSRxB, M_RXCIEx); cbi(M_UCSRxB, M_RXCIEx);
#ifndef SNMM
cbi(UCSR2B, RXEN2); cbi(UCSR2B, RXEN2);
cbi(UCSR2B, TXEN2); cbi(UCSR2B, TXEN2);
cbi(UCSR2B, RXCIE2); cbi(UCSR2B, RXCIE2);
#endif
} }

View File

@ -73,7 +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; extern uint8_t selectedSerialPort;
struct ring_buffer struct ring_buffer
{ {

File diff suppressed because it is too large Load Diff