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

📄 usbehcdutil.c

📁 vxWorks下USB2.0中的EHCI的HCD源码,极具有参考价值
💻 C
📖 第 1 页 / 共 5 页
字号:
/* usbEhcdUtil.c - contains the utility functions of EHCD *//* Copyright 2002-2003 Wind River Systems, Inc. *//*modification history--------------------01d,23Jul03,Incorporated changes identified during testing on MIPS.01c,16Jul03,updated the next link pointer of the aligned pointer in the free            list to be NULL.01b,26jun03,gpd changing the code to WRS standards.01a,25apr02,ram written.*//*DESCRIPTIONThis module defines the functions which serve as utility functions for theEHCI Host Controller Driver.INCLUDE FILES: usbhst.h, usbEhcdDataStructures.h, usbEhcdUtil.h, usbEhcdDebug.h,SEE ALSO:.I "USB specification, revision 2.0".I "EHCI specification, revision 1.0"*//* INTERNAL ******************************************************************************* * * Filename         : EHCD_Util.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 contains the utility functions which are used by the *                     EHCI Driver. * * ******************************************************************************/#include "usb2/usbOsal.h"#include "usb2/BusAbstractionLayer.h"#include "usb2/usbHst.h"#include "usb2/usbEhcdDataStructures.h"#include "usb2/usbEhcdUtil.h"#include <math.h>#include "usb2/usbHcdInstr.h"/* To hold the head of the Free QH list */LOCAL pUSB_EHCD_QH pHeadFreeQH  = NULL;/* To hold the tail of the Free QH list */LOCAL pUSB_EHCD_QH pTailFreeQH  = NULL;/* To hold the head of the Free QTD list */LOCAL pUSB_EHCD_QTD pHeadFreeQTD  = NULL;/* To hold the tail of the Free QTD list */LOCAL pUSB_EHCD_QTD pTailFreeQTD  = NULL;/* To hold the head of the free isochronous TD list */LOCAL pUSB_EHCD_ITD pHeadFreeITD = NULL;/* To hold the tail of the free isochronous TD list */LOCAL pUSB_EHCD_ITD pTailFreeITD = NULL;/* To hold the head of the free split isochronous TD list */LOCAL pUSB_EHCD_SITD pHeadFreeSITD = NULL;/* To hold the tail of the free split isochronous TD list */LOCAL pUSB_EHCD_SITD pTailFreeSITD = NULL;/* To hold the event which prevents the list accesses */#define pUSB_EHCD_QTD_NEXT_QTD_POINTER_OFFSET 0#define pUSB_EHCD_QTD_pNext_OFFSET 22extern OS_EVENT_ID g_ListAccessEvent;extern char *ehcdDMAPool;extern PART_ID ehcdmemPartID;LOCAL pUSB_EHCD_ITD usbEhcdFormEmptyITD    (    pUSB_EHCD_PIPE  pHCDPipe /* Pointer to the USB_EHCD_PIPE structure */    );/* forward declarations */LOCAL UINT32 usbEhcdFillITDBuffer    (    pUSB_EHCD_ITD pITD, /* Pointer to the ITD */    UINT8 uMicroFrameMask, /* Microframe mask value */    UCHAR *pBuffer,  /* Pointer to the buffer value */    UINT32 uSize     /* Size of the buffer */    );LOCAL pUSB_EHCD_SITD usbEhcdFormEmptySITD    (    pUSB_EHCD_PIPE  pHCDPipe /* Pointer to the USB_EHCD_PIPE structure */    );/* forward declarations */LOCAL UINT32 usbEhcdFillSITDBuffer    (    pUSB_EHCD_SITD pSITD, /* Pointer to the ITD */    UCHAR *pBuffer,  /* Pointer to the buffer value */    UINT32 uSize     /* Size of the buffer */    );LOCAL UINT32 usbEhcdFillITD    (    pUSB_EHCD_ITD pITD, /* Pointer to the ITD */    UINT8 uMicroFrameMask, /* Microframe mask value */    UCHAR *pBuffer,  /* Pointer to the buffer value */    UINT32 uPktCnt,     /* No of packet */    pUSBHST_ISO_PACKET_DESC pIsoPktDesc /* array of packet descriptor */    );LOCAL BOOLEAN usbEhcdFillSITD    (    pUSB_EHCD_SITD    pSITD, /* Pointer to the SITD */    UCHAR *        pBuffer,  /* Pointer to the start of the buffer */    UINT32     uTransferLength  /* Transfer length */    );/***************************************************************************** usbEhcdAlign - aligns the memory location** This function is used to align a memory location.** <pMemory> Pointer to the allocated memory.* <uAlignment> Alignment size.** RETURNS: Pointer to a void.** ERRNO:*   None.** \NOMANUAL*/VOID * usbEhcdAlign    (    VOID * pMemory,    UINT32  uAlignment    )    {    /* To hold the offset value */    UINT32 uOffset = 0;    OS_LOG_MESSAGE_LOW(EHCD,"usbEhcdAlign - Entry\n",0,0,0,0);    /* Check if the parameters are valid */    if (NULL == pMemory || 0 == uAlignment)        {    	OS_LOG_MESSAGE_HIGH(EHCD,"usbEhcdAlign - Parameters not valid\n",0,0,0,0);    	return NULL;        }    /* Calculate the offset value */    uOffset = (UINT32)pMemory & (uAlignment - 1);    /* If it not aligned, align it */    if (0 != uOffset)        {        pMemory = ((UINT8 *)pMemory) + uAlignment - uOffset;        }    OS_LOG_MESSAGE_LOW(EHCD,"usbEhcdAlign - Exit\n",0,0,0,0);    /* Return the aligned memory location */    return pMemory;    }    /* End of function usbEhcdAlign() *//***************************************************************************** usbEhcdAddToFreeQHList - adds the QH to the free list** This function is used to add a QH to the free QH list.** <pQH> Pointer to the USB_EHCD_QH data structure.** RETURNS: TRUE if the QH is added successfully.*          FALSE if the QH is not added successfully.** ERRNO:*   None.* * \NOMANUAL*/BOOLEAN usbEhcdAddToFreeQHList    (    pUSB_EHCD_QH pQH    )    {    /* Pointer to the allocated memory location */    VOID * pAllocatedMem = NULL;    OS_LOG_MESSAGE_LOW(EHCD,"usbEhcdAddToFreeQHList - Entry\n",0,0,0,0);    /* Check the validity of the parameter */    if (NULL == pQH)        {    	OS_LOG_MESSAGE_HIGH(EHCD,"usbEhcdAddToFreeQHList - \                        Parameter not valid\n",0,0,0,0);        return FALSE;        }    /* Assert if the Allocated memory for the QH is not valid */    OS_ASSERT(NULL != pQH->pAllocatedMem);    /* Store the allocated memory in a temporary pointer */    pAllocatedMem = pQH->pAllocatedMem;    /* Reinitialize the memory */    OS_MEMSET(pQH, 0, sizeof(USB_EHCD_QH));    /* Copy the allocated memory pointer back */    pQH->pAllocatedMem = pAllocatedMem;    /* Wait on the signalling of the event */    OS_WAIT_FOR_EVENT(g_ListAccessEvent,OS_WAIT_INFINITE);    /* Update the next element of the QTD */    pQH->pNext = pHeadFreeQH;    /* Make this QTD as the head of the free list */    pHeadFreeQH = pQH;    /* If tail pointer is NULL, this QTD becomes the tail pointer */    if (NULL == pTailFreeQH)        {        pTailFreeQH = pQH;        }    /* Release the event */    OS_RELEASE_EVENT(g_ListAccessEvent);    OS_LOG_MESSAGE_LOW(EHCD,"usbEhcdAddToFreeQHList - Exit\n",0,0,0,0);    return TRUE;    }    /* End of usbEhcdAddToFreeQHList() *//***************************************************************************** usbEhcdAddToFreeQTDList - adds the QTD to the free list** This function is used to add a QTD to the free QH list.** <pQTD> Pointer to the USB_EHCD_QTD data structure.** RETURNS: TRUE if the QTD is added successfully.*          FALSE if the QTD is not added successfully.** ERRNO:*   None.** \NOMANUAL*/BOOLEAN usbEhcdAddToFreeQTDList    (    pUSB_EHCD_QTD pQTD    )    {    /* Pointer to the allocated memory location */    VOID * pAllocatedMem = NULL;    /* Check the validity of the parameter */    if (NULL == pQTD)        {    	OS_LOG_MESSAGE_HIGH(EHCD,"usbEhcdAddToFreeQTDList - \                            Parameter not valid\n",0,0,0,0);        return FALSE;        }    /* Assert if the Allocated memory for the QTD is not valid */    OS_ASSERT(NULL != pQTD->pAllocatedMem);    /* Store the allocated memory in a temporary pointer */    pAllocatedMem = pQTD->pAllocatedMem;    /* Reinitialize the memory */    OS_MEMSET(pQTD, 0, sizeof(USB_EHCD_QTD));    /* Copy the allocated memory pointer back */    pQTD->pAllocatedMem = pAllocatedMem;    /* Wait on the signalling of the event */    OS_WAIT_FOR_EVENT(g_ListAccessEvent,OS_WAIT_INFINITE);    /* Update the next element of the QTD */    pQTD->pNext = pHeadFreeQTD;    /* Make this QTD as the head of the free list */    pHeadFreeQTD = pQTD;    /* If tail pointer is NULL, this QTD becomes the tail pointer */    if (NULL == pTailFreeQTD)        {        pTailFreeQTD = pQTD;        }    /* Release the event */    OS_RELEASE_EVENT(g_ListAccessEvent);    return TRUE;    }    /* End of EHCD_AddToFreeTDList() *//***************************************************************************** usbEhcdAddToFreeITDList - adds the ITD to the free list** This function is used to add a ITD to the free QH list.** <pITD> Pointer to the USB_EHCD_ITD data structure.** RETURNS: TRUE if the ITD is added successfully.*          FALSE if the ITD is not added successfully.** ERRNO:*   None.* * \NOMANUAL*/BOOLEAN usbEhcdAddToFreeITDList    (    pUSB_EHCD_ITD pITD    )    {    /* Pointer to the allocated memory location */    VOID * pAllocatedMem = NULL;    OS_LOG_MESSAGE_LOW(EHCD,"usbEhcdAddToFreeITDList - Entry\n",0,0,0,0);    /* Check the validity of the parameter */    if (NULL == pITD)        {    	OS_LOG_MESSAGE_HIGH(EHCD,"usbEhcdAddToFreeITDList - \                                Parameter not valid\n",0,0,0,0);        return FALSE;        }    /* Assert if the Allocated memory for the ITD is not valid */    OS_ASSERT(NULL != pITD->pAllocatedMem);    /* Store the allocated memory in a temporary pointer */    pAllocatedMem = pITD->pAllocatedMem;    /* Reinitialize the memory */    OS_MEMSET(pITD, 0, sizeof(USB_EHCD_ITD));    /* Copy the allocated memory pointer back */    pITD->pAllocatedMem = pAllocatedMem;    /* Wait on the signalling of the event */    OS_WAIT_FOR_EVENT(g_ListAccessEvent,OS_WAIT_INFINITE);    /* Update the next element of the ITD */    pITD->pNext = pHeadFreeITD;    /* Make this ITD as the head of the free list */    pHeadFreeITD = pITD;    /* If tail pointer is NULL, this ITD becomes the tail pointer */    if (NULL == pTailFreeITD)        {        pTailFreeITD = pITD;        }    /* Release the event */    OS_RELEASE_EVENT(g_ListAccessEvent);    OS_LOG_MESSAGE_LOW(EHCD,"usbEhcdAddToFreeITDList - Exit\n",0,0,0,0);    return TRUE;    }    /* End of usbEhcdAddToFreeITDList() *//***************************************************************************** usbEhcdAddToFreeSITDList - adds the SITD to the free list** This function is used to add a SITD to the free QH list.** <pSITD> Pointer to the USB_EHCD_ITD data structure.** RETURNS: TRUE if the SITD is added successfully.*          FALSE if the SITD is not added successfully.** ERRNO:*   None.** \NOMANUAL*/BOOLEAN usbEhcdAddToFreeSITDList    (    pUSB_EHCD_SITD pSITD    )    {

⌨️ 快捷键说明

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