📄 usbehcdinitexit.c
字号:
* D1 - Holds the status change information of the Port 1 * * Dn - holds the status change information of the Port n * So if the number of downstream ports is N, the size of interrupt * transfer data would be N + 1 bits. */ uTempVariable = (pHCDData->RHData.uNumDownstreamPorts + 1)/ 8; if (0 != ((pHCDData->RHData.uNumDownstreamPorts + 1) % 8)) { uTempVariable = uTempVariable + 1; } /* Allocate memory for the interrupt transfer data */ pHCDData->RHData.pHubInterruptData = OS_MALLOC(uTempVariable); /* Check if memory allocation is successful */ if (NULL == pHCDData->RHData.pHubInterruptData) { OS_LOG_MESSAGE_HIGH(EHCD,"usbEhcdDataInitialize - memory not allocated for \ interrupt transfer data \n",0,0,0,0); usbEhcdDataUninitialize(pHCDData); return FALSE; } /* Initialize the interrupt data */ OS_MEMSET(pHCDData->RHData.pHubInterruptData, 0, uTempVariable); /* Copy the size of the interrupt data */ pHCDData->RHData.uSizeInterruptData = uTempVariable; /* Create the default pipe */ pHCDData->pDefaultPipe = (pUSB_EHCD_PIPE)OS_MALLOC(sizeof(USB_EHCD_PIPE)); /* Check if default pipe is created successfully */ if (NULL == pHCDData->pDefaultPipe) { OS_LOG_MESSAGE_HIGH(EHCD,"usbEhcdDataInitialize - memory not allocated for \ the default pipe \n",0,0,0,0); usbEhcdDataUninitialize(pHCDData); return FALSE; } /* Initialize the USB_EHCD_PIPE data structure */ USB_EHCD_PIPE_INITIALIZE(pHCDData->pDefaultPipe); /* * Allocate a QH for the default endpoint * and add it to the asynchronous schedule */ /* Get an aligned QH */ pHCDData->pDefaultPipe->pQH = usbEhcdFormEmptyQH(pHCDData); /* Check if a valid QH is retrieved */ if (NULL == pHCDData->pDefaultPipe->pQH) { OS_LOG_MESSAGE_HIGH(EHCD,"usbEhcdDataInitialize - invalid QH \n",0,0,0,0); usbEhcdDataUninitialize(pHCDData); return FALSE; } /* Store this pointer as the tail of the asynchronous list */ pHCDData->pAsynchTailPipe = pHCDData->pDefaultPipe; /* As it is a circular list, the next pointer also points to itself */ pHCDData->pDefaultPipe->pNext = pHCDData->pDefaultPipe; /* Store the USB_EHCD_PIPE pointer in the QH */ pHCDData->pDefaultPipe->pQH->pHCDPipe = pHCDData->pDefaultPipe; /* Populate the fields of the QH - Start */ /* Fetch the host controller accessible region */ pQHTemp = (PUCHAR) pHCDData->pDefaultPipe->pQH; pQHTemp += USB_EHCD_QH_HEADER_SIZE; /* Update the next link pointer to point to itself */ USB_EHCD_SET_BITFIELD(uBusIndex, QH, pHCDData->pDefaultPipe->pQH->uQueueHeadHorizontalLinkPointer, ((unsigned) USB_EHCD_CONVERT_TO_BUS_MEM( uBusIndex, pQHTemp) >> 5), HORIZONTAL_LINK_POINTER); /* Make the next QH as a valid element */ USB_EHCD_SET_BITFIELD(uBusIndex, QH, pHCDData->pDefaultPipe->pQH->uQueueHeadHorizontalLinkPointer, USB_EHCD_VALID_LINK, HORIZONTAL_LINK_POINTER_T); /* Address of the default endpoint is 0 */ USB_EHCD_SET_BITFIELD(uBusIndex, QH, pHCDData->pDefaultPipe->pQH->uEndPointCharacteristics, 0, ENDPOINT_CHARACTERISTICS_DEVICE_ADDRESS ); /* Endpoint number */ USB_EHCD_SET_BITFIELD(uBusIndex, QH,pHCDData->pDefaultPipe->pQH->uEndPointCharacteristics, 0, ENDPOINT_CHARACTERISTICS_ENDPT_NUMBER); /* Indicate the speed as high speed */ USB_EHCD_SET_BITFIELD(uBusIndex, QH, pHCDData->pDefaultPipe->pQH->uEndPointCharacteristics, USBHST_HIGH_SPEED, ENDPOINT_CHARACTERISTICS_ENDPT_SPEED ); /* Retrieve the data toggle bit from the QTD */ USB_EHCD_SET_BITFIELD(uBusIndex, QH, pHCDData->pDefaultPipe->pQH->uEndPointCharacteristics, USB_EHCD_DTC_RETRIEVE_FROM_QTD, ENDPOINT_CHARACTERISTICS_DTC); /* Set this QH as the head of the reclamation list */ USB_EHCD_SET_BITFIELD(uBusIndex, QH, pHCDData->pDefaultPipe->pQH->uEndPointCharacteristics, 1, ENDPOINT_CHARACTERISTICS_HEAD_RECLAMATION_LIST); /* Initialize the maximum packet size of the default pipe */ USB_EHCD_SET_BITFIELD(uBusIndex, QH, pHCDData->pDefaultPipe->pQH->uEndPointCharacteristics, USB_EHCD_DEFAULT_MAX_PACKET_SIZE, ENDPOINT_CHARACTERISTICS_MAXIMUM_PACKET_LENGTH ); /* Update the NAK count Reload field */ USB_EHCD_SET_BITFIELD(uBusIndex, QH, pHCDData->pDefaultPipe->pQH->uEndPointCharacteristics, USB_EHCD_MAX_NAK_RATE, ENDPOINT_CHARACTERISTICS_RL); /* Flush the contents to the RAM */ CACHE_DMA_FLUSH (pHCDData->pDefaultPipe->pQH, sizeof(USB_EHCD_QH)); /* * Fetch the host controller accessible region by adding offset * USB_EHCD_QH_HEADER_SIZE. */ pQHTemp = (PUCHAR) pHCDData->pDefaultPipe->pQH; pQHTemp += USB_EHCD_QH_HEADER_SIZE; /* Update the QH in the ASYNCLISTADDR */ USB_EHCD_SET_FIELD(pHCDData, ASYNCLISTADDR, LINK_PTR_LOW, ((UINT32)USB_EHCD_CONVERT_TO_BUS_MEM( uBusIndex, pQHTemp) >> USB_EHCD_ASYNCHLISTADDR_LINK_PTR_LOW)); /* Enable the asynchronous schedule */ USB_EHCD_SET_BIT(pHCDData, USBCMD, ASYNCH_SCHEDULE_ENABLE); /* Populate the fields of the QH - End */ /* Create the event which is used for signalling the thread on interrupt */ pHCDData->InterruptEvent = OS_CREATE_EVENT(OS_EVENT_NON_SIGNALED); /* Check if the event is created successfully */ if (NULL == pHCDData->InterruptEvent) { OS_LOG_MESSAGE_HIGH(EHCD,"usbEhcdDataInitialize - signal event not created\n",0,0,0,0); usbEhcdDataUninitialize(pHCDData); return FALSE; } /* Create the event used for synchronisation of the requests */ pHCDData->RequestSynchEventID = OS_CREATE_EVENT(OS_EVENT_SIGNALED); /* Check if the event is created successfully */ if (NULL == pHCDData->RequestSynchEventID) { OS_LOG_MESSAGE_HIGH(EHCD,"usbEhcdDataInitialize - synch event not created\n",0,0,0,0); usbEhcdDataUninitialize(pHCDData); return FALSE; } /* Create the event used for synchronisation of the reclamation list */ pHCDData->ReclamationListSynchEventID = OS_CREATE_EVENT(OS_EVENT_SIGNALED); /* Check if the event is created successfully */ if (NULL == pHCDData->ReclamationListSynchEventID) { OS_LOG_MESSAGE_HIGH(EHCD,"usbEhcdDataInitialize - reclamation synch event is \ not created\n",0,0,0,0); usbEhcdDataUninitialize(pHCDData); return FALSE; } /* Create the event for bandwidth reservation */ pHCDData->BandwidthEventID = OS_CREATE_EVENT(OS_EVENT_SIGNALED); /* Check if the event is created successfully */ if (NULL == pHCDData->BandwidthEventID) { OS_LOG_MESSAGE_HIGH(EHCD,"usbEhcdDataInitialize - bandwidth event is \ not created\n",0,0,0,0); usbEhcdDataUninitialize(pHCDData); return FALSE; } /* Assign an unique name for the interrupt handler thread */ ThreadName[8] = pHCDData->uBusIndex; /* Create the interrupt handler thread for handling the interrupts */ pHCDData->IntHandlerThreadID = OS_CREATE_THREAD((char *)ThreadName, USB_EHCD_INT_THREAD_PRIORITY, usbEhcdInterruptHandler, pHCDData); /* Check whether the thread creation is successful */ if (OS_THREAD_FAILURE == pHCDData->IntHandlerThreadID) { OS_LOG_MESSAGE_HIGH(EHCD,"usbEhcdDataInitialize - interrupt handler thread \ is not created\n",0,0,0,0); usbEhcdDataUninitialize(pHCDData); return FALSE; } OS_LOG_MESSAGE_LOW(EHCD,"usbEhcdDataInitialize - Exit\n",0,0,0,0); return TRUE; } /* End of function usbEhcdDataInitialize() *//***************************************************************************** usbEhcdDestroyInterruptTree - destroys the periodic tree created.** This function destroys the periodic tree created for the interrupt* endpoints.** RETURNS: N/A.** ERRNO:* None.** \NOMANUAL*/VOID usbEhcdDestroyInterruptTree ( pUSB_EHCD_DATA pHCDData ) { /* To hold the index into the frame list */ UINT32 uCount = 0; /* To hold the Queue Head pointer */ pUSB_EHCD_QH pQH = NULL; /* Temporary Queue Head */ pUSB_EHCD_QH pTempQH = NULL; OS_LOG_MESSAGE_LOW(EHCD,"usbEhcdDestroyInterruptTree - Entry\n",0,0,0,0); /* Check the validity of the parameter */ if (NULL == pHCDData) { OS_LOG_MESSAGE_HIGH(EHCD,"usbEhcdDestroyInterruptTree - invalid parameter\n",0,0,0,0); return; } /* This loop removes all the elements of the tree */ for (uCount = 0; USB_EHCD_MAX_TREE_NODES > uCount; uCount++) { /* This loop searches for the QHs in the tree and frees them */ for (pQH = pHCDData->TreeListData[uCount].pHeadPointer; (pHCDData->TreeListData[uCount].pHeadPointer != pHCDData->TreeListData[uCount].pTailPointer) && (NULL != pQH); pQH = pTempQH) { /* Retrieve the pointer to HCD specific data */ pQH = (pUSB_EHCD_QH)((UINT32)pQH - USB_EHCD_QH_HEADER_SIZE); /* Store the next element temporarily */ pTempQH = (pUSB_EHCD_QH)((UINT32)pQH->pNext + USB_EHCD_QH_HEADER_SIZE); OS_ASSERT(NULL != pQH->pAllocatedMem); /* Note : This only frees the QHs and not the QTDs associated */ /* Free the memory allocated for the QH */ OS_FREE(pQH->pAllocatedMem); } /* Check if QH is not NULL and if it is the same as the tail element */ if ((pQH != NULL) && (pQH == pHCDData->TreeListData[uCount].pTailPointer)) { /* Retrieve the pointer to HCD specific data */ pQH = (pUSB_EHCD_QH)((UINT32)pQH - USB_EHCD_QH_HEADER_SIZE); /* Free memory allocated for the tail */ OS_ASSERT(NULL != pQH->pAllocatedMem); /* Note : This only frees the QHs and not the QTDs associated */ /* Free the memory allocated for the QH */ OS_FREE(pQH->pAllocatedMem); } /* Update the head and tail pointers to NULL */ pHCDData->TreeListData[uCount].pHeadPointer = NULL; pHCDData->TreeListData[uCount].pTailPointer = NULL; } OS_LOG_MESSAGE_LOW(EHCD,"usbEhcdDestroyInterruptTree - Exit\n",0,0,0,0); return; } /* End of usbEhcdDestroyInterruptTree() *//***************************************************************************** usbEhcdHostBusUninitialize - performs the host bus specific* uninitialization.** RETURNS: N/A.** ERRNO:* None.** \NOMANUAL*/VOID usbEhcdHostBusUninitialize ( pUSB_EHCD_DATA pHCDData ) { OS_LOG_MESSAGE_LOW(EHCD,"usbEhcdHostBusUninitialize - Entry\n",0,0,0,0); /* Check the validity of the parameter */ if (NULL == pHCDData) { OS_LOG_MESSAGE_HIGH(EHCD,"usbEhcdHostBusUninitialize - invalid parameter\n",0,0,0,0); return; } /* Unregister the interrupt handler for the IRQ */ if (pEhciBusInfo[pHCDData->uBusIndex]->pFuncIntDisconnect != NULL) pEhciBusInfo[pHCDData->uBusIndex]->pFuncIntDisconnect(usbEhcdISR, pHCDData, pHCDData->uIRQ); OS_LOG_MESSAGE_LOW(EHCD,"usbEhcdHostBusUninitialize - Exit\n",0,0,0,0); return; } /* End of function usbEhcdHostBusUninitialize() *//***************************************************************************** usbEhcdDataUninitialize - performs the EHCD_DATA structure* uninitialization.** RETURNS: N/A.** ERRNO:* None.** \NOMANUAL*/VOID usbEhcdDataUninitialize ( pUSB_EHCD_DATA pHCDData ) { OS_LOG_MESSAGE_LOW(EHCD,"usbEhcdDataUninitialize - Entry\n",0,0,0,0); /* Check the validity of the parameter */ if (NULL == pHCDData) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -