次の方法で共有


UsbDbgPdd_RecvData (Compact 2013)

10/16/2014

Implement this function to start a receive transfer on a USB endpoint and to receive data from an endpoint after getting an endpoint receive interrupt from UsbDbgPdd_EventHandler.

Syntax

extern "C" DWORD UsbDbgPdd_RecvData(
    DWORD epNum,
    PBYTE pBuffer,
    DWORD cbBufLen,
    DWORD transferFlags,
    DWORD* pTransferStatus
)

Parameters

  • epNum
    [in] Endpoint on which to receive data.

    Endpoint

    RNDIS

    Serial

    0

    INT IN

    BULK OUT

    1

    INT IN

    BULK OUT

    2

    BULK IN

    BULK IN

    3

    BULK OUT

    Not used.

  • pBuffer
    [in] Buffer to receive data in.
  • cbBufLen
    [in] Size of pBuffer in bytes.
  • transferFlags
    [in] Flag indicating transfer status. Multiple flags may be ORed together.
  • pTransferStatus
    [out] Pointer to a flag indicating transfer status.

Return Value

Implement this function to return the number of bytes received if successful; otherwise, return -1 if not successful. The model device driver (MDD) cancels the transfer if -1 is returned.

Remarks

Endpoint 0 is also used for control transfers. Use control transfers for command and status operations.

When transferFlags is set to USBDBG_MDD_TRANSFER_START, start a receive transfer on the epNum, but do not read a value from the receive first in, first out (FIFO) buffer yet. When transferFlags is no longer set to USBDBG_MDD_TRANSFER_START, read data from the FIFO and write it to pBuffer. If the buffer is filled up completely or a short packet (less than the maximum packet size) is received, disable the receive FIFO and set pTransferStatus to USBDBG_PDD_TRANSFER_COMPLETE; otherwise, reenable the receive FIFO for the next packet.

Example

The following example shows a typical implementation of the UsbDbgPdd_RecvData function.

Important

For readability, the following code example does not contain security checking or error handling. Do not use the following code in a production environment.

extern "C" DWORD UsbDbgPdd_RecvData(
    DWORD epNum,
    PBYTE pBuffer,
    DWORD cbBufLen,
    DWORD transferFlags,
    DWORD* pTransferStatus
    )
{
   USBFN_PDD *pPddContext  = (USBFN_PDD *)&usbfn_pdd;
   DWORD dwBytesTransfered = 0;
   DWORD cbFullPkt = 0;

    USBDBGMSG(USBDBG_ZONE_FUNC, (L"usbdbgpdd: +UsbDbgPdd_RecvData\r\n"));

    USBDBGMSG(USBDBG_ZONE_VERBOSE, (L"+UsbDbgPdd_RecvData::  epNum --> 0x%x\r\n", epNum));
    USBDBGMSG(USBDBG_ZONE_VERBOSE, (L"+UsbDbgPdd_RecvData::  pBuffer --> 0x%x\r\n", pBuffer));
    USBDBGMSG(USBDBG_ZONE_VERBOSE, (L"+UsbDbgPdd_RecvData::  cbBufLen --> 0x%x\r\n", cbBufLen));
    USBDBGMSG(USBDBG_ZONE_VERBOSE, (L"+UsbDbgPdd_RecvData::  transferFlags --> 0x%x\r\n", transferFlags));

    // just prime the buffer and return
    // MDD is not expecting data at this time
    if (transferFlags & USBDBG_MDD_TRANSFER_START)
    {
         IssueTransfer( pPddContext, epNum, pBuffer,  cbBufLen,  OUT_TRANSFER, &dwBytesTransfered);
         dwBytesTransfered = 0;
    }
    else
    {
        if (pPddContext->ep[epNum]->bRecvBufferInUse)
        {
            if (pPddContext->qhbuffer->qh[epNum*2].dtd.tb > pPddContext->ep[epNum]->cbBuffer)
            {
                USBDBGMSG(USBDBG_ZONE_ERROR, (L"UsbDbgPdd_RecvData:: Fatal Error! Buffer Overflow\r\n"));
                return dwBytesTransfered;
            }
            dwBytesTransfered= pPddContext->ep[epNum]->cbBuffer  - pPddContext->qhbuffer->qh[epNum*2].dtd.tb;
            //Copy the received data from the Uncached buffer to the MDD passed buffer.
            memcpy(pBuffer, pPddContext->ep[epNum]->RecvBuffer, dwBytesTransfered);
            pPddContext->ep[epNum]->bRecvBufferInUse = FALSE;

            *pTransferStatus = USBDBG_PDD_TRANSFER_COMPLETE;
         }

        USBDBGMSG(USBDBG_ZONE_VERBOSE, (L"UsbDbgPdd_RecvData:: Data received 0x%x\r\n", dwBytesTransfered));
        USBDBGMSG(USBDBG_ZONE_VERBOSE, (L"UsbDbgPdd_RecvData::  pPddContext->ep[epNum]->RecvBufferPhysical  0x%x\r\n",  \
                                                pPddContext->ep[epNum]->RecvBufferPhysical));
        USBDBGMSG(USBDBG_ZONE_VERBOSE, (L"UsbDbgPdd_RecvData:: bp0  0x%x\r\n", pPddContext->qhbuffer->td[epNum*2].bp0));
        USBDBGMSG(USBDBG_ZONE_VERBOSE, (L"UsbDbgPdd_RecvData:: current offset of td  0x%x\r\n", pPddContext->qhbuffer->td[epNum*2].curr_off));
    }


    USBDBGMSG(USBDBG_ZONE_VERBOSE, (L"UsbDbgPdd_RecvData::  pTransferStatus --> 0x%x\r\n", *pTransferStatus));
    USBDBGMSG(USBDBG_ZONE_VERBOSE, (L"UsbDbgPdd_RecvData:: Received 0x%x bytes\r\n", dwBytesTransfered));

    USBDBGMSG(USBDBG_ZONE_FUNC, (L"usbdbgpdd: -UsbDbgPdd_RecvData\r\n"));
    return dwBytesTransfered;
}

Requirements

Header

UsbDbgDdsi.h

See Also

Reference

USBDBG PDD Functions