Remove GOTO from HardWareSerial.cpp #1262

Closed
RobTillaart opened this Issue Feb 3, 2013 · 1 comment

Comments

2 participants
@RobTillaart

The code for HardwareSerial.cpp contains a goto statement which is not needed by rewriting the code.
This GOTO is in void HardwareSerial::begin(unsigned long baud)

proposed alternative :

void HardwareSerial::begin(unsigned long baud)
{
  *_ucsra = 1 << _u2x;
  uint16_t baud_setting = (F_CPU / 4 / baud - 1) / 2;

  // hardcoded exception for compatibility with the bootloader shipped
  // with the Duemilanove and previous boards and the firmware on the 8U2
  // on the Uno and Mega 2560.
  if (((F_CPU == 16000000UL) && (baud == 57600)) || (baud_setting >4095))
  {
    *_ucsra = 0;
    baud_setting = (F_CPU / 8 / baud - 1) / 2;
  }

  // assign the baud_setting, a.k.a. ubbr (USART Baud Rate Register)
  *_ubrrh = baud_setting >> 8;
  *_ubrrl = baud_setting;

  transmitting = false;

  sbi(*_ucsrb, _rxen);
  sbi(*_ucsrb, _txen);
  sbi(*_ucsrb, _rxcie);
  cbi(*_ucsrb, _udrie);
}

idem for - void HardwareSerial::begin(unsigned long baud, byte config) -

Detailed discussion see - http://arduino.cc/forum/index.php/topic,146683.0.html

matthijskooijman added a commit to matthijskooijman/Arduino that referenced this issue Apr 19, 2013

Simplify HardwareSerial::begin()
This simplifies the baud rate calculation, removing the need for a goto
and shortening the code a bit. Other than that, this code should not use
any different settings than before.

Code was suggested by Rob Tillaart on github.

Closes: #1262

matthijskooijman added a commit to matthijskooijman/Arduino that referenced this issue Dec 18, 2013

Simplify HardwareSerial::begin()
This simplifies the baud rate calculation, removing the need for a goto
and shortening the code a bit. Other than that, this code should not use
any different settings than before.

Code was suggested by Rob Tillaart on github.

Closes: #1262

cmaglie added a commit to cmaglie/Arduino that referenced this issue Jan 20, 2014

Simplify HardwareSerial::begin()
This simplifies the baud rate calculation, removing the need for a goto
and shortening the code a bit. Other than that, this code should not use
any different settings than before.

Code was suggested by Rob Tillaart on github.

Closes: #1262
@cmaglie

This comment has been minimized.

Show comment
Hide comment
@cmaglie

cmaglie Jan 28, 2014

Member

Merged for 1.5.6. Thanks!

Member

cmaglie commented Jan 28, 2014

Merged for 1.5.6. Thanks!

@cmaglie cmaglie closed this Jan 28, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment