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

📄 usbtcdnet2280endpoint.c

📁 This the compressed USB driver source code for vxworks5.6. It has device controller driver and other
💻 C
📖 第 1 页 / 共 5 页
字号:
/* usbTcdNET2280Endpoint.c - Endpoint Related Routines *//* Copyright 2004 Wind River Systems, Inc. *//*Modification history--------------------01j,19oct04,ami  Fixes in usbTcdNET2280EndpointRelease() identified during SH                 testing01i,30sep04,pdg  DMA testing fixes01h,29sep04,ami  Cleared merge error01g,29sep04,ami  Mips Related Changes01f,23sep04,pdg  Fix for short packet handling01e,21sep04,pdg  Full speed testing fixes01d,20sep04,ami  NET2280 tested for High Speed01c,17sep04,ami  After Control, Interrupt IN and Bulk OUT Testing01b,08sep04,ami  Code Review Comments Incorporated01a,10sep04,ami  First*//*DESCRIPTIONThis file implements the endpoint related functionalities of TCD(Target Controller Driver) for the Netchip NET2280INCLUDE FILES: usb/usbPlatform.h, usb/ossLib.h, usb/usb.h,               string.h, usb/target/usbHalCommon.h, usb/target/usbTcd.h               drv/usb/target/usbNET2280.h,               drv/usb/target/usbTcdNET2280Debug.h,               drv/usb/target/usbNET2280Tcd.h, usb/target/usbPeriphInstr.h               *//* includes */#include "usb/usbPlatform.h"#include "usb/ossLib.h"#include "usb/usb.h"#include "string.h"#include "usb/target/usbHalCommon.h"#include "usb/target/usbTcd.h"               #include "drv/usb/target/usbNET2280.h"       #include "drv/usb/target/usbNET2280Tcd.h"   #include "drv/usb/target/usbTcdNET2280Debug.h" #include "usb/target/usbPeriphInstr.h"/* defines */#define NET2280_E_F_MAXPACKET		0x40#ifdef NET2280_DMA_SUPPORTED#define NET2280_DMA_TRANS_SIZE		16000000 /* forward declaration */LOCAL UINT32 initializeDma    (pUSB_TCD_NET2280_TARGET  pTarget,pUSB_TCD_NET2280_ENDPOINT pEndpointInfo);LOCAL VOID disableDma    (    pUSB_TCD_NET2280_TARGET  pTarget,pUSB_TCD_NET2280_ENDPOINT pEndpointInfo    );#endif/********************************************************************************* usbTcdNET2280FncEndpointAssign - implements TCD_FNC_ENDPOINT_ASSIGN** This utility function is called to assign an endpoint depending on the* endpoint descriptor value.** RETURNS: OK or ERROR, if not able to assign the endpoint.** ERRNO:* \is* \i S_usbTcdLib_BAD_PARAM* Bad Parameter is passed.** \i S_usbTcdLib_HW_NOT_READY* Hardware is not ready.** \i S_usbTcdLib_GENERAL_FAULT* Fault in the upper software layer.** \i S_usbTcdLib_OUT_OF_MEMORY* Heap is out of memory.* \ie** \NOMANUAL*/    LOCAL STATUS usbTcdNET2280FncEndpointAssign    (    pTRB_ENDPOINT_ASSIGN pTrb			/* TRB to be executed */    )      {    pTRB_HEADER	pHeader = (pTRB_HEADER) pTrb;	/* TRB_HEADER */    pUSB_TCD_NET2280_TARGET	pTarget = NULL;	/* USB_TCD_NET2280_TARGET */    pUSB_TCD_NET2280_ENDPOINT	pEndpointInfo = NULL;						/* USB_TCD_NET2280_ENDPOINT */    pUSB_ENDPOINT_DESCR		pEndptDescr = NULL;  /* USB_ENDPOINT_DESCR */    UINT8	transferType = 0;		/* trasfer type of endpoint */    UINT8	direction = 0;			/* direction 1-IN, 0-OUT */    UINT16	maxPacketSize = 0;		/* max packet size */    UINT8	endpointIndex = 0;		/* endpoint index */    UINT8	i = 0;    UINT8	nTrans = 0;    UINT32	data32 = 0;			    UINT8	endpointNum = 0;		/* endpoint number */    UINT32	fifoConfMode = 0;		/* fifo config value */    /* WindView Instrumentation */    USB_TCD_LOG_EVENT(USB_TCD_NET2280_ENDPOINT,    "usbTcdNET2280FncEndpointAssign entered...", USB_TCD_NET2280_WV_FILTER);    USB_NET2280_DEBUG ("usbTcdNET2280FncEndpointAssign : Entered...\n",    0,0,0,0,0,0);    /* Validate parameters */    if ((pHeader == NULL) || (pHeader->trbLength < sizeof (TRB_HEADER)) ||        (pHeader->handle == NULL) || (pTrb->pEndpointDesc == NULL))    	{        /* WindView Instrumentation */        USB_TCD_LOG_EVENT (USB_TCD_NET2280_ENDPOINT,        "usbTcdNET2280FncEndpointAssign exiting...Bad Parameters received",        USB_TCD_NET2280_WV_FILTER);    	USB_NET2280_ERROR ("usbTcdNET2280FncEndpointAssign : Bad Parameters \        ...\n",0,0,0,0,0,0);        return ossStatus (S_usbTcdLib_BAD_PARAM);        }        /* Get the endpoint descriptor */    pEndptDescr = pTrb->pEndpointDesc;    pTarget = (pUSB_TCD_NET2280_TARGET)pHeader->handle;    /* Determine direction */    if ((pEndptDescr->endpointAddress & USB_ENDPOINT_DIR_MASK) != 0)        direction = USB_TCD_ENDPT_IN;    else        direction = USB_TCD_ENDPT_OUT;    /* Determine the endpoint number */    endpointNum = (pEndptDescr->endpointAddress & USB_ENDPOINT_MASK);    /* Determine the transfer type */    transferType = pEndptDescr->attributes & USB_ATTR_EPTYPE_MASK;    /*     * Determine the Max Packet Size. According to USB Specification only     * first 10 bits signifies max packet size and bits 11 & 12 states     * number of transaction per frame.     */    maxPacketSize = FROM_LITTLEW (pEndptDescr->maxPacketSize) &                     USB_MAX_PACKET_SIZE_MASK;    /* Determine the number of transaction per frame and validate it. */    nTrans =  (FROM_LITTLEW(pEndptDescr->maxPacketSize) &                 USB_NUMBER_OF_TRANSACTIONS_MASK)                 >> USB_NUMBER_OF_TRANSACTIONS_BITPOSITION;    if (transferType == USB_ATTR_CONTROL)        {        /* Transfer Type is Control. Verify endpoint number and maxpacket size */        if (endpointNum != USB_ENDPOINT_CONTROL)             {            /* WindView Instrumentation */            USB_TCD_LOG_EVENT (USB_TCD_NET2280_ENDPOINT,            "usbTcdNET2280FncEndpointAssign exiting...Bad Parameters received",            USB_TCD_NET2280_WV_FILTER);            USB_NET2280_ERROR ("usbTcdNET2280FncEndpointAssign : Bad Parameters\            ...\n",0,0,0,0,0,0);            return ossStatus (S_usbTcdLib_BAD_PARAM);            }        if (maxPacketSize > USB_MAX_CTRL_PACKET_SIZE)            {            /* WindView Instrumentation */            USB_TCD_LOG_EVENT (USB_TCD_NET2280_ENDPOINT,            "usbTcdNET2280FncEndpointAssign exiting...Bad Parameters received",            USB_TCD_NET2280_WV_FILTER);            USB_NET2280_ERROR ("usbTcdNET2280FncEndpointAssign : Bad Parameters\            ...\n",0,0,0,0,0,0);            return ossStatus (S_usbTcdLib_BAD_PARAM);            }         /*          * If request comes form upper layer to allocate more than one control          * OUT or control IN, return ERROR          */        if (((direction == USB_TCD_ENDPT_OUT) &&             ((pTarget->endpointIndexInUse & (1 << NET2280_ENDPT_0_OUT)) != 0))             ||             ((direction == USB_TCD_ENDPT_IN) && ((pTarget->endpointIndexInUse             & (1 << NET2280_ENDPT_0_IN)) != 0)))            {            /* WindView Instrumentation */            USB_TCD_LOG_EVENT (USB_TCD_NET2280_ENDPOINT,            "usbTcdNET2280FncEndpointAssign exiting...Bad Parameters received",            USB_TCD_NET2280_WV_FILTER);            USB_NET2280_ERROR ("usbTcdNET2280FncEndpointAssign : Bad Parameters\            ...\n",0,0,0,0,0,0);            return ossStatus (S_usbTcdLib_BAD_PARAM);            }         /* Check if endpoint 0 OUT is not alloted */                 if (direction == USB_TCD_ENDPT_OUT)            {            /* Endpoint 0 OUT is not assigned */           	    /* allot endpoint Index */     	            endpointIndex = NET2280_ENDPT_0_OUT;              /*             * Set Setup Packet Interrupt Enable & Endpoint 0 Interrupt Enable              * bits of PCIIRQENB0 register             */             data32 = NET2280_CFG_READ (pTarget, NET2280_PCIIRQENB0_REG);             data32 |= NET2280_XIRQENB0_SETUP | (1 << NET2280_ENDPT_0_OUT);            /* Write into PCIIRQENB0 regsiter */            NET2280_CFG_WRITE (pTarget, NET2280_PCIIRQENB0_REG, data32);            /* Set Control Status Interrupt bit of PCIIRQENB1 register */            data32 = NET2280_CFG_READ (pTarget, NET2280_PCIIRQENB1_REG);            data32 |= NET2280_XIRQENB1_CS;            NET2280_CFG_WRITE (pTarget, NET2280_PCIIRQENB1_REG, data32);            }        else	    /* allot endpoint Index */     	            endpointIndex = NET2280_ENDPT_0_IN;                 }        else        /* Any Generic Transfer type. Determine a valid endpoint Index */        {        /*          * If the maximum packet size is less than or equal to 64,         * check if endpoint E or F is available         */        if (maxPacketSize <= NET2280_E_F_MAXPACKET)            {            if ((pTarget->endpointIndexInUse & (0x01 << NET2280_ENDPT_E)) == 0)                endpointIndex = NET2280_ENDPT_E;            else if ((pTarget->endpointIndexInUse & (0x01 << NET2280_ENDPT_F)) == 0)                endpointIndex = NET2280_ENDPT_F;            else                endpointIndex = 0;            }        /*          * endpointIndex is 0 due to one of these reasons         * 1. max packet size is <= 64 and the endpoint indices E and F are         *    already occupied.         * 2. max packet size is > 64.         */        if (endpointIndex == 0)            {            /*             * If the maximum packet size is greater than              * USB_MAX_HIGH_SPEED_BULK_SIZE, then this is an isochronous             * endpoint. Double buffering can be used in this case. A and B             * support double buffering.             * Based on the endpoints which are configured earlier, decide             * on the FIFO configuration.             */            if (maxPacketSize > USB_MAX_HIGH_SPEED_BULK_SIZE)                {                for (i = NET2280_ENDPT_A; i <= NET2280_ENDPT_D; i++)                    {                    if ((pTarget->endpointIndexInUse & (1 << i)) == 0)                        {		        /* 		         * The particular endpoint index is free.                          * Valid endpoint found                         */		        endpointIndex = i;                              break;                        }                    }                      /* If the endpoint index cannot be allotted, return an error */                 if ( endpointIndex == 0 )                    /* Valid Index not found */                    return ossStatus (S_usbTcdLib_GENERAL_FAULT);                /* Set the default configuration to 0 */                fifoConfMode = NET2280_FIFOCTL_CFG0;                /*                  * Decide the FIFO configuration based on the current                 * index and the earlier endpoints occupied                 */                switch(endpointIndex)                    {                    case NET2280_ENDPT_A:                    case NET2280_ENDPT_B:                         /*                          * If C and D are not configured, Configuration 2                          * can be set                         */                        if ((pTarget->endpointIndexInUse &                             (0x3 << NET2280_ENDPT_C)) == 0)                            fifoConfMode = NET2280_FIFOCTL_CFG2;                        /*                          * If D is already configured, only Configuration 0                          * can be set                         */                        else if ((pTarget->endpointIndexInUse &                             (0x1 << NET2280_ENDPT_D)) != 0)                            fifoConfMode = NET2280_FIFOCTL_CFG0;                        /*                          * If only C is configured, Configuration 1                          * can be set                         */                        else                            fifoConfMode = NET2280_FIFOCTL_CFG1;                        break;                    case NET2280_ENDPT_C:                         /*                          * If D is not already configured, Configuration 1                          * can be set                         */                        if ((pTarget->endpointIndexInUse &                             (0x1 << NET2280_ENDPT_D)) == 0)                            fifoConfMode = NET2280_FIFOCTL_CFG1;                        break;                    default:                        fifoConfMode = NET2280_FIFOCTL_CFG0;                        break;                    }                }             else                {                /* Set the default configuration mode */                fifoConfMode = NET2280_FIFOCTL_CFG0;                /*                  * Fill up the elements in this order ie C, B, A and finally D.                 * This will help in using configuration 1 also.                  */                /* Check if endpoint C is available */                if ((pTarget->endpointIndexInUse & (1 << NET2280_ENDPT_C)) == 0)                    endpointIndex = NET2280_ENDPT_C;                /* Check if endpoint B is available */                else if ((pTarget->endpointIndexInUse & (1 << NET2280_ENDPT_B)) == 0)                    endpointIndex = NET2280_ENDPT_B;                /* Check if endpoint A is available */                else if ((pTarget->endpointIndexInUse & (1 << NET2280_ENDPT_A)) == 0)                    endpointIndex = NET2280_ENDPT_A;                /* Check if endpoint D is available */                else if ((pTarget->endpointIndexInUse & (1 << NET2280_ENDPT_D)) == 0)                    endpointIndex = NET2280_ENDPT_D;                else                    endpointIndex = 0;	                /* If the endpoint index cannot be allotted, return an error */                if ( endpointIndex == 0 )                    /* Valid Index not found */                    return ossStatus (S_usbTcdLib_GENERAL_FAULT);                /*                  * Check if D is not configured. If it is not configured,                 * then configuration 1 or 2 can be used.                 */                if (((pTarget->endpointIndexInUse & (1 << NET2280_ENDPT_D))                      == 0) && (endpointIndex != NET2280_ENDPT_D))                     fifoConfMode = NET2280_FIFOCTL_CFG2;                    }              }        }          /* Allocate USB_TCD_ISP1582_ENDPOINT structure */    if ((pEndpointInfo = OSS_CALLOC (sizeof (USB_TCD_ISP1582_ENDPOINT)))== NULL)        {        /* WindView Instrumentation */        USB_TCD_LOG_EVENT (USB_TCD_NET2280_ENDPOINT,        "usbTcdNET2280FncEndpointAssign exiting...Memory Allocation Error",        USB_TCD_NET2280_WV_FILTER);        USB_NET2280_ERROR ("usbTcdNET2280FncEndpointAssign: Bad Parameters \        ...\n",0,0,0,0,0,0);        return ossStatus (S_usbTcdLib_OUT_OF_MEMORY);        }

⌨️ 快捷键说明

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