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

📄 chw.cpp

📁 Latest USB 802.3, HID printer and mass storage divers from Microsoft for Platform Builder 4.2.
💻 CPP
📖 第 1 页 / 共 4 页
字号:
    }
}
// ******************************************************************
VOID CHW::PowerMgmtCallback( IN BOOL fOff )
//
// Purpose: System power handler - called when device goes into/out of
//          suspend.
//
// Parameters:  fOff - if TRUE indicates that we're entering suspend,
//                     else signifies resume
//
// Returns: Nothing
//
// Notes: This needs to be implemented for HCDI
// ******************************************************************
{
    if ( fOff )
    {
        if ((GetCapability() & HCD_SUSPEND_RESUME)!= 0) {
            m_bDoResume=TRUE;
            SuspendHostController();
        }
        else {
            m_bDoResume=FALSE;;
            CHW::StopHostController();
        }
    }
    else
    {   // resuming...
        g_fPowerUpFlag = TRUE;
        if (m_bDoResume)
            ResumeHostController();
        if (!g_fPowerResuming)
            // can't use member data while `this' is invalid
            SetInterruptEvent(m_dwSysIntr);
    }
    return;
}
VOID CHW::SuspendHostController()
{
    if ( m_portBase != 0 ) {
        // initialize interrupt register - set only RESUME interrupts to enabled
        WORD wUSBCmd = Read_USBCMD();
        wUSBCmd &= ~UHCD_USBCMD_RUN_STOP;
        Write_USBCMD(wUSBCmd);
        Write_USBCMD(wUSBCmd | UHCD_USBCMD_ENTER_GLOBAL_SUSPEND_MODE);
    }
}
VOID CHW::ResumeHostController()
{
    if ( m_portBase != 0 ) {
        WORD wUSBCmd = Read_USBCMD();
        wUSBCmd |= UHCD_USBCMD_FORCE_GLOBAL_RESUME;
        Write_USBCMD(wUSBCmd);
        // I need 20 ms delay here 30(30ns)*1000*20
        for (DWORD dwIndex =0; dwIndex<30*1000*20; dwIndex++)
            Read_USBCMD();
        wUSBCmd &= ~(UHCD_USBCMD_FORCE_GLOBAL_RESUME | UHCD_USBCMD_ENTER_GLOBAL_SUSPEND_MODE);
        wUSBCmd |= UHCD_USBCMD_RUN_STOP;
        Write_USBCMD(wUSBCmd);
    }

}
DWORD CHW::SetCapability(DWORD dwCap)
{
    m_dwCapability |= dwCap; 
    if ( (m_dwCapability & HCD_SUSPEND_RESUME)!=0) {
        KernelIoControl(IOCTL_HAL_ENABLE_WAKE, &m_dwSysIntr, sizeof(m_dwSysIntr), NULL, 0, NULL);
    }
    return m_dwCapability;
};


