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

📄 usbtcdpdiusbd12endpoint.c

📁 This the compressed USB driver source code for vxworks5.6. It has device controller driver and other
💻 C
📖 第 1 页 / 共 4 页
字号:
/* usbTcdPdiusbd12Endpoint.c - Endpoint related functionalities of PDIUSBD12 *//* Copyright 2004 Wind River Systems, Inc. *//*Modification history--------------------01g,17sep04,ami  WindView Instrumentation Changes01f,02aug04,ami  Warning Messages Removed01e,29jul04,pdg  Diab warnings fixed01d,19jul04,ami  Coding Convention Changes01c,03may04,pdg  Fix for DMA bugs01b,27apr04,pdg  Testing bug fixes01a,15mar04,mat  First.*//*DESCRIPTIONThis file implements the endpoint related functionalities of TCD(Target Controller Driver) for the Philips PDIUSBD12.INCLUDE FILES: usb/usbPlatform.h, usb/ossLib.h, usb/target/usbIsaLib.h,               string.h, drv/usb/target/usbPdiusbd12Eval.h,               drv/usb/target/usbTcdPdiusbd12EvalLib.h,               drv/usb/target/usbPdiusbd12Tcd.h,               drv/usb/target/usbPdiusbd12Debug.h,               usb/target/usbPeriphInstr.h*//* includes */#include "usb/usbPlatform.h"                    #include "usb/ossLib.h" 		     #include "string.h"                          #include "drv/usb/target/usbPdiusbd12Eval.h"	#include "drv/usb/target/usbTcdPdiusbd12EvalLib.h"#include "drv/usb/target/usbPdiusbd12Tcd.h"     #include "drv/usb/target/usbPdiusbd12Debug.h"#include "usb/target/usbPeriphInstr.h"       /* globals *//*  In order to demonstrate the proper operation of the Philips * PDIUSBD12 with DMA, we use these buffers for DMA transfers. */IMPORT UINT	sysFdBuf;		/* physical address of DMA bfr */IMPORT UINT	sysFdBufSize;		/* size of DMA buffer *//* functions *//***************************************************************************** usbTcdPdiusbd12FncEndpointAssign - implements TCD_FNC_ENDPOINT_ASSIGN** This function assigns an endpoint for a specific kind of transfer.** RETURNS: OK or ERROR if failed to configure the endpoint** ERRNO:*  None** \NOMANUAL*/LOCAL STATUS usbTcdPdiusbd12FncEndpointAssign    (    pTRB_ENDPOINT_ASSIGN	pTrb		/* Trb to be executed */    )    {    pTRB_HEADER	pHeader = (pTRB_HEADER) pTrb;	/* TRB_HEADER */    UINT8	transferType = 0;		/* transfer type */    UINT8	direction = 0;			/* direction */    UINT16	maxPacketSize = 0;		/* max packet size */    pUSB_TCD_PDIUSBD12_ENDPOINT	pEndpointInfo = NULL; 						/* USB_TCD_PDIUSBD12_ENDPOINT*/    pUSB_ENDPOINT_DESCR		pEndptDescr = NULL;						/* pUSB_ENDPOINT_DESCR */    pUSB_TCD_PDIUSBD12_TARGET	pTarget = NULL;	/* USB_TCD_PDIUSBD12_TARGET */    UINT8	endpointNo = 0;			/* endpoint number */    UINT8	endpointIndex = 0;		/* endpoint index */    BOOL	indexFound= FALSE;    /* WindView Instrumentation */    USB_TCD_LOG_EVENT(USB_TCD_PDIUSBD12_ENDPOINT,    "usbTcdPdiusbd12FncEndpointAssign entered ...",    USB_TCD_PDIUSBD12_WV_FILTER);       USBPDIUSBD12_DEBUG ( "usbTcdPdiusbd12FncEndpointAssign : Entered \    ...\n",0,0,0,0,0,0);    /* Validate parameters */    if ((pHeader == NULL) || (pHeader->trbLength < sizeof (TRB_HEADER)) ||        (pTrb->pEndpointDesc == NULL))	{        /* WindView Instrumentation */        USB_TCD_LOG_EVENT(USB_TCD_PDIUSBD12_ENDPOINT,        "usbTcdPdiusbd12FncEndpointAssign exiting: Bad Paramter Received ...",        USB_TCD_PDIUSBD12_WV_FILTER);           USBPDIUSBD12_ERROR ( "usbTcdPdiusbd12FncEndpointAssign : Invalid  \        Parameter...\n",0,0,0,0,0,0);        return ERROR;        }    /* Get the endpoint descriptor */    pEndptDescr = pTrb->pEndpointDesc;    pTarget = (pUSB_TCD_PDIUSBD12_TARGET)pHeader->handle;    if ( pTarget == NULL )        {        /* WindView Instrumentation */        USB_TCD_LOG_EVENT(USB_TCD_PDIUSBD12_ENDPOINT,        "usbTcdPdiusbd12FncEndpointAssign exiting: Error assigning pTarget ...",        USB_TCD_PDIUSBD12_WV_FILTER);           USBPDIUSBD12_ERROR ( "usbTcdPdiusbd12FncEndpointAssign : Error \        assigning pTarget...\n",0,0,0,0,0,0);        return ERROR;        }    /* determine the transfer type */    transferType = pEndptDescr->attributes & USB_ATTR_EPTYPE_MASK;    /* determine the direction */    if ((pEndptDescr->endpointAddress & USB_ENDPOINT_DIR_MASK) != 0)        direction = USB_ENDPOINT_IN;    else        direction = USB_ENDPOINT_OUT;    /* determine the max packet size */    maxPacketSize = pEndptDescr->maxPacketSize;    /* Extract the endpoint number */    endpointNo = pEndptDescr->endpointAddress & USB_ENDPOINT_MASK;    /* determine if the maxpacket size can be supported */    if (((transferType == USB_ATTR_CONTROL) &&          (maxPacketSize >D12_MAX_PKT_CONTROL))||        ((transferType == USB_ATTR_BULK) &&           (endpointNo == D12_ENDPOINT_NO_1) &&          (maxPacketSize > D12_MAX_PKT_ENDPOINT_1))||        ((transferType == USB_ATTR_BULK) &&  (endpointNo == D12_ENDPOINT_NO_2) &&          (maxPacketSize > D12_MAX_PKT_ENDPOINT_2_NON_ISO))||        ((transferType == USB_ATTR_INTERRUPT) &&           (endpointNo == D12_ENDPOINT_NO_1) &&         (maxPacketSize > D12_MAX_PKT_ENDPOINT_1))||        ((transferType == USB_ATTR_INTERRUPT) &&          (endpointNo == D12_ENDPOINT_NO_2) &&         (maxPacketSize > D12_MAX_PKT_ENDPOINT_2_NON_ISO))||        ((transferType == USB_ATTR_ISOCH) &&                          (maxPacketSize > D12_MAX_PKT_ENDPOINT_2_ISO_IO)))        {        USBPDIUSBD12_ERROR ( "usbTcdPdiusbd12FncEndpointAssign : Max Packet \        Size not supported...\n",0,0,0,0,0,0);        /* WindView Instrumentation */        USB_TCD_LOG_EVENT(USB_TCD_PDIUSBD12_ENDPOINT,        "usbTcdPdiusbd12FncEndpointAssign exiting: Max Packet Size not supported...",        USB_TCD_PDIUSBD12_WV_FILTER);           return ERROR;        }    /* determine a valid endpoint number and index*/    USBPDIUSBD12_DEBUG ( "usbTcdPdiusbd12FncEndpointAssign : Determining \    Valid endpoint number and Index...\n",0,0,0,0,0,0);    if(transferType == USB_ATTR_CONTROL && direction == USB_ENDPOINT_OUT)        {        USBPDIUSBD12_DEBUG ( "usbTcdPdiusbd12FncEndpointAssign : Transfer \        Type is Control and Direction is Out...",0,0,0,0,0,0);        /* detemine if endpoint index 0 is free */        if((pTarget->endpointIndexInUse & (0x1<<D12_ENDPOINT_CONTROL_OUT))==0)            {            USBPDIUSBD12_DEBUG ( "usbTcdPdiusbd12FncEndpointAssign : \            Endpoint Index  0 alloted...\n",0,0,0,0,0,0);            endpointIndex = D12_ENDPOINT_CONTROL_OUT;            indexFound = TRUE;            }        }    else if(transferType == USB_ATTR_CONTROL && direction == USB_ENDPOINT_IN)        {        USBPDIUSBD12_DEBUG ( "usbTcdPdiusbd12FncEndpointAssign : Transfer \        Type is Control and Direction is In...",0,0,0,0,0,0);        /* determine if endpoint index 1 is free */        if((pTarget->endpointIndexInUse & ( 0x1<<D12_ENDPOINT_CONTROL_IN))==0)            {            USBPDIUSBD12_DEBUG ( "usbTcdPdiusbd12FncEndpointAssign : \            Endpoint Index 1 alloted...\n",0,0,0,0,0,0);            endpointIndex = D12_ENDPOINT_CONTROL_IN;            indexFound = TRUE;            }        }    else if((transferType == USB_ATTR_BULK ||            (transferType ==USB_ATTR_INTERRUPT)) &&             (direction == USB_ENDPOINT_OUT))        {        USBPDIUSBD12_DEBUG ( "usbTcdPdiusbd12FncEndpointAssign : Transfer \        Type is Bulk / Interrupt and Direction is Out...",0,0,0,0,0,0);        /* If the endpoint number is 1, check if endpoint 1 is free */        if ((endpointNo == D12_ENDPOINT_NO_1) &&             ((pTarget->endpointIndexInUse & ( 0x1<<D12_ENDPOINT_1_OUT))==0))            {            endpointIndex = D12_ENDPOINT_1_OUT;            indexFound = TRUE;            }                /* If the endpoint number is 2, check if endpoint 2 is free */        else if ((endpointNo == D12_ENDPOINT_NO_2) &&             ((pTarget->endpointIndexInUse & ( 0x1<<D12_ENDPOINT_2_OUT))==0))              {            endpointIndex = D12_ENDPOINT_2_OUT;            indexFound = TRUE;            }        }        else if((transferType == USB_ATTR_BULK ||           (transferType ==USB_ATTR_INTERRUPT)) && direction == USB_ENDPOINT_IN)        {        USBPDIUSBD12_DEBUG ( "usbTcdPdiusbd12FncEndpointAssign : Transfer \        Type is Bulk / Interrupt and Direction is In...",0,0,0,0,0,0);        /* If the endpoint number is 1, check if endpoint 1 is free */        if ((endpointNo == D12_ENDPOINT_NO_1) &&             ((pTarget->endpointIndexInUse & ( 0x1<<D12_ENDPOINT_1_IN))==0))            {            endpointIndex = D12_ENDPOINT_1_IN;            indexFound = TRUE;            }        /* If the endpoint number is 2, check if endpoint 2 is free */        else if ((endpointNo == D12_ENDPOINT_NO_2) &&             ((pTarget->endpointIndexInUse & ( 0x1<<D12_ENDPOINT_2_IN))==0))              {            endpointIndex = D12_ENDPOINT_2_IN;            indexFound = TRUE;            }        }    else if(transferType == USB_ATTR_ISOCH && direction == USB_ENDPOINT_OUT)        {        USBPDIUSBD12_DEBUG ( "usbTcdPdiusbd12FncEndpointAssign : Transfer \        Type is Isochronous and Direction is Out...",0,0,0,0,0,0);        /* determine if endpoint index 4 is free */        if(((pTarget->endpointIndexInUse & ( 0x1 << D12_ENDPOINT_2_OUT)) == 0) &&           (endpointNo == D12_ENDPOINT_NO_2))            {            USBPDIUSBD12_DEBUG ( "usbTcdPdiusbd12FncEndpointAssign : \            Endpoint 4 is free ...\n",0,0,0,0,0,0);            endpointIndex = D12_ENDPOINT_2_OUT;            indexFound = TRUE;            }        }    else if(transferType == USB_ATTR_ISOCH && direction == USB_ENDPOINT_IN)        {        USBPDIUSBD12_DEBUG ( "usbTcdPdiusbd12FncEndpointAssign : Transfer \        Type is Isochronous and Direction is In...",0,0,0,0,0,0);        /* determine if endpoint index 5 is free */        if(((pTarget->endpointIndexInUse & ( 0x1 << D12_ENDPOINT_2_IN) )== 0) &&           (endpointNo == D12_ENDPOINT_NO_2))            {            USBPDIUSBD12_DEBUG ( "usbTcdPdiusbd12FncEndpointAssign : \            Endpoint 5 is free ...\n",0,0,0,0,0,0);            endpointIndex = D12_ENDPOINT_2_IN;            indexFound = TRUE;            }        }    else        return ERROR;    /* If index is not found, return ERROR */    if ( indexFound == FALSE)        {        /* WindView Instrumentation */        USB_TCD_LOG_EVENT(USB_TCD_PDIUSBD12_ENDPOINT,        "usbTcdPdiusbd12FncEndpointAssign exiting: Invalid endpoint index obtained...",        USB_TCD_PDIUSBD12_WV_FILTER);           /* No valid endpoint index determined */        USBPDIUSBD12_ERROR ( "usbTcdPdiusbd12FncEndpointAssign : No valid \        endpoint index determined...\n ",0,0,0,0,0,0);        return ERROR;        }    /* Validate the endpoint number */    if (endpointNo != (pEndptDescr->endpointAddress & USB_ENDPOINT_MASK))        {        /* WindView Instrumentation */        USB_TCD_LOG_EVENT(USB_TCD_PDIUSBD12_ENDPOINT,        "usbTcdPdiusbd12FncEndpointAssign exiting: Endpoint number is Invalid...",        USB_TCD_PDIUSBD12_WV_FILTER);           USBPDIUSBD12_ERROR ( "usbTcdPdiusbd12FncEndpointAssign : Endpoint \        number is invalid...\n",0,0,0,0,0,0);        return ERROR;        }    /* Create a USB_TCD_PDIUSBD12_ENDPOINT structure to manage the endpoint */    if ((pEndpointInfo = OSS_CALLOC (sizeof (USB_TCD_PDIUSBD12_ENDPOINT))) == NULL )        {        /* WindView Instrumentation */        USB_TCD_LOG_EVENT(USB_TCD_PDIUSBD12_ENDPOINT,        "usbTcdPdiusbd12FncEndpointAssign exiting: Failed to allocate memory...",        USB_TCD_PDIUSBD12_WV_FILTER);           USBPDIUSBD12_ERROR ( "usbTcdPdiusbd12FncEndpointAssign : Could not \        allocate memory...\n",0,0,0,0,0,0);        return ERROR;        }    /*     * Store direction, transfer type, maxpacket size, endpoint number     * endpoint Index     */    pEndpointInfo->transferType = transferType;    pEndpointInfo->direction = direction;    pEndpointInfo->maxPacketSize = maxPacketSize;    pEndpointInfo->endpointNo = endpointNo;    pEndpointInfo->endpointIndex = endpointIndex;    /* if main endpoint*/    if (endpointNo == D12_ENDPOINT_NO_2)        {            /*     * Check whether its a non-isochronous transfer type across the main     * endpoint and increment epMainGenericCount     */            if ((transferType == USB_ATTR_BULK) ||        (transferType ==USB_ATTR_INTERRUPT))        pTarget->epMainGenericCount++;        USBPDIUSBD12_DEBUG ( "usbTcdPdiusbd12FncEndpointAssign : Main \        Endpoint in use...\n",0,0,0,0,0,0);        if (transferType == USB_ATTR_ISOCH )            {

⌨️ 快捷键说明

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