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

📄 usbehcdinitexit.c

📁 vxWorks下USB2.0中的EHCI的HCD源码,极具有参考价值
💻 C
📖 第 1 页 / 共 5 页
字号:
    if (NULL != pHCDData->InterruptEvent)        {        OS_DESTROY_EVENT(pHCDData->InterruptEvent);        pHCDData->InterruptEvent = NULL;        }    /* Destroy the synchronisation event */    if (NULL != pHCDData->RequestSynchEventID)        {        OS_DESTROY_EVENT(pHCDData->RequestSynchEventID);        pHCDData->RequestSynchEventID = NULL;        }    /* Destroy the reclamation list synchronisation event */    if (NULL != pHCDData->ReclamationListSynchEventID)        {        OS_DESTROY_EVENT(pHCDData->ReclamationListSynchEventID);        pHCDData->ReclamationListSynchEventID = NULL;        }    /* Destroy the bandwidth reservation event */    if (NULL != pHCDData->BandwidthEventID)        {        OS_DESTROY_EVENT(pHCDData->BandwidthEventID);        pHCDData->BandwidthEventID = NULL;        }    /* Destroy the thread created for handling the interrupts */    if (0 != pHCDData->IntHandlerThreadID)        {        OS_DESTROY_THREAD(pHCDData->IntHandlerThreadID);        pHCDData->IntHandlerThreadID = 0;        }    /* Free memory allocated for the port status */    if (NULL != pHCDData->RHData.pPortStatus)        {        OS_FREE(pHCDData->RHData.pPortStatus);        pHCDData->RHData.pPortStatus = NULL;        }    /* Free memory allocated for the interrupt data */    if (NULL != pHCDData->RHData.pHubInterruptData)        {        OS_FREE(pHCDData->RHData.pHubInterruptData);        pHCDData->RHData.pHubInterruptData = NULL;        }    /* Free memory allocated for the default pipe */    if (NULL != pHCDData->pDefaultPipe)        {	/* Free the memory allocated for the QH */    	if (NULL != pHCDData->pDefaultPipe->pQH)       	    {            OS_ASSERT(NULL != pHCDData->pDefaultPipe->pQH->pAllocatedMem);    	    OS_FREE(pHCDData->pDefaultPipe->pQH->pAllocatedMem);            }    	OS_FREE(pHCDData->pDefaultPipe);    	pHCDData->pDefaultPipe = NULL;        }    OS_LOG_MESSAGE_LOW(EHCD,"usbEhcdDataUninitialize - Exit\n",0,0,0,0);    return;    }    /* End of function usbEhcdDataUninitialize() *//***************************************************************************** usbEhcdInit - initializes the EHCI Host Controller** This routine intializes the EHCI Host Controller Driver and can be called* from either the target initialization code (bootup) or during runtime. * The usbd and hub interfaces should be initialized before this routine is * called.** RETURNS: TRUE, or FALSE if there is an error during HCD initialization.** ERRNO:*   None.*/BOOLEAN usbEhcdInit(VOID)    {    /* To hold the return value of bus initialization function call */    BUS_OPERATION_STATUS BusInitStatus = FALSE;    /* To hold the status of a function call */    USBHST_STATUS Status = USBHST_FAILURE;    /* To hold the count of the number of host controllers in the system */    UINT32 uCount = 0;    /* To hold the pointer to the HCD maintained data structure */    pUSB_EHCD_DATA pHCDData = NULL;    /* To hold the status of the EHCD_DATA structure initialization */    BOOLEAN bInitStatus = FALSE;    /* Temporary variable to hold the count value */    UINT32 uTempCount = 0;    OS_LOG_MESSAGE_LOW(EHCD,"usbEhcdInit - Entry\n",0,0,0,0);    /*     * Check whether the globals are initialized - This can happen if this     * function is called more than once.     */    OS_ASSERT(g_pEHCDriverInfo == NULL);    OS_ASSERT(g_EHCDHandle == 0);    /* Initialize the global array */    for (uCount = 0; uCount < USB_EHCD_MAX_HOST_CONTROLLERS; uCount++)        {        g_pEHCDData[uCount] = NULL;        }    /* Create the event used for synchronising the free list accesses */    g_ListAccessEvent = OS_CREATE_EVENT(OS_EVENT_SIGNALED);    /* Check if the event is created successfully */     if (NULL == g_ListAccessEvent)        {    	OS_LOG_MESSAGE_HIGH(EHCD,"usbEhcdInit - Error in creating the list event\n",0,0,0,0);		/* WindView Instrumentation */		USB_HCD_LOG_EVENT(			USB_EHCI_WV_INIT_EXIT,			"usbEhcdInit() exits - Creating list access event failed",			USB_EHCD_WV_FILTER);    	return FALSE;        }    /* Allocate memory for the HCD maintained data structure */    g_pEHCDriverInfo  = (pUSBHST_HC_DRIVER)OS_MALLOC(sizeof(USBHST_HC_DRIVER));    /* check if memory allocation is successful */    if (NULL == g_pEHCDriverInfo)        {        OS_LOG_MESSAGE_HIGH(EHCD,"usbEhcdInit - memory not allocated for driver data",0,0,0,0);        /* Destroy the event */        OS_DESTROY_EVENT(g_ListAccessEvent);        g_ListAccessEvent = NULL;		/* WindView Instrumentation */		USB_HCD_LOG_EVENT(			USB_EHCI_WV_INIT_EXIT,			"usbEhcdInit() exits - Memory allocation failed",			USB_EHCD_WV_FILTER);        return FALSE;        }    /* Initialize the members of the data structure */    OS_MEMSET(g_pEHCDriverInfo, 0, sizeof(USBHST_HC_DRIVER));    /* Populate the members of the HC Driver data structure - start */    /* Function to retrieve the frame number */    g_pEHCDriverInfo->getFrameNumber = usbEhcdGetFrameNumber;    /* Function to change the frame interval */    g_pEHCDriverInfo->setBitRate = usbEhcdSetBitRate;    /* Function to check whether bandwidth is available */    g_pEHCDriverInfo->isBandwidthAvailable = usbEhcdIsBandwidthAvailable;    /* Function to create a pipe */    g_pEHCDriverInfo->createPipe = usbEhcdCreatePipe;    /* Function to modify the default pipe */    g_pEHCDriverInfo->modifyDefaultPipe = usbEhcdModifyDefaultPipe;    /* Function to delete the pipe */    g_pEHCDriverInfo->deletePipe = usbEhcdDeletePipe;    /* Function to check if the request is pending */    g_pEHCDriverInfo->isRequestPending = usbEhcdIsRequestPending;    /* Function to submit an URB */    g_pEHCDriverInfo->submitURB = usbEhcdSubmitURB;    /* Function to cancel an URB */    g_pEHCDriverInfo->cancelURB = usbEhcdCancelURB;    /* Function to submit a clear tt request complete  */    g_pEHCDriverInfo->clearTTRequestComplete = usbEhcdClearTTRequestComplete;    /* Function to submit a clear tt request complete  */    g_pEHCDriverInfo->resetTTRequestComplete = usbEhcdResetTTRequestComplete;    /* Populate the members of the HC Driver data structure - End */    /* Register the HCD with the USBD */    Status = usbHstHCDRegister            (            g_pEHCDriverInfo,            &g_EHCDHandle            ,&g_USBDRequestFunctions            );    /* Check whether the registration is successful */    if (USBHST_SUCCESS != Status)        {    	OS_LOG_MESSAGE_HIGH(EHCD,"usbEhcdInit - Error in registering the HCD\n",0,0,0,0);    	/* Free memory allocated */    	OS_FREE(g_pEHCDriverInfo);        g_pEHCDriverInfo = NULL;        /* Destroy the event */        OS_DESTROY_EVENT(g_ListAccessEvent);        g_ListAccessEvent = NULL;		/* WindView Instrumentation */		USB_HCD_LOG_EVENT(			USB_EHCI_WV_INIT_EXIT,			"usbEhcdInit() exits - EHCD registration failed",			USB_EHCD_WV_FILTER);    	return FALSE;        }    /* Allocate memory for the DMA */    ehcdDMAPool = cacheDmaMalloc (USB_EHCD_DMA_MEMORY_SIZE);    /* Check if memory allocation is successful */    if (ehcdDMAPool == NULL)    	{    	OS_LOG_MESSAGE_HIGH(EHCD,"usbEhcdInit - Error in allocating memory\n",0,0,0,0);    	/* Free memory allocated */    	OS_FREE(g_pEHCDriverInfo);        g_pEHCDriverInfo = NULL;        /* Destroy the event */        OS_DESTROY_EVENT(g_ListAccessEvent);        g_ListAccessEvent = NULL;		/* WindView Instrumentation */		USB_HCD_LOG_EVENT(			USB_EHCI_WV_INIT_EXIT,			"usbEhcdInit() exits - Cache DMA mem alloc failure",			USB_EHCD_WV_FILTER);    	return FALSE;	}     ehcdmemPartID = memPartCreate (ehcdDMAPool,			 	    USB_EHCD_DMA_MEMORY_SIZE);    /* Check if memory allocation is successful */    if (ehcdmemPartID == NULL)    	{    	OS_LOG_MESSAGE_HIGH(EHCD,"usbEhcdInit - Error in allocating partition memory\n",0,0,0,0);    	/* Free memory allocated */    	OS_FREE(g_pEHCDriverInfo);        g_pEHCDriverInfo = NULL;        /* Destroy the event */        OS_DESTROY_EVENT(g_ListAccessEvent);        g_ListAccessEvent = NULL;        /* Release memory allocated for the cache DMA */        cacheDmaFree(ehcdDMAPool);        ehcdDMAPool = NULL;		/* WindView Instrumentation */		USB_HCD_LOG_EVENT(			USB_EHCI_WV_INIT_EXIT,			"usbEhcdInit() exits - Partition mem alloc failure",			USB_EHCD_WV_FILTER);    	return FALSE;	}    /*     * This loop performs the initialization of all     * the Host Controllers in the system.     */    for (g_EHCDControllerCount = 0;         g_EHCDControllerCount < USB_EHCD_MAX_HOST_CONTROLLERS;)        {        /* Call the bus specific initialization function to initialize the         * host controllers in the system         */        BusInitStatus = usbEhcdHostBusInitialize(&pHCDData,                                               g_EHCDControllerCount);        /*         * If the bus is not present, release memory allocated only         * for this instance and return         */        if (USB_EHCD_HC_NOT_PRESENT == BusInitStatus)            {    	    OS_LOG_MESSAGE_HIGH(EHCD,"usbEhcdInit - No other HC is present\n",0,0,0,0);    	        	    /* If atleast one host controller is found, then it is not an error*/    	    if (0 != g_EHCDControllerCount)        	    {                /* WindView Instrumentation */                USB_HCD_LOG_EVENT(                    USB_EHCI_WV_INIT_EXIT,                    "usbEhcdInit() exits successfully - no host controller",                    USB_EHCD_WV_FILTER);                /* If the Host Controller is not present, it is not an error */   	    	    return TRUE;        	    }            else                {                /* WindView Instrumentation */                USB_HCD_LOG_EVENT(                    USB_EHCI_WV_INIT_EXIT,                    "usbEhcdInit() exits - BusInit reported no controller",                    USB_EHCD_WV_FILTER);            	return FALSE;                }            }        /* If the bus initialization is not successful, return an error */        if (USB_EHCD_HCBUS_NOT_INITIALIZED == BusInitStatus)            {    	    OS_LOG_MESSAGE_HIGH(EHCD,"usbEhcdInit - Bus initialization is \                                 unsuccessful\n",0,0,0,0);    	    return FALSE;            }        /* Initialize the array element */        g_pEHCDData[g_EHCDControllerCount] = pHCDData;        /* Update the bus index in the structure */        pHCDData->uBusIndex = g_EHCDControllerCount;        /* Initialize the Host Controller data structure */        bInitStatus = usbEhcdDataInitialize(pHCDData);        /* Check if the EHCD_DATA structure initialization is successful */        if (TRUE != bInitStatus)            {    	    OS_LOG_MESSAGE_HIGH(EHCD,"usbEhcdInit - EHCD_DATA initialization is \                                 unsuccessful\n",0,0,0,0);            /* Call the uninitialization function of the HC bus */            usbEhcdHostBusUninitialize(pHCDData);		    /* WindView Instrumentation */		    USB_HCD_LOG_EVENT(			    USB_EHCI_WV_INIT_EXIT,			    "usbEhcdInit() exits - Controller Data Initialisation failed",			    USB_EHCD_WV_FILTER);    	    return FALSE;            }        /* Power off all the root hub ports */        /*         * The EHC_PPC field indicates whether the EHCI Host Controller supports         * per port power switching.         * Check whether the port supports per port power switching.         */        if (1 == USB_EHCD_GET_FIELD(pHCDData,                                HCSPARAMS,                                PPC))            {            /* This loop will power off all the ports */

⌨️ 快捷键说明

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