From: Gwenhael Goavec-Merou <gwenhael.goavec-me...@trabucayre.com>

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 <gwenhael.goavec-me...@trabucayre.com>
---
 src/hardware/openbench-logic-sniffer/api.c      |  9 +--------
 src/hardware/openbench-logic-sniffer/protocol.c | 12 ++++++++++++
 src/hardware/openbench-logic-sniffer/protocol.h |  1 +
 3 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/src/hardware/openbench-logic-sniffer/api.c 
b/src/hardware/openbench-logic-sniffer/api.c
index 1e22c5b..c045953 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 a7c3f96..0d6efeb 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 1e6cd69..4525ba2 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);
-- 
2.10.2


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
sigrok-devel mailing list
sigrok-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sigrok-devel

Reply via email to