X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=hardware%2Fcommon%2Fserial.c;h=ebc6979763100a2399a5d9678ed666c16caa81db;hb=50a9aba21b912b44559290ece466b46aaa8840cf;hp=e32c0f1e2656571f6d564e6bebd76d89f5c13aad;hpb=b1a051544d502f15a1da05682e625755563b86c2;p=libsigrok.git diff --git a/hardware/common/serial.c b/hardware/common/serial.c index e32c0f1e..ebc69797 100644 --- a/hardware/common/serial.c +++ b/hardware/common/serial.c @@ -1,5 +1,5 @@ /* - * This file is part of the sigrok project. + * This file is part of the libsigrok project. * * Copyright (C) 2010-2012 Bert Vermeulen * Copyright (C) 2010-2012 Uwe Hermann @@ -27,7 +27,6 @@ #ifdef _WIN32 #include #else -#include #include #include #endif @@ -37,14 +36,14 @@ #include "libsigrok.h" #include "libsigrok-internal.h" -/* Message logging helpers with driver-specific prefix string. */ -#define DRIVER_LOG_DOMAIN "serial: " -#define sr_log(l, s, args...) sr_log(l, DRIVER_LOG_DOMAIN s, ## args) -#define sr_spew(s, args...) sr_spew(DRIVER_LOG_DOMAIN s, ## args) -#define sr_dbg(s, args...) sr_dbg(DRIVER_LOG_DOMAIN s, ## args) -#define sr_info(s, args...) sr_info(DRIVER_LOG_DOMAIN s, ## args) -#define sr_warn(s, args...) sr_warn(DRIVER_LOG_DOMAIN s, ## args) -#define sr_err(s, args...) sr_err(DRIVER_LOG_DOMAIN s, ## args) +/* Message logging helpers with subsystem-specific prefix string. */ +#define LOG_PREFIX "serial: " +#define sr_log(l, s, args...) sr_log(l, LOG_PREFIX s, ## args) +#define sr_spew(s, args...) sr_spew(LOG_PREFIX s, ## args) +#define sr_dbg(s, args...) sr_dbg(LOG_PREFIX s, ## args) +#define sr_info(s, args...) sr_info(LOG_PREFIX s, ## args) +#define sr_warn(s, args...) sr_warn(LOG_PREFIX s, ## args) +#define sr_err(s, args...) sr_err(LOG_PREFIX s, ## args) // FIXME: Must be moved, or rather passed as function argument. #ifdef _WIN32 @@ -549,7 +548,7 @@ SR_PRIV int serial_set_params(struct sr_serial_dev_inst *serial, int baudrate, return SR_ERR; } - term.c_iflag &= ~(IXON | IXOFF); + term.c_iflag &= ~(IXON | IXOFF | IXANY); term.c_cflag &= ~CRTSCTS; switch (flowcontrol) { case 0: @@ -562,7 +561,7 @@ SR_PRIV int serial_set_params(struct sr_serial_dev_inst *serial, int baudrate, break; case 2: sr_spew("Configuring XON/XOFF flow control."); - term.c_iflag |= IXON | IXOFF; + term.c_iflag |= (IXON | IXOFF | IXANY); break; default: sr_err("Unsupported flow control setting %d.", flowcontrol); @@ -570,7 +569,7 @@ SR_PRIV int serial_set_params(struct sr_serial_dev_inst *serial, int baudrate, } term.c_iflag &= ~IGNPAR; - term.c_cflag &= ~(PARODD | PARENB); + term.c_cflag &= ~(PARENB | PARODD); switch (parity) { case SERIAL_PARITY_NONE: sr_spew("Configuring no parity."); @@ -591,11 +590,17 @@ SR_PRIV int serial_set_params(struct sr_serial_dev_inst *serial, int baudrate, /* Turn off all serial port cooking. */ term.c_iflag &= ~(ISTRIP | INLCR | ICRNL); - term.c_oflag &= ~(ONLCR | OCRNL | ONOCR | OFILL ); + term.c_oflag &= ~(OPOST | ONLCR | OCRNL | ONOCR); +#if !defined(__FreeBSD__) && !defined(__OpenBSD__) && !defined(__NetBSD__) + term.c_oflag &= ~OFILL; +#endif /* Disable canonical mode, and don't echo input characters. */ term.c_lflag &= ~(ICANON | ECHO); + /* Ignore modem status lines; enable receiver */ + term.c_cflag |= (CLOCAL | CREAD); + /* Write the configured settings. */ if (tcsetattr(serial->fd, TCSADRAIN, &term) < 0) { sr_err("tcsetattr() error: %s.", strerror(errno)); @@ -784,7 +789,8 @@ SR_PRIV int serial_readline(struct sr_serial_dev_inst *serial, char **buf, if (g_get_monotonic_time() - start > timeout_ms) /* Timeout */ break; - g_usleep(2000); + if (len < 1) + g_usleep(2000); } if (*buflen) sr_dbg("Received %d: '%s'.", *buflen, *buf); @@ -865,7 +871,8 @@ SR_PRIV int serial_stream_detect(struct sr_serial_dev_inst *serial, sr_dbg("Detection timed out after %dms.", time); break; } - g_usleep(byte_delay_us); + if (len < 1) + g_usleep(byte_delay_us); } *buflen = ibuf;