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

📄 usbfx2lk_power.cpp

📁 基于vc++6.0环境的cypress USB 驱动源代码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
//      This routine is a completion routine that gets called when the WaitWake
//      Irp is completed.
//
//  INPUTS:
//
//      DeviceObject  - Pointer to our Device Object.
//      Irp           - Completing Irp
//      DevExt        - Address of our Device Extension
//
//  OUTPUTS:
//
//      None.
//
//  RETURNS:
//
//      None.
//
//  IRQL:
//
//      This routine is called at IRQL <= DISPATCH_LEVEL
//
//  CONTEXT:
//
//      This routine is called in an arbitrary thread context
//
//  NOTES:
//
//
///////////////////////////////////////////////////////////////////////////////
NTSTATUS WaitWakeCompletionRoutine(PDEVICE_OBJECT DeviceObject,PIRP Irp,PUSBFX2LK_EXT DevExt)
{
    ASSERT(KeGetCurrentIrql() <= DISPATCH_LEVEL);
    VALID_DEVEXT(DevExt);

    OsrTracePrint(TRACE_LEVEL_VERBOSE,OSRDBG_WAIT_WAKE,("WaitWakeCompletionRoutine: Entered.\n"));

    //
    // Propagate the Pending Returned Flag if Set.
    //
    if(Irp->PendingReturned) {
        IoMarkIrpPending(Irp);
    }

    //
    // Nullify the WaitWakeIrp pointer-the Irp is released 
    // as part of the completion process. If it's already NULL, 
    // avoid race with the CancelWaitWake routine.
    //
    if(InterlockedExchangePointer((volatile PVOID*)&DevExt->WaitWakeIrp, NULL)) {

        //
        // The CancelWaitWake routine already got the Irp.
        //
        OsrTracePrint(TRACE_LEVEL_INFORMATION,OSRDBG_WAIT_WAKE, 
                ("WaitWakeCompletionRoutine: Wait Wake Irp Completed by CancelWaitWake.\n"));

        //
        // Tell the Power Manager we are ready for another Power Irp.
        //
        PoStartNextPowerIrp(Irp);

        OsrTracePrint(TRACE_LEVEL_VERBOSE,OSRDBG_WAIT_WAKE,("WaitWakeCompletionRoutine: Exit.\n"));

        return STATUS_SUCCESS;
    }

    //
    // CancelWaitWake has run. 
    // If FlagWWCancel != 0, complete the Irp.
    // If FlagWWCancel == 0, CancelWaitWake completes it.
    //
    if(InterlockedExchange(&DevExt->FlagWWCancel, 1)) {

        //
        // CancelWaitWake has not run, so we must complete the Irp.
        //

        //
        // Tell the Power Manager we are ready for another Power Irp.
        //
        PoStartNextPowerIrp(Irp);

        OsrTracePrint(TRACE_LEVEL_VERBOSE,OSRDBG_WAIT_WAKE,
            ("WaitWakeCompletionRoutine: Exit Irp Not Canceled.\n"));

        return STATUS_CANCELLED;
    }

    OsrTracePrint(TRACE_LEVEL_VERBOSE,OSRDBG_WAIT_WAKE,("WaitWakeCompletionRoutine: Exit.\n"));

    //
    // Tell the I/O Manager that we want to hold on to the IRP.
    //
    return STATUS_MORE_PROCESSING_REQUIRED;
}



///////////////////////////////////////////////////////////////////////////////
//
// WaitWakeCallback
//
//      This routine is a completion routine that is called when the IRP_MN_WAIT_WAKE 
//      Power request has completed.
//
//  INPUTS:
//
//      DeviceObject  - Pointer to our Device Object.
//      MinorFunction - Minor Function of the Power Irp Completing
//      PowerState    - Current Device Power State
//      Context       - Address of our Device Extension
//      IoStatus      - Completion Status.
//
//  OUTPUTS:
//
//      None.
//
//  RETURNS:
//
//      None.
//
//  IRQL:
//
//      This routine is called at IRQL <= DISPATCH_LEVEL
//
//  CONTEXT:
//
//      This routine is called in an arbitrary thread context
//
//  NOTES:
//
//
///////////////////////////////////////////////////////////////////////////////
VOID WaitWakeCallback(PDEVICE_OBJECT DeviceObject,UCHAR MinorFunction,POWER_STATE PowerState,
                      PVOID Context,PIO_STATUS_BLOCK IoStatus)
{
    PUSBFX2LK_EXT   devExt = (PUSBFX2LK_EXT) Context;

    ASSERT(MinorFunction == IRP_MN_WAIT_WAKE);
    VALID_DEVEXT(devExt);

    OsrTracePrint(TRACE_LEVEL_VERBOSE,OSRDBG_WAIT_WAKE, 
            ("WaitWakeCallback: Entered status = 0x%x (%s)\n",IoStatus->Status,
                OsrNtStatusToString(IoStatus->Status)));

    //
    // Indicate that there is no Wait Wake Irp Outstanding.
    //
    InterlockedExchange(&devExt->FlagWWOutstanding, 0);

    //
    // Make sure that the Irp Completed Successfully
    //
    if(!NT_SUCCESS(IoStatus->Status)) {
        OsrTracePrint(TRACE_LEVEL_ERROR,OSRDBG_WAIT_WAKE,
            ("WaitWakeIrpCompletionFunc: Error 0x%x (%s).\n",
            IoStatus->Status,OsrNtStatusToString(IoStatus->Status)));
        return;
    }

    //
    // We may need to be the one to power the device up now (because we were
    //  armed for wake but the system was in S0). We'll do this power
    //  up asynchronously
    //
    SSPowerUpDeviceAsync(devExt);

    OsrTracePrint(TRACE_LEVEL_VERBOSE,OSRDBG_WAIT_WAKE,("WaitWakeCallback: Exit.\n"));

    return;
}

 

