⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 usbhubbusmanager.c

📁 风河的vxworks-6.3 FOR amcc440epx BSP!
💻 C
📖 第 1 页 / 共 2 页
字号:
/* usbHubBusManager.c - Manages topology and other information about bus */

/* Copyright 2004 Wind River Systems, Inc. 

   This software includes software licensed to Wind River Systems, Inc.
   by Wipro, Ltd. Wind River licensees may use this software according  
   to the terms of their Wind River license agreement(s) applicable to 
   this software.
*/

/*
Modification history
--------------------
01b,15oct04,ami  Refgen Changes
01a,27jun03,nrv Changing the code to WRS standards
*/

/*
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:  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
         */
#if 0 /* XXX if sleep is not long enough usbHubStatusChangeHandler() does not debounce correctly. */
        OS_DELAY_MS(2);
#else
        taskDelay(sysClkRateGet()/4);
#endif
        
    } /* 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.
     */
#ifdef DEBUG
if ((pHub->pStatus)[0] != 0)
	logMsg("(pHub->pStatus)[0] : 0x%x.\n", (pHub->pStatus)[0],2,3,4,5,6) ;
#endif
    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(

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -