📄 hwctxt.h
字号:
#pragma once
// -----------------------------------------------------------------------------
//
// 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.
// Copyright (c) 1995-2000 Microsoft Corporation. All rights reserved.
//
// -----------------------------------------------------------------------------
/*
** INTEL CONFIDENTIAL
** Copyright 2000-2003 Intel Corporation All Rights Reserved.
**
** The source code contained or described herein and all documents
** related to the source code (Material) are owned by Intel Corporation
** or its suppliers or licensors. Title to the Material remains with
** Intel Corporation or its suppliers and licensors. The Material contains
** trade secrets and proprietary and confidential information of Intel
** or its suppliers and licensors. The Material is protected by worldwide
** copyright and trade secret laws and treaty provisions. No part of the
** Material may be used, copied, reproduced, modified, published, uploaded,
** posted, transmitted, distributed, or disclosed in any way without Intel抯
** prior express written permission.
** No 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. Any license under such intellectual property rights
** must be express and approved by Intel in writing.
*/
#include <oalintr.h>
#include <gpio.h>
#include <bvd1.h>
#include <bvd1bd.h>
#include "ac97.h"
#define OUTCHANNELS (2)
#define BITSPERSAMPLE (16)
//#define SAMPLERATE (44100)
//#define SAMPLERATE (11025)
#define SAMPLERATE (22050)
// 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_DMA_PAGE_SIZE AUDIO_BUFFER_SIZE * 4
#define AUDIO_DMA_NUMBER_PAGES 2
class HardwareContext
{
public:
BOOL m_Sleeping;
BOOL m_InPowerHandler; // Must be public so wavemain can control value.
static BOOL CreateHWContext(DWORD Index);
HardwareContext();
~HardwareContext();
void Lock() {EnterCriticalSection(&m_Lock);}
void Unlock() {LeaveCriticalSection(&m_Lock);}
void HardwareContext::ClearDmac( );
short int MsgWriteAC97(DWORD dwParam1,DWORD dwParam2);
short int MsgReadAC97(DWORD dwParam1,DWORD dwParam2);
DWORD GetNumInputDevices() {return 1;}
DWORD GetNumOutputDevices() {return 1;}
short int SafeWriteAC97(BYTE Offset, unsigned short int Data, BYTE DevId);
short int SafeReadAC97(BYTE Offset, unsigned short int * Data, BYTE DevId);
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
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
void InputInterruptThread(); //handle interrupts from recording DMA
void OutputInterruptThread(); //handle interrupts from playback DMA
DWORD ForceSpeaker (BOOL bSpeaker);
BOOL SetCfgHeadSet();
BOOL SetCfgHandSet();
BOOL SetCfgSpeakerPhone();
BOOL SetCfgCarKit();
BOOL SetCfgNone();
protected:
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;
volatile BLR_REGS *m_vpBLReg;
/*
volatile DMADescriptorChannelType *m_vpAudioRcvA; // Audio recieve buffer A 128 bits (16 byte aligned)
volatile DMADescriptorChannelType *m_vpAudioRcvB; // Audio recieve buffer B 128 bits (16 byte aligned)
volatile DMADescriptorChannelType *m_vpAudioXmitA; // Audio transmit buffer A 128 bits (16 byte aligned)
volatile DMADescriptorChannelType *m_vpAudioXmitB; // Audio transmit buffer B 128 bits (16 byte aligned)
volatile DMADescriptorChannelType *m_vpAudioMicA; // Audio Microphone buffer A 128 bits (16 byte aligned)
volatile DMADescriptorChannelType *m_vpAudioMicB; // Audio Microphone buffer B 128 bits (16 byte aligned)
*/
BOOL InitInterruptThread();
void InitInputDMA();
void InitOutputDMA();
void InitCodec();
PVOID MapRegisters(PVOID pBase, DWORD dwSize);
void UnmapRegisters(PVOID pReg, DWORD dwSize);
BOOL MapDMABuffers();
ULONG TransferInputBuffer(ULONG NumBuf);
ULONG TransferOutputBuffer(ULONG NumBuf);
ULONG TransferInputBuffers(DWORD dwDCSR);
ULONG TransferOutputBuffers(DWORD dwDCSR);
//AUDIO_STATE GetInterruptType( VOID );
void HardwareContext::DumpDmacRegs();
DWORD GetInterruptThreadPriority();
DWORD m_DriverIndex;
CRITICAL_SECTION m_Lock;
BOOL m_Initialized;
DWORD m_IntrAudio;
volatile struct _DRIVER_GLOBALS *m_pDriverGlobals; // Driver Globals
//volatile struct mcpreg *m_pMCPRegisters; // xsc Registers for accessing UCB1200
XLLP_GPIO_T *m_pGPIORegisters; // xsc GPIO Registers
volatile struct OST_REGS *m_pOSTimer; // xsc OS Timer Registers
volatile DMAC_REGS *m_pDMARegisters; // xsc DMA Registers
volatile struct INTC_REGS *m_pInterruptController; // xsc Interrupt Controller Registers
volatile AC97_REGS *m_pAc97regs;
InputDeviceContext m_InputDeviceContext;
OutputDeviceContext m_OutputDeviceContext;
PBYTE m_Input_pbDMA_PAGES[AUDIO_DMA_NUMBER_PAGES];
PBYTE m_Output_pbDMA_PAGES[AUDIO_DMA_NUMBER_PAGES];
BOOL m_InputDMARunning;
BOOL m_OutputDMARunning;
ULONG m_OutBytes[AUDIO_DMA_NUMBER_PAGES];
ULONG m_InBytes[AUDIO_DMA_NUMBER_PAGES];
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.
HANDLE hOutputIntEvent;
HANDLE hInputIntEvent;
HANDLE m_hAudioOutputInterruptThread;
HANDLE m_hAudioInputInterruptThread;
LONG m_NumForcedSpeaker;
void SetSpeakerEnable(BOOL bEnable);
void RecalcSpeakerEnable();
private:
volatile ULONG v_nNextPage[2];
BOOL TestAcLink();
BOOL FillOutputDescriptors();
BOOL FillInputDescriptors();
BOOL AC97SetSampleRate(unsigned short int SampleRate, WAPI_INOUT apidir );
BOOL StopDmac(int Channel);
};
void CallInputInterruptThread(HardwareContext *pHWContext);
void CallOutputInterruptThread(HardwareContext *pHWContext);
extern HardwareContext *g_pHWContext;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -