📄 usbtcdnet2280endpoint.c
字号:
/* WindView Instrumentation */ USB_TCD_LOG_EVENT (USB_TCD_NET2280_ENDPOINT, "usbTcdNET2280FncCopyDataToEpBuf: Intiating DMA \ Activity... ",USB_TCD_NET2280_WV_FILTER); /* Initiate DMA activity on that endpoint */ pTrb->uActLength = initializeDma (pTarget, pEndpointInfo); } else /* Disable the DMA */ disableDma (pTarget, pEndpointInfo); return OK; } else /* DMA is in USE */ return OK; } else { /* Find the length of dma transfer */ pEndpointInfo->dmaTransferLength = (pTrb->uActLength < NET2280_DMA_TRANS_SIZE) ? pTrb->uActLength : NET2280_DMA_TRANS_SIZE; /* Copy the buffer pointer */ pEndpointInfo->dmaBuffer = pTrb->pBuffer; /* Initiate DMA activity on that endpoint */ pTrb->uActLength = initializeDma (pTarget, pEndpointInfo); } } else {#endif if (transferType == USB_ATTR_CONTROL) { if (pTarget->statusINPending && (pTrb->uActLength == 0)) { /* * Status Stage. The zero length packet will be sent when * Control Transfer Handshake bit is cleared. Thisis handled * in the Interrupt routines */ UINT32 cntEnb = 0; /* Enable the Control Interrupt Status bit. This was disabled * whle handling DATA OUT interrupt in * usbTcdNET2280InterruptStatusGet */ cntEnb = NET2280_CFG_READ (pTarget, NET2280_PCIIRQENB1_REG); cntEnb |= NET2280_XIRQENB1_CS; NET2280_CFG_WRITE (pTarget, NET2280_PCIIRQENB1_REG, cntEnb); pTarget->statusINPending = FALSE; return OK; } } /* Update sizeToCopy */ sizeToCopy = (pTrb->uActLength < pEndpointInfo->maxPacketSize) ? pTrb->uActLength : pEndpointInfo->maxPacketSize; /* Update the statusOUT pending flag */ if ((transferType == USB_ATTR_CONTROL) && (pTrb->uActLength == sizeToCopy)) pTarget->statusOUTPending = FALSE; /* update size to copy */ pTrb->uActLength = sizeToCopy; /* * Initially the byte count feild of the endpoint configuration register * should be set to some value greater than 3, other wise it would be * treated as a short packet */ data32 = NET2280_CFG_READ (pTarget, NET2280_EP_CFG_OFFSET (endpointIndex)); data32 |= 4 << NET2280_EP_CFG_BYTE_CNT_SHIFT; /* Write the value in the EP_CFG register */ NET2280_CFG_WRITE (pTarget, NET2280_EP_CFG_OFFSET (endpointIndex), data32); while (sizeToCopy >= 4) { data32 = 0; /* Write 4 byte of data into the Endpoint FIFO */ for (i = 0; i < 4; i++) { data32 |= (*(pBuf + i) << (i * 8)); } /* Write the data in the Endpoint FIFO */ NET2280_CFG_WRITE (pTarget, NET2280_EP_DATA_OFFSET (endpointIndex), data32); /* update pBuf */ pBuf += 4; /* Decrement size to copy */ sizeToCopy -= 4; } if (transferType == USB_ATTR_CONTROL) maxPacket = 64; else maxPacket = pEndpointInfo->maxPacketSize; /* * If the data size is less than max packet size, write to the * EP_CFG register */ if (pTrb->uActLength < maxPacket) { /* * Update byte count feild of endpoint configuration register with * sizeToCopy */ data32 = NET2280_CFG_READ (pTarget, NET2280_EP_CFG_OFFSET (endpointIndex)); /* Mask off the bits for Byte Count */ data32 &= ~NET2280_EP_CFG_EBC; data32 &= NET2280_EP_CFG_REG_MASK; data32 |= sizeToCopy << NET2280_EP_CFG_BYTE_CNT_SHIFT; /* Write the value in the EP_CFG register */ NET2280_CFG_WRITE (pTarget, NET2280_EP_CFG_OFFSET (endpointIndex), data32); /* Write the data from TRB Buffer in the FIFO */ data32 = 0; for (i = 0 ; i < sizeToCopy; i++ ) data32 |= (*(pBuf + i) << (i * 8)); /* Write the data in the Endpoint FIFO */ NET2280_CFG_WRITE (pTarget, NET2280_EP_DATA_OFFSET (endpointIndex), data32); }#ifdef NET2280_DMA_SUPPORTED }#endif USB_NET2280_DEBUG ("usbTcdNET2280FncCopyDataToEpBuf: Exiting...\n", 0,0,0,0,0,0); return OK; } #ifdef NET2280_DMA_SUPPORTED/********************************************************************************* initializeDma - initializes the DMA** This is a utility function which is used to initilize the DMA for DMA* operations.** RETURNS: N/A** ERRNO:* none** \NOMANUAL*/LOCAL UINT32 initializeDma ( pUSB_TCD_NET2280_TARGET pTarget, /* USB_TCD_NET2280_TARGET */ pUSB_TCD_NET2280_ENDPOINT pEndpointInfo /* USB_TCD_NET2280_ENDPOINT */ ) { UINT8 endpointIndex = 0; UINT32 sizeCopied = 0; UINT32 data32 = 0; if ((pTarget == NULL) || (pEndpointInfo == NULL)) { USB_NET2280_ERROR ("initializeDma: Bad Parameters \ ...\n",0,0,0,0,0,0); return ossStatus(S_usbTcdLib_BAD_PARAM); } endpointIndex = pEndpointInfo->endpointIndex; /* Write the address to the DMA Address Regsiter */ NET2280_CFG_WRITE (pTarget, NET2280_DMAADDR_OFFSET (endpointIndex), (UINT32) USB_MEM_TO_PCI (pEndpointInfo->dmaBuffer)); if (pEndpointInfo->direction == USB_TCD_ENDPT_IN) { NET2280_CFG_WRITE (pTarget, NET2280_DMACOUNT_OFFSET(endpointIndex), NET2280_DMACOUNT_DIR); /* Flush the DMA Buffer */ USB_PCI_MEM_FLUSH ((pVOID)pEndpointInfo->dmaBuffer, pEndpointInfo->dmaTransferLength); } else { NET2280_CFG_WRITE (pTarget, NET2280_DMACOUNT_OFFSET(endpointIndex), pEndpointInfo->dmaTransferLength); } /* * Disable the endpoint interrupts for the corresponding endpoint. * Enable short packet OUT done interrupt. */ data32 = NET2280_EP_IRQENB_SPOD; NET2280_CFG_WRITE (pTarget, NET2280_EP_IRQENB_OFFSET(endpointIndex), data32); /* clear the endpoint interrupt */ pTarget->endptIntPending &= ~(1 << endpointIndex); /* Clear all the interrupts for this endpoint */ data32 = NET2280_CFG_READ (pTarget, NET2280_EP_STAT_OFFSET(endpointIndex)); data32 &= ~NET2280_EP_STAT_SPOD; NET2280_CFG_WRITE (pTarget, NET2280_EP_STAT_OFFSET(endpointIndex),data32); /* * Set the DMA Enable bit of DMA Control Register. * If it is an IN endpoint and the transfer length is not a * multiple of maxpacket size, then set * the bit which validates the FIFO after a dma transfer. */ data32 = NET2280_CFG_READ (pTarget, NET2280_DMACTL_OFFSET(endpointIndex)); if ((pEndpointInfo->direction == USB_TCD_ENDPT_IN) && ((pEndpointInfo->dmaTransferLength % pEndpointInfo->maxPacketSize) != 0)) data32 |= (NET2280_DMACTL_EN | NET2280_DMACTL_FIFOVAL); else { data32 &= ~NET2280_DMACTL_FIFOVAL; data32 |= NET2280_DMACTL_EN; } NET2280_CFG_WRITE (pTarget, NET2280_DMACTL_OFFSET (endpointIndex), data32); /* Set the DMA Done Interrupt Enable of DMA Count Regsiter */ data32 = NET2280_CFG_READ (pTarget, NET2280_DMACOUNT_OFFSET(endpointIndex)); NET2280_CFG_WRITE (pTarget, NET2280_DMACOUNT_OFFSET (endpointIndex), (data32 | NET2280_DMACOUNT_DIE)); /* Update DMA Transfer Length in DMA Count Register */ data32 = NET2280_CFG_READ (pTarget, NET2280_DMACOUNT_OFFSET(endpointIndex)); /* Clear the byte count fields */ data32 &= ~NET2280_DMACOUNT_BC; NET2280_CFG_WRITE (pTarget, NET2280_DMACOUNT_OFFSET (endpointIndex), (data32 | pEndpointInfo->dmaTransferLength)); /* Reset DMA EOT for the Endpoint */ pTarget->dmaEot &= ~(1 << endpointIndex); /* Set dmaInUse to TRUE */ pEndpointInfo->dmaInUse = TRUE; /* Update the size which has to be updated in the TRB */ if (pEndpointInfo->direction == USB_TCD_ENDPT_IN) sizeCopied = pEndpointInfo->dmaTransferLength; else sizeCopied = 0; /* Enable the dma interrupt for this endpoint */ data32 = NET2280_CFG_READ (pTarget, NET2280_PCIIRQENB1_REG); data32 |= NET2280_IRQENB1_DMA(endpointIndex); NET2280_CFG_WRITE (pTarget, NET2280_PCIIRQENB1_REG, data32); /* Start the DMA Transfer */ data32 = NET2280_CFG_READ (pTarget, NET2280_DMASTAT_OFFSET (endpointIndex)); NET2280_CFG_WRITE (pTarget, NET2280_DMASTAT_OFFSET (endpointIndex), (data32 | NET2280_DMASTAT_START)); /* Return the size of data which has to be copied */ return sizeCopied; } /********************************************************************************* disableDma - disableDma the DMA** This is a utility function which is used to disable the DMA* operations.** RETURNS: N/A** ERRNO:* none** \NOMANUAL*/LOCAL VOID disableDma ( pUSB_TCD_NET2280_TARGET pTarget, /* USB_TCD_NET2280_TARGET */ pUSB_TCD_NET2280_ENDPOINT pEndpointInfo /* USB_TCD_NET2280_ENDPOINT */ ) { UINT32 data32 = 0; /* temporary variable */ UINT8 endpointIndex = 0; if ((pTarget == NULL) || (pEndpointInfo == NULL)) { USB_NET2280_ERROR ("disableDma: Bad Parameters \ ...\n",0,0,0,0,0,0); return; } endpointIndex = pEndpointInfo->endpointIndex; /* reset the usbTcdNet2280Target :: dmaEot */ pTarget->dmaEot &= ~(1 << endpointIndex); /* clear the endpoint interrupt */ pTarget->endptIntPending &= ~(1 << endpointIndex); /* Set USB_TCD_NET2280_ENDPOINT :: dmaInUse to FALSE */ pEndpointInfo->dmaInUse = FALSE; /* Disable the DMA */ /* * disable the DMA INTERRUPT ENABLE for the endpoint from * PCIIRQENB1 */ data32 = NET2280_CFG_READ (pTarget, NET2280_PCIIRQENB1_REG); data32 &= ~NET2280_IRQENB1_DMA(endpointIndex); NET2280_CFG_WRITE (pTarget, NET2280_PCIIRQENB1_REG, data32); /* Reset the DMA Enable bit of DMACTL register */ data32 = NET2280_CFG_READ (pTarget, NET2280_DMACTL_OFFSET (endpointIndex)); data32 &= ~NET2280_DMACTL_EN; NET2280_CFG_WRITE (pTarget, NET2280_DMACTL_OFFSET (endpointIndex), data32); /* Reset the dma count field */ NET2280_CFG_WRITE (pTarget, NET2280_DMACOUNT_OFFSET (endpointIndex), 0); /* Reset the dma address field */ NET2280_CF
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -