serial: introduce "has receive data" query
Add a serial_has_receive_data() routine to the serial layer's API which returns the number of (known to be) available RX data bytes. Implement support in the libserialport specific code.
This commit is contained in:
parent
ae4c1fb637
commit
8c3df6e5cd
|
@ -1079,6 +1079,7 @@ SR_PRIV int serial_open(struct sr_serial_dev_inst *serial, int flags);
|
|||
SR_PRIV int serial_close(struct sr_serial_dev_inst *serial);
|
||||
SR_PRIV int serial_flush(struct sr_serial_dev_inst *serial);
|
||||
SR_PRIV int serial_drain(struct sr_serial_dev_inst *serial);
|
||||
SR_PRIV size_t serial_has_receive_data(struct sr_serial_dev_inst *serial);
|
||||
SR_PRIV int serial_write_blocking(struct sr_serial_dev_inst *serial,
|
||||
const void *buf, size_t count, unsigned int timeout_ms);
|
||||
SR_PRIV int serial_write_nonblocking(struct sr_serial_dev_inst *serial,
|
||||
|
@ -1132,6 +1133,7 @@ SR_PRIV GSList *sr_ser_libsp_find_usb(GSList *list, sr_ser_find_append_t append,
|
|||
uint16_t vendor_id, uint16_t product_id);
|
||||
SR_PRIV int sr_ser_libsp_get_frame_format(struct sr_serial_dev_inst *serial,
|
||||
int *baud, int *bits);
|
||||
SR_PRIV size_t sr_ser_libsp_get_rx_avail(struct sr_serial_dev_inst *serial);
|
||||
#endif
|
||||
|
||||
/*--- ezusb.c ---------------------------------------------------------------*/
|
||||
|
|
15
src/serial.c
15
src/serial.c
|
@ -152,6 +152,21 @@ SR_PRIV int serial_drain(struct sr_serial_dev_inst *serial)
|
|||
return sr_ser_libsp_drain(serial);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for available receive data.
|
||||
*
|
||||
* @param[in] serial Previously opened serial port instance.
|
||||
*
|
||||
* @returns The number of (known) available RX data bytes.
|
||||
*
|
||||
* Returns 0 if no receive data is available, or if the amount of
|
||||
* available receive data cannot get determined.
|
||||
*/
|
||||
SR_PRIV size_t serial_has_receive_data(struct sr_serial_dev_inst *serial)
|
||||
{
|
||||
return sr_ser_libsp_get_rx_avail(serial);
|
||||
}
|
||||
|
||||
static int _serial_write(struct sr_serial_dev_inst *serial,
|
||||
const void *buf, size_t count,
|
||||
int nonblocking, unsigned int timeout_ms)
|
||||
|
|
|
@ -473,3 +473,17 @@ SR_PRIV int sr_ser_libsp_get_frame_format(struct sr_serial_dev_inst *serial,
|
|||
|
||||
return ret;
|
||||
}
|
||||
|
||||
SR_PRIV size_t sr_ser_libsp_get_rx_avail(struct sr_serial_dev_inst *serial)
|
||||
{
|
||||
int rc;
|
||||
|
||||
if (!serial)
|
||||
return 0;
|
||||
|
||||
rc = sp_input_waiting(serial->sp_data);
|
||||
if (rc < 0)
|
||||
return 0;
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue