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

4.115
Last change on this file since e22af78 was 7fd5e89, checked in by Sebastian Huber <sebastian.huber@…>, on 10/07/14 at 14:28:04

termios: Partially hide rtems_termios_tty

Move interrupt lock to device context and expose only this structure to
the read, write and set attributes device handler. This makes these
device handler independent of the general Termios infrastructure
suitable for direct use in printk() support.

  • 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  struct termios *term,
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  term->c_cflag = (term->c_cflag & ~cbaud_mask) | cbaud;
45}
Note: See TracBrowser for help on using the repository browser.