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)
Tue, Nov 19, 8:23 PM
Unknown Object (File)
Thu, Nov 7, 8:46 AM
Unknown Object (File)
Oct 4 2024, 1:22 AM
Unknown Object (File)
Sep 17 2024, 6:10 PM
Unknown Object (File)
Sep 14 2024, 12:41 AM
Unknown Object (File)
Sep 12 2024, 6:30 AM
Unknown Object (File)
Sep 8 2024, 8:37 AM
Unknown Object (File)
Sep 8 2024, 7:51 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.