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

📄 cuhcd.cpp

📁 Intel PXA270 Wince5.0 BSP
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//
// 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.
//
//
// 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.
//
// Module Name:
//     uhcd.cpp
// Abstract:
//     This file contains the CUhcd object, which is the main entry
//     point for all HCDI calls by USBD
//
// Notes:
//


#include "cuhcd.hpp"
#include "cpipe.hpp"
#include "cdevice.hpp"
#include "chw.hpp"

#include <nkintr.h>

BOOL g_fPowerUpFlag = FALSE;

// ****************************************************************
// PUBLIC FUNCTIONS
// ****************************************************************

// ******************************************************************
CUhcd::CUhcd( )
// Purpose: Initialize variables associated with this class
//
// Parameters: None
//
// Returns: Nothing (Constructor can NOT fail!)
//
// Notes: *All* initialization which could possibly fail should be done
//        via the Initialize() routine, which is called right after
//        the constructor
// ******************************************************************
: m_pCRootHub( NULL )       // CRootHub object representing the built-in hardware USB ports
{
    DEBUGMSG(ZONE_UHCD && ZONE_VERBOSE, (TEXT("+CUhcd::CUhcd\n")));
    InitializeCriticalSection ( &m_csHCLock );
    DEBUGMSG(ZONE_UHCD && ZONE_VERBOSE, (TEXT("-CUhcd::CUhcd\n")));
}

// ******************************************************************
CUhcd::~CUhcd()
//
// Purpose: Destroy all memory and objects associated with this class
//
// Parameters: None
//
// Returns: Nothing
//
// Notes:
// ******************************************************************
{
    DEBUGMSG(ZONE_UHCD && ZONE_VERBOSE, (TEXT("+CUhcd::~CUhcd\n")));

    CHW::StopHostController();

    // make the API set inaccessible
    EnterCriticalSection( &m_csHCLock );
    CRootHub *pRoot = m_pCRootHub;
    m_pCRootHub = NULL;
    LeaveCriticalSection( &m_csHCLock );

    // signal root hub to close
    if ( pRoot ) {
        pRoot->HandleDetach();
        delete pRoot;
    }
    // this is safe because by now all clients have been unloaded
    DeleteCriticalSection ( &m_csHCLock );

    CDevice::DeInitialize();
    CPipe::DeInitialize();
    CHW::DeInitialize();

    DEBUGMSG(ZONE_UHCD && ZONE_VERBOSE, (TEXT("-CUhcd::~CUhcd\n")));
}

// ******************************************************************
BOOL CUhcd::Initialize( IN LPVOID pvUhcdPddObject,
                        IN CPhysMem * pCPhysMem,
                        IN LPCWSTR, // szDriverRegistryKey ignored for now
                        IN REGISTER portBase,
                        IN DWORD dwSysIntr)
//
// Purpose: Set up the Host Controller hardware, associated data structures,
//          and threads so that schedule processing can begin.
//
// Parameters: pvUhcdPddObject - pointer to the PDD object for this driver
//
//             pCPhysMem - pointer to class for managing physical memory
//
//             szDriverRegistryKey - unused ?
//
//             portBase - base address for USB registers
//
//             dwSysIntr - interrupt identifier for USB interrupts
//
// Returns: TRUE - if initializes successfully and is ready to process
//                 the schedule
//          FALSE - if setup fails
//
// Notes: This function is called by right after the constructor.
//        It is the starting point for all initialization.
//
//        This needs to be implemented for HCDI
// ******************************************************************
{
    DEBUGMSG(ZONE_INIT,(TEXT("+CUhcd::Initialize. Entry\r\n")));

    m_dwSysIntr = dwSysIntr;

    // All Initialize routines must be called, so we can't write
    // if ( !CDevice::Initialize() || !CPipe::Initialize() etc )
    // due to short circuit eval.
    {
        BOOL fCDeviceInitOK = CDevice::Initialize( this );
        BOOL fCHWInitOK = CHW::Initialize( portBase,
                                           dwSysIntr,
                                           pCPhysMem,
                                           pvUhcdPddObject );
        BOOL fCPipeInitOK = CPipe::Initialize( pCPhysMem );

        if ( !fCPipeInitOK || !fCPipeInitOK || !fCHWInitOK ) {
            DEBUGMSG(ZONE_ERROR, (TEXT("-CUhcd::Initialize. Error - could not initialize device/pipe/hw classes\n")));
            return FALSE;
        }
    }

    // set up the root hub object
    {
        USB_DEVICE_INFO deviceInfo;
        USB_HUB_DESCRIPTOR usbHubDescriptor;

        deviceInfo.dwCount = sizeof( USB_DEVICE_INFO );
        deviceInfo.lpConfigs = NULL;
        deviceInfo.lpActiveConfig = NULL;
        deviceInfo.Descriptor.bLength = sizeof( USB_DEVICE_DESCRIPTOR );
        deviceInfo.Descriptor.bDescriptorType = USB_DEVICE_DESCRIPTOR_TYPE;
        deviceInfo.Descriptor.bcdUSB = 0x110; // USB spec 1.10
        deviceInfo.Descriptor.bDeviceClass = USB_DEVICE_CLASS_HUB;
        deviceInfo.Descriptor.bDeviceSubClass = 0xff;
        deviceInfo.Descriptor.bDeviceProtocol = 0xff;
        deviceInfo.Descriptor.bMaxPacketSize0 = 0;
        deviceInfo.Descriptor.bNumConfigurations = 0;

        CHW::GetRootHubDescriptor(usbHubDescriptor);

        // FALSE indicates root hub is not low speed
        // (though, this is ignored for hubs anyway)
        m_pCRootHub = new CRootHub( deviceInfo, FALSE, usbHubDescriptor );
    }

    if ( !m_pCRootHub ) {
        DEBUGMSG( ZONE_ERROR, (TEXT("-CUhcd::Initialize - unable to create root hub object\n")) );
        return FALSE;
    }

    // Signal root hub to start processing port changes
    // The root hub doesn't have any pipes, so we pass NULL as the
    // endpoint0 pipe
    if ( !m_pCRootHub->EnterOperationalState( NULL ) ) {
        DEBUGMSG(ZONE_ERROR, (TEXT("-CUhcd::Initialize. Error initializing root hub\n")));
        return FALSE;
    }

    // Start processing frames
    CHW::EnterOperationalState();

    DEBUGMSG(ZONE_INIT,(TEXT("-CUhcd::Initialize. Success!!\r\n")));
    return TRUE;
}

// ******************************************************************
BOOL CUhcd::GetFrameNumber( OUT LPDWORD lpdwFrameNumber )
//
// Purpose: Get the current frame number
//
// Parameters: lpdwFrameNumber - pointer to receive the frame number
//
// Returns: TRUE - if frame number stored into lpdwFrameNumber
//          FALSE - on error
//
// Notes:
//
//        This needs to be implemented for HCDI
// ******************************************************************
{
    DEBUGMSG( ZONE_UHCD, (TEXT("+CUhcd::GetFrameNumber\n")) );
    *lpdwFrameNumber = CHW::GetFrameNumber();
    DEBUGMSG( ZONE_UHCD, (TEXT("-CUhcd::GetFrameNumber\n")) );
    return TRUE;
}

// ******************************************************************
BOOL CUhcd::GetFrameLength( OUT LPUSHORT lpuFrameLength )
//
// Purpose: Get the Frame Length in 12 Mhz clocks. i.e. 12000 = 1ms
//
// Parameters: lpuFrameLength - pointer to receive the frame length
//
// Returns: TRUE - if frame length stored into lpuFrameLength
//          FALSE - on error
//
// Notes:
//
//        This needs to be implemented for HCDI
// ******************************************************************
{
    DEBUGMSG( ZONE_UHCD, (TEXT("+CUhcd::GetFrameLength\n")) );
    *lpuFrameLength = CHW::GetFrameLength();
    DEBUGMSG( ZONE_UHCD, (TEXT("-CUhcd::GetFrameLength\n")) );
    return TRUE;
}

// ******************************************************************
BOOL CUhcd::SetFrameLength( IN HANDLE hEvent,
                            IN USHORT uFrameLength )
//
// Purpose: Set the Frame Length in 12 Mhz clocks. i.e. 12000 = 1ms
//
// Parameters:  hEvent - event to set when frame has reached required
//                       length
//
//              uFrameLength - new frame length
//
// Returns: Return value of CHW class to the request
//
// Notes:
//
//        This needs to be implemented for HCDI
// ******************************************************************
{
    return CHW::SetFrameLength( hEvent, uFrameLength );
}

// ******************************************************************
BOOL CUhcd::StopAdjustingFrame( void )
//
// Purpose: Stop modifying the host controller frame length
//
// Parameters: None
//
// Returns: Return value of CHW class to the request
//
// Notes:
//
//        This needs to be implemented for HCDI
// ******************************************************************
{
    return CHW::StopAdjustingFrame( );
}

// ******************************************************************
BOOL CUhcd::OpenPipe( IN UINT address,
                      IN LPCUSB_ENDPOINT_DESCRIPTOR lpEndpointDescriptor,
                      OUT LPUINT lpPipeIndex )
//
// Purpose: Create a logical communication pipe to the endpoint described
//          by lpEndpointDescriptor for device address.
//
// Parameters:  address - address of device to open pipe for
//
//              lpEndpointDescriptor - describes endpoint to open
//
//              lpPipeIndex - out param, indicating index of opened pipe
//
// Returns: TRUE if pipe opened ok, FALSE otherwise
//
// Notes: This needs to be implemented for HCDI
// ******************************************************************
{
    DEBUGMSG(ZONE_UHCD, (TEXT("+CUhcd::OpenPipe for device on addr %d\n"), address));
    BOOL fSuccess = FALSE;

    EnterCriticalSection( &m_csHCLock );
    CRootHub *pRoot = m_pCRootHub;

    if ( pRoot != NULL &&
         lpEndpointDescriptor != NULL &&
         lpEndpointDescriptor->bDescriptorType == USB_ENDPOINT_DESCRIPTOR_TYPE &&
         lpEndpointDescriptor->bLength >= sizeof( USB_ENDPOINT_DESCRIPTOR ) &&
         lpPipeIndex != NULL ) {

        // root hub will send the request to the appropriate device
        fSuccess = ( requestOK == pRoot->OpenPipe( address,
                                                   lpEndpointDescriptor,

⌨️ 快捷键说明

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