📄 usbuhcdinitialization.c
字号:
/* Increment the Resource allocation count */ pResourceAllocated[g_UhcdHostControllerCount]++; /* increment the host controller found count */ hostControllerFound++; /* Enable the Interrupts - End */ } if (hostControllerFound == 0) { OS_FREE(hcDriver); usbHstHCDDeregister (hHcDriver); hHcDriver = 0; /* free the allocated resources */ if (pResourceAllocated != NULL) { OS_FREE (pResourceAllocated); pResourceAllocated = NULL; } if (g_pUHCDData != NULL) { OS_FREE (g_pUHCDData); g_pUHCDData = NULL; } return USBHST_FAILURE; } for (g_UhcdHostControllerCount = 0; g_UhcdHostControllerCount < maxUhciCount; g_UhcdHostControllerCount++) { if(pResourceAllocated[g_UhcdHostControllerCount] == MAX_RESOURCE_ALLOCATED) { /*logMsg("HCD registers for HC [%d]\n",g_HostControllerCount,0,0,0,0,0);*/ } else if(pResourceAllocated[g_UhcdHostControllerCount] != 0) { usbUhcdRemoveResources(g_pUHCDData[g_UhcdHostControllerCount], pResourceAllocated[g_UhcdHostControllerCount], g_UhcdHostControllerCount); } } OS_LOG_MESSAGE_MEDIUM(UHCD,"Exiting UHCD init\n",0,0,0,0); /* WindView Instrumentation */ USB_HCD_LOG_EVENT( USB_UHCI_WV_INIT_EXIT, "usbUhciInit() exits successfully", USB_UHCD_WV_FILTER); /* Release memory allocated for the resource array */ OS_FREE(pResourceAllocated); /* Make the alreadyInited Flag to TRUE */ alreadyInited = TRUE; /* Return from the function */ return USBHST_SUCCESS; }/* End of usbUhcdInit() *//***************************************************************************** usbUhcdExit - uninitialise the USB UHCD Host Controller Driver.** This function uninitialise the USB UHCD Host Controller Driver and detaches* it from the usbd interface layer.** RETURNS: USBHST_SUCCESS, USBHST_FALIURE if the UHCD Host Controller * uninitializaton fails** ERRNO:* None.*/USBHST_STATUS usbUhcdExit ( void ) { /* To hold the pointer to the HCD maintained data structure */ PUHCD_DATA pHCDData = NULL; USB_UHCD_HCD_PIPE *tempPipe = NULL; USB_UHCD_HCD_PIPE *delPipe = NULL; USB_UHCD_NON_ISO_REQUEST_QUEUE * tempReq = NULL; USB_UHCD_NON_ISO_REQUEST_QUEUE * delReq = NULL; USB_UHCD_ISO_REQUEST_QUEUE * tempIsoReq = NULL; USB_UHCD_ISO_REQUEST_QUEUE * delIsoReq = NULL; USBHST_STATUS status = USBHST_FAILURE; OS_LOG_MESSAGE_MEDIUM(UHCD,"Entering UHCD exit\n",0,0,0,0); /* check whether the UHCI Controller is Initialized or not */ if (alreadyInited == FALSE) { OS_LOG_MESSAGE_MEDIUM(UHCD,"Host Controller not initialized\n",0,0,0,0); return USBHST_FAILURE; } /* * This loop performs the initialization of all * the Host Controllers in the system. */ for (g_UhcdHostControllerCount = 0; g_UhcdHostControllerCount < maxUhciCount; g_UhcdHostControllerCount++) { /* Store in global array */ pHCDData = g_pUHCDData[g_UhcdHostControllerCount]; if (pHCDData) { /*usbUhcdHcReset (pHCDData);*/ /* Call the function to remove all the resources allocated as part of initialization. */ status = usbUhcdRemoveResources(pHCDData,MAX_RESOURCE_ALLOCATED, g_UhcdHostControllerCount ); if (USBHST_FAILURE == status) { return USBHST_FAILURE; } /* deallocate the non ischronous request blocks */ tempReq = pHCDData->usbUhcdNonIsoRequestQ; while (tempReq) { delReq = tempReq; tempReq = tempReq->next; if (delReq->head && delReq->tail) usbUhcdFreeTds(delReq->head, delReq->tail); OS_FREE(delReq); } /* deallocate the ischronous request blocks */ tempIsoReq = pHCDData->usbUhcdIsoRequestQ; while (tempIsoReq) { delIsoReq = tempIsoReq; tempIsoReq = tempIsoReq->next; if (delIsoReq->head && delIsoReq->tail) usbUhcdFreeTds (delIsoReq->head, delIsoReq->tail); OS_FREE(delIsoReq); } /* deallocate the list of pipes */ tempPipe = pHCDData->usbUhcdPipe; while (tempPipe) { delPipe = tempPipe; tempPipe= tempPipe->next; if (delPipe->qh) UHCI_FREE((UCHAR*)delPipe->qh - delPipe->qh->offsetForFreeing); OS_FREE(delPipe); } } else { continue; } } /* deregister the HC driver */ status = usbHstHCDDeregister(hHcDriver); if (USBHST_FAILURE == status) { return USBHST_FAILURE; } OS_FREE(hcDriver); /* free the global allocated variable */ OS_FREE (g_pUHCDData); g_pUHCDData = NULL; /* Set alreadyInited flag to FALSE */ alreadyInited = FALSE; OS_LOG_MESSAGE_MEDIUM(UHCD,"Exiting UHCD exit\n",0,0,0,0); return USBHST_SUCCESS; }/***************************************************************************** usbUhcdRemoveResources - Frees the resources taken by initialization routine.** Release all resources allocated at initialization time** RETURNS: USBHST_SUCCESS, USBHST_FALIURE if the free of resources failed** ERRNO:* None.** \NOMANUAL*/USBHST_STATUS usbUhcdRemoveResources ( PUHCD_DATA pHCDData, INT8 aResourceAllocated, UINT32 index ) { /* To hold the staus */ USBHST_STATUS status = USBHST_FAILURE; switch(aResourceAllocated) { case 14: /* Deregister the Bus */ status = usbHstBusDeregister (hHcDriver,index, (UINT32)pHCDData->hcDefaultPipe ); if (USBHST_FAILURE == status) { break; } /* * Bit 0 of the USBCMD register enables the Host Controller to be * operational or non-operational. Setting this bit to 0 makes the * Host Controller non-operational. */ usbUhcdRegxClearBit (pHCDData, USB_UHCD_USBCMD, 0); case 13: /* Unregister the ISR */ if (pUhciBusInfo[index]->pFuncIntDisconnect != NULL) pUhciBusInfo[index]->pFuncIntDisconnect(usbUhcdIsr, (PVOID)pHCDData, pHCDData->irq); case 12: /* Unable to Register Interrupt ..*/ OS_DESTROY_THREAD(pHCDData->usbUhcdThdTransferComp); case 11: /* Unable to Create thread used for handling transfer completion */ OS_DESTROY_EVENT (pHCDData->usbUhcdSemCleanupTd); case 10: /* Unable to Create semaphore used to cleanup the resources allocated after completion of a transfer request. */ OS_DESTROY_THREAD (pHCDData->usbUhcdThdManagePort); case 9: /* Unable to Create thread which polls the ports of the UHCI Root Hub */ OS_DESTROY_EVENT (pHCDData->usbUhcdSemPortInterruptTransfer); case 8: /* Unable to Create semaphore used by the Root Hub Emulation module's Interrupt task */ OS_DESTROY_EVENT (pHCDData->usbUhcdSemCheckPort); case 7: case 6: /* Unable to disable interrupts */ pHCDData->usbUhcdPipe = NULL; OS_FREE (pHCDData->hcDefaultPipe); case 5: /* Unable to Create Default Pipe */ usbUhcdDeleteFrameList(pHCDData); case 4: /* Unable to create framelist */ case 3: /* Invalid USB Base Addres */ case 2: /* Error in Reading USB Regiater */ case 1: if (pHCDData->usbUhcdSemCritical) { OS_DESTROY_EVENT (pHCDData->usbUhcdSemCritical); } OS_FREE(pHCDData); return USBHST_SUCCESS; case 0: /* memory not allocated For HCD_DATA structure */ /* invalid values in the CLASSC register */ /* Error in reading the CLASSC register */ /* UHC not found */ return USBHST_SUCCESS; default: break; }; return USBHST_FAILURE; }/******************************************************************************** usbUhcdDisableHC - called on a reboot to disable the host controller** This routine is called on a warm reboot to disable the host controller by* the BSP.** RETURNS: None.** ERRNO:* None.** \NOMANUAL*/VOID usbUhcdDisableHC ( int startType ) { /* Pointer to the HCD data structure */ PUHCD_DATA pHCDData = NULL; UINT8 index = 0; if ((g_pUHCDData == NULL) || (maxUhciCount == 0)) return; while (index < maxUhciCount) { pHCDData = g_pUHCDData [index]; if (pHCDData) { /* Reset the host controller */ usbUhcdHcReset (pHCDData); /* Unregister the ISR */ if ((pUhciBusInfo[index] != NULL) && (pUhciBusInfo[index]->pFuncIntDisconnect != NULL)) pUhciBusInfo[index]->pFuncIntDisconnect(usbUhcdIsr, (PVOID)pHCDData, pHCDData->irq); } index++; } return; }/************* End of usbUhcdInitialisation.c ******************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -