Skip to content

Commit ec5cd54

Browse files
committed
ols: Make resetting more robust, reset at the end
In my experiments, this helped when not all data was read from the device. Otherwise, sigrok-cli would just hang. Also, be nice and reset the device when an acquisition ends. This is not strictly necessary, but is a nice touch, I think.
1 parent 3dadbfb commit ec5cd54

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

src/hardware/openbench-logic-sniffer/protocol.c

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,26 @@ static int ols_send_longdata(struct sr_serial_dev_inst *serial,
7171

7272
SR_PRIV int ols_send_reset(struct sr_serial_dev_inst *serial)
7373
{
74-
unsigned int i;
74+
int i, ret;
75+
char dummy[16];
76+
77+
/* Drain all data so that the remote side is surely listening. */
78+
while ((ret = serial_read_nonblocking(serial, &dummy, 16)) > 0);
79+
if (ret != SR_OK)
80+
return ret;
7581

76-
for (i = 0; i < 5; i++) {
82+
for (i = 0; i < 5; i++)
7783
RETURN_ON_ERROR(send_shortcommand(serial, CMD_RESET));
78-
}
7984

80-
return SR_OK;
85+
/*
86+
* Remove all stray output that arrived in between.
87+
* This is likely to happen when RLE is being used because
88+
* the device seems to return a bit more data than we request.
89+
*/
90+
int delay_ms = serial_timeout(serial, 16);
91+
while ((ret = serial_read_blocking(serial, &dummy, 16, delay_ms)) > 0);
92+
93+
return ret;
8194
}
8295

8396
/* Configures the channel mask based on which channels are enabled. */
@@ -348,13 +361,11 @@ SR_PRIV int ols_set_samplerate(const struct sr_dev_inst *sdi,
348361

349362
SR_PRIV void abort_acquisition(const struct sr_dev_inst *sdi)
350363
{
351-
struct sr_serial_dev_inst *serial;
364+
struct sr_serial_dev_inst *serial = sdi->conn;
352365

353-
serial = sdi->conn;
354366
ols_send_reset(serial);
355367

356368
serial_source_remove(sdi->session, serial);
357-
358369
std_session_send_df_end(sdi);
359370
}
360371

0 commit comments

Comments
 (0)