MCPcopy Create free account
hub / github.com/DreamSourceLab/DSView / hw_dev_open

Function hw_dev_open

libsigrok4DSL/hardware/DSL/dsl.c:303–391  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

301}
302
303static int hw_dev_open(struct sr_dev_driver *di, struct sr_dev_inst *sdi)
304{
305 (void)di;
306
307 libusb_device *dev_handel=NULL;
308 struct sr_usb_dev_inst *usb;
309 struct version_info vi;
310 int ret;
311 struct ctl_rd_cmd rd_cmd;
312 uint8_t rd_cmd_data[2];
313
314 usb = sdi->conn;
315
316 if (usb->usb_dev == NULL){
317 sr_err("hw_dev_open(), usb->usb_dev is null.");
318 return SR_ERR;
319 }
320
321 if (sdi->status == SR_ST_ACTIVE) {
322 /* Device is already in use. */
323 sr_detail("The usb device is opened, handle:%p", usb->usb_dev);
324 return SR_OK;
325 }
326
327 if (sdi->status == SR_ST_INITIALIZING) {
328 sr_info("The device instance is still boosting.");
329 }
330 dev_handel = usb->usb_dev;
331
332 sr_info("Open usb device instance, handle: %p", dev_handel);
333
334 ret = libusb_open(dev_handel, &usb->devhdl);
335 if (ret != LIBUSB_SUCCESS){
336 sr_err("%s:%d, Failed to open device: %s, handle:%p",
337 __func__, __LINE__, libusb_error_name(ret), dev_handel);
338 ds_set_last_error(SR_ERR_DEVICE_IS_EXCLUSIVE);
339 return SR_ERR;
340 }
341 //sr_info("------------Open returns the libusb_device_handle: %p, struct:%p", usb->devhdl, usb);
342
343 if (usb->address == 0xff){
344 /*
345 * First time we touch this device after FW
346 * upload, so we don't know the address yet.
347 */
348 usb->address = libusb_get_device_address(dev_handel);
349 }
350
351 rd_cmd.header.dest = DSL_CTL_FW_VERSION;
352 rd_cmd.header.size = 2;
353 rd_cmd.data = rd_cmd_data;
354
355 if ((ret = command_ctl_rd(usb->devhdl, rd_cmd)) != SR_OK) {
356 sr_err("%s:%d, Failed to get firmware version.",
357 __func__, __LINE__);
358 ds_set_last_error(SR_ERR_DEVICE_USB_IO_ERROR);
359 return ret;
360 }

Callers 1

dsl_dev_openFunction · 0.70

Calls 2

ds_set_last_errorFunction · 0.85
command_ctl_rdFunction · 0.85

Tested by

no test coverage detected