Example #1
0
static int hw_opendev(int device_index)
{
	GTimeVal cur_time;
	struct sr_device_instance *sdi;
	struct fx2_device *fx2;
	int timediff, err;

	if (!(sdi = sr_get_device_instance(device_instances, device_index)))
		return SR_ERR;
	fx2 = sdi->priv;

	/*
	 * if the firmware was recently uploaded, wait up to MAX_RENUM_DELAY ms
	 * for the FX2 to renumerate
	 */
	err = 0;
	if (GTV_TO_MSEC(fx2->fw_updated) > 0) {
		sr_info("saleae: waiting for device to reset");
		/* takes at least 300ms for the FX2 to be gone from the USB bus */
		g_usleep(300*1000);
		timediff = 0;
		while (timediff < MAX_RENUM_DELAY) {
			if ((err = sl_open_device(device_index)) == SR_OK)
				break;
			g_usleep(100*1000);
			g_get_current_time(&cur_time);
			timediff = GTV_TO_MSEC(cur_time) - GTV_TO_MSEC(fx2->fw_updated);
		}
		sr_info("saleae: device came back after %d ms", timediff);
	} else {
		err = sl_open_device(device_index);
	}

	if (err != SR_OK) {
		sr_warn("unable to open device");
		return SR_ERR;
	}
	fx2 = sdi->priv;

	err = libusb_claim_interface(sdi->usb->devhdl, USB_INTERFACE);
	if (err != 0) {
		sr_warn("Unable to claim interface: %d", err);
		return SR_ERR;
	}

	if (fx2->cur_samplerate == 0) {
		/* Samplerate hasn't been set; default to the slowest one. */
		if (hw_set_configuration(device_index, SR_HWCAP_SAMPLERATE,
		    &supported_samplerates[0]) == SR_ERR)
			return SR_ERR;
	}

	return SR_OK;
}
Example #2
0
int hw_opendev(int device_index)
{
	GTimeVal cur_time;
	struct usb_device_instance *udi;
	int timediff, err;
	unsigned int cur, upd;

	if(firmware_updated.tv_sec > 0)
	{
		/* firmware was recently uploaded */
		g_get_current_time(&cur_time);
		cur = cur_time.tv_sec * 1000 + cur_time.tv_usec / 1000;
		upd = firmware_updated.tv_sec * 1000 + firmware_updated.tv_usec / 1000;
		timediff = cur - upd;
		if(timediff < FIRMWARE_RENUM_DELAY)
		{
			timediff = FIRMWARE_RENUM_DELAY - timediff;
			g_message("waiting %d ms for device to reset", timediff);
			g_usleep(timediff * 1000);
			firmware_updated.tv_sec = 0;
		}
	}

	if( !(udi = sl_open_device(device_index)) )
	{
		g_warning("unable to open device");
		return SIGROK_NOK;
	}

	err = libusb_claim_interface(udi->devhdl, USB_INTERFACE);
	if(err != 0)
	{
		g_warning("Unable to claim interface: %d", err);
		return SIGROK_NOK;
	}

	if(cur_sample_rate == 0)
	{
		/* sample rate hasn't been set; default to the slowest it has */
		if(hw_set_configuration(device_index, HWCAP_SAMPLERATE, &supported_sample_rates[0]) == SIGROK_NOK)
			return SIGROK_NOK;
	}

	return SIGROK_OK;
}