#ifdef DEBUG
// ******************************************************************
void CHW::DumpUSBCMD( void )
//
// Purpose: Queries Host Controller for contents of USBCMD, and prints
//          them to DEBUG output. Bit definitions are in UHCI spec 2.1.1
//
// Parameters: None
//
// Returns: Nothing
//
// Notes: used in DEBUG mode only
//
//        This function is static
// ******************************************************************
{
    DWORD    dwData = 0;

    __try {
        dwData = Read_USBCMD();

        DEBUGMSG(ZONE_REGISTERS, (TEXT("\tCHW - USB COMMAND REGISTER (USBCMD) = 0x%X. Dump:\n"), dwData));
        DEBUGMSG(ZONE_REGISTERS, (TEXT("\t\tMax Reclamation Packet size = %s\n"), ((dwData & UHCD_USBCMD_MAX_RECLAMATION_SIZE_64) ? TEXT("64 bytes") : TEXT("32 bytes"))));
        DEBUGMSG(ZONE_REGISTERS, (TEXT("\t\tConfigure Flag = %s\n"), ((dwData & UHCD_USBCMD_CONFIGURE_FLAG) ? TEXT("Configured") : TEXT("Not Configured"))));
        DEBUGMSG(ZONE_REGISTERS, (TEXT("\t\tSoftware Debug = %s\n"), ((dwData & UHCD_USBCMD_SOFTWARE_DEBUG) ? TEXT("Debug Mode") : TEXT("Normal Mode"))));
        DEBUGMSG(ZONE_REGISTERS, (TEXT("\t\tForce Global Resume = %s\n"), ((dwData & UHCD_USBCMD_FORCE_GLOBAL_RESUME) ? TEXT("Set") : TEXT("Not Set"))));
        DEBUGMSG(ZONE_REGISTERS, (TEXT("\t\tEnter Global Suspend Mode = %s\n"), ((dwData & UHCD_USBCMD_ENTER_GLOBAL_SUSPEND_MODE) ? TEXT("Set") : TEXT("Not Set"))));
        DEBUGMSG(ZONE_REGISTERS, (TEXT("\t\tGlobal Reset = %s\n"), ((dwData & UHCD_USBCMD_GLOBAL_RESET) ? TEXT("Set") : TEXT("Not Set"))));
        DEBUGMSG(ZONE_REGISTERS, (TEXT("\t\tHost Controller Reset = %s\n"), ((dwData & UHCD_USBCMD_HOST_CONTROLLER_RESET) ? TEXT("Set") : TEXT("Not Set"))));
        DEBUGMSG(ZONE_REGISTERS, (TEXT("\t\tRun/Stop = %s\n"), ((dwData & UHCD_USBCMD_RUN_STOP) ? TEXT("Run") : TEXT("Stop"))));
    } __except(EXCEPTION_EXECUTE_HANDLER) {
        DEBUGMSG(ZONE_REGISTERS, (TEXT("\t\tCHW - FAILED WHILE DUMPING USBCMD!!!\n")));
    }
}
// ******************************************************************
void CHW::DumpUSBSTS( void )
//
// Purpose: Queries Host Controller for contents of USBSTS, and prints
//          them to DEBUG output. Bit definitions are in UHCI spec 2.1.2
//
// Parameters: None
//
// Returns: Nothing
//
// Notes: used in DEBUG mode only
//
//        This function is static
// ******************************************************************
{
    DWORD    dwData = 0;

    __try {
        dwData = Read_USBSTS();
        DEBUGMSG(ZONE_REGISTERS, (TEXT("\tCHW - USB STATUS REGISTER (USBSTS) = 0x%X. Dump:\n"), dwData));
        DEBUGMSG(ZONE_REGISTERS, (TEXT("\t\tHCHalted = %s\n"), ((dwData & UHCD_USBSTS_HCHALTED) ? TEXT("Halted") : TEXT("Not Halted"))));
        DEBUGMSG(ZONE_REGISTERS, (TEXT("\t\tHost Controller Process Error = %s\n"), ((dwData & UHCD_USBSTS_HOST_CONTROLLER_PROCESS_ERROR) ? TEXT("Fatal Error") : TEXT("Not Set"))));
        DEBUGMSG(ZONE_REGISTERS, (TEXT("\t\tHost System Error = %s\n"), ((dwData & UHCD_USBSTS_HOST_SYSTEM_ERROR) ? TEXT("Set") : TEXT("Not Set"))));
        DEBUGMSG(ZONE_REGISTERS, (TEXT("\t\tResume Detect = %s\n"), ((dwData & UHCD_USBSTS_RESUME_DETECT) ? TEXT("Set") : TEXT("Not Set"))));
        DEBUGMSG(ZONE_REGISTERS, (TEXT("\t\tUSB Error Interrupt = %s\n"), ((dwData & UHCD_USBSTS_USB_ERROR_INTERRUPT) ? TEXT("Set") : TEXT("Not Set"))));
        DEBUGMSG(ZONE_REGISTERS, (TEXT("\t\tUSB Interrupt = %s\n"), ((dwData & UHCD_USBSTS_USB_INTERRUPT) ? TEXT("Set") : TEXT("Not Set"))));

    } __except(EXCEPTION_EXECUTE_HANDLER) {
        DEBUGMSG(ZONE_REGISTERS, (TEXT("\t\tCHW - FAILED WHILE DUMPING USBSTS!!!\n")));
    }
}
// ******************************************************************
void CHW::DumpUSBINTR( void )
//
// Purpose: Queries Host Controller for contents of USBINTR, and prints
//          them to DEBUG output. Bit definitions are in UHCI spec 2.1.3
//
// Parameters: None
//
// Returns: Nothing
//
// Notes: used in DEBUG mode only
//
//        This function is static
// ******************************************************************
{
    DWORD    dwData = 0;

    __try {
        dwData = Read_USBINTR();
        DEBUGMSG(ZONE_REGISTERS, (TEXT("\tCHW - USB INTERRUPT REGISTER (USBINTR) = 0x%X. Dump:\n"), dwData));
        DEBUGMSG(ZONE_REGISTERS, (TEXT("\t\tShort Packet Interrupt Enable = %s\n"), ((dwData & UHCD_USBINTR_SHORT_PACKET_INTERRUPT) ? TEXT("Enabled") : TEXT("Disabled"))));
        DEBUGMSG(ZONE_REGISTERS, (TEXT("\t\tInterrupt on Complete (IOC) Enable = %s\n"), ((dwData & UHCD_USBINTR_INTERRUPT_ON_COMPLETE) ? TEXT("Enabled") : TEXT("Disabled"))));
        DEBUGMSG(ZONE_REGISTERS, (TEXT("\t\tResume Interrupt Enable = %s\n"), ((dwData & UHCD_USBINTR_RESUME_INTERRUPT) ? TEXT("Enabled") : TEXT("Disabled"))));
        DEBUGMSG(ZONE_REGISTERS, (TEXT("\t\tTimeout/CRC Interrupt Enable = %s\n"), ((dwData & UHCD_USBINTR_TIMEOUT_CRC_INTERRUPT) ? TEXT("Enabled") : TEXT("Disabled"))));
    } __except(EXCEPTION_EXECUTE_HANDLER) {
        DEBUGMSG(ZONE_REGISTERS, (TEXT("\t\tCHW - FAILED WHILE DUMPING USBINTR!!!\n")));
    }
}
// ******************************************************************
void CHW::DumpFRNUM( void )
//
// Purpose: Queries Host Controller for contents of FRNUM, and prints
//          them to DEBUG output. Bit definitions are in UHCI spec 2.1.4
//
// Parameters: None
//
// Returns: Nothing
//
// Notes: used in DEBUG mode only
//
//        This function is static
// ******************************************************************
{
    DWORD    dwData = 0;

    __try {
        dwData = Read_FRNUM();
        DEBUGMSG(ZONE_REGISTERS, (TEXT("\tCHW - FRAME NUMBER REGISTER (FRNUM) = 0x%X. Dump:\n"), dwData));
        DEBUGMSG(ZONE_REGISTERS, (TEXT("\t\tFrame number (bits 10:0) = %d\n"), (dwData & UHCD_FRNUM_MASK)));
        DEBUGMSG(ZONE_REGISTERS, (TEXT("\t\tFrame index (bits 9:0) = %d\n"), (dwData & UHCD_FRNUM_INDEX_MASK)));
    } __except(EXCEPTION_EXECUTE_HANDLER) {
        DEBUGMSG(ZONE_REGISTERS, (TEXT("\t\tCHW - FAILED WHILE DUMPING FRNUM!!!\n")));
    }
}

// ******************************************************************
void CHW::DumpFLBASEADD( void )
//
// Purpose: Queries Host Controller for contents of FLBASEADD, and prints
//          them to DEBUG output. Bit definitions are in UHCI spec 2.1.5
//
// Parameters: None
//
// Returns: Nothing
//
// Notes: used in DEBUG mode only
//
//        This function is static
// ******************************************************************
{
    DWORD    dwData = 0;

    __try {
        dwData = Read_FLBASEADD();
        DEBUGMSG(ZONE_REGISTERS, (TEXT("\tCHW - FRAME LIST BASE ADDRESS REGISTER (FLBASEADD) = 0x%X. Dump:\n"), dwData));
        DEBUGMSG(ZONE_REGISTERS, (TEXT("\t\tFLBASEADD address base (bits 11:0 masked) = 0x%X\n"), (dwData & UHCD_FLBASEADD_MASK)));
    } __except(EXCEPTION_EXECUTE_HANDLER) {
        DEBUGMSG(ZONE_REGISTERS, (TEXT("\t\tCHW - FAILED WHILE DUMPING FLBASEADD!!!\n")));
    }
}
// ******************************************************************
void CHW::DumpSOFMOD( void )
//
// Purpose: Queries Host Controller for contents of SOFMOD, and prints
//          them to DEBUG output. Bit definitions are in UHCI spec 2.1.6
//
// Parameters: None
//
// Returns: Nothing
//
// Notes: used in DEBUG mode only
//
//        This function is static
// ******************************************************************
{
    DWORD    dwData = 0;

    __try {
        dwData = Read_SOFMOD();
        DEBUGMSG(ZONE_REGISTERS, (TEXT("\tCHW - START OF FRAME MODIFY REGISTER (SOFMOD) = 0x%X. Dump:\n"), dwData));
        DEBUGMSG(ZONE_REGISTERS, (TEXT("\t\tFrame Length in 12Mhz clocks = %d\n"), (dwData & UHCD_SOFMOD_MASK) + UHCD_SOFMOD_MINIMUM_LENGTH));
    } __except(EXCEPTION_EXECUTE_HANDLER) {
        DEBUGMSG(ZONE_REGISTERS, (TEXT("\t\tCHW - FAILED WHILE DUMPING SOFMOD!!!\n")));
    }
}

// ******************************************************************
void CHW::DumpPORTSC(IN const USHORT port)
//
// Purpose: Queries Host Controller for contents of PORTSC #port, and prints
//          them to DEBUG output. Bit definitions are in UHCI spec 2.1.7
//
// Parameters: port - the port number to read. It must be such that
//                    1 <= port <= UHCD_NUM_ROOT_HUB_PORTS
//
// Returns: Nothing
//
// Notes: used in DEBUG mode only
//
//        This function is static
// ******************************************************************
{
    DWORD    dwData = 0;

    __try {
        DEBUGCHK( port >=  1 && port <= UHCD_NUM_ROOT_HUB_PORTS );

        dwData = Read_PORTSC( port );
        DEBUGMSG(ZONE_REGISTERS, (TEXT("\tCHW - PORT STATUS AND CONTROL REGISTER (PORTSC%d) = 0x%X. Dump:\n"), port, dwData));
        if ( dwData & UHCD_PORTSC_PORT_ENABLED ) {
            DEBUGMSG(ZONE_REGISTERS, (TEXT("\t\tHub State = %s\n"), ((dwData & UHCD_PORTSC_SUSPEND) ? TEXT("Suspend") : TEXT("Enable"))));
        } else {
            DEBUGMSG(ZONE_REGISTERS, (TEXT("\t\tHub State = Disabled\n")));
        }
        DEBUGMSG(ZONE_REGISTERS, (TEXT("\t\tPort Reset = %s\n"), ((dwData & UHCD_PORTSC_PORT_RESET) ? TEXT("Reset") : TEXT("Not Reset"))));
        DEBUGMSG(ZONE_REGISTERS, (TEXT("\t\tDevice Speed = %s\n"), ((dwData & UHCD_PORTSC_LOW_SPEED_DEVICE) ? TEXT("Low") : TEXT("Full"))));
        DEBUGMSG(ZONE_REGISTERS, (TEXT("\t\tResume Detect = %s\n"), ((dwData & UHCD_PORTSC_RESUME_DETECT) ? TEXT("Set") : TEXT("Not Set"))));
        DEBUGMSG(ZONE_REGISTERS, (TEXT("\t\tLine Status = %d\n"), ( (dwData & UHCD_PORTSC_LINE_STATUS) >> 4)));
        DEBUGMSG(ZONE_REGISTERS, (TEXT("\t\tPort Enable/Disable Change  = %s\n"), ((dwData & UHCD_PORTSC_PORT_ENABLE_CHANGE) ? TEXT("Set") : TEXT("Not Set"))));
        DEBUGMSG(ZONE_REGISTERS, (TEXT("\t\tPort = %s\n"), ((dwData & UHCD_PORTSC_PORT_ENABLED) ? TEXT("Enabled") : TEXT("Disabled"))));
        DEBUGMSG(ZONE_REGISTERS, (TEXT("\t\tConnect Status Change = %s\n"), ((dwData & UHCD_PORTSC_CONNECT_STATUS_CHANGE) ? TEXT("Set") : TEXT("Not Set"))));
        DEBUGMSG(ZONE_REGISTERS, (TEXT("\t\tConnect Status = %s\n"), ((dwData & UHCD_PORTSC_CONNECT_STATUS) ? TEXT("Device Present") : TEXT("No Device Present"))));

    } __except(EXCEPTION_EXECUTE_HANDLER) {
        DEBUGMSG(ZONE_REGISTERS, (TEXT("\t\tCHW - FAILED WHILE DUMPING PORTSC%d!!!\n"), port));
    }
}

// ******************************************************************
void CHW::DumpAllRegisters( void )
//
// Purpose: Queries Host Controller for all registers, and prints
//          them to DEBUG output. Register definitions are in UHCI spec 2.1
//
// Parameters: None
//
// Returns: Nothing
//
// Notes: used in DEBUG mode only
//
//        This function is static
// ******************************************************************
{
    DEBUGMSG(ZONE_REGISTERS, (TEXT("CHW - DUMP REGISTERS BEGIN\n")));
    DumpUSBCMD();
    DumpUSBSTS();
    DumpUSBINTR();
    DumpFRNUM();
    DumpFLBASEADD();
    DumpSOFMOD();
    for ( USHORT port = 1; port <= UHCD_NUM_ROOT_HUB_PORTS; port++ ) {
        DumpPORTSC( port );
    }
    DEBUGMSG(ZONE_REGISTERS, (TEXT("CHW - DUMP REGISTERS DONE\n")));
}
#endif

⌨️ 快捷键说明

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