📄 usbtransunitmisc.c
字号:
if(status != USBHST_SUCCESS) return ERROR; else return OK; }/********************************************************************************* usbdAddressGet - gets the USB address for a given device** This function returns the USB address assigned to device specified by* <nodeId>.** RETURNS: OK, or ERROR** ERRNO: none*/STATUS usbdAddressGet ( USBD_CLIENT_HANDLE clientHandle, /* Client handle */ USBD_NODE_ID nodeId, /* Node Id of device/hub */ pUINT16 pDeviceAddress /* Currently assigned device address */ ) { /* This interface is not exposed by the Host Stack to Client Modules * This is a stub. */ if (pDeviceAddress == NULL) return ERROR; *pDeviceAddress = 0; return OK; }/***************************************************************************** usbdAddressSet - sets the USB address for a given device** This function sets the USB address at which a device will respond to future* requests. Upon return, the address of the device identified by <nodeId>* will be changed to the value specified in <deviceAddress>. <deviceAddress>* must be in the range from 0..127. The <deviceAddress> must also be unique* within the scope of each USB host controller.** The USBD manages USB device addresses automatically, and this function* should never be called by normal USBD clients. Changing a device address* may cause serious problems, including device address conflicts, and may* cause the USB to cease operation.** RETURNS: OK, or ERROR ** ERRNO: none*/STATUS usbdAddressSet ( USBD_CLIENT_HANDLE clientHandle, /* Client handle */ USBD_NODE_ID nodeId, /* Node Id of device/hub */ UINT16 deviceAddress /* New device address */ ) { /* This interface is not exposed by the Host Stack to Client Modules. * This is a stub. */ if (deviceAddress > 127) return ERROR; else return OK; }/******************************************************************************** usbdVersionGet - Returns USBD version information** This function returns the USBD version. If <pVersion> is not NULL, the* USBD returns its version in BCD in <pVersion>. For example, version* "1.02" would be coded as 01h in the high byte and 02h in the low byte.** If <pMfg> is not NULL it must point to a buffer of at least USBD_NAME_LEN* bytes in length in which the USBD will store the NULL terminated name of* the USBD manufacturer (e.g., "Wind River Systems" + \0).** RETURNS: OK, or ERROR** ERRNO: none*/STATUS usbdVersionGet ( pUINT16 pVersion, /* UINT16 bfr to receive version */ pCHAR pMfg /* bfr to receive USBD mfg string */ ) { if ( pVersion == NULL || pMfg == NULL) return ERROR; *pVersion = USBTUMISC_USBD_VERSION; strncpy (pMfg, (char *)USBTUMISC_USBD_MFG, USBD_NAME_LEN + 1); return OK; } /********************************************************************************* usbdStatisticsGet - Retrieves USBD operating statistics** This function returns operating statistics for the USB to which the* specified <nodeId> is connected.** The USBD copies the current operating statistics into the <pStatistics>* structure provided by the caller. This structure is defined as:** \cs* typedef struct usbd_stats* {* UINT16 totalTransfersIn;* UINT16 totalTransfersOut;* UINT16 totalReceiveErrors;* UINT16 totalTransmitErrors;* } USBD_STATS, *pUSBD_STATS;* \ce** It is anticipated that this structure may grow over time. To provide* backwards compatibility, the client must pass the total size of the* USBD_STATS structure it has allocated in <statLen>. The USBD will copy* fields into this structure only up to the statLen indicated by the caller.** RETURNS: OK* * ERRNO: N/A*/STATUS usbdStatisticsGet ( USBD_CLIENT_HANDLE clientHandle, /* Client handle */ USBD_NODE_ID nodeId, /* Node Id of node on desired USB */ pUSBD_STATS pStatistics, /* Ptr to structure to receive stats */ UINT16 statLen /* Len of bfr provided by caller */ ) { /* Support is required from USBD to retrieve actual data. * This is a currently a stub. All members are filled with zeros */ memset ( (char*)pStatistics, 0, statLen); return OK; }/***************************************************************************** usbdCurrentFrameGet - returns the current frame number for a USB** It is sometimes necessary for clients to retrieve the current USB frame * number for a specified host controller. This function allows a client to * retrieve the current USB frame number for the host controller to which* <nodeId> is connected. Upon return, the current frame number is stored * in <pFrameNo>.** If <pFrameWindow> is not NULL, the USBD will also return the maximum frame * scheduling window for the indicated USB host controller. The frame * scheduling window is essentially the number of unique frame numbers * tracked by the USB host controller. Most USB host controllers maintain an * internal frame count which is a 10- or 11-bit number, allowing them to * track typically 1024 or 2048 unique frames. When starting an isochronous * transfer, a client may wish to specify that the transfer will begin in a * specific USB frame. For the given USB host controller, the starting frame * number can be no more than <frameWindow> frames from the current <frameNo>.** Note: The USBD is capable of simultaneously managing multiple USB host * controllers, each of which operates independently. Therefore, it is * important that the client specify the correct <nodeId> when retrieving the * current frame number. Typically, a client will be interested in the * current frame number for the host controller to which a specific device is * attached.** RETURNS: OK, or ERROR if unable to retrieve current frame number.** ERRNO: none*/STATUS usbdCurrentFrameGet ( USBD_CLIENT_HANDLE clientHandle, /* Client handle */ USBD_NODE_ID nodeId, /* Node Id of node on desired USB */ pUINT32 pFrameNo, /* bfr to receive current frame no. */ pUINT32 pFrameWindow /* bfr to receive frame window */ ) { UINT16 frameno; USBHST_STATUS status; if (pFrameNo == NULL || pFrameWindow == NULL) return ERROR; status = usbHstGetFrameNumber((UINT32)nodeId, &frameno); if (status != USBHST_SUCCESS) return ERROR; *pFrameNo = frameno; *pFrameWindow = 1024; return OK; }/***************************************************************************** HubEnumerate - enumerate all ports on the specified hub* * This routine enumerates all devices from the specified HubId down.* <clientHandle> must be a valid USBD_CLIENT_HANDLE. <hubId> specifies* the Node Id of the first USB hub to be enumerated.** RETURNS: OK, or ERROR if USBD returns an error.** ERRNO: N/A* *\NOMANUAL*/#define INDENT 2LOCAL UINT16 HubEnumerate ( USBD_CLIENT_HANDLE clientHandle, /* Caller抯 USBD client handle */ USBD_NODE_ID hubId, /* Node Id for hub to enumerate */ UINT16 indent, pUSBD_NODE_INFO pNodeInfo, /* Structure to receive node info */ USBD_NODE_ID nodeId_passed /* id of node being enumerated */ ) { UINT16 portCount; /* Number of ports on this hub */ UINT16 portIndex; /* current port index */ UINT16 nodeType; /* type of node being enumerated */ USBD_NODE_ID nodeId; /* id of node being enumerated */ /* Retrieve the number of ports for this hub. */ if ( usbdHubPortCountGet (clientHandle, hubId, &portCount) != OK ) { return ERROR; } /* See if a device is attached to each of the hub抯 ports. */ for (portIndex = 0; portIndex < portCount; portIndex++) { if ( usbdNodeIdGet (clientHandle, hubId, portIndex, &nodeType, &nodeId) != OK) { return ERROR; } if(nodeId==nodeId_passed) { pNodeInfo->nodeType = nodeType; pNodeInfo->parentHubId = hubId; pNodeInfo->parentHubPort = portIndex; } switch (nodeType) { case USB_NODETYPE_HUB: /* Another hub found. */ if (HubEnumerate (clientHandle, nodeId, indent+INDENT,pNodeInfo,nodeId_passed ) != OK) return ERROR; break; default: /* Unknown node type code */ break; } } return OK; }/********************************************************************************* usbdNodeInfoGet - returns information about a USB node** This function retrieves information about the USB device specified by * <nodeId>. The USBD copies node information into the <pNodeInfo> structure * provided by the caller. This structure is of the form USBD_NODEINFO as* shown below:** \cs* typedef struct usbd_nodeinfo* {* UINT16 nodeType;* UINT16 nodeSpeed;* USBD_NODE_ID parentHubId;* UINT16 parentHubPort;* USBD_NODE_ID rootId;* } USBD_NODEINFO, *pUSBD_NODEINFO;* \ce** <nodeType> specifies the type of node identified by <nodeId> and is defined * as USB_NODETYPE_xxxx. <nodeSpeed> identifies the speed of the device and * is defined as USB_SPEED_xxxx, Currently this field is not updated.* <parentHubId> and <parentHubPort> identify the Node Id and port of the hub * to which the indicated node is attached upstream. * If the indicated <nodeId> happens to be a root hub, then * <parentHubId> and <parentHubPort> will both be 0. ** Similarly, <rootId> identifies the Node Id of the root hub for the USB to * which nodeId is attached. If <nodeId> itself happens to be the root hub, * then the same value will be returned in <rootId>.** It is anticipated that this structure may grow over time. To provide * backwards compatibility, the client must pass the total size of the * USBD_NODEINFO structure it has allocated in <infoLen>. The USBD will copy * fields into this structure only up to the <infoLen> indicated by the caller.** RETURNS: OK, or ERROR if unable to retrieve node information.** ERRNO: None*/STATUS usbdNodeInfoGet ( USBD_CLIENT_HANDLE clientHandle,/* Client handle */ USBD_NODE_ID nodeId, /* Node Id of device/hub */ pUSBD_NODE_INFO pNodeInfo, /* Structure to receive node info */ UINT16 infoLen /* Len of bfr allocated by client */ ) { UINT16 busCount; /* Number of USB host controllers */ UINT16 busIndex; /* current bus index */ USBD_NODE_ID rootId; /* Root hub id for current bus */ /* Retrieve the number of USB host controllers in the system. */ if( NULL == pNodeInfo ) { return ERROR; } if ( usbdBusCountGet (clientHandle, &busCount) != OK) { return ERROR; } /* Retrieve the root hub id for each host controller and enumerate it. */ for (busIndex = 0; busIndex < busCount; busIndex++) { if ( usbdRootNodeIdGet (clientHandle, busIndex, &rootId) != OK ) { return ERROR; } pNodeInfo->rootId = rootId; if (HubEnumerate (clientHandle, rootId, INDENT,pNodeInfo ,nodeId ) != OK) return ERROR; } return OK; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -