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

📄 usbhubutility.c

📁 风河的vxworks-6.3 FOR amcc440epx BSP!
💻 C
📖 第 1 页 / 共 5 页
字号:
     * Browse the HUB_BUS_INFO list and check if gpGlobalBus exists. If it
     * exists, return NULL.
     */
    while (NULL != pBusList)
    {
        /* Check for duplicate entries */
        if (pBusList->uBusHandle == uBusHandle)
        {
            /* Debug Message */
            OS_LOG_MESSAGE_MEDIUM(
                HUB,
                "usbHubCreateBusStructure:already there 0x%x \n",
                uBusHandle,
                0,
                0,
                0);

            return NULL;

        } /* End of if (pBusList->....*/

        /* move to the next bus */
        pBusList=pBusList->pNextBus;

    } /* End of While (NULL != pBusList) */

    /*
     * Call OS_MALLOC() to allocate memory for HUB_BUS_INFO structure.
     * If failed, return NULL
     */
    pBusList = OS_MALLOC(sizeof(USB_HUB_BUS_INFO));

    /* Check the result */
    if (NULL == pBusList)
    {
        /* Debug Message */
        OS_LOG_MESSAGE_HIGH(
            HUB,"usbHubCreateBusStructure:memory insuff -  pBusList\n",0,0,0,0);

        return NULL;

    }/* End of if (NULL== pBusList) */

    /* Clear the allocated structure.*/
    OS_MEMSET(pBusList,0,sizeof(USB_HUB_BUS_INFO));


    /* set HUB_BUS_INFO::uBusHandle as uBusHandle*/
    pBusList->uBusHandle = uBusHandle;

    /* set HUB_BUS_INFO::pNextBus as gpGlobalBus*/
    pBusList->pNextBus = gpGlobalBus;

    /* 
     * Call the OS_CREATE_THREAD() function to create a thread (the function as
     * HUB_BusManager() will be spawned as a thread with HUB_BUS_INFO as the
     * parameter) If the thread creation fails:
     * i.    Call the OS_FREE() function to free the memory allocated to the
     *       HUB_BUS_INFO structure.
     * ii.    Return NULL
     * Set the HUB_BUS_INFO::BusManagerThreadID as the thread id returned by
     * the OS_CREATE_THREAD() function.
     */
    pBusList->BusManagerThreadID=OS_CREATE_THREAD((char *) busManagerName,
                                                  USB_HUB_THREAD_PRIORITY,
                                                  usbHubThread,
                                                  pBusList);

    /* Check for the success  of thread creation */
    if (OS_THREAD_FAILURE == pBusList->BusManagerThreadID)
    {
        /* Free the memory allocated */
        OS_FREE(pBusList);
        
        /* Debug Message */
        OS_LOG_MESSAGE_HIGH(
            HUB,
            "usbHubCreateBusStructure:thread create failed=0x%x\n",
            pBusList->BusManagerThreadID,
            0,
            0,
            0);

        /*return failure */
        return NULL;

    }/* End of if (NULL==pBusList->BusMan... */

   /* Set  gpGlobalBus  as HUB_BUS_INFO*/
   gpGlobalBus = pBusList;

   /* Debug Message */
   OS_LOG_MESSAGE_LOW(
       HUB,"usbHubCreateBusStructure:Created ok\n",0,0,0,0);

   /* Return HUB_BUS_INFO structure.*/
   return pBusList;

   }/* End of HUB_CreateBusStructure() */


/***************************************************************************
*
* usbHubDeleteBusStructure - deletes the Bus Structure.
*
* This routine deletes the Bus Structure and kills any threadassociated with it.
*
* RETURNS: None
*
* ERRNO: None
* 
* \NOMANUAL
*/

LOCAL void usbHubDeleteBusStructure 
    ( 
    UINT8 uBusHandle
    )
    {
    /* Bus List pointer */
    pUSB_HUB_BUS_INFO pBusList = gpGlobalBus;

    /* Previous bus pointer -to be used for unlinking */
    pUSB_HUB_BUS_INFO pPrevBusList = gpGlobalBus;

    /* Debug Message */
    OS_LOG_MESSAGE_LOW(
        HUB,
        "usbHubDeleteBusStructure:Called 0x%x\n",
        uBusHandle,
        0,
        0,
        0);

    /*
     * Browse the gpGlobalBus list and check if uBusHandle exists. If it does
     * not exists, return.
     */
    while (NULL != pBusList)
    {
        /* Check for correct entry */
        if (pBusList->uBusHandle == uBusHandle)
        {
            /* Jump out of the loop */
            break;

        } /* End of if (pBusList->....*/

        /* Set the previous bus list pointer as the current one */
        pPrevBusList=pBusList;

        /* Go to the next bus list */
        pBusList=pBusList->pNextBus;

    } /* End of While (NULL != pBusList) */

    /* Check if we found the bus */
    if (NULL==pBusList)
    {
        /* Debug Message */
        OS_LOG_MESSAGE_HIGH(
            HUB,
            "usbHubDeleteBusStructure: bus handle 0x%x not found\n",
            uBusHandle,
            0,
            0,
            0);

        /* nope.. we did nto find the bus, so we return */
        return;

    } /* End of if (NULL==pBusList) */

    /* Unlink the HUB_BUS_INFO from the gpGlobalBus list.(BEGIN) */

    /* Check if the previous bus list is the same as the global bus list */
    if ( ( pPrevBusList == gpGlobalBus)&& (pPrevBusList==pBusList) )
    {
        /* This is the first bus */
        
        /* Set the global pointer to this */
        gpGlobalBus = pBusList->pNextBus;
    }
    else
    {
    	/* This is not the first bus */

        /* Reset the pointer to point to the next bus */
        pPrevBusList->pNextBus=pBusList->pNextBus;

    } /* End of if (pPrevBusList ==.. */

    /* Unlink the HUB_BUS_INFO from the gpGlobalBus list.(END) */

    /*
     * Call OS_DESTROY_THREAD() to kill the thread with thread ID as
     * HUB_BUS_INFO:: BusManagerThreadID
     */
    OS_DESTROY_THREAD(pBusList->BusManagerThreadID);

    /* Call OS_FREE() function to free the memory allocated for HUB_BUS_INFO*/
    OS_FREE(pBusList);

    /* Debug Message */
    OS_LOG_MESSAGE_LOW(
        HUB,
        "usbHubDeleteBusStructure:Done 0x%x\n",
        uBusHandle,
        0,
        0,
        0);

    /* Return*/
    return;

}/* End of Hub_DeleteBusStructure() */

/***************************************************************************
*
* usbHubRemoveDevice - calls the remove device of the Host stack.
*
* This routine calls the remove device of the Host stack.This also frees the 
* memory as required.
*
* RETURNS: USBHST_SUCCESS, USBHST_INVALID_PARAMETER if there are invalid params
*
* ERRNO: None
*
* \NOMANUAL
*/

LOCAL USBHST_STATUS usbHubRemoveDevice
    (
    pUSB_HUB_INFO pHub, 
    UINT8 uPortIndex
    )
    {
    /* To Store the port information */
    pUSB_HUB_PORT_INFO pPort = NULL;

		/* WindView Instrumentation */
		USB_HUB_LOG_EVENT(
			USB_HUB_WV_DEVICE,
			"Entering usbHubRemoveDevice() Function",
			USB_HUB_WV_FILTER);

    /* Debug Message */
    OS_LOG_MESSAGE_LOW(
        HUB,
        "usbHubRemoveDevice : Entered pHub= 0x%x, uPortIndex =%d\n",
        (UINT32)pHub,
        uPortIndex,
        0,
        0);

    /* Verify the Parameters */
    if (NULL == pHub)
    {
        /* Debug Message */
        OS_LOG_MESSAGE_HIGH(
            HUB,"usbHubRemoveDevice: pHub is NULL\n",0,0,0,0);

        /* Return invalid parameter */
        return USBHST_INVALID_PARAMETER;

    } /* End of if (NULL == pHub) */

    /* Verify the Parameters */
    if (uPortIndex >= pHub->HubDescriptor.bNbrPorts)
    {
        /* Debug Message */
        OS_LOG_MESSAGE_HIGH(
            HUB,
            "usbHubRemoveDevice: portIndex = %d NbrPort =%d is Invalid\n",
            uPortIndex,
            pHub->HubDescriptor.bNbrPorts,
            0,
            0);

        /* Return invalid parameter */
        return USBHST_INVALID_PARAMETER;

    } /* End of if (uPortIndex >= pHub->HubDescriptor.bNbrPorts) */

    /* Copy the pPort value */
    pPort= pHub->pPortList[uPortIndex];

    /*
     * If the port is enabled then Call the
     * g_USBHSTFunctionList::USBHST_RemoveDevice() function with
     * HUB_PORT_INFO::uDeviceHandle.
     */
    if (NULL != pPort)
    {
        /* Debug Message */
        OS_LOG_MESSAGE_HIGH(
            HUB,
            "usbHubRemoveDevice: port present - deleting %d\n",
            uPortIndex,
            0,
            0,
            0);

        /*
         * Check what state this device was in - if this was in being configured,
         * then we need to reset the global bus's variable and then mark the
         * port for delete
         */

        USB_MARK_FOR_DELETE_PORT(pHub,pPort); 

        /* Check if this port is a hub device or not */
        if (NULL == pPort->pHub)
        {
            /* Debug Message */
            OS_LOG_MESSAGE_LOW(
                HUB,
                "usbHubRemoveDevice: non Hub Device\n",
                0,
                0,
                0,
                0);

            /* disable the port */
            pHub->pPortList[uPortIndex]=NULL;

            /* Call remove device */
            if (0 != pPort->uDeviceHandle)
                {
                g_usbHstFunctionList.UsbdToHubFunctionList.removeDevice(pPort->uDeviceHandle);
                }/* End of if (0 != pPort->uDeviceHandle) */
            /* Free the memory */
            OS_FREE(pPort);

            pPort=NULL;
        }
        else
        /* an Hub device */
        {
            /* Debug Message */
            OS_LOG_MESSAGE_LOW(
                HUB,"usbHubRemoveDevice: Hub Device\n",0,0,0,0);

            /* Call remove device */
        g_usbHstFunctionList.UsbdToHubFunctionList.removeDevice(pPort->uDeviceHandle);

        } /* End of if (NULL == pPort->pHub) */


    }/* End of if (NULL != pPort ) */

		/* WindView Instrumentation */
		USB_HUB_LOG_EVENT(
			USB_HUB_WV_DEVICE,
			"Exiting usbHubRemoveDevice() Function",
			USB_HUB_WV_FILTER);

    /* Debug Message */
    OS_LOG_MESSAGE_LOW(
        HUB,
        "usbHubRemoveDevice : Done pHub= 0x%x, uPortIndex =%d\n",
        (UINT32)pHub,
        uPortIndex,
        0,
        0);

    /* Return SUCCESS */
    return USBHST_SUCCESS;

    } /* End of HUB_RemoveDevice() */


/***************************************************************************
*
* usbHubPortDebounceHandler - used for handling de-bounce condition.
*
* This routine handles the de-bounce condition.
*
* RETURNS: USBHST_SUCCESS, USBHST_FAILURE,
* USBHST_INVALID_PARAMETER if there are invalid params
*
* ERRNO: None
* 
* \NOMANUAL
*/

LOCAL USBHST_STATUS usbHubPortDebounceHandler 
    (
    pUSB_HUB_INFO pHub,
    UINT8 uPortIndex 
    )
    {
    /* Storage for the port informaiton */
    pUSB_HUB_PORT_INFO pPort=NULL;

    /* Current Frame storage */
    UINT16 uCurrentFrame = 0;

    /* To store the port status */
    pUSB_HUB_PORT_STATUS pPortStatus = NULL;

    /* To Store the time difference */
    UINT16 uTimeDiff = 0;

    /* To store the length of the  status */
    UINT8 uLength = sizeof(USB_HUB_PORT_STATUS) ;

    /* To store the result of the requests */
    USBHST_STATUS  Result;

    /* To store the max tier possible  */
    UINT8 uMaxTier =0;

    /* Debug Message */
    OS_LOG_MESSAGE_LOW(
        HUB,
        "usbHubPortDebounceHandler:Called pHub=0x%x port=%d\n",
        (UINT32)pHub,
        uPortIndex,
        0,
        0);

    /* If the pHub is NULL then return USBHST_INVALID_PARAMETER */
    if (NULL==pHub)
    {
        /* Debug Message */
        OS_LOG_MESSAGE_MEDIUM(
            HUB,
            "usbHubPortDebounceHandler:pHub=0x%x NULL\n",
            (UINT32)pHub,
            0,
            0,
            0);

        return USBHST_INVALID_PARAMETER;

    }/* End of if (NULL ==pHub) */

    /*
     * If the uPortIndex greater than pHub::HubDescriptor::bNbrPorts then
     * return USBHST_INVALID_PARAMETER.
     * Note: the actual port number is the port index + 1
     */
    if (uPortIndex >= pHub->HubDescriptor.bNbrPorts)
    {
        /* Debug Message */
        OS_LOG_MESSAGE_MEDIUM(
            HUB,

⌨️ 快捷键说明

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