📄 pipe.h
字号:
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
#ifndef _PIPE_H_
#define _PIPE_H_
#include "xferqueue.h"
#include "xferlist.h"
#include "transfer.h"
// Forward declaration
typedef struct UFN_MDD_CONTEXT *PUFN_MDD_CONTEXT;
#define UFN_PIPE_SIG 'PnfU' // "UfnP" signature
typedef class CPipe {
public:
CPipe(DWORD dwPhysicalEndpoint, PUFN_PDD_INTERFACE_INFO pPddInfo,
CFreeTransferList *pFreeTransferList);
~CPipe();
DWORD Open(UFN_BUS_SPEED Speed, PUSB_ENDPOINT_DESCRIPTOR pEndpointDesc);
DWORD Close();
BOOL IsOpen() const { return m_fOpen; }
DWORD GetPhysicalEndpoint() const { return m_dwPhysicalEndpoint; }
DWORD GetEndpointAddress() const {
DWORD dwEndpointAddress;
if (m_pFullSpeedEndpointDesc) {
dwEndpointAddress = m_pFullSpeedEndpointDesc->bEndpointAddress;
}
else if (m_pHighSpeedEndpointDesc) {
dwEndpointAddress = m_pHighSpeedEndpointDesc->bEndpointAddress;
}
else if (GetPhysicalEndpoint() == 0) {
dwEndpointAddress = 0;
}
else {
// This endpoint has not been reserved.
dwEndpointAddress = -1;
}
return dwEndpointAddress;
}
VOID Reserve(UFN_BUS_SPEED Speed, BOOL fReserve, DWORD dwInterfaceNumber,
DWORD dwEndpointIndex, PUSB_ENDPOINT_DESCRIPTOR pEndpointDesc);
BOOL IsReserved(UFN_BUS_SPEED speed) { return (m_dwReservedSpeedMask & speed) != 0; }
DWORD IssueTransfer(
LPTRANSFER_NOTIFY_ROUTINE lpNotifyRoutine,
PVOID pvNotifyContext,
DWORD dwFlags,
DWORD cbBuffer,
PVOID pvBuffer,
DWORD dwBufferPhysicalAddress,
PCUfnMddTransfer *ppTransfer,
PVOID pDMATransferInfo);
DWORD AbortTransfer(
PCUfnMddTransfer pTransfer
);
VOID AbortAllTransfers();
static DWORD GetTransferStatus(
const CUfnMddTransfer *pTransfer,
PDWORD pcbTransferred,
PDWORD pdwUsbError
);
DWORD CloseTransfer(
PCUfnMddTransfer pTransfer
);
DWORD TransferComplete(
PCUfnMddTransfer pTransfer,
BOOL fTransferWasInPdd
);
DWORD Stall();
DWORD ClearStall();
DWORD SendControlStatusHandshake();
VOID Reset() {
Lock();
DEBUGCHK(m_dwSig == UFN_PIPE_SIG);
DEBUGCHK(IsOpen() == FALSE);
DEBUGCHK(m_TransferQueue.IsEmpty());
m_dwEndpointIndex = -1;
m_dwInterfaceNumber = -1;
m_dwReservedSpeedMask = 0;
m_pFullSpeedEndpointDesc = NULL;
m_pHighSpeedEndpointDesc = NULL;
Unlock();
}
VOID FreeTransfer(
PCUfnMddTransfer pTransfer
);
static DWORD ValidatePipeHandle(const CPipe *pPipe);
#ifdef DEBUG
VOID Validate();
#else
VOID Validate() {}
#endif
private:
VOID Lock() {
EnterCriticalSection(&m_cs);
#ifdef DEBUG
if (m_dwLockCount++ == 0) {
m_dwThreadId = GetCurrentThreadId();
}
#endif
}
VOID Unlock() {
#ifdef DEBUG
if (--m_dwLockCount == 0) {
m_dwThreadId = 0;
}
#endif
LeaveCriticalSection(&m_cs);
}
DWORD m_dwSig;
CRITICAL_SECTION m_cs;
BOOL m_fOpen;
PUFN_PDD_INTERFACE_INFO m_pPddInfo;
CTransferQueue<CUfnMddTransfer> m_TransferQueue;
CFreeTransferList *m_pFreeTransferList;
DWORD m_dwPhysicalEndpoint; // PDD endpoint index (0 based)
DWORD m_dwEndpointIndex; // Index into the UFN_CONFIGURATION tree
DWORD m_dwInterfaceNumber; // Number of the interface in descriptor
DWORD m_dwReservedSpeedMask;
CTransferQueue<CUfnMddTransfer> m_DoneTransferQueue;
DWORD m_dwCompletionCount;
PUSB_ENDPOINT_DESCRIPTOR m_pFullSpeedEndpointDesc;
PUSB_ENDPOINT_DESCRIPTOR m_pHighSpeedEndpointDesc;
#ifdef DEBUG
DWORD m_dwThreadId;
DWORD m_dwLockCount;
#endif
} *PCPipe;
#endif // _PIPE_H_
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -