RTEMS | Termios: cannot set all baud rates with `rtems_termios_set_best_baud()` (#5162)

Felix Passenberg (@fp) gitlab at rtems.org
Thu Nov 21 16:37:00 UTC 2024



Felix Passenberg created an issue: https://gitlab.rtems.org/rtems/rtos/rtems/-/issues/5162



## Summary
<!--
rtems_termios_set_best_baud() cannot set all Baudrates, because `rtems_termios_baud_table` is unsorted.
-->


## Steps to reproduce
https://gitlab.rtems.org/rtems/rtos/rtems/-/blob/main/cpukit/libcsupport/src/termios_baudtable.c?ref_type=heads
https://gitlab.rtems.org/rtems/rtos/rtems/-/blob/main/cpukit/libcsupport/src/termios_setbestbaud.c?ref_type=heads#L43

The algorithm in `rtems_termios_set_best_baud()` successively iterates over the elements of the `rtems_termios_baud_table` and searches for a fitting baud rate (checking by "is element lower than the `baud` parameter, then checks the next element, ...). 

The table of baud rates is not sorted correctly from a certain point on, therefore the algorithm for choosing the optimal baud rate does not work for every baud rate.

e.g. if the input is `7200` (which is in the table) the search terminates at `9600` as that is larger, the last entry was `4800`, so in the check it sets it to either of those, but not the `7200`.

We observed it when we entered `38401` (due to measurement errors on the hardware was a bit larger).
We identified the search ending at `57600` and it ended using the `last = 28800`.


### Pre-set options

-- 
View it on GitLab: https://gitlab.rtems.org/rtems/rtos/rtems/-/issues/5162
You're receiving this email because of your account on gitlab.rtems.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rtems.org/pipermail/bugs/attachments/20241121/5981b3b5/attachment-0001.htm>


More information about the bugs mailing list