Page MenuHomeFreeBSD

Correct baud rate error calculation.
ClosedPublic

Authored by jhb on Apr 10 2020, 4:25 PM.
Tags
None
Referenced Files
Unknown Object (File)
Jan 23 2024, 8:34 PM
Unknown Object (File)
Dec 29 2023, 1:43 PM
Unknown Object (File)
Dec 20 2023, 4:36 AM
Unknown Object (File)
Dec 2 2023, 7:56 PM
Unknown Object (File)
Oct 5 2023, 6:47 PM
Unknown Object (File)
Sep 6 2023, 8:42 AM
Unknown Object (File)
Aug 30 2023, 3:52 AM
Unknown Object (File)
Aug 30 2023, 3:50 AM
Subscribers
None

Details

Summary

Shifting right by 1 is not the same as dividing by 2 for signed
values. In particular, dividing a signed value by 2 gives the integer
ceiling of the (e.g. -5 / 2 == -2) whereas shifting right by 1 always
gives the floor (-5 >> 1 == -3).

An embedded board with a 25 Mhz base clock results in an error of
-30.5% when used with a baud rate of 115200. Using division, this
truncates to -30% and is permitted. Using the shift, this fails and
is rejected causing TIOCSETA requests to fail with EINVAL and breaking
getty(8).

Using division gives the same error range for both over and under baud
rates and also makes the code match the behavior documented in the
existing comment about supporting boards with 25 Mhz clocks.

Test Plan
  • boot FreeBSD on an FPGA platform whose uart uses a 25 Mhz base clock with a uart configured for 115200. Previously getty would fail on ttyu0. With the patch it works.

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

Not performance critical... so go for it.

This revision is now accepted and ready to land.Apr 10 2020, 6:40 PM
This revision was automatically updated to reflect the committed changes.