Пример #1
0
TEST( LipschitzConstant, Assignment )
{
    auto L = Spacy::LipschitzConstant{5.};
    EXPECT_EQ( L, 5. );

    L.setMinFactor( 1e-3 );
    L = -1e-3;
    EXPECT_EQ( L, 5e-3 );

    L.setMaxFactor( 1e6 );
    L = 1e4;
    EXPECT_EQ( L, 5e3 );

    auto eps = 1e-15;
    L.set_eps( eps );
    L = 0.5 * eps;
    EXPECT_EQ( L, eps );
}
Пример #2
0
/* After driver is bound, send a fake get configuration command to
 * gadget driver to get the configuration information */
static int gadget_get_config_desc(struct pxa3xx_comp *dev,
				  struct usb_gadget *gadget,
				  struct usb_gadget_driver *driver)
{
	struct usb_ctrlrequest  req;
	struct usb_config_descriptor *config_desc;
	struct usb_interface_descriptor *interface_desc;
	struct usb_endpoint_descriptor *ep_desc;
	unsigned config;
	int i;
	struct usb_config_descriptor *p_config_desc;
	int config_desc_length, ret;
#ifdef CONFIG_USB_COMPOSITE
	__u8 num_itfs;
	__u8 cur_intf = 0, last_intf = 0;
#endif

	DMSG("----------%s------------\n", __FUNCTION__);
	req.bRequestType = USB_RECIP_DEVICE | USB_DIR_IN;
	req.bRequest = USB_REQ_GET_DESCRIPTOR;
	req.wValue = (USB_DT_CONFIG<<8);
	req.wIndex = 0;
	req.wLength = MAX_CONFIG_LENGTH;

	gadget->speed = USB_SPEED_FULL;
	dev->ep0state = EP0_IN_FAKE;
	i = driver->setup(gadget, &req);
#ifdef CONFIG_USB_PXA3XX_U2D
	gadget->speed = USB_SPEED_UNKNOWN;
#endif

#ifndef CONFIG_USB_COMPOSITE
	config_desc = (struct usb_config_descriptor *)dev->configs;
#else
	config_desc = (struct usb_config_descriptor *)
		       dev->active_gadget->config_desc;
#endif
	p_config_desc = config_desc;
	config_desc_length = config_desc->wTotalLength;

	if (config_desc->bDescriptorType == USB_DT_CONFIG) {
		config = config_desc->bConfigurationValue;
	} else {
		DMSG("wrong configuration\n");
		return -EFAULT;
	}

#ifndef CONFIG_USB_COMPOSITE
	while (config_desc_length >= 0) {
		ret = get_extra_descriptor((char *)p_config_desc,
					  config_desc_length,
					  USB_DT_INTERFACE,
					  (void **) &interface_desc);
		if (ret >= 0) {
			/* search eps and fill the pxa27x_ep_config struct */
			if (interface_desc->bNumEndpoints) {
				set_eps(interface_desc->bNumEndpoints,
					(struct usb_endpoint_descriptor *)
					 interface_desc,
					config_desc_length, config,
					interface_desc->bInterfaceNumber,
					interface_desc->bAlternateSetting);

				DMSG("config=%d, intf assigned=%d,"
				     " alt=%d\n", config,
				     interface_desc->bInterfaceNumber,
				     interface_desc->bAlternateSetting);
			}
		} else {
			DMSG("interface config not find\n");
			return -EFAULT;
		}

		p_config_desc = (struct usb_config_descriptor *)
				((struct usb_interface_descriptor *)
				 interface_desc + 1);

		config_desc_length -= interface_desc->bLength;  /* yfw */
	}
#else
	num_itfs = config_desc->bNumInterfaces;

	DMSG("parse the config desc, assigned_intf_start=%d, num of intfs=%d\n",
	     dev->interface_count, num_itfs);

	dev->active_gadget->assigned_intf_start = dev->interface_count;
	dev->active_gadget->config = config;
	dev->active_gadget->num_intfs = num_itfs;

	/* get every interface desc, fill the gadget_driver_info structure */
	for (i = 0; i < num_itfs; i++) {
		DMSG("\nparse interface %d, p_config_desc=%p,"
		     " config_desc_length=%d\n", i, p_config_desc,
		     config_desc_length);

		while (config_desc_length >= 0) {
			ret = get_extra_descriptor((char *)p_config_desc,
						   config_desc_length,
						   USB_DT_INTERFACE,
						   (void **)&interface_desc);
			if (ret >= 0) {
				cur_intf = interface_desc->bInterfaceNumber;

				config_desc_length -= (u32)interface_desc -
						      (u32)p_config_desc;

				if (cur_intf != last_intf) {
					p_config_desc =
						(struct usb_config_descriptor *)
						interface_desc;
					goto next_intf;
				}

				/* set interface number to assigned one */
				interface_desc->bInterfaceNumber = i +
					dev->active_gadget->assigned_intf_start;

				interface_desc->iInterface = 0;

				/* search eps and fill the pxa27x_ep_config*/
				ep_desc = (struct usb_endpoint_descriptor *)
					   interface_desc;
				if (interface_desc->bNumEndpoints) {
					set_eps(interface_desc->bNumEndpoints,
						ep_desc, config_desc_length,
						config, cur_intf,
						interface_desc->bAlternateSetting);
				}

				DMSG("config=%d, intf=%d(assigned=%d),"
				     " alt=%d\n", config, cur_intf,
				     interface_desc->bInterfaceNumber,
				     interface_desc->bAlternateSetting);
			} else {
				DMSG("no more alt interfaces,"
				     " config_desc_length=%d, goto next_intf\n",
				config_desc_length);
				goto next_intf;
			} /* if */

			p_config_desc = (struct usb_config_descriptor *)
					((struct usb_interface_descriptor *)
					 interface_desc + 1);

			config_desc_length -= interface_desc->bLength;/* yfw */
			DMSG("  p_config_desc=%p, interface_desc=%p, "
			     "config_desc_length=%d\n",
			     p_config_desc, interface_desc, config_desc_length);
		} /* while */

next_intf:
		last_intf = cur_intf;
		dev->interface_count++;

		DMSG("parse interface %d finished, dev->interface_count=%d\n",
		     i, dev->interface_count);
	} /* for */

	/* set CDC union descriptors */
	set_cdc_desc(dev);
#endif
	return 0;
}