37 #include <sys/select.h> 
   46         : 
rp::hal::serial_rxtx(), _baudrate(0), _flags(0), serial_fd(-1)
 
   69         struct termios options, oldopt;
 
   71         bzero(&options, 
sizeof(
struct termios));
 
   75         if (termbaud == (
_u32)-1)
 
   80         cfsetispeed(&options, termbaud);
 
   81         cfsetospeed(&options, termbaud);
 
   84         options.c_cflag |= (CLOCAL | CREAD);
 
   86         options.c_cflag &= ~PARENB;  
 
   87         options.c_cflag &= ~CSTOPB;  
 
   89         options.c_cflag &= ~CSIZE;
 
   90         options.c_cflag |= CS8; 
 
   93         options.c_cflag &= ~CNEW_RTSCTS;  
 
   96         options.c_iflag &= ~(IXON | IXOFF | IXANY);  
 
   99         options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
 
  101         options.c_oflag &= ~OPOST;
 
  110         if (tcsetattr(
serial_fd, TCSANOW, &options))
 
  137         if (
data == 
nullptr || 
size == 0) 
return 0;
 
  145                 if (ans == -1) 
return tx_len;
 
  149         } 
while (tx_len < 
size);
 
  160         if (ans == -1) ans = 0;
 
  181         size_t data_count, 
_u32 timeout, 
size_t* returned_size)
 
  184         if (returned_size == 
nullptr) returned_size = (
size_t*)&
length;
 
  189         struct timeval timeout_val;
 
  197         timeout_val.tv_sec = timeout / 1000;
 
  198         timeout_val.tv_usec = (timeout % 1000) * 1000;
 
  203                 if (*returned_size >= data_count)
 
  212                 int n = ::select(max_fd, &input_set, 
nullptr, 
nullptr, &timeout_val);
 
  229                         if (ioctl(
serial_fd, FIONREAD, returned_size) == -1)
 
  231                         if (*returned_size >= data_count)
 
  238                                         timeout_val.tv_sec * 1000000 + timeout_val.tv_usec;
 
  239                                 int expect_remain_time =
 
  240                                         (data_count - *returned_size) * 1000000 * 8 / 
_baudrate;
 
  241                                 if (remain_timeout > expect_remain_time)
 
  242                                         usleep(expect_remain_time);
 
  255         if (::ioctl(
serial_fd, FIONREAD, &remaining) == -1) 
return 0;
 
  284 #define BAUD_CONV(_baud_) \