📄 usbtransunitstd.c
字号:
/* usbTransUnitStd.c - translation unit standard requests interfaces *//* Copyright 2003 Wind River Systems, Inc. *//*Modification history--------------------01g,15oct04,ami Apigen Changes01f,11oct04,ami Apigen changes01h,16sep04,hch Fix diab compiler error on strncpy01g,12apr04,cfc Apigen corrections01f,02dec03,cfc Merge for isochronous USB speaker support01e,17sep03,cfc Remove direct calls to wvEvent01d,10jul03,mat Set Configuration Fix01c,16jun03,mat prefixed "usb" to file name01b,06jun03,mat Wind View Instrumentation.01a,06jun03,mat Wind River Coding Convention API changes.*//*DESCRIPTIONImplements the Translation Unit Standard Requests Interfaces.INCLUDE FILES: drv/usb/usbTransUnit.h, usb2/usbHcdInstr.h*//* includes */#include "drv/usb/usbTransUnit.h"#include "usb2/usbHcdInstr.h"/* defines */#define USBTUSTD_RECIPIENT_MASK 0x03 #define USBTUSTD_STATUS_BUFFER_SIZE 2/********************************************************************************* usbdFeatureClear - clears a USB feature** This function allows a client to "clear" a USB feature. <nodeId> specifies* the Node Id of the desired device and <requestType> specifies whether the* feature is related to the device, to an interface, or to an endpoint as:** \is* \i 'USB_RT_DEVICE'* Device** \i 'USB_RT_INTERFACE'* Interface** \i 'USB_RT_ENDPOINT'* Endpoint* \ie** <requestType> also specifies if the request is standard, class-specific,* etc., as:** \is* \i 'USB_RT_STANDARD'* Standard** \i 'USB_RT_CLASS'* Class-specific** \i 'USB_RT_VENDOR'* Vendor-specific* \ie** For example, USB_RT_STANDARD | USB_RT_DEVICE in <requestType> specifies a* standard device request.** The client must pass the device抯 feature selector in <feature>. If* <featureType> specifies an interface or endpoint, then <index> must contain* the interface or endpoint index. <index> should be zero when <featureType>* is USB_SELECT_DEVICE.** RETURNS: OK, or ERROR if unable to clear feature.** ERRNO: none*/STATUS usbdFeatureClear ( USBD_CLIENT_HANDLE clientHandle, /* Client handle */ USBD_NODE_ID nodeId, /* Node Id of device/hub */ UINT16 requestType, /* Selects request type */ UINT16 feature, /* Feature selector */ UINT16 index /* Interface/endpoint index */ ) { USBHST_STATUS status; UINT8 recipient; pUSBTU_DEVICE_DRIVER pDriver = (pUSBTU_DEVICE_DRIVER) clientHandle; /* Wind View Instrumentation */ if ((usbtuInitWvFilter & USBTU_WV_FILTER) == TRUE) { char evLog[USBTU_WV_LOGSIZE]; strncpy ((char*)evLog, (char *)(pDriver->clientName),USBD_NAME_LEN ); strcat(evLog, " : Feature Clear "); USB_HCD_LOG_EVENT(USBTU_WV_CLIENT_STD, evLog, USBTU_WV_FILTER); } USBTU_LOG ( "usbdFeatureClear entered \n "); /* get the recipient */ recipient = (UINT8)(requestType & USBTUSTD_RECIPIENT_MASK); status = usbHstClearFeature( (UINT32) nodeId, recipient, index, feature); if ( status != USBHST_SUCCESS ) { USBTU_LOG( "usbdFeatureClear returns ERROR \n "); return ERROR; } else { USBTU_LOG( "usbdFeatureClear returns OK \n "); return OK; } }/********************************************************************************* usbdFeatureSet - sets a USB feature** This function allows a client to "set" a USB feature. <nodeId> specifies* the Node Id of the desired device and <requestType> specifies the nature* of the feature feature as defined for the usbdFeatureClear() function.** The client must pass the device抯 feature selector in <feature>. If* <requestType> specifies an interface or endpoint, then <index> must contain* the interface or endpoint index. <index> should be zero when <requestType>* includes USB_SELECT_DEVICE.** RETURNS: OK, or ERROR if unable to set feature.** ERRNO: none*/STATUS usbdFeatureSet ( USBD_CLIENT_HANDLE clientHandle, /* Client handle */ USBD_NODE_ID nodeId, /* Node Id of device/hub */ UINT16 requestType, /* Selects request type */ UINT16 feature, /* Feature selector */ UINT16 index /* Interface/endpoint index */ ) { USBHST_STATUS status; UINT8 recipient; pUSBTU_DEVICE_DRIVER pDriver = (pUSBTU_DEVICE_DRIVER) clientHandle; /* Wind View Instrumentation */ if ((usbtuInitWvFilter & USBTU_WV_FILTER) == TRUE) { char evLog[USBTU_WV_LOGSIZE]; strncpy ((char*)evLog, (char *)(pDriver->clientName),USBD_NAME_LEN ); strcat(evLog, " : Feature Set "); USB_HCD_LOG_EVENT(USBTU_WV_CLIENT_STD, evLog, USBTU_WV_FILTER); } USBTU_LOG ( "usbdFeatureSet entered \n "); /* get the recipient */ recipient = (UINT8)(requestType & USBTUSTD_RECIPIENT_MASK); status = usbHstSetFeature( (UINT32) nodeId, recipient, index, feature, 0); if ( status != USBHST_SUCCESS ) { USBTU_LOG( "usbdFeatureSet returns ERROR \n "); return ERROR; } else { USBTU_LOG( "usbdFeatureSet returns OK \n "); return OK; } }/********************************************************************************* usbdConfigurationGet - gets USB configuration for a device** This function returns the currently selected configuration for the device* or hub indicated by <nodeId>. The current configuration value is returned* in the low byte of <pConfiguration>. The high byte is currently reserved* and will be 0.** RETURNS: OK, or ERROR if unable to get configuration.** ERRNO: none*/STATUS usbdConfigurationGet ( USBD_CLIENT_HANDLE clientHandle, /* Client handle */ USBD_NODE_ID nodeId, /* Node Id of device/hub */ pUINT16 pConfiguration /* bfr to receive config value */ ) { USBHST_STATUS status; UCHAR configuration; pUSBTU_DEVICE_DRIVER pDriver = (pUSBTU_DEVICE_DRIVER) clientHandle; /* Wind View Instrumentation */ if ((usbtuInitWvFilter & USBTU_WV_FILTER) == TRUE) { char evLog[USBTU_WV_LOGSIZE]; strncpy ((char*)evLog, (char *)(pDriver->clientName),USBD_NAME_LEN ); strcat(evLog, " : Get Configuration "); USB_HCD_LOG_EVENT(USBTU_WV_CLIENT_STD, evLog, USBTU_WV_FILTER); } USBTU_LOG ( "usbdConfigurationGet entered \n "); status = usbHstGetConfiguration( (UINT32) nodeId, &configuration); if (status != USBHST_SUCCESS) { USBTU_LOG( "usbdConfigurationGet returns ERROR \n "); return ERROR; } /* Return result */ if (pConfiguration != NULL) *pConfiguration = configuration; USBTU_LOG( "usbdConfigurationGet returns OK \n "); return OK; }/********************************************************************************* usbdConfigurationSet - sets USB configuration for a device** This function sets the current configuration for the device identified* by <nodeId>. The client should pass the desired configuration value in* the low byte of <configuration>. The high byte is currently reserved and* should be 0.** The client must also pass the maximum current which will be used by this* configuration in <maxPower>** RETURNS: OK, or ERROR if unable to set configuration.** ERRNO: none*/STATUS usbdConfigurationSet ( USBD_CLIENT_HANDLE clientHandle, /* Client handle */ USBD_NODE_ID nodeId, /* Node Id of device/hub */ UINT16 configuration, /* New configuration to be set */ UINT16 maxPower /* max power this config will draw */ ) { USBHST_STATUS status; pUSBTU_DEVICE_DRIVER pDriver = (pUSBTU_DEVICE_DRIVER) clientHandle; pUSB_DEVICE_DESCR pDevDescr; /* pointer to device descriptor */ UINT8 bfr[255]; /* store for config descriptor */ UINT8 bfr1[255]; UINT8 * pBfr = bfr; /* pointer to the above store */ UINT8 * pBfr1 = bfr1; UINT16 actLength; /* actual length of descriptor */ UINT16 actLength1; UINT8 numCfg; /* number of configuration */ UINT8 index; pUSB_CONFIG_DESCR pCfgDescr; /* pointer to config'n descriptor */ /* Wind View Instrumentation */ if ((usbtuInitWvFilter & USBTU_WV_FILTER) == TRUE) { char evLog[USBTU_WV_LOGSIZE]; strncpy ((char*)evLog, (char *)(pDriver->clientName),USBD_NAME_LEN ); strcat(evLog, " : Set Configuration "); USB_HCD_LOG_EVENT(USBTU_WV_CLIENT_STD, evLog, USBTU_WV_FILTER); } USBTU_LOG ( "usbdConfigurationSet entered \n "); /* get the device descriptor */ if (usbdDescriptorGet (clientHandle, nodeId, USB_RT_STANDARD | USB_RT_DEVICE, USB_DESCR_DEVICE, 0, 0, 20, bfr, &actLength) != OK) return (ERROR); if ((pDevDescr = usbDescrParse ((pUINT8 )pBfr, actLength, USB_DESCR_DEVICE)) == NULL) return (ERROR); /* retrieve the num of configurations */ numCfg = pDevDescr->numConfigurations; for (index = 0; index < numCfg; index++) { /* get the config descriptor */ if (usbdDescriptorGet (clientHandle, nodeId, USB_RT_STANDARD | USB_RT_DEVICE, USB_DESCR_CONFIGURATION, index, 0, 255, bfr1, &actLength1) != OK) return (ERROR); if ((pCfgDescr = usbDescrParseSkip ((pUINT8* )& pBfr1, &actLength1, USB_DESCR_CONFIGURATION)) == NULL) return (ERROR); /* determine if config value in descriptor matches the parameter passed */ if (pCfgDescr->configurationValue == configuration) break; } if (index == numCfg) return (ERROR); status = usbHstSetConfiguration( (UINT32) nodeId, index); if (status != USBHST_SUCCESS) { USBTU_LOG( "usbdConfigurationSet returns ERROR \n "); return ERROR; } else { USBTU_LOG( "usbdConfigurationSet returns OK \n "); return OK; } }/********************************************************************************* usbdDescriptorGet - retrieves a USB descriptor** A client uses this function to retrieve a descriptor from the USB device* identified by <nodeId>. <requestType> is defined as documented for the* usbdFeatureClear() function. <descriptorType> specifies the type of the* descriptor to be retrieved and must be one of the following values:** \is* \i USB_DESCR_DEVICE* Specifies the DEVICE descriptor.** \i USB_DESCR_CONFIG* Specifies the CONFIGURATION descriptor.** \i USB_DESCR_STRING* Specifies a STRING descriptor.** \i USB_DESCR_INTERFACE* Specifies an INTERFACE descriptor.** \i USB_DESCR_ENDPOINT* Specifies an ENDPOINT descriptor.* \ie** <descriptorIndex> is the index of the desired descriptor.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -