sysclk-lwla: Attempt initialization three times

This is a desperate measure to improve the success rate of device
initialization even after it got into a bad state. Combine this
with a reduced USB timeout (1 second) so that if it fails, it fails
quickly. Also ignore USB errors from the initial dummy read of the
device test ID.
This commit is contained in:
Daniel Elstner 2015-12-22 15:52:40 +01:00
parent 04f2428354
commit e35a459248
4 changed files with 43 additions and 42 deletions

View File

@ -289,6 +289,7 @@ static int dev_open(struct sr_dev_inst *sdi)
struct drv_context *drvc;
struct dev_context *devc;
struct sr_usb_dev_inst *usb;
int i;
int ret;
drvc = sdi->driver->context;
@ -304,6 +305,8 @@ static int dev_open(struct sr_dev_inst *sdi)
return SR_ERR;
}
/* Try the whole shebang three times, fingers crossed. */
for (i = 0; i < 3; i++) {
ret = sr_usb_open(drvc->sr_ctx->libusb_ctx, usb);
if (ret != SR_OK)
return ret;
@ -342,16 +345,18 @@ static int dev_open(struct sr_dev_inst *sdi)
if (ret == SR_OK)
ret = (*devc->model->device_init_check)(sdi);
if (ret == SR_OK)
break;
if (ret != SR_OK) {
/* Rinse and repeat. */
sdi->status = SR_ST_INACTIVE;
sr_usb_close(usb);
return ret;
}
if (devc->short_transfer_quirk)
if (ret == SR_OK && devc->short_transfer_quirk)
sr_warn("Short transfer quirk detected! "
"Memory reads will be slow.");
return SR_OK;
return ret;
}
/* Shutdown and close device.

View File

@ -274,9 +274,7 @@ static int device_init_check(const struct sr_dev_inst *sdi)
const unsigned int test_count = 24;
ret = lwla_read_reg(sdi->conn, REG_TEST_ID, &value);
if (ret != SR_OK)
return ret;
lwla_read_reg(sdi->conn, REG_TEST_ID, &value);
/* Ignore the value returned by the first read. */
ret = lwla_read_reg(sdi->conn, REG_TEST_ID, &value);

View File

@ -358,9 +358,7 @@ static int device_init_check(const struct sr_dev_inst *sdi)
uint64_t value;
int ret;
ret = read_long_reg(sdi->conn, LREG_TEST_ID, &value);
if (ret != SR_OK)
return ret;
read_long_reg(sdi->conn, LREG_TEST_ID, &value);
/* Ignore the value returned by the first read. */
ret = read_long_reg(sdi->conn, LREG_TEST_ID, &value);

View File

@ -59,7 +59,7 @@ enum {
enum {
USB_CONFIG = 1,
USB_INTERFACE = 0,
USB_TIMEOUT_MS = 3000,
USB_TIMEOUT_MS = 1000,
};
/** USB device end points.