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

📄 hwctxt.h

📁 realtek562x系列驱动源码。wince
💻 H
字号:
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this sample source code is subject to the terms of the Microsoft
// license agreement under which you licensed this sample source code. If
// you did not accept the terms of the license agreement, you are not
// authorized to use this sample source code. For the terms of the license,
// please see the license agreement between you and Microsoft or, if applicable,
// see the LICENSE.RTF on your install media or the root of your tools installation.
// THE SAMPLE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES.
//
/* 
** Copyright 2000-2003 Intel Corporation All Rights Reserved.
**
** Portions of the source code contained or described herein and all documents
** related to such source code (Material) are owned by Intel Corporation
** or its suppliers or licensors and is licensed by Microsoft Corporation for distribution.  
** Title to the Material remains with Intel Corporation or its suppliers and licensors. 
** Use of the Materials is subject to the terms of the Microsoft license agreement which accompanied the Materials.  
** No other license under any patent, copyright, trade secret or other intellectual
** property right is granted to or conferred upon you by disclosure or
** delivery of the Materials, either expressly, by implication, inducement,
** estoppel or otherwise 
** Some portion of the Materials may be copyrighted by Microsoft Corporation.
*/
#pragma once


#include <ceddk.h>

#if USE_I2S_INTERFACE

#include <xllp_i2s.h>

#else

#include <xllp_ac97.h>

#endif

#include <xllp_dmac.h>
#include <bulverde.h>
#include "mainstoneii.h"

#define OUTCHANNELS (2)
#define BITSPERSAMPLE (16)
#define SAMPLERATE  (44100)

// Inverse sample rate, in .32 fixed format, with 1 added at bottom to ensure round up.
#define INVSAMPLERATE ((UINT32)(((1i64<<32)/SAMPLERATE)+1))

typedef INT16 HWSAMPLE;
typedef HWSAMPLE *PHWSAMPLE;

// Set USE_MIX_SATURATE to 1 if you want the mixing code to guard against saturation
// This costs a couple of instructions in the inner loop
#define USE_MIX_SATURATE (1)
// The code will use the follwing values as saturation points
#define AUDIO_SAMPLE_MAX    (32767)
#define AUDIO_SAMPLE_MIN    (-32768)

#define AUDIO_BUFFER_SIZE       0x1F80
#define AUDIO_DMA_PAGE_SIZE     AUDIO_BUFFER_SIZE * 4
#define AUDIO_DMA_NUMBER_PAGES  2
#define NUM_DMA_AUDIO_BUFFERS   4

class HardwareContext
{
public:
    BOOL m_Sleeping;
    BOOL m_InPowerHandler; // Must be public so wavemain can control value.
    
	DECLARE_RT_CODEC_CLASS

	DWORD RT_AudioMessage(UINT uMsg,DWORD dwParam1,DWORD dwParam2);
	void OSTDelayMilliSecTime(XLLP_UINT32_T MilliSec);
	
    static BOOL CreateHWContext(DWORD Index);
    HardwareContext();
    ~HardwareContext();

    void Lock()   {EnterCriticalSection(&m_Lock);}
    void Unlock() {LeaveCriticalSection(&m_Lock);}

    short int MsgWriteCodec(DWORD dwParam1,DWORD dwParam2);
    short int MsgReadCodec(DWORD dwParam1,DWORD dwParam2);

    BOOL SafeWriteCodec(BYTE Offset, unsigned short int Data, BYTE DevId);
    BOOL SafeReadCodec(BYTE Offset, unsigned short int * Data, BYTE DevId);

    DWORD GetNumInputDevices()  {return 1;}
    DWORD GetNumOutputDevices() {return 1;}

    DeviceContext *GetInputDeviceContext(UINT DeviceId)
    {
        return &m_InputDeviceContext;
    }

    DeviceContext *GetOutputDeviceContext(UINT DeviceId)
    {
        return &m_OutputDeviceContext;
    }

    BOOL Init(DWORD Index);  //setup the device so it can render quickly
    BOOL Deinit();           //completely disconnect the device, return GPIOs, etc

    void PowerUp();          //bring device quickly out of a low power state
    void PowerDown();        //put the device in a low power state capable of quick wake

    CEDEVICE_POWER_STATE GetPowerState(void);
    BOOL QueryPowerState(CEDEVICE_POWER_STATE dwState);
    DWORD SetPowerState(CEDEVICE_POWER_STATE dwState);
    void  GetPowerCapabilities(void * pBuf);

    void StartInputDMA();    //setup the DMAC for input
    void StartOutputDMA();   //setup the DMAC for output

    void StopInputDMA();     //return DMAC to a quiet state
    void StopOutputDMA();    //return DMAC to a quiet state

    void InterruptThread();          //handle interrupts from the audio controller, DMA, or codec

    DWORD ForceSpeaker (BOOL bSpeaker);

    BOOL SetCfgHeadSet();
    BOOL SetCfgHandSet();
    BOOL SetCfgSpeakerPhone();
    BOOL SetCfgCarKit();
    BOOL SetCfgNone();

protected:

