?? usbtransunitmisc.c
字號(hào):
/* usbTransUnitMisc.c - translation unit miscellaneous functions *//* Copyright 2003 Wind River Systems, Inc. *//* Modification History--------------------01d,15oct04,ami Apigen Changes01e,28sep04,hch Fix gnu compiler warning with usbdHcdAttach and usbdHcdDetach01d,03aug04,hch Fix compiler warning01c,03aug04,mta coverity error fixes01b,03aug04,ami Warning Messages Removed01a,19sep03,mta First*//*DESCRIPTIONImplements the Translation Unit Miscellaneous Interfaces.These interfaces are used only by UsbTool and not by Class Drivers.They interfaces are provided to Integrate Translation Unit with UsbToolINCLUDE FILES: drv/usb/usbTransUnit.h, usb/pciConstants.h, usb2/usbHubMisc.h,usb2/usbdMisc.h*//* includes */#include "drv/usb/usbTransUnit.h"#include "usb/pciConstants.h"#include "usb2/usbHubMisc.h"#include "usb2/usbdMisc.h"/* defines */#define USBTUMISC_USBD_VERSION 0x0200 /* USBD version in BCD */#define USBTUMISC_USBD_MFG "Wind River Systems, Inc." /* USBD Mfg *//* Add these in compiler options#define INCLUDE_OHCD#define INCLUDE_UHCD#define INCLUDE_EHCD*//* To hold the class code for UHCI Complaint USB Host Controllers */#define USB_UHCI_HOST_CONTROLLER 0x000C0300/* To hold the class code for OHCI Complaint USB Host Controllers */#define USB_OHCI_HOST_CONTROLLER 0x000C0310/* To hold the class code for EHCI Complaint USB Host Controllers */#define USB_EHCI_HOST_CONTROLLER 0x000C0320#define MAX_NO_OF_OHCI_CONTROLLERS 5#define MAX_NO_OF_UHCI_CONTROLLERS 5#define MAX_NO_OF_EHCI_CONTROLLERS 5#define TOKEN_FOR_OHCI 0x4#define TOKEN_FOR_UHCI 0x5#define TOKEN_FOR_EHCI 0x6/* Defines for the return types for detected devices */#define USBHUB_NODETYPE_HUB (0x02)#define USBHUB_NODETYPE_DEVICE (0x01)#define USBHUB_NODETYPE_NONE (0x00)/***************************************************************************** usbdHcdAttach - attaches an HCD to the USBD** The <hcdExecFunc> passed by the caller must point to an HCD抯 primary* entry point as defined below:** \cs* typedef UINT16 (*HCD_EXEC_FUNC) (pHRB_HEADER pHrb);* \ce** RETURNS: OK** ERRNO: none*/STATUS usbdHcdAttach ( HCD_EXEC_FUNC hcdExecFunc, /* Ptr to HCD抯 primary entry point */ void * hcdPciCfgHdr, /* HCD-specific parameter */ pGENERIC_HANDLE pAttachToken /* Token to identify HCD in future */ ) { UINT32 HCD_ID; PCI_CFG_HEADER *pciCfgHdr = (PCI_CFG_HEADER *)hcdPciCfgHdr; HCD_ID = ( (pciCfgHdr->pciClass << 16) | (pciCfgHdr->subClass << 8) | pciCfgHdr->pgmIf ); switch(HCD_ID) {#ifdef INCLUDE_EHCD case USB_EHCI_HOST_CONTROLLER : if(TRUE == usbEhcdInit()) *pAttachToken = TOKEN_FOR_EHCI ; break;#endif#ifdef INCLUDE_OHCD case USB_OHCI_HOST_CONTROLLER : if(TRUE == usbOhciInit()) *pAttachToken = TOKEN_FOR_OHCI; break;#endif#ifdef INCLUDE_UHCD case USB_UHCI_HOST_CONTROLLER : if(USBHST_SUCCESS == usbUhcdInit()) *pAttachToken = TOKEN_FOR_UHCI; break;#endif default: break; } return OK; }/***************************************************************************** usbdHcdDetach - Detaches an HCD from the USBD** The <attachToken> must be the attach token originally returned by* usbdHcdAttach() when it first attached to the HCD.** RETURNS: OK** ERRNO: none*/STATUS usbdHcdDetach ( GENERIC_HANDLE attachToken /* AttachToken returned */ ) {UINT32 token = (UINT32)attachToken;switch ( token ) {#ifdef INCLUDE_EHCD case TOKEN_FOR_EHCI: usbEhcdExit(); break;#endif#ifdef INCLUDE_OHCD case TOKEN_FOR_OHCI: usbOhciExit(); break;#endif#ifdef INCLUDE_UHCD case TOKEN_FOR_UHCI: usbUhcdExit(); break;#endif default: break; } return OK; }/***************************************************************************** usbdBusCountGet - get number of USBs attached to the host.** This function returns the total number of USB host controllers in the* system. Each host controller has its own root hub as required by the USB* specification; and clients planning to enumerate USB devices using the Bus* Enumeration Functions need to know the total number of host controllers in* order to retrieve the Node Ids for each root hub.** <pBusCount> must point to a UINT16 variable in which the total number of * USB host controllers will be stored.** Note: The number of USB host controllers is not constant. Bus controllers * can be added by calling usbdHcdAttach() and removed by calling * usbdHcdDetach(). Again, the Dynamic Attach Functions deal with these * situations automatically, and are the preferred mechanism by which most * clients should be informed of device attachment and removal.** RETURNS: OK, or ERROR if unable to retrieve bus count** ERRNO: none*/STATUS usbdBusCountGet ( USBD_CLIENT_HANDLE clientHandle, /* Client handle */ pUINT16 pBusCount /* Word bfr to receive bus count */ ) { if (pBusCount == NULL) return ERROR; *pBusCount = usbdBusCntGet(); return OK; }/***************************************************************************** usbdRootNodeIdGet - returns root node for a specific USB** This function returns the Node Id for the root hub for the specified * USB host controller. <busIndex> is the index of the desired USB host * controller. The first host controller is index 0 and the last host * controller's index is the total number of USB host controllers - as * returned by usbdBusCountGet() - minus 1. < pRootId> must point to a * USBD_NODE_ID variable in which the Node Id of the root hub will be stored.* * RETURNS: OK, or ERROR if unable to get root node ID.** ERRNO: none*/STATUS usbdRootNodeIdGet ( USBD_CLIENT_HANDLE clientHandle, /* Client handle */ UINT16 busIndex, /* Bus index */ pUSBD_NODE_ID pRootId /* bfr to receive Root Id */ ) { UINT32 rootId; if (pRootId == NULL) return ERROR; usbdRootNodeIDGet(busIndex,&rootId); *pRootId = (USBD_NODE_ID)rootId; return OK; }/********************************************************************************* usbdHubPortCountGet - returns number of ports connected to a hub** usbdHubPortCountGet() provides clients with a convenient mechanism to* retrieve the number of downstream ports provided by the specified hub.* Clients can also retrieve this information by retrieving configuration* descriptors from the hub using the Configuration Functions describe in* a following section.** <hubId> must be the Node Id for the desired USB hub. An error will be* returned if <hubId> does not refer to a hub. <pPortCount> must point to* a UINT16 variable in which the total number of ports on the specified* hub will be stored.** RETURNS: OK, or ERROR if unable to get hub port count.** ERRNO: none*/STATUS usbdHubPortCountGet ( USBD_CLIENT_HANDLE clientHandle, /* Client handle */ USBD_NODE_ID hubId, /* Node Id for desired hub */ pUINT16 pPortCount /* bfr to receive port count */ ) { /* Support is required from USBD to retrieve actual data. * This is currently a stub.The count that is returned is equal to the * number of USB devices already attached to USB or 2 which ever is higher */ USBHST_STATUS status; if(pPortCount == NULL) return ERROR; status = usbHubPortCntGet((UINT32)hubId,pPortCount); if (status != USBHST_SUCCESS) return ERROR; else return OK; }/********************************************************************************* usbdNodeIdGet - gets the id of the node connected to a hub port** Clients use this function to retrieve the Node Id for devices attached to* each of a hub抯 ports. <hubId> and <portIndex> identify the hub and port* to which a device may be attached. <pNodeType> must point to a UINT16* variable to receive a type code as follows:** \is* \i 'USB_NODETYPE_NONE'* No device is attached to the specified port.** \i 'USB_NODETYPE_HUB'* A hub is attached to the specified port.** \i 'USB_NODETYPE_DEVICE'* A device (non-hub) is attached to the specified port.* \ie** If the node type is returned as USBD_NODE_TYPE_NONE, then a Node Id is* not returned and the value returned in <pNodeId> is undefined. If the* node type indicates a hub or device is attached to the port, then* <pNodeId> will contain that hub or device抯 nodeId upon return.** RETURNS: OK, or ERROR if unable to get node ID.* * ERRNO: none*/STATUS usbdNodeIdGet ( USBD_CLIENT_HANDLE clientHandle, /* Client handle */ USBD_NODE_ID hubId, /* Node Id for desired hub */ UINT16 portIndex, /* Port index */ pUINT16 pNodeType, /* bfr to receive node type */ pUSBD_NODE_ID pNodeId /* bfr to receive Node Id */ ) { /* Support is required from USBD to retrieve actual data. * This is a currently a stub. The portIndex is used to chain through * the global device list to get to the appropriate device. */ UINT16 nodeType; UINT32 nodeId; USBHST_STATUS status; if ( pNodeType == NULL || pNodeId == NULL) return ERROR; status = usbHubNodeIDGet((UINT32)hubId, portIndex, &nodeType, &nodeId); switch( nodeType) { case USBHUB_NODETYPE_HUB : *pNodeType = USB_NODETYPE_HUB; *pNodeId = (USBD_NODE_ID) nodeId; break; case USBHUB_NODETYPE_DEVICE : *pNodeType = USB_NODETYPE_DEVICE; *pNodeId = (USBD_NODE_ID) nodeId; break; case USBHUB_NODETYPE_NONE : *pNodeType = USB_NODETYPE_NONE; *pNodeId = (USBD_NODE_ID) nodeId; break; }
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -