?? usbtcdisp1582endpoint.c
字號:
/* usbTcdIsp1582Endpoint.c - Endpoint Related Routines *//* Copyright 2004 Wind River Systems, Inc. *//*Modification history--------------------01g,17sep04,ami WindView Instrumentation Changes01f,02aug04,mta Modification History Changes01e,19jul04,ami Coding Convention Changes01d,14jul04,mta ISP1582 and Mass Storage Functionality Changes01c,08jul04,mta ISP1582 with mass storage on SH changes01b,30jun04,pdg Bug fixes - isp1582 full speed testing01a,21apr04,ami First*//*DESCRIPTIONThis file implements the endpoint related functionalities of TCD(Target Controller Driver) for the Philips ISP 1582.INCLUDE FILES: usb/usbPlatform.h, usb/ossLib.h, usb/usbPciLib.h, usb/usb.h, string.h, usb/target/usbHalCommon.h, usb/target/usbTcd.h drv/usb/target/usbisp1582.h, drv/usb/target/usbIsp1582Eval.h, drv/usb/target/usbIsp1582Tcd.h*//* includes */#include "usb/usbPlatform.h" #include "usb/ossLib.h" #include "usb/usbPciLib.h" #include "usb/usb.h" #include "string.h" #include "usb/target/usbHalCommon.h" #include "usb/target/usbTcd.h" #include "drv/usb/target/usbIsp1582.h" #include "drv/usb/target/usbIsp1582Eval.h" #include "drv/usb/target/usbIsp1582Tcd.h" #include "usb/target/usbPeriphInstr.h"/* defines */#define MAX_PACK_SIZE_MASK 0x07FF /* max packet size mask */#define NTRANS_SIZE_MASK 0x1800 /* number of transaction per */ /* frame mask */#define NTRANS_SHIFT 0xB /* ntrans shift value */ #undef DMA_SUPPORTED/* globals */#ifdef DMA_SUPPORTED/* *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 *//* forward declaration */LOCAL VOID disableDma (pUSB_TCD_ISP1582_TARGET pTarget, UINT8 endpointIndex);LOCAL VOID initializeDma (pUSB_TCD_ISP1582_TARGET pTarget, UINT8 endpointIndex, UINT8 command);#endif/* functions *//********************************************************************************* usbTcdIsp1582FncEndpointAssign - 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 usbTcdIsp1582FncEndpointAssign ( pTRB_ENDPOINT_ASSIGN pTrb /* Trb to be executed */ ) { pTRB_HEADER pHeader = (pTRB_HEADER) pTrb; /* TRB_HEADER */ pUSB_TCD_ISP1582_TARGET pTarget = NULL; /* USB_TCD_ISP1582_TARGET */ pUSB_TCD_ISP1582_ENDPOINT pEndpointInfo = NULL;/*USB_TCD_ISP1582_ENDPOINT*/ pUSB_ENDPOINT_DESCR pEndptDescr = NULL; /* pUSB_ENDPOINT_DESCR */ UINT8 transferType = 0; /* trasfer type of endpoint */ UINT8 direction = 0; /* direction 1-IN, 0-OUT */ UINT16 maxPacketSize = 0; /* max packet size */ BOOL indexFound = FALSE; UINT8 endpointIndex = 0; /* endpoint index */ UINT8 i = 0; UINT8 nTrans = 0; UINT16 data16 = 0; UINT32 data32 = 0; UINT8 endpointNum = 0; /* endpoint number */ /* WindView Instrumentation */ USB_TCD_LOG_EVENT(USB_TCD_ISP1582_ENDPOINT, "usbTcdIsp1582FncEndpointAssign entered...", USB_TCD_ISP582_WV_FILTER); USBISP1582_DEBUG ("usbTcdIsp1582FncEndpointAssign : 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_ISP1582_ENDPOINT, "usbTcdIsp1582FncEndpointAssign exiting...Bad Parameters Received", USB_TCD_ISP582_WV_FILTER); USBISP1582_ERROR ("usbTcdIsp1582FncEndpointAssign : 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_ISP1582_TARGET)pHeader->handle; /* Determine direction */ if ((pEndptDescr->endpointAddress & USB_ENDPOINT_DIR_MASK) != 0) direction = USB_ENDPOINT_IN; else direction = USB_ENDPOINT_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) & MAX_PACK_SIZE_MASK; /* Determine the number of transaction per frame and validate it. */ nTrans = (FROM_LITTLEW(pEndptDescr->maxPacketSize) & NTRANS_SIZE_MASK) >> NTRANS_SHIFT; /* * Determine if Max Packet size is supported by the hardware (Total FIFO * Size should not exceed 8K). If not, return ERROR. */ if (pTarget->bufSize + maxPacketSize > ISP1582_FIFO_SIZE) { /* WindView Instrumentation */ USB_TCD_LOG_EVENT(USB_TCD_ISP1582_ENDPOINT, "usbTcdIsp1582FncEndpointAssign exiting...ISP1582 FIFO full", USB_TCD_ISP582_WV_FILTER); return ossStatus (S_usbTcdLib_HW_NOT_READY); } if (transferType == USB_ATTR_CONTROL) { if (maxPacketSize > ISP1582_MAXPSIZE_64) { /* WindView Instrumentation */ USB_TCD_LOG_EVENT(USB_TCD_ISP1582_ENDPOINT, "usbTcdIsp1582FncEndpointAssign exiting...wrong control max packet size", USB_TCD_ISP582_WV_FILTER); return ossStatus (S_usbTcdLib_HW_NOT_READY); } else maxPacketSize = ISP1582_MAXPSIZE_64; } if ((transferType == USB_ATTR_CONTROL) || (transferType == USB_ATTR_BULK)) { if (nTrans != ISP1582_NTRANS_1) return ossStatus (S_usbTcdLib_HW_NOT_READY); } /* Determine a valid endpoint index */ /* Control Transfer */ if (transferType == USB_ATTR_CONTROL) { if (direction == USB_ENDPOINT_OUT) { /* * Control Out Transfer. * If Bit 0 of endpointIndexInUse is 0, then the corresponding * endpoint is not in use, allocate it. */ if ((pTarget->endpointIndexInUse & ( 0x1 << ISP1582_ENDPT_0_RX))==0) { indexFound = TRUE; endpointIndex = ISP1582_ENDPT_0_RX; } } else if (direction == USB_ENDPOINT_IN) { /* Control In Transfer. */ if ((pTarget->endpointIndexInUse & ( 0x1 << ISP1582_ENDPT_0_TX))==0) { indexFound = TRUE; endpointIndex = ISP1582_ENDPT_0_TX; } } } else { /* * Generic Transfer type. Any endpoint other then control in and out * can be alloted. Hence we need to check only the direction and * allocated endpoints accordingly. */ if (direction == USB_ENDPOINT_OUT) { i = endpointNum * 2; if ((pTarget->endpointIndexInUse & ( 0x1 << i)) == 0) { indexFound = TRUE; endpointIndex = i; } } else if (direction == USB_ENDPOINT_IN) { i = endpointNum * 2 + 1; if ((pTarget->endpointIndexInUse & ( 0x1 << i)) == 0) { indexFound = TRUE; endpointIndex = i; } } } if ( indexFound == FALSE ) { /* WindView Instrumentation */ USB_TCD_LOG_EVENT(USB_TCD_ISP1582_ENDPOINT, "usbTcdIsp1582FncEndpointAssign exiting...endpoint index not found", USB_TCD_ISP582_WV_FILTER); /* Valid Index not found */ return ossStatus (S_usbTcdLib_GENERAL_FAULT); } /* Allocate USB_TCD_ISP1582_ENDPOINT structure */ if ((pEndpointInfo = OSS_CALLOC (sizeof (USB_TCD_ISP1582_ENDPOINT)))== NULL) { /* WindView Instrumentation */ USB_TCD_LOG_EVENT(USB_TCD_ISP1582_ENDPOINT, "usbTcdIsp1582FncEndpointAssign exiting...memory not free", USB_TCD_ISP582_WV_FILTER); USBISP1582_ERROR ("usbTcdIsp1582FncEndpointAssign : Bad Parameters \ ...\n",0,0,0,0,0,0); return ossStatus (S_usbTcdLib_OUT_OF_MEMORY); } /* * Store Direction, transfer type, max packet size and endpoint index in * the USB_TCD_ISP1582_ENDPOINT. */ pEndpointInfo->transferType = transferType; pEndpointInfo->direction = direction; pEndpointInfo->maxPacketSize = FROM_LITTLEW (pEndptDescr->maxPacketSize) & MAX_PACK_SIZE_MASK; pEndpointInfo->endpointIndex = endpointIndex; pEndpointInfo->isDoubleBufSup = FALSE; /* * If transfer type is bulk or isochronous, endpoint may support double * buffering. */#ifdef DOUBLEBUF_SUPPORT if (((transferType == USB_ATTR_BULK) || (transferType == USB_ATTR_ISOCH)) && (pTarget->bufSize + 2 * maxPacketSize <= ISP1582_FIFO_SIZE)) { pTarget->bufSize += (2 * maxPacketSize); pEndpointInfo->isDoubleBufSup = TRUE; } else pTarget->bufSize += maxPacketSize;#else pTarget->bufSize += maxPacketSize;#endif /* Update endpointIndexInUse */ pTarget->endpointIndexInUse |= (1 << endpointIndex); /* * If this endpoint is alloted to the DMA as an un-used endpoint, alot any * other un-used endpoint to the DMA and write into the DMA endpoint * register. */ if (endpointIndex == pTarget->dmaEndptNotInUse) { for (i = ISP1582_ENDPT_7_TX ; i >= ISP1582_ENDPT_1_RX ; i--) { if ((pTarget->endpointIndexInUse & (0x1 << i)) == 0) break; } if ( i < ISP1582_ENDPT_1_RX) { /* WindView Instrumentation */ USB_TCD_LOG_EVENT(USB_TCD_ISP1582_ENDPOINT, "usbTcdIsp1582FncEndpointAssign exiting...no unused endpoint", USB_TCD_ISP582_WV_FILTER); USBISP1582_ERROR ("usbTcdIsp1582FncEndpointAssign : No Unused \ endpoint...\n",0,0,0,0,0,0); return ossStatus (S_usbTcdLib_HW_NOT_READY); } /* Initialize the DMA Endpoint Register to endpoint not used. */ isp1582Write8 (pTarget , ISP1582_DMA_ENDPT_REG , i); pTarget->dmaEndptNotInUse = i; } /* Initialize the endpoint index register */ isp1582Write8 ( pTarget , ISP1582_ENDPT_INDEX_REG , endpointIndex); /* Initialize Max Packet Size Register */ isp1582Write16 (pTarget , ISP1582_ENDPT_MAXPSIZE_REG , ISP1582_ENDPT_MAXPSIZE_REG_SHIFT_NTRANS (nTrans) | maxPacketSize); /* Initialize Buffer Length Register */ isp1582Write16 (pTarget , ISP1582_BUF_LEN_REG ,maxPacketSize); /* Form the value to be written into endpoint type register */ /* Determine transfer type */ switch (transferType) { case USB_ATTR_ISOCH: data16 = ISP1582_ENDPT_TYPE_REG_EPTYPE_ISO | ISP1582_ENDPT_TYPE_REG_ENDPT_ENABLE; if (pEndpointInfo->isDoubleBufSup) data16 |= ISP1582_ENDPT_TYPE_REG_DOUBLE_BUF; break; case USB_ATTR_BULK : data16 = ISP1582_ENDPT_TYPE_REG_EPTYPE_BULK | ISP1582_ENDPT_TYPE_REG_ENDPT_ENABLE; if (pEndpointInfo->isDoubleBufSup) data16 |= ISP1582_ENDPT_TYPE_REG_DOUBLE_BUF; break; case USB_ATTR_INTERRUPT : data16 = ISP1582_ENDPT_TYPE_REG_EPTYPE_INTP | ISP1582_ENDPT_TYPE_REG_ENDPT_ENABLE; break; case USB_ATTR_CONTROL :
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -