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

📄 usbfx2lk.h

📁 基于vc++6.0环境的cypress USB 驱动源代码
💻 H
📖 第 1 页 / 共 2 页
字号:
    //
    PUSBD_INTERFACE_INFORMATION     UsbInterface;

    //
    // Pipe Information
    //
    PUSBFX2LK_PIPE_CONTEXT          PipeContext;

    //
    // The PUSBFX2LK_PIPE_CONTEXT PipeContext pointer
    //  above is allocated as an array of PUSBFX2LK_PIPE_CONTEXT
    //  pointers. In our driver, there will be 3 pipes:
    //  1) Bulk In
    //  2) Bulk Out
    //  3) Interrupt
    //
    //  Because we'll need to access these individual
    //  pipes in different places, below are three pointers
    //  into the above array to reference each individual
    //  pipe. These should NOT be individually freed,
    //  only PipeContext need be freed
    //
    PUSBFX2LK_PIPE_CONTEXT          BulkInPipe;
    PUSBFX2LK_PIPE_CONTEXT          BulkOutPipe;
    PUSBFX2LK_PIPE_CONTEXT          InterruptPipe;

    //
    // The number of pipes that we found
    //
    ULONG                           NumberOfPipes;

    //
    // IO_CSQ for our cancel safe Io queue
    //
    IO_CSQ                          CancelSafeIoQueue;

    //
    // KSPIN_LOCK for protecting our cancel safe 
    //  IO queue
    //
    KSPIN_LOCK                      CancelSafeIoLock;
    KSPIN_LOCK                      IoStateLock;

    //
    // LIST_ENTRY for the head of our pending write irp queue
    //
    LIST_ENTRY                      IoQueue;

    //
    // Set to True if Device is Running at High Speed.
    // This is really only needed for W2k.
    //
    BOOLEAN                         RunningAtHighSpeed;

    //
    // WMI Information
    //
    WMILIB_CONTEXT                  WmiLibInfo;
    BOOLEAN                         WmiRegistered;
    USBFX2LK_STATISTICS             WmiStatistics;

    //
    // PnP State Variables
    //
    PNP_DEVICESTATE                 DevicePnPState;

    //
    // Number of Outstanding I/O requests queued to Driver Below
    //
    LONG                            OutStandingIoCount;
    KEVENT                          StopEvent;  // Signaled when no outstanding I/O
                                                // requests queued to driver
    KEVENT                          RemoveEvent;// Signaled when no outstanding
                                                // requests are queued to driver.

    //
    // Wait Wake Information.
    //
    PIRP                            WaitWakeIrp;    // Address of Irp 
    LONG                            FlagWWCancel;   // Cancel
    LONG                            FlagWWOutstanding;
    BOOLEAN                         WaitWakeEnable;
    ULONG                           PowerDownLevel;


    //
    // DEVICE_POWER_STATE the current device power state
    //
    DEVICE_POWER_STATE              DevicePowerState;

    //
    // SYSTEM_POWER_STATE the current system power state
    //
    SYSTEM_POWER_STATE              SystemPowerState;

    //
    // DEVICE_POWER_STATE[PowerSystemMaximum] array of system
    //  to device power mappings
    //
    DEVICE_POWER_STATE              SystemToDevicePowerMappings[PowerSystemMaximum];

    //
    // PIRP System power IRP temporary storage
    //
    PIRP                            SystemPowerIrp;

    //
    // Definitions for Selective Suspend support
    //

    //
    // KSPIN_LOCK used to protect all fields of the device extension
    //  used in selective suspend
    //
    KSPIN_LOCK                      SSLock;

    //
    // BOOLEAN indicating if the user wishes to allow the device
    //  to suspend when idle
    //
    BOOLEAN                         SSEnabledByUser;

    //
    // BOOLEAN indicating that the selective suspend
    //  members of our device extension have been initialized.
    //
    BOOLEAN                         SSInitialized;

    //
    // BOOLEAN indicating whether or not the device can suspend
    //  at this moment in time. 
    //
    BOOLEAN                         SSDeviceCanNowSuspend;

    //
    // ULONG current state of the selective suspend process
    //
    ULONG                           SSState;

    //
    // HANDLE to a thread that will monitor the activity
    //  on the device and will suspend the device when 
    //  appropriate
    //
    HANDLE                          SSSubmissionThread;

    //
    // PVOID pointer to the thread object of the 
    //  SS submission thread
    //
    PVOID                           SSSubmissionThreadObject;

    //
    // KEVENT to signal that the SSSubmissionThread should
    //  terminate itself
    //
    KEVENT                          SSSubmissionThreadTerminateEvent;

    //
    // KEVENT that is signalled when the device powers itself
    //  out of selective suspend. 
    //
    KEVENT                          SSDeviceNotSuspendedEvent;

    //
    // LARGE_INTEGER indicating the system time when the device
    //  was last marked as idle
    //
    LARGE_INTEGER                   SSTimeOfLastActivity;

#ifndef W2K

    //
    // USB_IDLE_CALLBACK_INFO used for idle callback notification
    //
    USB_IDLE_CALLBACK_INFO          SSIdleCallbackInfo;

    //
    // We need some extra state to avoid numerous race
    //  conditions within the idle notification callback
    //  scheme used on XP and later
    //

    //
    // KEVENT indicating whether or not the idle notification
    //  callback has fired
    //
    KEVENT                           SSIdleCallbackCalled;

    //
    // KEVENT indicating whether or not the completion
    //  routine for the IRP used to submit the idle notification
    //  callback has fired
    //
    KEVENT                           SSIdleCompletionRoutineCalled;

    //
    // PIRP for the outstanding IDLE request, if there is one
    //
    PIRP                             SSIdleIrp;

#endif

} USBFX2LK_EXT, *PUSBFX2LK_EXT;

#define USBFX2LK_EXT_MAGIC_NUMBER 0xFFEEFF00

#define VALID_DEVEXT(x) \
    ASSERT(x->MagicNumber == USBFX2LK_EXT_MAGIC_NUMBER);

//
// Context used to track I/O Requests.
//
typedef struct _USBFX2LK_IO_CONTEXT {

    PURB            Urb;
    PIRP            Irp;
    PMDL            Mdl;
    ULONG           RemainingLength; // remaining to xfer
    ULONG           Numxfer;        // cumulate xfer
    PUCHAR          VirtualAddress; // va for next segment of xfer.
    PUSBFX2LK_EXT   DevExt;
    ULONG           MaxmimumStageSize;
    ULONG           TotalLength;
    PIO_WORKITEM    PWorkItem;

} USBFX2LK_IO_CONTEXT, *PUSBFX2LK_IO_CONTEXT;



//
// Forward definitions
//

//
// In UsbFx2Lk.cpp
//
VOID UsbFx2LkUnload(PDRIVER_OBJECT DriverObject);
#ifdef WPP_TRACING
#ifdef W2K
VOID W2KInitializeWPPTracing(PDEVICE_OBJECT DeviceObject,
                             PUNICODE_STRING RegistryPath);
VOID W2KCleanupWPPTracing(PDEVICE_OBJECT DeviceObject);
#endif // W2K_BUILD
#endif //WPP_TRACING

//
// In UsbFx2Lk_CreateClose.cpp
//
NTSTATUS UsbFx2LkCreate(PDEVICE_OBJECT DeviceObject,PIRP Irp);
NTSTATUS UsbFx2LkClose(PDEVICE_OBJECT DeviceObject,PIRP Irp);

//
// In UsbFx2Lk_io.cpp
//
NTSTATUS UsbFx2LkRead(PDEVICE_OBJECT DeviceObject,PIRP Irp);
NTSTATUS UsbFx2LkWrite(PDEVICE_OBJECT DeviceObject,PIRP Irp);
VOID OsrProcessQueuedRequests(PUSBFX2LK_EXT DevExt);
VOID ProcessNextIrpInQueue(PUSBFX2LK_EXT DevExt);

//
// In UsbFx2Lk_devctrl.cpp
//
NTSTATUS UsbFx2LkDeviceControl(PDEVICE_OBJECT DeviceObject,PIRP Irp);

//
// In UsbFx2Lk_sysctrl.cpp
//
NTSTATUS UsbFx2LkSystemControl(PDEVICE_OBJECT DeviceObject,PIRP Irp);

//
// In UsbFx2Lk_pnp.cpp
//
NTSTATUS UsbFx2LkPnp(PDEVICE_OBJECT DeviceObject,PIRP Irp);
NTSTATUS UsbFx2LkAddDevice(PDRIVER_OBJECT PDriverObject,PDEVICE_OBJECT PPdo);
CONST PCHAR OsrPrintState(PUSBFX2LK_EXT PDevExt); 
VOID OsrWaitForStop(PUSBFX2LK_EXT DevExt); 
VOID OsrUpdateDeviceState(PUSBFX2LK_EXT DevExt,PNP_DEVICESTATE State);
VOID OsrDecrementOutstandingIoCount(PUSBFX2LK_EXT PDevExt,const char* FileName,ULONG LineNumber);
VOID OsrIncrementOutstandingIoCount(PUSBFX2LK_EXT PDevExt,const char* FileName,ULONG LineNumber);
NTSTATUS OsrWaitForSingleObject(PVOID Object);
NTSTATUS OsrWaitForMultipleObjects(ULONG ObjectCount, PVOID *Objects, 
                                   WAIT_TYPE WaitType, 
                                   PKWAIT_BLOCK WaitBlockArray);



//
// In UsbFx2Lk_power.cpp
//
NTSTATUS UsbFx2LkPower(PDEVICE_OBJECT DeviceObject,PIRP Irp);
NTSTATUS IssueWaitWake(PUSBFX2LK_EXT DevExt);
VOID CancelWaitWake(PUSBFX2LK_EXT DevExt);
VOID PrintDeviceCapabilities(PDEVICE_CAPABILITIES PParentCapabilities,PUCHAR Title);
PCHAR OsrPrintSystemPowerState(SYSTEM_POWER_STATE State);
PCHAR OsrPrintPowerAction(POWER_ACTION Action);
PCHAR OsrPrintDevicePowerState(DEVICE_POWER_STATE State);
PCHAR OsrPrintPowerStateType(POWER_STATE_TYPE Type);

//
// In UsbFx2Lk_Queue.cpp
//
#ifdef W2K3
NTSTATUS OsrCsqInsertIoIrpEx(PIO_CSQ Csq,PIRP Irp,PVOID InsertContext);
#else // W2K3
VOID OsrCsqInsertIoIrp(PIO_CSQ Csq,PIRP Irp);
#endif // W2K3
VOID OsrCsqRemoveIoIrp(PIO_CSQ Csq,PIRP Irp);
PIRP OsrCsqPeekNextIoIrp(PIO_CSQ Csq,PIRP Irp,PVOID PeekContext);
VOID OsrCsqAcquireIoLock(PIO_CSQ Csq,PKIRQL Irql);
VOID OsrCsqReleaseIoLock(PIO_CSQ Csq,KIRQL Irql);
VOID OsrCsqCompleteCancelledIoIrp(PIO_CSQ Csq,PIRP Irp);
VOID OsrClearQueues(PUSBFX2LK_EXT DevExt);

//
// In UsbFx2Lk_SelSusp.cpp
//
VOID EnableSelectiveSuspend(PUSBFX2LK_EXT DevExt);
VOID DisableSelectiveSuspend(PUSBFX2LK_EXT DevExt);
VOID SSPowerDeviceIfSuspended(PUSBFX2LK_EXT DevExt);
BOOLEAN SSPowerDeviceIfSuspendedAsync(PUSBFX2LK_EXT DevExt);
VOID SSSubmissionThreadRoutine(PVOID Context);
VOID SSPowerUpDevice(PUSBFX2LK_EXT DevExt);
VOID SSPowerUpDeviceAsync(PUSBFX2LK_EXT DevExt);
VOID SSSuspendDevice(PUSBFX2LK_EXT DevExt);
#ifndef WIN2K
VOID SSSuspendDeviceWithCallback(PUSBFX2LK_EXT DevExt);
#endif

//
// In UsbFx2Lk_SysCtrl.cpp
//
NTSTATUS UsbFx2LkWmiRegistration(PUSBFX2LK_EXT PDevExt);
NTSTATUS UsbFx2LkWmiDeRegistration(PUSBFX2LK_EXT PDevExt);

//
// In NtStatStr.cpp
//
CONST PCHAR OsrMinorFunctionToString(UCHAR MajorFunction,UCHAR MinorFunction);
CONST PCHAR OsrNtStatusToString(NTSTATUS Status);

//
// In UsbFx2Lk_Usb.cpp
//
NTSTATUS ReadandSelectUsbDescriptors(PUSBFX2LK_EXT PDevExt);
NTSTATUS DeconfigureUsbDevice(PUSBFX2LK_EXT PDevExt);
NTSTATUS SubmitResetPipe(PUSBFX2LK_EXT DevExt, PIRP Irp, USBFX2_PIPE_ENUM Pipe);
NTSTATUS SubmitGetBarGraphState(PUSBFX2LK_EXT DevExt, PIRP Irp);
NTSTATUS SubmitSetBarGraphState(PUSBFX2LK_EXT DevExt, PIRP Irp);
NTSTATUS SubmitGetSevenSegmentState(PUSBFX2LK_EXT DevExt, PIRP Irp);
NTSTATUS SubmitSetSevenSegmentState(PUSBFX2LK_EXT DevExt, PIRP Irp);
NTSTATUS SubmitGetSwitchState(PUSBFX2LK_EXT DevExt, PIRP Irp);
NTSTATUS GetDeviceDescriptor(PUSBFX2LK_EXT DevExt, PUSB_DEVICE_DESCRIPTOR DeviceDescriptor,
                             PULONG BytesTransferred);
NTSTATUS GetConfigurationDescriptor(PUSBFX2LK_EXT DevExt, PUSB_CONFIGURATION_DESCRIPTOR ConfigDescriptor,
                                    PULONG BytesTransferred);
NTSTATUS GetPipeInformation(PUSBFX2LK_EXT DevExt, USBFX2_PIPE_ENUM Pipe, PUSBD_PIPE_INFORMATION PipeInformation,
                            PULONG BytesTransferred);
NTSTATUS GetInterfaceInformation(PUSBFX2LK_EXT DevExt, PUSBD_INTERFACE_INFORMATION InterfaceDescriptor,
                                 PULONG BytesTransferred);
NTSTATUS SubmitInterruptDataRequest(PUSBFX2LK_EXT DevExt, PIRP Irp);

#endif //__USBFX2LK_H__

⌨️ 快捷键说明

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