libcsdbg  1.28
C++ exception (and generic) stack trace debug library
sttybuf & csdbg::sttybuf::config ( ) const
protectedvirtual

Configure the serial interface.

Returns
*this
Exceptions
csdbg::exception

Definition at line 22 of file sttybuf.cpp.

References __D_ASSERT, discard(), m_baud, m_devnode, csdbg::streambuf::m_handle, csdbg::util::memset(), translate_baud(), and unlikely.

Referenced by open(), and set_baud().

23 {
24  __D_ASSERT(m_handle >= 0);
25  if ( unlikely(m_handle < 0) )
26  return const_cast<sttybuf&> (*this);
27 
28  u32 real_baud = translate_baud(m_baud);
29 
30  struct termios conf;
31  util::memset(&conf, 0, sizeof(struct termios));
32  conf.c_cflag = real_baud | CS8 | CRTSCTS | CREAD | CLOCAL;
33  conf.c_iflag = IGNPAR;
34  conf.c_cc[VMIN] = 1;
35 
36  i32 retval;
37  do {
38  retval = tcsetattr(m_handle, TCSANOW, &conf);
39  }
40  while ( unlikely(retval < 0 && errno == EINTR) );
41 
42  if ( unlikely(retval < 0) )
43  throw exception(
44  "failed to configure serial interface '%s' (errno %d - %s)",
45  m_devnode,
46  errno,
47  strerror(errno)
48  );
49 
50  /* Discard all pending data */
51  return discard();
52 }
u32 m_baud
Baud rate.
Definition: sttybuf.hpp:36
sttybuf(const i8 *, u32=9600)
Object constructor.
Definition: sttybuf.cpp:67
static u32 translate_baud(u32)
Translate a number to a baud rate as defined in termios.h.
Definition: sttybuf.cpp:390
static void * memset(void *, u8, u32)
Fill a memory block with a constant byte.
Definition: util.cpp:320
i32 m_handle
Stream handle (descriptor)
Definition: streambuf.hpp:43
virtual sttybuf & discard() const
Discard the data cached in the serial interface (in-kernel) buffers.
Definition: sttybuf.cpp:355
i8 * m_devnode
Device node file (devfs)
Definition: sttybuf.hpp:34
unsigned int u32
32-bit unsigned integer
Definition: config.hpp:102
int i32
32-bit signed integer
Definition: config.hpp:82
#define unlikely(expr)
Offer a hint (negative) to the pipeline branch predictor.
Definition: config.hpp:349
#define __D_ASSERT(x)
Assertion macro.
Definition: config.hpp:268

+ Here is the call graph for this function:

+ Here is the caller graph for this function: