Телесистемы
 Разработка, производство и продажа радиоэлектронной аппаратуры
На главную   | Карта сайта | Пишите нам | В избранное
Требуется программист в Зеленограде
- обработка данных с датчиков; ColdFire; 40 тыс.
e-mail:jobsmp@pochta.ru

Телесистемы | Электроника | Конференция «Микроконтроллеры и их применение»

Пингвины делают так:

Отправлено ++ 20 октября 2008 г. 16:42
В ответ на: Специ по ЮСБ просветите (+) отправлено <font color=gray>MARS</font> 20 октября 2008 г. 16:22


/*=====================================================================================================*/
/* By the time we get here, the device has gotten a new device ID and is in the default state. We need to identify the thing and get the ball rolling..
* Returns 0 for success, != 0 for error. */
int usb_new_device(struct usb_device *dev, int devnum)
{int err, is_mass_storage=0;
/* USB v1.1 5.5.3 */
/* We read the first 8 bytes from the device descriptor to get to the bMaxPacketSize0 field. Then we set the maximum packet size for the control pipe, and retrieve the rest */
dev->epmaxpacketin [0] = 0x40;
dev->epmaxpacketout[0] = 0x40;
if(!usb_get_device_descriptor(dev, usb_buf_1, 0x40)) /* получаем стандартный дескриптор устройства */
{diag_printf("\t%s невозможно получить дескриптор устройства.\n", _EEXCHANGE);return -1;}
CYGACC_CALL_IF_DELAY_US (1000);
if((err = usb_set_address(dev, devnum)) < 0) /* задание устройству адреса на шине */
if (err < 0)
{diag_printf("\t%s устройство не принимает назначенный адрес, код ошибки=%d.\n",_EEXCHANGE, err);
return -1;
}
dev->devnum= devnum;
CYGACC_CALL_IF_DELAY_US (100000);
if(!usb_get_device_descriptor(dev, usb_buf_1, 0x40)) /* получаем стандартный дескриптор устройства */
{return -1;}
{struct usb_config_descriptor *c_d; /* */
struct usb_interface_descriptor *i_d;
struct usb_endpoint_descriptor e_d;
struct usb_descriptor_header *h_d;
int v, i;
c_d= (struct usb_config_descriptor *)usb_buf_1;
if ((err= usb_get_descriptor(dev, USB_DT_CONFIG, 0, usb_buf_1, USB_DT_CONFIG_SIZE)) < 0)
{diag_printf("\t%s\n", _EEXCHANGE);return -1;}
if (err < USB_DT_CONFIG_SIZE)
{diag_printf("\t%s\n", _EEXCHANGE);return -EINVAL;}
v=c_d->wTotalLength= le16_to_cpu(c_d->wTotalLength);
#ifdef USB_DEBUG
dump_conf_descriptor(c_d);
#endif
if ((err= usb_get_descriptor(dev, USB_DT_CONFIG, 0, usb_buf_1, c_d->wTotalLength)) < 0)
{diag_printf("\t%s\n", _EEXCHANGE);return -1;}
if (err < v)
{diag_printf("%s\n", _EEXCHANGE);return -EINVAL;}
for(i=USB_DT_CONFIG_SIZE; i < v; i+=h_d->bLength)
{h_d= (struct usb_descriptor_header *) (((unsigned int)usb_buf_1) + i);
switch(h_d->bDescriptorType)
{case USB_DT_INTERFACE: i_d= (struct usb_interface_descriptor *)h_d;
#ifdef USB_DEBUG
dump_intf_descriptor((struct usb_interface_descriptor *)h_d);
#endif
if(i_d->bInterfaceClass != USB_CLASS_MASS_STORAGE)
{continue;}
is_mass_storage=1;
continue;
case USB_DT_ENDPOINT: if(!is_mass_storage)
continue;
memcpy(&e_d, h_d, USB_DT_ENDPOINT_SIZE);
if((e_d.bmAttributes & USB_ENDPOINT_XFERTYPE_MASK)!= USB_ENDPOINT_XFER_BULK)
{
#ifdef USB_DEBUG
diag_printf( "endp_desc: не bulk функция (e_d.bmAttributes=0x%02x) - игнорируем.\n", e_d.bmAttributes);
#endif
continue;
}
e_d.wMaxPacketSize= le16_to_cpu(e_d.wMaxPacketSize);
#ifdef USB_DEBUG
dump_endp_descriptor(&e_d);
#endif
if(e_d.bEndpointAddress & USB_DIR_IN) /* in endpoint */
{dev->mass_storage_endpoint_in= e_d.bEndpointAddress & 0x7f;
dev->epmaxpacketin[dev->mass_storage_endpoint_in]= e_d.wMaxPacketSize;
continue;
}
dev->mass_storage_endpoint_out= e_d.bEndpointAddress;
dev->epmaxpacketout[dev->mass_storage_endpoint_out]= e_d.wMaxPacketSize;
continue;
default: diag_printf( "\tошибка: не поддержаваемый bDescriptorType=0x%02x\n", h_d->bDescriptorType);
continue;
}
}
}
/* we set the default configuration here */
if((err = usb_set_configuration(dev, 1)) < 0)
{diag_printf("\t%s [%d] код ошибки %d.\n", _EEXCHANGE, __LINE__, err); return -1;}
{char s[256];
if(!dev->descriptor.iManufacturer)dev->descriptor.iManufacturer=1;
if((err=usb_string(dev, dev->descriptor.iManufacturer, s, 256)) < 0)
{diag_printf("\t%s [%d] код ошибки %d.\n", _EEXCHANGE, __LINE__, err);return -1;}
diag_printf("\t- [%s", s);
if((err=usb_string(dev, dev->descriptor.iProduct, s, 256)) < 0)
{diag_printf("\t%s [%d] код ошибки %d.\n", _EEXCHANGE, __LINE__, err);return -1;}
diag_printf("/ %s]\n", s);
if(!(dev->mass_storage_endpoint_in && dev->mass_storage_endpoint_out) || !is_mass_storage)
{diag_printf("\t- не usb flash disk/cdrom устройство - игнорируем.\n"); return ENOERR;}
}
return usb_storage_probe(dev);
}




Составить ответ | Вернуться на конференцию

Ответы


Отправка ответа
Имя*: 
Пароль: 
E-mail: 
Тема*:

Сообщение:

Ссылка на URL: 
URL изображения: 

если вы незарегистрированный на форуме пользователь, то
для успешного добавления сообщения заполните поле, как указано ниже:
введите число 90:

Перейти к списку ответов | Конференция | Раздел "Электроника" | Главная страница | Карта сайта

Rambler's Top100 Рейтинг@Mail.ru
 
Web telesys.ru