///////////////////////////////////////////////////////////////////////////////
//
// OsrPrintSystemPowerState
//
//      This routine translates the input system power state to a string
//
//  INPUTS:
//
//      State  - System Power State.
//
//  OUTPUTS:
//
//      None.
//
//  RETURNS:
//
//      None.
//
//  IRQL:
//
//      This routine is called at IRQL <= DISPATCH_LEVEL
//
//  CONTEXT:
//
//      This routine is called in an arbitrary thread context
//
//  NOTES:
//
//
///////////////////////////////////////////////////////////////////////////////
PCHAR OsrPrintSystemPowerState(SYSTEM_POWER_STATE State) {

    PCHAR string;

    switch(State) {

        case PowerSystemUnspecified: // = 0,
            string = (PCHAR) "PowerSystemUnspecified";
            break;

        case PowerSystemWorking: //,
            string = (PCHAR) "PowerSystemWorking";
            break;

        case PowerSystemSleeping1: //,
            string = (PCHAR) "PowerSystemSleeping1";
            break;

        case PowerSystemSleeping2: //,
            string = (PCHAR) "PowerSystemSleeping2";
            break;

        case PowerSystemSleeping3: //,
            string = (PCHAR) "PowerSystemSleeping3";
            break;

        case PowerSystemHibernate: //,
            string = (PCHAR) "PowerSystemHibernate";
            break;

        case PowerSystemShutdown: //,
            string = (PCHAR) "PowerSystemShutdown";
            break;

        case PowerSystemMaximum: //
            string = (PCHAR) "PowerSystemMaximum";
            break;

        default:
            string = (PCHAR) "Unknown Power State ?????? Error";
            break;


    }

    return string;
}

///////////////////////////////////////////////////////////////////////////////
//
// OsrPrintPowerAction
//
//      This routine translates the input power action to a string
//
//  INPUTS:
//
//      Action  - Power Action.
//
//  OUTPUTS:
//
//      None.
//
//  RETURNS:
//
//      None.
//
//  IRQL:
//
//      This routine is called at IRQL <= DISPATCH_LEVEL
//
//  CONTEXT:
//
//      This routine is called in an arbitrary thread context
//
//  NOTES:
//
//
///////////////////////////////////////////////////////////////////////////////
PCHAR OsrPrintPowerAction(POWER_ACTION Action)
{

    PCHAR string;

    switch(Action) {

        case PowerActionNone: // = 0,
            string = (PCHAR) "PowerActionNone";
            break;

        case PowerActionReserved: //,
            string = (PCHAR) "PowerActionReserved";
            break;

        case PowerActionSleep: //,
            string = (PCHAR) "PowerActionSleep";
            break;

        case PowerActionHibernate: //,
            string = (PCHAR) "PowerActionHibernate";
            break;

        case PowerActionShutdown: //,
            string = (PCHAR) "PowerActionShutdown";
            break;

        case PowerActionShutdownReset: //,
            string = (PCHAR) "PowerActionShutdownReset";
            break;

        case PowerActionShutdownOff: //,
            string = (PCHAR) "PowerActionShutdownOff";
            break;

        case PowerActionWarmEject: //
            string = (PCHAR) "PowerActionWarmEject";
            break;

        default:
            string = (PCHAR) "Unknown Power Action ???? Error";
            break;

    }

    return string;
}

///////////////////////////////////////////////////////////////////////////////
//
// OsrPrintDevicePowerState
//
//      This routine translates the input device power state to a string
//
//  INPUTS:
//
//      State  - Device Power State.
//
//  OUTPUTS:
//
//      None.
//
//  RETURNS:
//
//      None.
//
//  IRQL:
//
//      This routine is called at IRQL <= DISPATCH_LEVEL
//
//  CONTEXT:
//
//      This routine is called in an arbitrary thread context
//
//  NOTES:
//
//
///////////////////////////////////////////////////////////////////////////////
PCHAR OsrPrintDevicePowerState(DEVICE_POWER_STATE State) 
{

    PCHAR string;

    switch(State) {

        case PowerDeviceUnspecified: // = 0,
            string = (PCHAR) "PowerDeviceUnspecified";
            break;

        case PowerDeviceD0: //,
            string = (PCHAR) "PowerDeviceD0";
            break;

        case PowerDeviceD1: //,
            string = (PCHAR) "PowerDeviceD1";
            break;

        case PowerDeviceD2: //,
            string = (PCHAR) "PowerDeviceD2";
            break;

        case PowerDeviceD3: //,
            string = (PCHAR) "PowerDeviceD3";
            break;

        case PowerDeviceMaximum: //
            string = (PCHAR) "PowerDeviceMaximum";
            break;

        default:
            string = (PCHAR) "Unknown Device Power State ???? Error";
            break;

    }

    return string;
}


///////////////////////////////////////////////////////////////////////////////
//
// OsrPrintPowerStateType
//
//      This routine translates the input Power state type to a string
//
//  INPUTS:
//
//      Type  - Powe

⌨️ 快捷键说明

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