From: Gwenhael Goavec-Merou Date: Sun, 30 Apr 2017 13:57:39 +0000 (+0200) Subject: openbench-logic-sniffer: add a function to handle reset command X-Git-Tag: libsigrok-0.5.0~77 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=244995a2e3cef0f971e21faf82531e785e552f9e;p=libsigrok.git openbench-logic-sniffer: add a function to handle reset command Openbench Logic Sniffer reset is a little more complex than a simple send. To avoid code duplication, this patch adds a new function dedicated to this task. Signed-off-by: Gwenhael Goavec-Merou --- diff --git a/src/hardware/openbench-logic-sniffer/api.c b/src/hardware/openbench-logic-sniffer/api.c index 1e22c5b8..c0459535 100644 --- a/src/hardware/openbench-logic-sniffer/api.c +++ b/src/hardware/openbench-logic-sniffer/api.c @@ -126,14 +126,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) if (serial_open(serial, SERIAL_RDWR) != SR_OK) return NULL; - ret = SR_OK; - for (i = 0; i < 5; i++) { - if ((ret = send_shortcommand(serial, CMD_RESET)) != SR_OK) { - sr_err("Port %s is not writable.", conn); - break; - } - } - if (ret != SR_OK) { + if (ols_send_reset(serial) != SR_OK) { serial_close(serial); sr_err("Could not use port %s. Quitting.", conn); return NULL; diff --git a/src/hardware/openbench-logic-sniffer/protocol.c b/src/hardware/openbench-logic-sniffer/protocol.c index a7c3f963..0d6efeb8 100644 --- a/src/hardware/openbench-logic-sniffer/protocol.c +++ b/src/hardware/openbench-logic-sniffer/protocol.c @@ -57,6 +57,18 @@ SR_PRIV int send_longcommand(struct sr_serial_dev_inst *serial, return SR_OK; } +SR_PRIV int ols_send_reset(struct sr_serial_dev_inst *serial) +{ + unsigned int i; + + for (i = 0; i < 5; i++) { + if (send_shortcommand(serial, CMD_RESET) != SR_OK) + return SR_ERR; + } + + return SR_OK; +} + /* Configures the channel mask based on which channels are enabled. */ SR_PRIV void ols_channel_mask(const struct sr_dev_inst *sdi) { diff --git a/src/hardware/openbench-logic-sniffer/protocol.h b/src/hardware/openbench-logic-sniffer/protocol.h index 1e6cd69d..4525ba2c 100644 --- a/src/hardware/openbench-logic-sniffer/protocol.h +++ b/src/hardware/openbench-logic-sniffer/protocol.h @@ -107,6 +107,7 @@ SR_PRIV int send_shortcommand(struct sr_serial_dev_inst *serial, uint8_t command); SR_PRIV int send_longcommand(struct sr_serial_dev_inst *serial, uint8_t command, uint8_t *data); +SR_PRIV int ols_send_reset(struct sr_serial_dev_inst *serial); SR_PRIV void ols_channel_mask(const struct sr_dev_inst *sdi); SR_PRIV int ols_convert_trigger(const struct sr_dev_inst *sdi); SR_PRIV struct dev_context *ols_dev_new(void);