source: rtems/cpukit/libcsupport/src/termios_setbestbaud.c @ a830cb8

4.115
Last change on this file since a830cb8 was 93726e5, checked in by Sebastian Huber <sebastian.huber@…>, on 07/09/14 at 13:44:13

termios: Add rtems_termios_set_best_baud()

  • Property mode set to 100644
File size: 1.0 KB
Line 
1/*
2 * Copyright (c) 2014 embedded brains GmbH.  All rights reserved.
3 *
4 *  embedded brains GmbH
5 *  Dornierstr. 4
6 *  82178 Puchheim
7 *  Germany
8 *  <rtems@embedded-brains.de>
9 *
10 * The license and distribution terms for this file may be
11 * found in the file LICENSE in this distribution or at
12 * http://www.rtems.org/license/LICENSE.
13 */
14
15#if HAVE_CONFIG_H
16  #include "config.h"
17#endif
18
19#include <rtems/termiostypes.h>
20
21void rtems_termios_set_best_baud(
22  rtems_termios_tty *tty,
23  uint32_t           baud
24)
25{
26  const rtems_assoc_t *current = &rtems_termios_baud_table[ 0 ];
27  const rtems_assoc_t *last = current;
28  tcflag_t cbaud_mask = CBAUD;
29  tcflag_t cbaud;
30
31  while ( current->name != NULL && current->local_value < baud ) {
32    last = current;
33    ++current;
34  }
35
36  if ( current->name != NULL ) {
37    uint32_t mid = (last->local_value + current->local_value) / UINT32_C( 2 );
38
39    cbaud = baud <= mid ? last->remote_value : current->remote_value;
40  } else {
41    cbaud = B460800;
42  }
43
44  tty->termios.c_cflag = (tty->termios.c_cflag & ~cbaud_mask) | cbaud;
45}
Note: See TracBrowser for help on using the repository browser.