    CEDEVICE_POWER_STATE m_dwPowerState;

    unsigned int m_ResetCaps; //HACK: If 0x2a0 it's rev 2a, if its 0x2a then its rev 1b 
    unsigned int m_CodecType;
    
    DWORD m_MicrophoneRouting;
    DWORD m_SpeakerRouting;
    DWORD m_InternalRouting;
    DWORD m_MasterOutputGain;


    void InitInputDMA();
    void InitOutputDMA();

    BOOL MapDMABuffers();

    ULONG TransferInputBuffer(ULONG NumBuf);
    ULONG TransferOutputBuffer(ULONG NumBuf);
        
    void DumpDmacRegs();

    DWORD GetInterruptThreadPriority();
    void HandleAudioInterrupt();

    DWORD m_DriverIndex;
    CRITICAL_SECTION m_Lock;

    BOOL   m_Initialized;
    DWORD  m_SysIntrAudioDMA;                 // audio SysIntr for the shared DMA interrupt
    HANDLE m_hDMAIsrHandler;

    volatile    XLLP_GPIO_T             *m_pGPIORegisters;       // xsc GPIO Registers
    volatile    XLLP_OST_T              *m_pOSTimer;             // xsc OS Timer Registers
    volatile    BULVERDE_DMA_REG        *m_pDMARegisters;        // xsc DMA Registers

#if USE_I2S_INTERFACE

	volatile 	XLLP_I2S_T  			*m_pI2SRegs; 
    

#else

	volatile    XLLP_AC97_T             *m_pAc97regs;

#endif

    volatile    XLLP_CLKMGR_T           *m_pClockRegs;
    volatile    MAINSTONEII_BLR_REGS    *m_vpBLReg;
    
    InputDeviceContext m_InputDeviceContext;
    OutputDeviceContext m_OutputDeviceContext;

    PBYTE m_Input_pbDMA_PAGES[AUDIO_DMA_NUMBER_PAGES];
    PBYTE m_Output_pbDMA_PAGES[AUDIO_DMA_NUMBER_PAGES];
    PBYTE m_Input_pbDMA_PAGES_Physical[AUDIO_DMA_NUMBER_PAGES];
    PBYTE m_Output_pbDMA_PAGES_Physical[AUDIO_DMA_NUMBER_PAGES];

    BOOL m_InputDMARunning;
    BOOL m_OutputDMARunning;
    BOOL m_saveOutputDMARunning;
    BOOL m_saveInputDMARunning;

    XLLP_DMAC_CHANNEL_T  m_PlaybackChannel;  // DMA_CH_OUT
    XLLP_DMAC_CHANNEL_T  m_RecordingChannel; // DMA_CH_RCV

    ULONG m_nVolume;        // Current HW Playback Volume (should be in device context??)

    HANDLE m_hAudioInterrupt;          // Handle to Audio Interrupt event.
    HANDLE m_hAudioInterruptThread;    // Handle to thread which waits on an audio interrupt event.
  
    LONG m_NumForcedSpeaker;
    void SetSpeakerEnable(BOOL bEnable);
    void RecalcSpeakerEnable();

private:

    BOOL m_audioDeinit;
    BOOL m_fOutputRenderMonoOnly;

    // Audio transmit buffers 128 bits (16 byte aligned)
    volatile DMADescriptorChannelType *m_vpAudioXmitA;          // Audio transmit buffer A
    volatile DMADescriptorChannelType *m_vpAudioXmitB;          // Audio transmit buffer B
    volatile DMADescriptorChannelType *m_vpAudioRcvA;           // Audio transmit buffer A
    volatile DMADescriptorChannelType *m_vpAudioRcvB;           // Audio transmit buffer B
    volatile DMADescriptorChannelType *m_vpAudioXmitA_Physical; // Audio transmit buffer A
    volatile DMADescriptorChannelType *m_vpAudioXmitB_Physical; // Audio transmit buffer B
    volatile DMADescriptorChannelType *m_vpAudioRcvA_Physical;  // Audio transmit buffer A
    volatile DMADescriptorChannelType *m_vpAudioRcvB_Physical;  // Audio transmit buffer B

    BOOL GetRegKeys();
    
#if !USE_I2S_INTERFACE

    BOOL TestAcLink();
    
#endif

    BOOL SetSampleRate(unsigned short int SampleRate, WAPI_INOUT apidir );
    int  GetNextOutputBuffer(void);
    int  GetLastInputBuffer(void);
    BOOL FillOutputDescriptors();
    BOOL FillInputDescriptors();
    void StopDmac(int Channel);
    void ClearDmac(int Channel);
    BOOL MapDMADescriptors(void);
    BOOL MapDeviceRegisters(void);
    BOOL InitAudioDMA(void);
    void UnMapDeviceRegisters(void);
    void DeinitAudioDMA(void);
    void UnmapDMA(void);
    void InitCodec(void);
    void DeInitCodec(void);

};

extern HardwareContext *g_pHWContext;

⌨️ 快捷键说明

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