?? usbtransunitinit.c
字號:
}/***************************************************************************** usbdClientUnregister - Unregisters a USBD client** A client invokes this function to release a previously assigned* USBD_CLIENT_HANDLE. The USBD will release all resources allocated to* the client, aborting any outstanding URBs which may exist for the client.** Once this function has been called with a given clientHandle, the client* must not attempt to reuse the indicated <clientHandle>.** RETURNS: OK, or ERROR if unable to unregister client.** ERRNO: N/A*/STATUS usbdClientUnregister ( USBD_CLIENT_HANDLE clientHandle /* Client handle */ ) { USBHST_STATUS status = USBHST_SUCCESS; pUSBTU_DEVICE_DRIVER pDriver = (pUSBTU_DEVICE_DRIVER) clientHandle; STATUS s = OK; USBTU_LOG ( "usbdClientUnRegister entered \n"); /* 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, " : USBD Unregister "); USB_HCD_LOG_EVENT(USBTU_WV_CLIENT_INIT, evLog, USBTU_WV_FILTER); } if ( !clientHandle) { USBTU_LOG("usbdClientUnRegister returns ERROR : NULL client handle \n"); return ERROR; } /* unregister the client */ if (pDriver->pDriverData) { status = usbHstDriverDeregister (pDriver->pDriverData); OSS_FREE (pDriver->pDriverData); } /* destroy the client thread */ if (pDriver->threadHandle) if (OSS_THREAD_DESTROY (pDriver->threadHandle) != OK) { USBTU_LOG("usbdClientUnRegister returns ERROR:thread destroy failed\n"); s = ERROR; } /* destroy the client message queue */ if (pDriver->msgQid) if (msgQDelete (pDriver->msgQid) != OK ) { USBTU_LOG("usbdClientUnRegister returns ERROR : message queue \ destroy failed \n"); s = ERROR; } /* destroy the irpComplete thread */ if (pDriver->irpThreadHandle) if (OSS_THREAD_DESTROY (pDriver->irpThreadHandle) != OK) { USBTU_LOG("usbdClientUnRegister returns ERROR:thread destroy failed\n"); s = ERROR; } /* destroy the irpComplete message queue */ if (pDriver->msgQidIrpComplete) if (msgQDelete (pDriver->msgQidIrpComplete) != OK ) { USBTU_LOG("usbdClientUnRegister returns ERROR : message queue \ destroy failed \n"); s = ERROR; } /* Unlink client structure */ OSS_MUTEX_TAKE (usbtuMutex, OSS_BLOCK); usbListUnlink (&pDriver->tuDriverLink); OSS_MUTEX_RELEASE(usbtuMutex); /* free the client structure */ OSS_FREE (pDriver); if ( status == USBHST_SUCCESS && s == OK ) { USBTU_LOG ( "usbdClientUnRegister returns OK \n"); return OK; } else { USBTU_LOG ( "usbdClientUnRegister returns ERROR \n"); return ERROR; } }/***************************************************************************** usbdMngmtCallbackSet - sets management callback for a client** Management callbacks provide a mechanism for the USBD to inform clients* of asynchronous management events on the USB. For example, if the USB* is in the SUSPEND state - see usbdBusStateSet() - and a USB device* drives RESUME signalling, that event can be reported to a client through* its management callback.** <clientHandle> is a client's registered handled with the USBD.* <mngmtCallback> is the management callback routine of type* USBD_MNGMT_CALLBACK which will be invoked by the USBD when management* events are detected. <mngmtCallbackParam> is a client-defined parameter* which will be passed to the <mngmtCallback> each time it is invoked.* Passing a <mngmtCallback> of NULL cancels management event callbacks.** When the <mngmtCallback> is invoked, the USBD will also pass it the* USBD_NODE_ID of the root node on the bus for which the management event* has been detected and a code signifying the type of management event* as USBD_MNGMT_xxxx.** Clients are not required to register a management callback routine.* Clients that do use a management callback are permitted to register at* most one management callback per USBD_CLIENT_HANDLE.** RETURNS: OK, or ERROR if unable to register management callback** ERRNO: N/A*/STATUS usbdMngmtCallbackSet ( USBD_CLIENT_HANDLE clientHandle, /* Client handle */ USBD_MNGMT_CALLBACK mngmtCallback, /* management callback */ pVOID mngmtCallbackParam /* client-defined parameter */ ) { pUSBTU_DEVICE_DRIVER pDriver = (pUSBTU_DEVICE_DRIVER)clientHandle; USBTU_LOG ( "usbdMngmtCallbackSet entered \n"); /* 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, " : Management Callback Register "); USB_HCD_LOG_EVENT(USBTU_WV_CLIENT_INIT, evLog, USBTU_WV_FILTER); } /* If management callback already registered return ERROR */ if (pDriver->mngmtCallback && mngmtCallback != NULL) { USBTU_LOG("usbdMngmtCallbackSet returns ERROR : callback already set\n"); return ERROR; } /* register management callback */ pDriver->mngmtCallback = mngmtCallback; pDriver->mngmtCallbackParam = mngmtCallbackParam; USBTU_LOG ( "usbdMngmtCallbackSet returns OK \n"); return OK; }/***************************************************************************** usbdBusStateSet - Sets bus state (e.g., suspend/resume)** This function allows a client to set the state of the bus to which* the specified <nodeId> is attached. The desired <busState> is specified* as USBD_BUS_xxxx.** Typically, a client will use this function to set a bus to the SUSPEND* or RESUME state. Clients must use this capability with care, as it will* affect all devices on a given bus - and hence all clients communicating* with those devices.*** RETURNS: OK, or ERROR if unable to set specified bus state** ERRNO: N/A*/STATUS usbdBusStateSet ( USBD_CLIENT_HANDLE clientHandle, /* Client handle */ USBD_NODE_ID nodeId, /* node ID */ UINT16 busState /* new bus state: USBD_BUS_xxxx */ ) { /* This functionality is not yet provided */#if 0 USBHST_STATUS status; USBD_NODE_ID rootId; USBD_NODE_INFO nodeInfo; USBTU_LOG ( "usbdBusStateSet entered \n"); /* get the root id */ usbdNodeInfoGet (clientHandle, nodeId, &nodeInfo, sizeof (USBD_NODE_INFO)); rootId = nodeInfo.rootId; switch( busState ) { case USBD_BUS_SUSPEND : status = usbHstSelectiveSuspend ((UINT32)rootId); break; case USBD_BUS_RESUME : status = usbHstSelectiveResume ((UINT32)rootId); break; default : break; } if ( status != USBHST_SUCCESS) { USBTU_LOG ( "usbdBusStateSet returns ERROR \n"); return ERROR; } else { USBTU_LOG ( "usbdBusStateSet returns OK \n"); return OK; }#endif return OK; }/***************************************************************************** usbdDynamicAttachRegister - Registers client for dynamic attach notification** Clients call this function to indicate to the USBD that they wish to be* notified whenever a device of the indicated class/sub-class/protocol is* attached or removed from the USB. A client may specify that it wants to* receive notification for an entire device class or only for specific* sub-classes within that class.** <deviceClass>, <deviceSubClass>, and <deviceProtocol> must specify a USB* class/sub-class/protocol combination according to the USB specification. For* the client抯 convenience, usbdLib.h automatically includes usb.h which defines* a number of USB device classes as USB_CLASS_xxxx and USB_SUBCLASS_xxxx. A* value of USBD_NOTIFY_ALL in any/all of these parameters acts like a wildcard* and matches any value reported by the device for the corresponding field.** <attachCallback> must be a non-NULL pointer to a client-supplied callback* routine of the form USBD_ATTACH_CALLBACK:** \cs* typedef VOID (*USBD_ATTACH_CALLBACK)* (* USBD_NODE_ID nodeId,* UINT16 attachAction,* UINT16 configuration,* UINT16 interface,* UINT16 deviceClass,* UINT16 deviceSubClass,* UINT16 deviceProtocol* );* \ce** Immediately upon registration the client should expect that it may begin* receiving calls to the <attachCallback> routine. Upon registration,* Translation Unit will call the <attachCallback> for each device of the* specified class which is already attached to the system. Thereafter, the* Translation unit will call the <attachCallback> whenever a new device of the* specified class is attached to the system or an already-attached device is* removed.** Each time the <attachCallback> is called, Translation Unit will pass the* Node Id of the device in <nodeId> and an attach code in <attachAction> which* explains the reason for the callback. Attach codes are defined as:** \is* \i 'USBD_DYNA_ATTACH'* USBD is notifying the client that nodeId is a device which is now attached* to the system.** \i 'USBD_DYNA_REMOVE'* USBD is notifying the client that nodeId has been detached (removed) from* the system.* \ie** When the <attachAction> is USBD_DYNA_REMOVE the <nodeId> refers to a Node Id* which is no longer valid. The client should interrogate its internal data* structures and delete any references to the specified Node Id. If the client* had outstanding requests to the specified <nodeId>, such as data transfer* requests, then the USBD will fail those outstanding requests prior to calling* the <attachCallback> to notify the client that the device has been removed.* In general, therefore, transfer requests related to removed devices should* already be taken care of before the <attachCallback> is called.** A client may re-use a single <attachCallback> for multiple notification* registrations. As a convenience to the <attachCallback> routine, the USBD* also passes the <deviceClass>, <deviceSubClass>, and <deviceProtocol> of the* attached/removed <nodeId> each time it calls the <attachCallback>.** Finally, clients need to be aware that not all USB devices report their class* information at the "device" level. Rather, some devices report class types* on an interface-by-interface basis. When the device reports class information* at the device level, then the USBD passes a <configuration> value of zero to* the attach callback and calls the callback only a single time for each device.* When the device reports class information at the interface level, then the* Translation Unit invokes the attach callback once for each interface which* matches the client's <deviceClass>/<deviceSubClass>/<deviceProtocol>* specification.* In this case, the USBD also passes the corresponding configuration & interface* numbers in <configuration> and <interface> each time it invokes the callback.** RETURNS: OK, or ERROR if unable to register for attach/removal notification.** ERRNO: N/A*/STATUS usbdDynamicAttachRegister ( USBD_CLIENT_HANDLE clientHandle, /* Client handle */ UINT16 deviceClass, /* USB class code */ UINT16 deviceSubClass, /* USB sub-class code */ UINT16 deviceProtocol, /* USB device protocol code */ USBD_ATTACH_CALLBACK attachCallback /* User-supplied callback */ ) { pUSBHST_DEVICE_DRIVER pDriverData; pUSBTU_DEVICE_DRIVER pDriver = (pUSBTU_DEVICE_DRIVER)clientHandle; USBHST_STATUS status; USBTU_LOG ( "usbdDynamicAttachRegister entered \n"); /* 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, " : Dynamic Attach/Dettach Callback Register "); USB_HCD_LOG_EVENT(USBTU_WV_CLIENT_INIT, evLog, USBTU_WV_FILTER); } /* allocate structure for driver specific data */ if ( !(pDriverData = OSS_CALLOC (sizeof (USBHST_DEVICE_DRIVER)))) { USBTU_LOG ("usbdDynamicAttachRegister returns ERROR: alloc failed \n"); return ERROR; } /* initialize structure with driver specific data */ pDriverData->bFlagVendorSpecific = 0; pDriverData->uVendorIDorClass = deviceClass; pDriverData->uProductIDorSubClass = deviceSubClass; pDriverData->uBCDUSBorProtocol = deviceProtocol; pDriverData->addDevice = usbtuInitDeviceAdd; pDriverData->removeDevice = usbtuInitDeviceRemove; pDriverData->suspendDevice = usbtuInitDeviceSuspend; pDriverData->resumeDevice = usbtuInitDeviceResume; /* register the client with USBD */ status = usbHstDriverRegister (pDriverData, NULL); if (status != USBHST_SUCCESS) { /* release driver specific structure */ OSS_FREE (pDriverData); USBTU_LOG ( "usbdDynamicAttachRegister returns ERROR \n"); return ERROR; } /* initialize client structure */ pDriver->class = deviceClass; pDriver->subclass = deviceSubClass; pDriver->protocol = deviceProtocol; pDriver->attachCallback = attachCallback; pDriver->pDriverData = pDriverData; USBTU_LOG ( "usbdDynamicAttachRegister returns OK \n"); return OK; }/***************************************************************************** usbdDynamicAttachUnRegister - Unregisters client for attach notification** This function cancels a client抯 earlier request to be notified for the* attachment and removal of devices within the specified class. <deviceClass>,* <deviceSubClass>, <deviceProtocol>, and <attachCallback> are defined as for* the usbdDynamicAttachRegister() function and must match exactly the parameters* passed in an earlier call to usbdDynamicAttachRegister.** RETURNS: OK, or ERROR if unable to unregister for attach/removal notification.** ERRNO: N/A*/STATUS usbdDynamicAttachUnRegister ( USBD_CLIENT_HANDLE clientHandle, /* Client handle */ UINT16 deviceClass, /* USB class code */ UINT16 deviceSubClass, /* USB sub-class code */ UINT16 deviceProtocol, /* USB device protocol code */ USBD_ATTACH_CALLBACK attachCallback /* user-supplied callback routine */ ) { USBHST_STATUS status = USBHST_SUCCESS;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -