⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 usbtargkbdlib.c

📁 This the compressed USB driver source code for vxworks5.6. It has device controller driver and other
💻 C
📖 第 1 页 / 共 3 页
字号:
    pVOID	pContext		/* Context value */    )    {    pUSB_APPLN_DEVICE_INFO	pDeviceInfo = NULL; /* Pointer to */						    /* USB_APPLN_DEVICE_INFO */    switch (mngmtCode)        {    	case TARG_MNGMT_ATTACH:            if (pContext == NULL)                return ERROR;            /* Retrieve the pointer to the device info data structure */            pDeviceInfo = (pUSB_APPLN_DEVICE_INFO)pContext;    	    /* Initialize global data */            uDeviceFeature = pDeviceInfo->uDeviceFeature;            uEndpointNumberBitmap = pDeviceInfo->uEndpointNumberBitmap;    	    channel = targChannel;            /*              * If the device is USB 2.0, initialize the bcdUSB field of             * the device descriptor and the device qualifier descriptor.             */            if ((uDeviceFeature & USB_FEATURE_USB20) != 0)                {                devDescr.bcdUsb = TO_LITTLEW(KBD_USB20_VERSION);                devQualifierDescr.bcdUsb = TO_LITTLEW(KBD_USB20_VERSION);                }            /* 	     * If the device supports remote wakeup, modify the configuration             * descriptor accordingly.             */            if ((uDeviceFeature & USB_FEATURE_DEVICE_REMOTE_WAKEUP) != 0)                {                configDescr.attributes |= USB_ATTR_REMOTE_WAKEUP;                if ((uDeviceFeature & USB_FEATURE_USB20) != 0)                    otherSpeedConfigDescr.attributes |= USB_ATTR_REMOTE_WAKEUP;                }            /*              * Check if the endpoint number is supported.             * The shift value is directly taken as the endpoint address             * as the application is specifically written for keyboard and it             * supports only the interrupt IN endpoint.             */            if ((uEndpointNumberBitmap >>                (16 + (USB_ENDPOINT_MASK & epDescr.endpointAddress))) == 0)                {                /* Search through the bitmap and arrive at an endpoint address*/                UINT32 uIndex = 1;                for (uIndex = 16; uIndex < 32; uIndex++)                    {                    if ((uEndpointNumberBitmap >> uIndex) != 0)                        {                        epDescr.endpointAddress = USB_ENDPOINT_IN | (uIndex - 16);                        break;                        }                    }                if (uIndex == 32)                    return ERROR;                }    	    break;    	case TARG_MNGMT_DETACH:            /* Reset the globals */            channel = 0;            uDeviceFeature = 0;            uEndpointNumberBitmap = 0;            /* Reset the device and device qualifier descriptors' bcusb field */            devDescr.bcdUsb = TO_LITTLEW(KBD_USB10_VERSION);            devQualifierDescr.bcdUsb = TO_LITTLEW(KBD_USB10_VERSION);            epDescr.endpointAddress = KBD_INTERRUPT_ENDPOINT_NUM;    	    break;    	case TARG_MNGMT_BUS_RESET:            /* Copy the operating speed of the device */    	    uSpeed = (UINT32)pContext;    	    curConfiguration = 0;    	    uDeviceAddress = 0;            /* Reset the device status to indicate that it is self powered */            uDeviceStatus = 0x01;            /* Delete the interrupt pipe if created */    	    if (intPipeHandle != NULL)    	        {    	        usbTargPipeDestroy (intPipeHandle);    	        intPipeHandle = NULL;    	        }    	    /* Initialize the descriptor values */    	    if (uSpeed == USB_TCD_HIGH_SPEED)    	        {    	        /*Initialize the max packet sizes for the default control pipe*/        	devDescr.maxPacketSize0 = KBD_HIGH_SPEED_CONTROL_MAX_PACKET_SIZE;                devQualifierDescr.maxPacketSize0 = USB_MIN_CTRL_PACKET_SIZE;                epDescr.interval = KBD_HIGH_SPEED_POLLING_INTERVAL;                }       	     else       	        {                devDescr.bcdUsb = TO_LITTLEW(KBD_USB10_VERSION);                devQualifierDescr.bcdUsb = TO_LITTLEW(KBD_USB10_VERSION);        	devDescr.maxPacketSize0 = USB_MIN_CTRL_PACKET_SIZE;                epDescr.interval = KBD_INTERRUPT_ENDPOINT_INTERVAL;       	        /*                  * If the device is a USB 2.0 device, then set the device                 * qualifier descriptor's maximum packet size        	 */        	if ((uDeviceFeature & USB_FEATURE_USB20) != 0)        	    {        	        devQualifierDescr.maxPacketSize0 =                                         KBD_HIGH_SPEED_CONTROL_MAX_PACKET_SIZE;        	    }                }            break;    	case TARG_MNGMT_DISCONNECT:    	    curConfiguration = 0;            /* Delete the interrupt pipe if created */    	                if (intPipeHandle != NULL)    	        {    	        usbTargPipeDestroy (intPipeHandle);    	        intPipeHandle = NULL;    	        }     	    break;        case TARG_MNGMT_SUSPEND:        case TARG_MNGMT_RESUME:    	default:    	    break;    	}    return OK;    }/******************************************************************************** featureClear - invoked by usbTargLib for CLEAR_FEATURE request** This function is called to clear device or endpoint specific features.** RETURNS: OK, or ERROR if unable to clear requested feature** ERRNO:*  none.** \NOMANUAL*/LOCAL STATUS featureClear    (    pVOID	param,			/* TCD specific parameter */    USB_TARG_CHANNEL	targChannel,	/* Target Channel */    UINT8	requestType,		/* Type of request */    UINT16	feature,		/* Feature to be cleared */    UINT16	index			/* 0, interface or endpoint */    )    {    STATUS status = ERROR;    /* This request is not accepted when the device is in the default state */    if (uDeviceAddress == 0)        return ERROR;    /* Switch based on the feature which needs to be cleared */    switch(feature)        {        case USB_FSEL_DEV_REMOTE_WAKEUP:                        /*              * If the device supports remote wakeup, call the function             * to clear the remote wakeup feature             */                        if ((uDeviceFeature & USB_FEATURE_DEVICE_REMOTE_WAKEUP) != 0)                {                status = usbTargDeviceFeatureClear(targChannel, feature);                /* Clear the global status */                if (status == OK)                    uDeviceStatus &= ~0x02;                }            break;        case USB_FSEL_DEV_ENDPOINT_HALT:            /* Check whether the endpoint address is valid */            if ((index == epDescr.endpointAddress) && (intPipeHandle != NULL))                {                /* Call the function to clear the endoint halt feature */                status = usbTargPipeStatusSet(intPipeHandle,                                              TCD_ENDPOINT_UNSTALL);                }            break;        default:            break;        }        return status;    }/******************************************************************************** featureSet - invoked by usbTargLib for SET_FEATURE request** This function is used to set device or endpoint specific features.* <feature> consists of the feature to set.** RETURNS: OK, or ERROR if unable to set requested feature** ERRNO:*  none.** \NOMANUAL*/LOCAL STATUS featureSet    (    pVOID	param,			/* TCD Specific Parameter */    USB_TARG_CHANNEL	targChannel,	/* Target Channel */    UINT8	requestType,		/* Type of Request */    UINT16	feature,		/* Feature to set */    UINT16	index			/* 0, interface or endpoint */    )    {    STATUS	status = ERROR;		/* varaiable to hold error status */    /*      * This request is not accepted when the the device is in the default state     * and the feature to be set is not TEST_MODE     */    if ((uDeviceAddress == 0) && (feature != USB_FSEL_DEV_TEST_MODE))        return ERROR;    /* Switch based on the feature which needs to be set */    switch(feature)        {        case USB_FSEL_DEV_REMOTE_WAKEUP:            /*              * If the device supports remote wakeup, call the function             * to set the remote wakeup feature             */            if ((uDeviceFeature & USB_FEATURE_DEVICE_REMOTE_WAKEUP) != 0)                {                status = usbTargDeviceFeatureSet(targChannel, feature, index);                /* Set the global status */                if (status == OK)                    uDeviceStatus |= 0x02;                }            break;                case USB_FSEL_DEV_TEST_MODE:            /*              * If the device supports remote wakeup, call the function             * to set the test mode feature             */                        if ((uDeviceFeature & USB_FEATURE_TEST_MODE) != 0)                {                status = usbTargDeviceFeatureSet(targChannel,                                                 feature,                                                 ((index & 0xFF00) << 8));                }            break;                case USB_FSEL_DEV_ENDPOINT_HALT:            /* Check whether the endpoint address is valid */            if ((index == epDescr.endpointAddress) && (intPipeHandle != NULL))                {                /* Call the function to stall the endoint */                status = usbTargPipeStatusSet(intPipeHandle,                                              TCD_ENDPOINT_STALL);                }            break;                default:            break;        }    return status;    }/******************************************************************************** configurationGet - invoked by usbTargLib for GET_CONFIGURATION request** This function is used to get the current configuration of the device.* <pConfiguration> is set with the current configuration and sent to the* host.** RETURNS: OK, or ERROR if unable to return configuration setting** ERRNO:*  none** \NOMANUAL*/LOCAL STATUS configurationGet    (    pVOID	param,			/* TCD Specific Parameter */    USB_TARG_CHANNEL	targChannel,	/* Target Channel */    pUINT8	pConfiguration		/* Configuration value to sent */    )    {    /* This request is not accepted when the device is in the default state */    if (uDeviceAddress == 0)        return ERROR;    *pConfiguration = curConfiguration;    return OK;    }/******************************************************************************** configurationSet - invoked by usbTargLib for SET_CONFIGURATION request*** This function is used to set the current configuration to the configuration* value sent by host. <configuration> consist of the value to set.** RETURNS: OK, or ERROR if unable to set specified configuration** ERRNO:*  none.** \NOMANUAL*/LOCAL STATUS configurationSet    (    pVOID	param,			/* TCD Specific Parameter */    USB_TARG_CHANNEL	targChannel,	/* Target Channel */    UINT8	configuration		/* Configuration value to set */    )    {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -