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

📄 phcd.hpp

📁 ISP1161 USB Driver under WinCE for StrongARM processor implementation
💻 HPP
📖 第 1 页 / 共 3 页
字号:
/*++
THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
PARTICULAR PURPOSE.
Copyright (c) 1995, 1996, 1997, 1998  Microsoft Corporation

Module Name:  
    ohcd.hpp

Abstract:  
    
Notes: 
--*/
#ifndef _PHCD_HPP_
#define _PHCD_HPP_

#define PLAT_STRONGARM		

#define DEFAULT_PHCD_IST_PRIORITY 101 // UsbDriverThread
#define RELATIVE_PRIO_RESET     1     // ResetPort
#define RELATIVE_PRIO_STSCHG    1     // DeviceStatusChange
#define RELATIVE_PRIO_CRITICAL  1     // UsbDriverCriticalThread (really -5)

// Original design was to have a TIME_CRITICAL thread for processing large data
// transfers.  But, there are some tricky interactions between the normal IST and
// the TIME_CRITICAL one which haven't been fully tested, so leave this disabled
// for now.
#undef USE_CRITICAL_THREAD

// These structures MUST have exactly the same
// data types as the USB_* structues in usbtypes.h
typedef struct _PHCI_ENDPOINT {
    DWORD                                   dwCount;

    USB_ENDPOINT_DESCRIPTOR                 Descriptor;
    LPBYTE                                  lpbExtended;
} PHCI_ENDPOINT, * LPPHCI_ENDPOINT;

typedef struct _PHCI_INTERFACE {
    DWORD                                   dwCount;

    USB_INTERFACE_DESCRIPTOR                Descriptor;
    LPBYTE                                  lpbExtended;
    LPPHCI_ENDPOINT                         lpEndpoints;
} PHCI_INTERFACE, * LPPHCI_INTERFACE;

typedef struct _PHCI_CONFIGURATION {
    DWORD                                   dwCount;

    USB_CONFIGURATION_DESCRIPTOR            Descriptor;
    LPBYTE                                  lpbExtended;
    // Total number of interfaces (including alternates)
    DWORD                                   dwNumInterfaces;
    LPPHCI_INTERFACE                        lpInterfaces;
} PHCI_CONFIGURATION, * LPPHCI_CONFIGURATION;

typedef struct _PHCI_DEVICE {
    DWORD                                   dwCount;

    USB_DEVICE_DESCRIPTOR                   Descriptor;
    LPPHCI_CONFIGURATION                    lpConfigs;
    LPPHCI_CONFIGURATION                    lpActiveConfig;
} PHCI_DEVICE, * LPPHCI_DEVICE;


extern const WCHAR * gcPortNamesArray[2];
const UINT gcMaxNameSize = 32;

const UINT gcUsbEndptDescNumMask = 0x0F;
const UINT gcUsbEndptDescDirMask = 0x80;

const UINT gcAddr0MaxRetryValue = 10;

// This assumes at most a root hub with 3 ports (addr 0 used for attach)
// and no hubs.  Most devices will only have 2 endpoints.
const UINT gcInitialMaxNumDevices = 4;
const UINT gcInitialMaxNumEndpts = 2;
const UINT gcRootHubNum = 0;

const UINT gcMaxRootHubPorts = 15;

const UINT gcNumExtraGeneralTds = 32;

const UINT gcEndpoint0Addr = 0;
const UINT gcHubIntrEndptAddr = 1;

const UINT gcMaxClassesPerDevice = 25;

// When DMAing, you need to flush the cache first.  If the cache flush
// algorithm is sufficiently bad, it can become more expensive to flush
// the cache than to just copy all the data into/from a non-cached buffer.
// We've determined that copying is better for anything less than this
// number of bytes
const UINT gcMaxSizeCopyBetterThanFlush = 256;

// Delay to allow device power to stabilize (sec 11.6.3)
const UINT gcDevicePowerDelay = 100; // ms

const UINT gcMaxDevices = 127;  // maximum number of devices on USB bus
const UINT gcMaxHubChaining = 7; // maximum number of hubs than can be chained into one another

// Consts needed for bandwidth info.
const UINT gcControlOverheadBytes = 45;
const UINT gcInterruptOverheadBytes = 13;
const UINT gcIsochronousOverheadBytes = 9;
const UINT gcBulkOverheadBytes = 13;

const UINT gcLowSpeedBWMultiplier = 8;

const UINT gcFramesPerSecond = 1000;
const UINT gcTotalBWBytes = (12 * 1024 * 1024)/8;
const UINT gcTotalFrameBWBytes = gcTotalBWBytes / gcFramesPerSecond;

// control transfers reserve 10% of the bandwidth.
const UINT gcMaxUsableFrameBWBytes = 9 * gcTotalFrameBWBytes / 10;

inline UINT
AdjustForBitStuffing(UINT nData)
{
   // Calculate worst case bit stuffing overhead, as per USB spec
   return(nData*7/6);
}

// Consts for dealing with the interrupt structure
const UINT gcIntrNumStaticEds = 63;
const UINT gcIntrNumListHeads = 32;

const UINT gcIntrNumLevelsFor1ms = 5;
const UINT gcIntrNumLevelsFor2ms = 4;
const UINT gcIntrNumLevelsFor4ms = 3;
const UINT gcIntrNumLevelsFor8ms = 2;
const UINT gcIntrNumLevelsFor16ms = 1;
const UINT gcIntrNumLevelsFor32ms = 0;

const UINT gcIntrTotalNumLevels = gcIntrNumLevelsFor1ms + 1;

const DWORD gcStaticEdIdentifier = 0xFFFFFFF0;
const UINT gcInterval32ms = 32;

const UINT gcInitialConfigDescriptorSize = 4;
const UINT gcInitialDeviceDescriptorSize = 8;

const UCHAR gcEndptTypeControl      = 0x00;
const UCHAR gcEndptTypeIsochronous  = 0x01;
const UCHAR gcEndptTypeBulk         = 0x02;
const UCHAR gcEndptTypeInterrupt    = 0x03;


const UCHAR gcDevConfigStatusNone                           = 0x0;
const UCHAR gcDevConfigStatusUsingAddr0                     = 0x1;
const UCHAR gcDevConfigStatusGettingInitialDeviceDescriptor = 0x2;
const UCHAR gcDevConfigStatusSettingAddress                 = 0x3;
const UCHAR gcDevConfigStatusGettingDeviceDescriptor        = 0x4;
const UCHAR gcDevConfigStatusGettingInitialConfig           = 0x5;
const UCHAR gcDevConfigStatusGettingConfig                  = 0x6;
const UCHAR gcDevConfigStatusSettingConfig                  = 0x7;
const UCHAR gcDevConfigStatusDone                           = 0x8;
//const UCHAR gcDevConfigStatusConnectedToClass             = 0x9;
//const UCHAR gcDevConfigStatusRemoved                      = 0xA;

const UCHAR gcDevConfigStatusHubGettingDescriptor           = 0x10;
const UCHAR gcDevConfigStatusHubConfiguring                 = 0x11;
const UCHAR gcDevConfigStatusHubPoweringPorts               = 0x12;
const UCHAR gcDevConfigStatusHubReady                       = 0x13;
const UCHAR gcDevConfigStatusHubClearingChanges             = 0x14;
const UCHAR gcDevConfigStatusHubGettingPortStatus           = 0x15;
const UCHAR gcDevConfigStatusHubStartingPortReset           = 0x16;
const UCHAR gcDevConfigStatusHubResettingPort               = 0x17;
const UCHAR gcDevConfigStatusHubWaitingForPortReset         = 0x18;
const UCHAR gcDevConfigStatusHubWaitingForPortShutoff       = 0x19;
const UCHAR gcDevConfigStatusHubKillingPort                 = 0x1A;

const UCHAR gcDevConfigStatusHubWaitingForHubClearFlags     = 0x20;
const UCHAR gcDevConfigStatusHubClearingHubLocalPowerFlag   = 0x21;
const UCHAR gcDevConfigStatusHubClearingOverCurrentFlag     = 0x22;
const UCHAR gcDevConfigStatusHubWaitingForPowerGood         = 0x23;
const UCHAR gcDevConfigStatusHubWaitingForPortResetAck      = 0x24;

const UCHAR gcDevConfigStatusHubGettingPoweredStatus        = 0x25;
//const UCHAR gcDevConfigStatusHubResettingPort               = 0x26;
//const UCHAR gcDevConfigStatusHubWaitingForResetIssue        = 0x27;
//const UCAHR gcDevConfigStatusHubWaitingForDisableAndReset   = 0x28;
//const UCAHR gcDevConfigStatusHubWaitingForDisable           = 0x29;

const UCHAR gcDevConfigStatusInvalid                        = 0xFF;

// This is not a class transfer so this flag is not used.
const ULONG gcBufTypeUnused    = 0x00;

// We're using and internal buffer and copying user data to/from it.
const ULONG gcBufTypeCopied     = 0x01;
// It's an Isoch transfer and we're using the special class provided
// physical address.  
const ULONG gcBufTypeAlt        = 0x02;

class CPhcd;

struct STransfer
{
    //this pointer changed only by critical thread until last two TD
    //where less critical thread changes it
    PBYTE       lpbClientBuffer;
    DWORD       dwClientBufferPerms;   // ProcPerms for accessing client buf

    LPVOID      lpCompletionParameter;
    LPTRANSFER_NOTIFY_ROUTINE lpCompletionStartAddress;

    LPVOID      lpCancelParameter;
    LPTRANSFER_NOTIFY_ROUTINE lpCancelStartAddress;

    LPCVOID     lpvCancelId;

    PBOOL       pfComplete;
    PDWORD      pdwBytesTransfered;
    PDWORD      pdwError;

    PDWORD      adwIsochErrors;
    PDWORD      adwIsochLengths;

    LPBYTE      pSetupBuffer;

    UINT        cbBuffer1;
    LPBYTE      pDataBuffer1;
    ULONG       paDataBuffer1;

    UINT        cbBuffer2;
    LPBYTE      pDataBuffer2;
    ULONG       paDataBuffer2;

    PDWORD      aCopyLengths;
    // this pointer is changed ONLY by the critical thread
    PDWORD      pCopyLength;
#ifdef USE_CRITICAL_THREAD
    UINT        cCriticalTds;
#endif
    UINT        cNormalTds;

    BOOL        fCanceled;
    BOOL        fActiveCanceled;

    UINT        fIn;
    UINT        fCompress;
    UINT        bufType;

    ULONG       paLastTD;

    STransfer * pNext;

};


struct SEndpoint
{
    SEndpointDescriptor * pEd;

    CRITICAL_SECTION csSTransferListLock;
#ifdef USE_CRITICAL_THREAD
    CRITICAL_SECTION csCriticalThreadCancel;
#endif
    STransfer *pTransferHead;

    BOOL  fHalted;

    USHORT maxPacket;
    UCHAR endptArrayNum;
    UCHAR endptType;
    DWORD dwIsochNextFreeFrame;


	BOOL fPhcdToggleBit; //Code added by Zou Ying to support data toggling. 
};

struct SHubPort
{
    UCHAR addr;
    UCHAR hubConfigStatus;
    UCHAR flags;
    DWORD dwPowerGoodTime;
};

struct SDevice
{
    CRITICAL_SECTION csAccessingEndpointArray;
    SEndpoint * * ppEndpts;
    // For our memory allocation routines, we need some BOOLs to handle aborting
    // transfers blocked waiting for memory.
    BOOL * pfEndptAbortTransfers; 

    UCHAR configStatus;
    UCHAR configRetries;// For tracking retries during configuration
    UCHAR maxEndpts;
    UCHAR bIsLowSpeed;  //should be a BOOL, but UINTs are too big
    UCHAR hubNum;
    UCHAR port;
    UCHAR address;
//  UCHAR numInterfaces; //available in usbDevice
    UCHAR hubNumPorts;
    DWORD hubPowerOnToPowerGood;
    SHubPort * pHubPorts;
//    DWORD * pnHubPortPowerDraw;
    BOOL  fBusPoweredHub;
    BOOL  fRemovable;

    UINT iCurrentConfig;
    PHCI_DEVICE ohciDevice;

    // REVIEW t-paulk this Critical Section isn't used in the code????
    // It isn't used, but I'm not removing it for Cedar SP2
    CRITICAL_SECTION csAttachementDetachement;
    BOOL fAttached;
    BOOL fDetached;

    LPVOID lpvDetachId;
};

struct SPhysAddr
{
    PBYTE virtAddr;
    ULONG physAddr;

    UINT cIsochOffsets;
    UINT length;
    SPhysAddr *pNext;
};


struct SEdInfo
{
    SEndpoint * pEndpt;
    SEndpointDescriptor * pEd;
    UCHAR endptType;
    USHORT uFrame;

    SEdInfo *pNext;
};

struct STdInfo
{
    SDevice * pDev;
    SEndpoint * pEndpt;
    BOOL    fResetPipe;

    LPCVOID     lpvCancelId;

    USHORT uFrame;

    STdInfo *pNext;
};

struct SThreadParams
{
    CPhcd * pPhcd;
    SDevice * pDev;
    BOOL    fAttach;  // TRUE = attach, FALSE = detach
    DWORD   dwDelay;
    SThreadParams * pNext;
};

⌨️ 快捷键说明

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