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

📄 device.cpp

📁 完整的基于Conxant平台的USB电视棒的WIN驱动程序。
💻 CPP
📖 第 1 页 / 共 5 页
字号:
/*+++ *******************************************************************\ 
* 
* Copyright and Disclaimer: 
* 
* --------------------------------------------------------------- 
* This software is provided "AS IS" without warranty of any kind, 
* either expressed or implied, including but not limited to the 
* implied warranties of noninfringement, merchantability and/or 
* fitness for a particular purpose.
* --------------------------------------------------------------- 
* 
* Copyright (c) 2008 Conexant Systems, Inc. 
* All rights reserved. 
*
\******************************************************************* ---*/ 

#include "Device.h"
#include "RegistryAccess.h"
#include "I2CIF.h"
#include "FormatData.h"
#include "debug.h"
#include "capturefilter.h"
#include "main.h"

#include "crossbarprop.h"
#include "crossbarfilter.h"
#include "TvAudioFilter.h"

#include "ITunerProperties.h"
#include "SidewinderTunerProp.h"
#include "tunerfilter.h"
#include "BdaTunerFilter.h"
#include "GenTunerDemod.h"
#include "GenSiTuner.h"

#include "thresher.h"
#include "Merlin.h"
#include "DirectIF.h"
#include "miscfuncs.h"
#include "pindataranges.h"
#include "SyncRegIo.h"

#include "DriverI2C.h"
#include "IDataTransfer.h"

#include "cusbintf.h"
#include "PolarisUsbInterface.h"
#include "pcbconfig.h"
#include "Polaris_GPIOPin.h"

#include "ir_control.h"
#include "ResetIF.h"
#include "Colibri.h"
#include "Flatrion.h"

#include "DeviceGuid.h"

#define PWR_SLEEP_INTERVAL 5

LONG g_debug_level = 2;
BOOL g_break_on_error = FALSE;
LONG g_medium_instance_id = 0;

const DWORD NTSCASPECT_ANALOG_VIDEO_STANDARDS = KS_AnalogVideo_NTSC_M   |
KS_AnalogVideo_NTSC_M_J |
KS_AnalogVideo_PAL_M;

Device::Device(PKSDEVICE p_ks_dev):
_p_ks_dev           (p_ks_dev),
_running_streams    (DEVICE_STREAM_NONE),
_disable_VBI        (0),
_p_decoder          (NULL),
_p_audio            (NULL),
_inited             (FALSE),
_p_crossbar_properties(NULL),
_p_tuner_properties	(NULL),
_power_state        (PowerDeviceD0),
_p_capture_filter_factory(NULL),
_initialization_thread_object(NULL),
_p_sync_registers   (NULL),
_p_copy_protect     (NULL),
_p_usb              (NULL),
_p_usb_firmware     (NULL),
_p_usb_i2c_interface(NULL),
_p_i2c_0            (NULL),
_p_i2c_1            (NULL),
_p_i2c_2            (NULL),
_p_DigitalI2C       (NULL),
_p_AnalogI2C        (NULL),
_p_video_transfer   (NULL),
_p_audio_transfer   (NULL),
_p_vbi_transfer     (NULL),
_p_sliced_cc_transfer(NULL),
_p_ts1_transfer     (NULL),
_p_ts2_transfer     (NULL),
_p_current_config   (NULL),
_usb_speed          (FULL_SPEED),
_device_closing     (FALSE),
_current_graph_mode (GRAPH_MODE_UNASSIGNED),
_fwload_thread_active(FALSE),
_p_filter_template  (NULL),
_current_config_num (NOT_SUPPORTED),
_p_DIF              (NULL),
_p_colibri          (NULL),
_p_flatrion         (NULL),
_p_bda_tuner        (NULL),
_p_ir_control       (NULL),
_p_GPIOPin          (NULL),
_vbi_pin_index      (CAPTURE_FILTER_VIDEO_OUT + 2),  // default with the audio out pin
_bSurpriseRemoval(FALSE),
_tuner_instance(0),
_reset_digital_frequency(TRUE),
_bda_tuner_power_up_pending(TRUE),
_i2c_speed(I2C_SPEED_400K),
_enable_bda(FALSE),
_enable_soft_encoder(FALSE),
_current_video_alt(0),
_current_audio_alt(0),
_current_VANC_alt(0),
_current_HANC_alt(0),
_current_TS1_alt(0),
_current_TS2_alt(0),
_polaris_rev_id(POLARIS_REVID_INVALID),
_config_changed(0),
_is_TS_configuration(FALSE),
_usb_type(USB_BUS_POWER),
_power_mode(POLARIS_AVMODE_DEFAULT)
{
    //initialize mutex
    KeInitializeMutex(&_stream_control_mutex, 0);
    KeInitializeMutex(&_tuner_mutex, 0);

    RegistryAccess registry(_p_ks_dev->PhysicalDeviceObject);

    _medium_instance_id = InterlockedIncrement(&g_medium_instance_id);
    KeInitializeEvent(&_hw_init_event, NotificationEvent, TRUE);
    KeClearEvent(&_hw_init_event);

    //Register device Pnp interface when device is being created
    RegisterPnpInterface();

}

/////////////////////////////////////////////////////////////////////////////////////////
Device::~Device()
{
    DbgLogInfo(("Device : ~Device\n"));
    if(_inited)
    {
        DbgLogInfo(("Device : CleanUp\n"));
        unInit();
    }
}

// Initialize any Hammerhead registers after object creation
// I2C and interrupts allowed


/////////////////////////////////////////////////////////////////////////////////////////
NTSTATUS Device::dispatchCreate(PKSDEVICE p_ks_dev)
{
    p_ks_dev->Context = new Device( p_ks_dev );

    if( !p_ks_dev->Context )
        return STATUS_INSUFFICIENT_RESOURCES;

    return STATUS_SUCCESS;
}


/////////////////////////////////////////////////////////////////////////////////////////
NTSTATUS Device::dispatchPnpStart(
                                KSDEVICE         *p_ks_dev,
                                IRP              *p_irp,
                                CM_RESOURCE_LIST *p_trans_res_list,
                                CM_RESOURCE_LIST *p_raw_res_list)
{
    PKSFILTERFACTORY p_ks_filter_factory = NULL;
    NTSTATUS status = STATUS_SUCCESS;

    DbgLogInfo(("Device::dispatchPnpStart : Build: %s , %s\n",__DATE__,__TIME__));

    if(p_ks_dev)
    {
        if(!NT_SUCCESS(status = (reinterpret_cast<Device*>( p_ks_dev->Context ))->
		init( p_trans_res_list ) ))
        {
             DbgLogInfo(("Device:dispatchPnpStart : Failed to init resource list\n"));
             return status;
        }       

        UNREFERENCED_PARAMETER(p_irp);
        UNREFERENCED_PARAMETER(p_trans_res_list);
        UNREFERENCED_PARAMETER(p_raw_res_list);
    }
    else
    {
        return STATUS_INSUFFICIENT_RESOURCES;
    }

    return STATUS_SUCCESS;
}

/////////////////////////////////////////////////////////////////////////////////////////
VOID Device::dispatchPnpStop(
                             KSDEVICE *p_ks_dev,
                             IRP      *p_irp)
{
    DbgLogInfo(("Device::dispatchPnpStop\n"));
    return (reinterpret_cast<Device*>( p_ks_dev->Context ))->
        unInit();
}

/////////////////////////////////////////////////////////////////////////////////////////
VOID Device::dispatchPnpSurpriseRemoval(
                                        KSDEVICE *p_ks_dev,
                                        IRP      *p_irp)
{
    DbgLogInfo(("Device::dispatchPnpSurpriseRemoval \n"));

    Device* p_device = reinterpret_cast<Device *>(p_ks_dev->Context);
    if(!p_device)
    {
        return;
    }

    int i=0;     
    //Stop all streaming pins by enumerate all pin types(video/audio/vbi .etc)
    //This process applies to any case of combination of DVT/EVK and T0/A0
    for(i=0;i<PIN_TYPE_MAX_NUM;i++)       
    {
        if(p_device->_p_pins_with_resources[i])
        {            
            if(p_device->IsPinStreaming((PIN_TYPES)i))
            {
                p_device->stop(p_device->_p_pins_with_resources[i]);
            }            
        }
    }
    
    p_device->EnableEepromI2C();

    //Disable Pnp interface
    p_device->EnablePnpInterface(FALSE);

    p_device->_bSurpriseRemoval = TRUE;
    if(p_device->_p_usb)
    {
        p_device->_p_usb->SetSurpriseRemovalFlag(TRUE);
    }
}

/////////////////////////////////////////////////////////////////////////////////////////
VOID Device::dispatchRemove(
                            KSDEVICE *p_ks_dev,
                            IRP      *p_irp)
{
    DbgLogInfo(("Device::dispatchRemove\n"));

    //Disable device Pnp interface
    reinterpret_cast<Device*>( p_ks_dev->Context )->EnablePnpInterface(FALSE);

    delete reinterpret_cast<Device*>( p_ks_dev->Context );
    p_ks_dev->Context = NULL;
}

/////////////////////////////////////////////////////////////////////////////////////////
NTSTATUS Device::dispatchQueryPower(
                                    KSDEVICE           *p_ks_dev,
                                    IRP                *p_irp,
                                    DEVICE_POWER_STATE  dev_to,
                                    DEVICE_POWER_STATE  dev_from,
                                    SYSTEM_POWER_STATE  sys_to,
                                    SYSTEM_POWER_STATE  sys_from,
                                    POWER_ACTION        action)
{
    PIO_STACK_LOCATION pIOStack = IoGetCurrentIrpStackLocation(p_irp);
    if (pIOStack->Parameters.Power.Type == SystemPowerState)
    {
        return STATUS_SUCCESS;
    }

    if(dev_to != PowerDeviceD0 && dev_to != PowerDeviceD3 && dev_to != PowerDeviceD2)
    {
        return STATUS_NOT_SUPPORTED;
    }

    Device* p_device = (Device*)p_ks_dev->Context;

    if( p_device->_running_streams!=DEVICE_STREAM_NONE )
    {
        return STATUS_INVALID_DEVICE_STATE;
    }

    return STATUS_SUCCESS;
}

/////////////////////////////////////////////////////////////////////////////////////////
VOID Device::powerDown()
{
    KeClearEvent(&_hw_init_event);  
    if(_p_copy_protect)
    {
        _p_copy_protect->stopCpThread();
    }

    if(_p_tuner_properties)
    {
        _p_tuner_properties->powerDown();
    }
    
    if(_p_bda_tuner)
    {
        _p_bda_tuner->bdaTuner_powerDown();
    }
    
    if(_p_flatrion)
    {
        _p_flatrion->powerDown();
    }
    
    if(_p_colibri)
    {
        _p_colibri->powerDown();
    }
    
    if(_p_DIF)
    {
        
        _p_DIF->powerDown();
    }
    
    if(_p_decoder)
    {
        _p_decoder->powerDown();
    }
    
    if(_p_audio)
    {
        _p_audio->powerDown();
    }

    DWORD revID = getRevID();    
    if(revID >=POLARIS_REVID_A0)
    {
        powerSuspend();
    }
    
    if(_p_usb_firmware)
    {
        _p_usb_firmware->powerDown();
        _p_usb_firmware->Release();
    }
    
    if(_p_usb)
    {
        _p_usb->Release();
    }

}


VOID Device::powerUpModule(AV_MODE power_mode)
{
    switch(power_mode)
    {
    case POLARIS_AVMODE_ENXTERNAL_AV:
        
        if(_p_flatrion)
        {
            _p_flatrion->powerUp();
        }
        
        if(_p_decoder)
        {
            _p_decoder->powerUp();  
        }
        
        if(_p_audio)
        {
            _p_audio->powerUp();
        }  
        
        if ( ! _disable_audio_out_pin )
        {
            _p_audio->initialize();
        }
        
        break;
        
    case POLARIS_AVMODE_ANALOGT_TV:
        
        if(_p_decoder)
        {
            _p_decoder->powerUp();  
        }
        
        if(_p_audio)
        {
            _p_audio->powerUp();
        }  
        
        if ( ! _disable_audio_out_pin )
        {
            _p_audio->initialize();
        }
        
        if(_p_tuner_properties)
        {
            _p_tuner_properties->powerUp();
        } 
        break;
        
        
    case POLARIS_AVMODE_DIGITAL:
        
        //enable merlin to load its firmware
        setPowerMode(POLARIS_AVMODE_ENXTERNAL_AV);
        
        if ( ! _disable_audio_out_pin )
        {
            _p_audio->initialize();
        }
        
        setPowerMode(POLARIS_AVMODE_DIGITAL);

⌨️ 快捷键说明

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