?? usbhubbusmanager.c
字號:
/* usbHubBusManager.c - Manages topology and other information about bus *//* Copyright 2003 Wind River Systems, Inc. *//*Modification history--------------------01a,27jun03,nrv Changing the code to WRS standards*//*DESCRIPTIONThis is the module that manages the topology and other informationabout a bus. This is an autonomous thread that is initiated every timea root hub is detected and this ends only when the USB Hub Class Driveris unloaded or when the root hub is disabled. This is used in conjunctionwith the Port Event Handling Module and Hub Event Handling Module.INCLUDE FILES: usb2/usbOsal.h usb2/usbHst.h usb2/usbHubCommon.h usb2/usbHubUtility.h usb2/usbHubEventHandler.h usb2/usbHubPortEventHandler.h usb2/usbHubBusManager.h usb2/usbHubGlobalVariables.h*//*INTERNAL ******************************************************************************* * Filename : HUB_BusManager.c * * Copyright : * * THE COPYRIGHT IN THE CONTENTS OF THIS SOFTWARE VEST WITH WIPRO * LIMITED A COMPANY INCORPORATED UNDER THE LAWS OF INDIA AND HAVING * ITS REGISTERED OFFICE AT DODDAKANNELLI SARJAPUR ROAD BANGALORE * 560 035. DISTRIBUTION OR COPYING OF THIS SOFTWARE BY * ANY INDIVIDUAL OR ENTITY OTHER THAN THE ADDRESSEE IS STRICTLY * PROHIBITED AND MAY INCUR LEGAL LIABILITY. IF YOU ARE NOT THE * ADDRESSEE PLEASE NOTIFY US IMMEDIATELY BY PHONE OR BY RETURN EMAIL. * THE ADDRESSEE IS ADVISED TO MAINTAIN THE PROPRIETARY INTERESTS OF * THIS COPYRIGHT AS PER APPLICABLE LAWS. * * Description : This is the module that manages the topology and other * information about a bus. This is an autonomous thread that * is initiated every time a root hub is detected and this * ends only when the USB Hub Class Driver is unloaded or * when the root hub is disabled. This is used in conjunction * with the Port Event Handling Module and * Hub Event Handling Module. * * ******************************************************************************//************************** INCLUDE FILES *************************************/#include "usb2/usbOsal.h"#include "usb2/usbHst.h"#include "usb2/usbHubCommon.h"#include "usb2/usbHubUtility.h"#include "usb2/usbHubEventHandler.h"#include "usb2/usbHubPortEventHandler.h"#include "usb2/usbHubBusManager.h"#include "usb2/usbHubGlobalVariables.h"/****************** MODULE SPECIFIC FUNCTIONS DECLARATION *********************//* * This function is used to recursively work on a hub to handle any event that * may have occurred on the hub. */LOCAL void usbHubStatusChangeHandler (pUSB_HUB_INFO pHub);/************************ GLOBAL FUNCTIONS DEFINITION *************************//***************************************************************************** usbHubThread - thread that keeps checking every hub on a bus.** This routine checks every hub on a bus for events that require handling.** RETURNS: N/A** ERRNO: None** \NOMANUAL*/LOCAL void usbHubThread ( void * pContext ) { /* The pointer for the scanning of the buses */ pUSB_HUB_BUS_INFO pWorkingBus = NULL; /* If pContext is NULL then return*/ if (NULL == pContext) { /* Debug Message */ OS_LOG_MESSAGE_HIGH( HUB, "usbHubThread: pContext is NULL:0x%x\n", (UINT32)pContext, 0, 0, 0); return; } /* Retrieve the HUB_BUS_INFO structure from the pContext.*/ pWorkingBus=(pUSB_HUB_BUS_INFO) pContext; /* Debug Message */ OS_LOG_MESSAGE_LOW( HUB, "usbHubThread: Started for Bus ID:0x%x\n", pWorkingBus->uBusHandle, 0, 0, 0); /* * Loop infintely * i. If HUB_BUS_INFO::pRootHubInfo is not NULL then call * HUB_StatusChangeHandler() with HUB_BUS_INFO::pRootHubInfo */ while (1) { if (NULL != pWorkingBus->pRootHubInfo) { /* Call the status change handler for the Root hub info */ usbHubStatusChangeHandler(pWorkingBus->pRootHubInfo); } /* End of if (NULL!=pWorking.... */ /* * Sleep for some time to allow for the rest of the threads to do thier * work */ OS_DELAY_MS(2); } /* End of while (1) */ /* Return*/ return;} /* End of HUB_BusManager() *//******************* MODULE SPECIFIC FUNCTIONS DEFINITION *********************//***************************************************************************** usbHubStatusChangeHandler - used to recursively work on a hub.** usbHubStatusChangeHandler - used to recursively work on a hub to handle* any event that may have occurred on the hub.** RETURNS: N/A** ERRNO: None** \NOMANUAL*/LOCAL void usbHubStatusChangeHandler ( pUSB_HUB_INFO pHub ) { /* For Storing the results. */ USBHST_STATUS Result=USBHST_SUCCESS; BOOLEAN bResult = FALSE; /* Counter for the ports */ UINT8 uPortCount = 0; /* If the pHub is NULL then return.*/ if (NULL == pHub) { /* Debug Message */ OS_LOG_MESSAGE_MEDIUM( HUB, "usbHubStatusChangeHandler:pHub is NULL:0x%x\n", (UINT32)pHub, 0, 0, 0); /* return */ return; } /* End of if (NULL==.. */ /* * Call HUB_IS_HUB_EVENT() to check if any hub event has occurred on this * hub. If this calls returns TRUE, * * i. Call HUB_HubEventHandler() with pHub and if this call fails, set the * pHub::StateOfHub as MARKED_FOR_DELETION. */ if (TRUE == USB_HUB_IS_EVENT(pHub->pStatus)) { /* Debug Message */ OS_LOG_MESSAGE_LOW( HUB, "usbHubStatusChangeHandler:HubEvent Detected:0x%x: 0x%x\n", pHub->uDeviceHandle, (pHub->pStatus)[0], 0, 0); /* Call the Hub event handler */ Result = usbHubEventHandler(pHub); /* check the result */ if (USBHST_SUCCESS != Result) { /* Debug Message */ OS_LOG_MESSAGE_HIGH( HUB, "usbHubStatusChangeHandler:HubEventHdlr Failed:0x%x:0x%x\n", pHub->uDeviceHandle, Result, 0, 0); /* Mark the hub for deletion */ pHub->StateOfHub = USB_MARKED_FOR_DELETION; } /* End of if (USBHST_SUCCESS !=Result) */ }/* End of if (TRUE== HUB_IS_HUB_EVENT()) */ if (USB_MARKED_FOR_DELETION != pHub->StateOfHub) { /* * For each port available, do: * i. If pHub::pBus::nNumberOfHubEvents is non zero then go to step 6. * ii. If pHub::StateOfHub is MARKED_FOR_DELETION then go to step 5. * iii.If pHub::pStatus contains 1 for the index corresponding to the * port number then, * a. Call HUB_PortEventHandler() with the pHub and the port * number if this call fails, set the pHub::StateOfHub as * MARKED_FOR_DELETION and go to step 5. * iv. Retrieve the HUB_PORT_INFO structure from the * pHub::pPortList[port number]. If this port is enabled, * a. If the HUB_PORT_INFO::StateOfPort is HUB_DEBOUNCE_PENDING * then call HUB_DebounceHandler(). If this call fails, then * set the pHub::StateOfHub as MARKED_FOR_DELETION and * go to step 5. * b. If the HUB_PORT_INFO::StateOfPort is HUB_RESET_PENDING then * call the HUB_HandleDeviceConnection(). If this call fails, * then set the pHub::StateOfHub as MARKED_FOR_DELETION * and go to step 5. * c. If the HUB_PORT_INFO::StateOfPort is not * MARKED_FOR_DELETION then go to step 3 * d. If HUB_PORT_INFO::pHub is NULL then call * HUB_RemoveDevice() and free HUB_PORT_INFO and set the * pHub::pPortList[port count] as NULL. * e. If HUB_PORT_INFO::pHub is not NULL then call * USBHST_RemoveDevice(). * f. Call HUB_CLEAR_PORT_FEATURE() with the PORT_ENABLE as the * feature. If this call fails then set the pHub::StateOfHub * as MARKED_FOR_DELETION and go to step 5. */ for (uPortCount = 0; uPortCount < pHub->HubDescriptor.bNbrPorts; uPortCount++) { /* To store the HUB_PORT_INFO structure */ pUSB_HUB_PORT_INFO pPort = NULL; /* * i. If pHub::pBus::uNumberOfHubEvents is non zero then * go to step 6. */ if (0 < pHub->pBus->uNumberOfHubEvents) { /* Debug Message */ OS_LOG_MESSAGE_HIGH( HUB, "usbHubStatusChangeHandler:HubEvents detect:0x%x:Evts=%d\n", pHub->uDeviceHandle, pHub->pBus->uNumberOfHubEvents, 0, 0); break; } /* End of if (0<pHub->pBus->nNumberOfHubEvents) */ /* * ii. If pHub::StateOfHub is MARKED_FOR_DELETION then * go to step 5. */ if (USB_MARKED_FOR_DELETION == pHub->StateOfHub) { /* Debug Message */ OS_LOG_MESSAGE_MEDIUM( HUB, "HUB_StatusChangeHandler:hub marked for delete:0x%x:\n", pHub->uDeviceHandle, 0, 0, 0); break; } /* End of if (MARKED_FOR_DELETION ==pHub->StateOfHub) */ /* * iii.If pHub::pStatus contains 1 for the index * corresponding to the port number then, * Note: The port number is port count +1 */ bResult = USB_HUB_IS_PORT_EVENT(pHub->pStatus,uPortCount+1); if (TRUE == bResult) { /* Debug Message */ OS_LOG_MESSAGE_LOW( HUB, "usbHubStatusChangeHandler:Port Evnt detect:0x%x:port=%d\n", pHub->uDeviceHandle, uPortCount, 0, 0);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -