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

📄 usbhubporteventhandler.c

📁 usb2 driver for vxwokrs
💻 C
📖 第 1 页 / 共 3 页
字号:
/* usbHubPortEventHandler.c - Functions for handling the port events *//* Copyright 2004-2005 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--------------------01c,28mar05,pdg  Allocation of hardware accessed memory changed01b,15oct04,ami  Refgen Changes01a,27jun03,nrv Changing the code to WRS standards*//*DESCRIPTIONThis provides the functions for handling the port events. This module is used in conjunction with the Hub Event Handling Module and Bus Manager Module.INCLUDE FILES:  usb2/usbOsal.h, usb2/usbHst.h, usb2/usbHubGlobalVariables.h,usb2/usbHubUtility.h, usb2/usbHubPortEventHandler.h, usb2/usbHubEventHandler.h*//*INTERNAL ******************************************************************************* * Filename         : HUB_PortEventHandler.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 provides the functions for handling the port events. *                    This module is used in conjunction with the Hub Event *                    Handling Module and Bus Manager Module. * * ******************************************************************************//************************** INCLUDE FILES *************************************/#include "usb2/usbOsal.h"#include "usb2/usbHst.h"#include "usb2/usbHubGlobalVariables.h"#include "usb2/usbHubUtility.h"#include "usb2/usbHubPortEventHandler.h"#include "usb2/usbHubEventHandler.h"/****************** MODULE SPECIFIC FUNCTIONS DECLARATION *********************//* This function is the handler for the port connection change. */LOCAL USBHST_STATUS usbHubPortConnectChangeHandler                   (                   pUSB_HUB_INFO        pHub,                   UINT8            uPortIndex,                   pUSB_HUB_PORT_STATUS pPortStatus                   );/* This function is the handler for the port enable change. */LOCAL USBHST_STATUS usbHubPortEnableChangeHandler                    (                   pUSB_HUB_INFO        pHub,                   UINT8            uPortIndex,                   pUSB_HUB_PORT_STATUS pPortStatus                   );/* This function is the handler for the port suspend change. */LOCAL USBHST_STATUS usbHubPortSuspendChangeHandler                   (                   pUSB_HUB_INFO        pHub,                   UINT8            uPortIndex,                   pUSB_HUB_PORT_STATUS pPortStatus                   );/* This function is the handler for the port reset state change. */LOCAL USBHST_STATUS usbHubPortResetChangeHandler                   (                   pUSB_HUB_INFO        pHub,                   UINT8            uPortIndex,                   pUSB_HUB_PORT_STATUS pPortStatus);/* This function is the handler for the port over current change. */LOCAL USBHST_STATUS usbHubPortOverCurrentChangeHandler                   (                   pUSB_HUB_INFO        pHub,                   UINT8            uPortIndex,                   pUSB_HUB_PORT_STATUS pPortStatus                   );/************************ GLOBAL FUNCTIONS DEFINITION *************************//***************************************************************************** usbHubPortEventHandler - Handler for any port event that has happened.** This routine handles any port event that has happened.** RETURNS: USBHST_SUCCESS, USBHST_INVALID_PARAMETER, USBHST_FAILURE If any event * handler failed.** ERRNO: None* * \NOMANUAL*/LOCAL USBHST_STATUS usbHubPortEventHandler    (    pUSB_HUB_INFO pHub,     UINT8 uPortIndex    )    {    /* To store the result of the port status. */    pUSB_HUB_PORT_STATUS pPortStatus = NULL;    /* To store the length of the transfers */    UINT8 uLength = sizeof(USB_HUB_PORT_STATUS);    /* To store the results */    USBHST_STATUS Result;    /* For calulation which byte of pStatus to clear */    UINT8 uByteToClear=0;    /* To calculate which bit of uByteToClear in pStatus to clear */    UINT8 uBitToClear=0;		/* WindView Instrumentation */		USB_HUB_LOG_EVENT(			USB_HUB_WV_EVENT_HANDLER,			"Entering usbHubPortEventHandler() Function",			USB_HUB_WV_FILTER);    /* Debug Message */    OS_LOG_MESSAGE_LOW(        HUB,        "usbHubPortEventHandler: Called pHub=0x%x uPortIndex=%d\n",        (UINT32)pHub,        uPortIndex,        0,        0);    /* If pHub is NULL then return USBHST_INVALID_PARAMETER. */    if (NULL == pHub)    {        /* Debug Message */        OS_LOG_MESSAGE_MEDIUM(            HUB,"usbHubPortEventHandler: pHub NULL\n",0,0,0,0);        return USBHST_INVALID_PARAMETER;    }/* End of (NULL == pHub) */    /* If pHub::pBus is NULL then return USBHST_INVALID_PARAMETER. */    if (NULL == pHub->pBus)    {        /* Debug Message */        OS_LOG_MESSAGE_MEDIUM(            HUB,"usbHubPortEventHandler: pHub->pBus NULL\n",0,0,0,0);        return USBHST_INVALID_PARAMETER;    }/* End of (NULL == pHub->pBus) */    /* Allocate memory for the port status */    pPortStatus = OS_MALLOC(4);    /* Check if memory allocation is successful */    if (pPortStatus == NULL)        {        /* Debug Message */        OS_LOG_MESSAGE_HIGH(            HUB,            "usbHubPortEventHandler: Failed GetPortStatus"            "res=0x%x, leng=0x%x\n",            Result,            uLength,            0,            0);        return USBHST_INSUFFICIENT_MEMORY;                }    /* Initialize all the fields of the allocated memory */    OS_MEMSET(pPortStatus, 0, 4);        /*     * Call the HUB_GET_PORT_STATUS() function to retrieve the HUB_PORT_STATUS     * structure. If failed, then return USBHST_FAILURE.     * Note: actual port number is 1+ the port index     */    Result = USB_HUB_GET_PORT_STATUS(pHub,                                 uPortIndex,                                 (UINT8 *)(pPortStatus),                                 &uLength);    if ((USBHST_SUCCESS !=Result)||( uLength != sizeof(USB_HUB_PORT_STATUS)) )    {        /* Debug Message */        OS_LOG_MESSAGE_HIGH(            HUB,            "usbHubPortEventHandler: Failed GetPortStatus"            "res=0x%x, leng=0x%x\n",            Result,            uLength,            0,            0);        /* Free the memory allocated for the port status */        OS_FREE(pPortStatus);        return Result;    }/* End of if (USBHST_SUCCESS... */    pPortStatus->wPortChange  = OS_UINT16_LE_TO_CPU(pPortStatus->wPortChange);    pPortStatus->wPortStatus  = OS_UINT16_LE_TO_CPU(pPortStatus->wPortStatus);    /*     * Call HUB_IS_CONNECTION_CHANGE() with HUB_PORT_STATUS::wPortChange. If     * there is a change in connect status, call HUB_PortConnectChangeHandler()     * with HUB_PORT_STATUS structure, pHub and uPortIndex.     * If failed, return result.     */    if (TRUE == USB_HUB_IS_CONNECTION_CHANGE(pPortStatus->wPortChange))    {        Result=usbHubPortConnectChangeHandler(pHub, uPortIndex, pPortStatus);        if (USBHST_SUCCESS !=Result)        {            /* Debug Message */            OS_LOG_MESSAGE_HIGH(                HUB,                "usbHubPortEventHandler: Failed port conn hdlr res=0x%x\n",                Result,                0,                0,                0);                    /* Free the memory allocated for the port status */            OS_FREE(pPortStatus);            return Result;        }/* End of if USBHST_SUCCESS != Result */    }/* End of if TRUE == HUB... */    /*     * Call HUB_IS_RESET_CHANGE() with HUB_PORT_STATUS::wPortChange.     * If there is a change in reset status, call HUB_PortResetChangeHandler()     * with HUB_PORT_STATUS structure, pHub and uPortIndex.     * If failed, return result.     */    if (TRUE == USB_HUB_IS_RESET_CHANGE(pPortStatus->wPortChange))    {        Result=usbHubPortResetChangeHandler(pHub, uPortIndex, pPortStatus);        if (USBHST_SUCCESS !=Result)        {            /* Debug Message */            OS_LOG_MESSAGE_HIGH(                HUB,                "usbHubPortEventHandler: Failed reset chg hdlr res=0x%x\n",                Result,                0,                0,                0);            /* Free the memory allocated for the port status */            OS_FREE(pPortStatus);            return Result;        }/* End of if USBHST_SUCCESS != Result */    }/* End of if TRUE == HUB... */    /*     * Call HUB_IS_ENABLE_CHANGE() with HUB_PORT_STATUS::wPortChange.     * If there is a change in enable status, call HUB_PortEnableChangeHandler()     * with HUB_PORT_STATUS structure, pHub and uPortIndex.     * If failed, return result.     */    if (TRUE == USB_HUB_IS_ENABLE_CHANGE(pPortStatus->wPortChange))    {        Result=usbHubPortEnableChangeHandler(pHub,uPortIndex,pPortStatus);        if (USBHST_SUCCESS !=Result)        {            /* Debug Message */            OS_LOG_MESSAGE_HIGH(                HUB,                "usbHubPortEventHandler: Failed enabl chg hdlr res=0x%x\n",                Result,                0,                0,                0);            /* Free the memory allocated for the port status */            OS_FREE(pPortStatus);            return Result;        }/* End of if USBHST_SUCCESS != Result */    }/* End of if TRUE == HUB... */    /*     * Call HUB_IS_SUSPEND_CHANGE() with HUB_PORT_STATUS::wPortChange.     * If there is a change in suspend status,     * call HUB_PortSuspendChangeHandler() with HUB_PORT_STATUS structure,     * pHub and uPortIndex. If failed, return result.     */    if (TRUE == USB_HUB_IS_SUSPEND_CHANGE(pPortStatus->wPortChange))    {        Result=usbHubPortSuspendChangeHandler(pHub,uPortIndex,pPortStatus);        if (USBHST_SUCCESS !=Result)        {            /* Debug Message */            OS_LOG_MESSAGE_HIGH(                HUB,                "usbHubPortEventHandler: Failed susp chg hdlr res=0x%x\n",                Result,                0,                0,                0);            /* Free the memory allocated for the port status */            OS_FREE(pPortStatus);            return Result;        }/* End of if USBHST_SUCCESS != Result */    }/* End of if TRUE == HUB... */    /*     * Call HUB_IS_OVER_CURRENT_CHANGE() with HUB_PORT_STATUS::wPortChange.     * If there is a change in over current status, call     * HUB_PortOverCurrentChangeHandler() with HUB_PORT_STATUS structure,     * pHub and uPortIndex. If failed, return result.     */    if (TRUE == USB_HUB_IS_OVER_CURRENT_CHANGE(pPortStatus->wPortChange))    {        Result=usbHubPortOverCurrentChangeHandler(pHub,uPortIndex,pPortStatus);        if (USBHST_SUCCESS !=Result)        {            /* Debug Message */            OS_LOG_MESSAGE_HIGH(                HUB,                "usbHubPortEventHandler: Failed ovr curr hdlr res=0x%x\n",                Result,                0,                0,                0);            /* Free the memory allocated for the port status */            OS_FREE(pPortStatus);            return Result;        }/* End of if USBHST_SUCCESS != Result */    }/* End of if TRUE == HUB... */    /* Free the memory allocated for the port status */    OS_FREE(pPortStatus);    /* Clear the port number  bit of the pHub::pStatus. (BEGIN) */    /* Find the byte by taking an integer division */    uByteToClear = (uPortIndex+1)/8;    /* Find the bit by taking the remainder */    uBitToClear = (uPortIndex+1)%8;    /* Clean up the bit */    pHub->pStatus[uByteToClear] =        ( pHub->pStatus[uByteToClear]& (~((UINT8)0x1<<(uBitToClear))) );    /* Clear the port number bit of the pHub::pStatus. (END) */		/* WindView Instrumentation */		USB_HUB_LOG_EVENT(			USB_HUB_WV_EVENT_HANDLER,			"Exiting usbHubPortEventHandler() Function",			USB_HUB_WV_FILTER);    /* Debug Message */    OS_LOG_MESSAGE_LOW(        HUB,        "usbHubPortEventHandler: Done pHub=0x%x uPortIndex=%d\n",        (UINT32)pHub,        uPortIndex,        0,        0);    /* Return  USBHST_SUCCESS. */    return USBHST_SUCCESS;    }/* End of HUB_PortEventHandler() *//******************* MODULE SPECIFIC FUNCTIONS DEFINITION *********************//***************************************************************************** usbHubPortConnectChangeHandler - handler for the connection change.** This routine handles the connection change.** RETURNS: USBHST_SUCCESS, USBHST_INVALID_PARAMETER, USBHST_FAILURE If any event* handler failed.** ERRNO: None** \NOMANUAL*/LOCAL  USBHST_STATUS usbHubPortConnectChangeHandler    (    pUSB_HUB_INFO        pHub,    UINT8            uPortIndex,    pUSB_HUB_PORT_STATUS pPortStatus    )    {    /* Storage for the port information */    pUSB_HUB_PORT_INFO pPort=NULL;    /* to store the result of submissions */    USBHST_STATUS Result;		/* WindView Instrumentation */		USB_HUB_LOG_EVENT(			USB_HUB_WV_EVENT_HANDLER,			"Entering usbHubPortConnectChangeHandler() Function",			USB_HUB_WV_FILTER);    /* Debug Message */    OS_LOG_MESSAGE_LOW(        HUB,        "usbHubPortConnectChangeHandler: Called "        "pHub=0x%x uPortIndex=%d pPortStatus=0x%x\n",

⌨️ 快捷键说明

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