Skip to content

Remove GOTO from HardWareSerial.cpp #1262

Closed
@RobTillaart

Description

@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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions