Skip to content

Remove GOTO from HardWareSerial.cpp #1262

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Remove GOTO from HardWareSerial.cpp #1262

RobTillaart opened this issue Feb 3, 2013 · 1 comment
Milestone

Comments

@RobTillaart
Copy link

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
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: arduino#1262
matthijskooijman added a commit to matthijskooijman/Arduino that referenced this issue Dec 18, 2013
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: arduino#1262
cmaglie pushed a commit to cmaglie/Arduino that referenced this issue Jan 20, 2014
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: arduino#1262
@cmaglie
Copy link
Member

cmaglie commented Jan 28, 2014

Merged for 1.5.6. Thanks!

@cmaglie cmaglie closed this as completed Jan 28, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants