i am a newer to qnx.now i am trying to design a usb driver.however,the programm can not detect the usb keyboard when running to the step “usbd_attach”.return value is “ENODEV”.the value of VENTOR and DEVICE is finded from the Linux.
(i am running the qnx on VMware!)
can anyone help me? Thank you.
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <sys/usbdi.h>
#define ERROR -1
#define NORMAL 0
#define MAX_BUFFER_SIZE 2048
#define VENTOR 0x413c
#define DEVICE 0x2003
#define DCLASS USBD_CONNECT_WILDCARD
#define SUBCLASS USBD_CONNECT_WILDCARD
#define PROTOCAL USBD_CONNECT_WILDCARD
int usbDevInit(int argc,char argv[]); / Initialize the usb device */
void usbDevInsertion(void ); /usb Device insertion/
usbd_device_instance_t instance ;
struct usbd_device *usbD ;
usbd_connect_parm_t pDev; / Connection parameters describing how to connect to the USB stack
and how you intend to operate with it */
struct usbd_connection usbdHandle=NULL; / An opaque handle returned on a successful connection */
int main(int argc, char *argv[]) {
if (usbDevInit(argc, argv))
{
printf (“Initialize USB device Failed \n”);
}
usbDevInsertion();
printf (“Initialize USB device Sucessed \n”);
return EXIT_SUCCESS;
}
/Initialize the usb device/
int usbDevInit(int argc,char argv[]){
/ Initialize the globle device structure for the usb */
usbd_funcs_t usbFuns = {
_USBDI_NFUNCS,
NULL,
NULL,
NULL
};
usbd_device_ident_t usbIdent={
VENTOR,
DEVICE,
DCLASS,
SUBCLASS,
PROTOCAL
};
/* allocate memory space for pDev */
pDev = (usbd_connect_parm_t *)malloc( sizeof(usbd_connect_parm_t) );
pDev->path = NULL; /* Default path(/dev/io-usb/io-usb) */
pDev->vusb = USB_VERSION; /* Versions of the USB stack (USB_VERSION) */
pDev->vusbd = USBD_VERSION; /* Versions of the USB DDK (USBD_VERSION) */
pDev->flags = 0; /* Currently none defined.Pass 0 */
pDev->argc = argc;
pDev->argv = argv;
pDev->evtbufsz = 0; /* Size of the event buffer used by the handler
thread to buffer events from the USB stack. For the default size, pass 0 */
pDev->ident = &usbIdent ; /* identifies the devices you're interested in receiving insertion/removal callbacks */
pDev->funcs = &usbFuns; /* A pointer to a usbd_funcs_t structure that specifies the insertion/removal callbacks */
pDev->connect_wait = USBD_CONNECT_WAIT;
if( (usbd_connect(pDev,&usbdHandle)) != EOK ){
printf("Could not connect to USB stack\n");
return ERROR;
}
printf("Connect to USB stack\n");
return NORMAL;
}
/usb Device insertion/
void usbDevInsertion(void){
int retVal; /* ??? */
int busno,devno;
usbd_device_descriptor_t *usbDesc; /* The opaque handle for the device whose descriptors you want to search */
struct usbd_desc_node *ept =NULL; /* ??? */
//usbd_string_descriptor_t *sdesc=NULL;
//char * ID;
printf("SUB Device Insertion called\n");
instance.config = 1;
instance.iface = 0;
instance.alternate = 0;
for(busno=0;busno<8;busno++)
for(devno=0;devno<8;devno++){
memset(&instance, USBD_CONNECT_WILDCARD, sizeof(usbd_device_instance_t));
instance.path = 0;
instance.devno = devno;
if((retVal = usbd_attach (usbdHandle,&instance,0,&usbD)) != EOK){
printf("%d,%dFailed:",busno,devno);
switch(retVal){
case ENODEV:
printf("ENODEV\n");
break;
case EBUSY:
printf("EBUSY\n");
break;
case ENOMEM :
printf("ENOMEM\n");
break;
}
}
else{
usbDesc = usbd_device_descriptor(usbD,&ept);
if(usbDesc == NULL){
printf("usbDesc == NULL\n");
return;
}
printf("Find it!!!\n");
return;
}
}
usbd_disconnect(usbdHandle);
}