removed unecessary indirect register adressing in serial.

This commit is contained in:
Bernhard 2011-11-28 19:28:38 +01:00
parent dd5ca68c87
commit b9ad0bb2ce
2 changed files with 20 additions and 47 deletions

View file

@ -75,22 +75,9 @@ inline void store_char(unsigned char c)
// Constructors //////////////////////////////////////////////////////////////// // Constructors ////////////////////////////////////////////////////////////////
MarlinSerial::MarlinSerial( MarlinSerial::MarlinSerial()
volatile uint8_t *ubrrh, volatile uint8_t *ubrrl,
volatile uint8_t *ucsra, volatile uint8_t *ucsrb,
volatile uint8_t *udr,
uint8_t rxen, uint8_t txen, uint8_t rxcie, uint8_t udre, uint8_t u2x)
{ {
_ubrrh = ubrrh;
_ubrrl = ubrrl;
_ucsra = ucsra;
_ucsrb = ucsrb;
_udr = udr;
_rxen = rxen;
_txen = txen;
_rxcie = rxcie;
_udre = udre;
_u2x = u2x;
} }
// Public Methods ////////////////////////////////////////////////////////////// // Public Methods //////////////////////////////////////////////////////////////
@ -98,39 +85,39 @@ MarlinSerial::MarlinSerial(
void MarlinSerial::begin(long baud) void MarlinSerial::begin(long baud)
{ {
uint16_t baud_setting; uint16_t baud_setting;
bool use_u2x = true; bool useU2X0 = true;
#if F_CPU == 16000000UL #if F_CPU == 16000000UL
// hardcoded exception for compatibility with the bootloader shipped // hardcoded exception for compatibility with the bootloader shipped
// with the Duemilanove and previous boards and the firmware on the 8U2 // with the Duemilanove and previous boards and the firmware on the 8U2
// on the Uno and Mega 2560. // on the Uno and Mega 2560.
if (baud == 57600) { if (baud == 57600) {
use_u2x = false; useU2X0 = false;
} }
#endif #endif
if (use_u2x) { if (useU2X0) {
*_ucsra = 1 << _u2x; UCSR0A = 1 << U2X0;
baud_setting = (F_CPU / 4 / baud - 1) / 2; baud_setting = (F_CPU / 4 / baud - 1) / 2;
} else { } else {
*_ucsra = 0; UCSR0A = 0;
baud_setting = (F_CPU / 8 / baud - 1) / 2; baud_setting = (F_CPU / 8 / baud - 1) / 2;
} }
// assign the baud_setting, a.k.a. ubbr (USART Baud Rate Register) // assign the baud_setting, a.k.a. ubbr (USART Baud Rate Register)
*_ubrrh = baud_setting >> 8; UBRR0H = baud_setting >> 8;
*_ubrrl = baud_setting; UBRR0L = baud_setting;
sbi(*_ucsrb, _rxen); sbi(UCSR0B, RXEN0);
sbi(*_ucsrb, _txen); sbi(UCSR0B, TXEN0);
sbi(*_ucsrb, _rxcie); sbi(UCSR0B, RXCIE0);
} }
void MarlinSerial::end() void MarlinSerial::end()
{ {
cbi(*_ucsrb, _rxen); cbi(UCSR0B, RXEN0);
cbi(*_ucsrb, _txen); cbi(UCSR0B, TXEN0);
cbi(*_ucsrb, _rxcie); cbi(UCSR0B, RXCIE0);
} }
@ -367,7 +354,7 @@ void MarlinSerial::printFloat(double number, uint8_t digits)
// Preinstantiate Objects ////////////////////////////////////////////////////// // Preinstantiate Objects //////////////////////////////////////////////////////
#if defined(UBRR0H) && defined(UBRR0L) #if defined(UBRR0H) && defined(UBRR0L)
MarlinSerial MSerial( &UBRR0H, &UBRR0L, &UCSR0A, &UCSR0B, &UDR0, RXEN0, TXEN0, RXCIE0, UDRE0, U2X0); MarlinSerial MSerial;
#else #else
#error no serial port defined (port 0) #error no serial port defined (port 0)
#endif #endif

View file

@ -46,23 +46,9 @@ struct ring_buffer
class MarlinSerial //: public Stream class MarlinSerial //: public Stream
{ {
private:
volatile uint8_t *_ubrrh;
volatile uint8_t *_ubrrl;
volatile uint8_t *_ucsra;
volatile uint8_t *_ucsrb;
volatile uint8_t *_udr;
uint8_t _rxen;
uint8_t _txen;
uint8_t _rxcie;
uint8_t _udre;
uint8_t _u2x;
public: public:
MarlinSerial( MarlinSerial();
volatile uint8_t *ubrrh, volatile uint8_t *ubrrl,
volatile uint8_t *ucsra, volatile uint8_t *ucsrb,
volatile uint8_t *udr,
uint8_t rxen, uint8_t txen, uint8_t rxcie, uint8_t udre, uint8_t u2x);
void begin(long); void begin(long);
void end(); void end();
inline int available(void) inline int available(void)
@ -74,10 +60,10 @@ class MarlinSerial //: public Stream
void flush(void); void flush(void);
inline void write(uint8_t c) inline void write(uint8_t c)
{ {
while (!((*_ucsra) & (1 << _udre))) while (!((UCSR0A) & (1 << UDRE0)))
; ;
*_udr = c; UDR0 = c;
} }