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

📄 hwctxt.cpp

📁 Xcale270Bsp包,wince平台
💻 CPP
📖 第 1 页 / 共 4 页
字号:
// -----------------------------------------------------------------------------
//
//      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 <windows.h>
#include <types.h>
#include <memory.h>
#include <excpt.h>
#include <wavepdd.h>
#include <waveddsi.h>
#include <wavedbg.h>
#include <nkintr.h>
#include <ceddk.h>
//$$#include "oalintr.h"
#ifdef __cplusplus
extern "C"{
#endif 

#include "xllp_dmac.h"

#ifdef __cplusplus
}
#endif 

#include "wavemain.h"
#include <gpio.h>
#include <bvd1.h>
#include <bvd1bd.h>
#include "ac97.h"
#include "aclinkcontrol.h"
#include "xllp_defs.h"
#include "dmac.h"
#include <drv_glob.h>
#include <memdefs.h>

HardwareContext *g_pHWContext=NULL;
//$$							PASS:	imp	tst	HWExcel
//outline of functions:
//HardwareContext::Init(DWORD Index)	x	x
//      MapRegisters()					x   f
//		MapDMABuffers()					x	x				
//		InitInterruptThread()			x   x
//		InitCodec()						x   x
//		InitInputDMA();                 x   x
//		InitOutputDMA();				x   x
//HardwareContext::GetInterruptType		x	x	
//		TransferInputBuffers()          x	x
//		TransferOutputBuffers()         x	x
//		StopInputDMA()                  x	x
//		StopStopOutputDMA               x	x
//		DumpDmacRegs					x	x	
//HardwareContext::StartOutputDMA		x	x
//		TransferOutputBuffers           x	x
//		AC97SetSampleRate               x	x
//HardwareContext::StopOutputDMA		x	x
//		StopDmac                        x   x



//static PBYTE  Output_pbDMA_PAGES[AUDIO_DMA_NUMBER_PAGES];
//static PBYTE  Input_pbDMA_PAGES[AUDIO_DMA_NUMBER_PAGES];
static ULONG  dma_page_size = AUDIO_BUFFER_SIZE;
//static ULONG  dma_buffer_size;
volatile static ULONG   v_nNextPage[2];
volatile DMADescriptorChannelType *m_vpAudioXmitA=NULL; //	Audio transmit buffer A		128 bits (16 byte aligned)
volatile DMADescriptorChannelType *m_vpAudioXmitB=NULL; //	Audio transmit buffer B		128 bits (16 byte aligned)
volatile DMADescriptorChannelType *m_vpAudioRcvA=NULL; //	Audio transmit buffer A		128 bits (16 byte aligned)
volatile DMADescriptorChannelType *m_vpAudioRcvB=NULL; //	Audio transmit buffer B		128 bits (16 byte aligned)
const short MySineWave[164] = {0, 0, 1285, 2563, 2563, 5063, 3825, 7438, 5063, 9630, 6270, 11585, 7438, 13255, 8561, 14598, 9630, 15582, 10641, 16182, 11585, 16384, 12458, 16182, 13255, 15582, 13970, 14598, 14598, 13255, 15137, 11585, 15582, 9630, 15931, 7438, 16182, 5063, 16333, 2563, 16384, 0, 16333, -2563, 16182, -5063, 15931, -7438, 15582, -9630, 15137, -11585, 14598, -13255, 13970, -14598, 13255, -15582, 12458, -16182, 11585, -16384, 10641, -16182, 9630, -15582, 8561, -14598, 7438, -13255, 6270, -11585, 5063, -9630, 3825, -7438, 2563, -5063, 1285, -2563, 0, 0, -1285, 2563, -2563, 5063, -3825, 7438, -5063, 9630, -6270, 11585, -7438, 13255, -8561, 14598, -9630, 15582, -10641, 16182, -11585, 16384, -12458, 16182, -13255, 15582, -13970, 14598, -14598, 13255, -15137, 11585, -15582, 9630, -15931, 7438, -16182, 5063, -16333, 2563, -16384, 0, -16333, -2563, -16182, -5063, -15931, -7438, -15582, -9630, -15137, -11585, -14598, -13255, -13970, -14598, -13255, -15582, -12458, -16182, -11585, -16384, -10641, -16182, -9630, -15582, -8561, -14598, -7438, -13255, -6270, -11585, -5063, -9630, -3825, -7438, -2563, -5063, -1285, -2563, 0, 0};
volatile DMA_GLOBALS  *pDMAGlobals = NULL;

#ifdef __cplusplus
extern "C"{
#endif 
//---------------------------------------------------------------------------
//These functions below are part of our Driver Lib
//---------------------------------------------------------------------------
//TODO: These should be XLLP funcitons
BOOL set_BCRVal(unsigned my_bcrSetBits, unsigned my_bcrClrBits, BOOL inpowerhandler);
extern PVOID VirtualAllocCopy(unsigned size,char *str,PVOID pVirtualAddress);
extern void DelayInit(void);
//extern XLLP_STATUS_T  XllpDmacAllocChannel(P_XLLP_DMAC_CHANNEL_T pChannel, XLLP_DMAC_CHANNEL_PRIORITY_T aChannelPriority);
extern XLLP_STATUS_T	XllpDmacInit(void); 

short int AC97GpioUnConfigure(volatile XLLP_GPIO_T *, BOOL, BYTE );
short int AC97GpioConfigure(volatile XLLP_GPIO_T *, BOOL, BYTE );

short int WriteAC97(BYTE Offset, unsigned short int Data, BYTE DevId);
short int ReadAC97(BYTE Offset, unsigned short int * Data, BYTE DevId);
short int RawAC97Write(BYTE Offset, unsigned short int Data, BYTE DevId);
short int RawAC97Read(BYTE Offset, unsigned short int * Data, BYTE DevId);
short int AllocAcLink(BYTE);
//short int InitAcLink(volatile XLLP_GPIO_T *, BOOL, BYTE );
//short int DeInitAcLink(volatile XLLP_GPIO_T *, BOOL, BYTE);
short int Ac97ColdReset();
short int DeAllocAcLink(BYTE DevId);
const ULONG g_dma_buffer_size = AUDIO_BUFFER_SIZE;

XLLP_DMAC_CHANNEL_T  PlaybackChannel, RecordingChannel;


	

		
//void usWait(unsigned usVal);
//void msWait(unsigned msVal);
//---------------------------------------------------------------------------
// driver lib functions above
//---------------------------------------------------------------------------
#ifdef __cplusplus
}
#endif 



DBGPARAM dpCurSettings = {
    TEXT("UCB1400")
	, {
		 TEXT("Test")
		,TEXT("Params")
		,TEXT("Verbose")
		,TEXT("Interrupt")
		,TEXT("WODM")
		,TEXT("WIDM")
		,TEXT("PDD")
		,TEXT("MDD")
		,TEXT("8")
		,TEXT("Misc")
		,TEXT("10")
		,TEXT("IOcontrol")
		,TEXT("Alloc")
		,TEXT("Function")
		,TEXT("Warning")
		,TEXT("Error")
	}
	, 0xFFFF
};


BOOL HardwareContext::CreateHWContext(DWORD Index)
{
	FUNC_WPDD("+HardwareContext::CreateHWContext");
	//if the hardware context exists then don't init again
    if (g_pHWContext)
    {
        return TRUE;
    }

    g_pHWContext = new HardwareContext;
    if (!g_pHWContext)
    {
        return FALSE;  //oops we should have not be null
    }

	FUNC_WPDD("-HardwareContext::CreateHWContext");

    return g_pHWContext->Init(Index);
}

HardwareContext::HardwareContext(): m_InputDeviceContext(), m_OutputDeviceContext()
{
    InitializeCriticalSection(&m_Lock);  //some code is not reentrant
    m_Initialized=FALSE;  //we are just getting started, we are not initialized yet
}

HardwareContext::~HardwareContext()
{
    DeleteCriticalSection(&m_Lock);		//we're going down, clean up semiphore
}



BOOL HardwareContext::Init(DWORD Index)
{
	FUNC_WPDD("+HardwareContext::Init");

	//initialize the hardware, bring it up to a state ready for quick rendering of 
	//audio streams and UI sounds
    m_DriverIndex = Index;
    m_IntrAudio         = SYSINTR_AUDIO;
    m_InPowerHandler    = FALSE;
    m_InputDMARunning   = FALSE;
    m_OutputDMARunning  = FALSE;
    m_NumForcedSpeaker  = 0;
	m_Sleeping=FALSE;

	//
    // Map hardware registers into driver space
    //
    //
    m_pDriverGlobals =       (struct _DRIVER_GLOBALS *)MapRegisters((PVOID)DRIVER_GLOBALS_PHYSICAL_MEMORY_START, sizeof(*m_pDriverGlobals));
    //m_pMCPRegisters  =       (struct mcpreg          *)MapRegisters((PVOID)MCP_BASE,  sizeof(*m_pMCPRegisters));
    m_pGPIORegisters =       (XLLP_GPIO_T         *)MapRegisters((PVOID)GPIO_BASE_U_VIRTUAL, sizeof(*m_pGPIORegisters));
    //m_pOSTimer       =       (struct OST_REGS          *)MapRegisters((PVOID)OST_BASE_U_VIRTUAL,  sizeof(*m_pOSTimer));
    m_pDMARegisters  =       (volatile DMAC_REGS          *)MapRegisters((PVOID)DMAC_BASE_U_VIRTUAL, sizeof(*m_pDMARegisters));
    //m_pInterruptController = (struct IC_REGS           *)MapRegisters((PVOID)IC_BASE_U_VIRTUAL, sizeof(*m_pInterruptController));
	m_pAc97regs=       (volatile AC97_REGS          *)MapRegisters((PVOID)AC97_BASE_U_VIRTUAL, sizeof(*m_pAc97regs));

	pDMAGlobals = (volatile DMA_GLOBALS *)MapRegisters((PVOID)GDE_BUFFER_VIRTUAL, sizeof(*m_pDMARegisters));

	//#ifdef PLAT_LUBBOCK
	m_vpBLReg  = (volatile BLR_REGS *)					 MapRegisters((PVOID)FPGA_REGS_BASE_U_VIRTUAL,    sizeof(*m_vpBLReg));
//#endif


	XllpDmacInit();
    XllpDmacAllocChannel(&PlaybackChannel, XLLP_DMAC_CHANNEL_PRIORITY_MEDIUM );	
    XllpDmacAllocChannel(&RecordingChannel, XLLP_DMAC_CHANNEL_PRIORITY_MEDIUM);
	m_vpBLReg->hex_led = PlaybackChannel;

    hOutputIntEvent = pDMAGlobals->hDMAEvent[PlaybackChannel];
    hInputIntEvent = pDMAGlobals->hDMAEvent[RecordingChannel];

	if (m_vpAudioXmitA==NULL)
	{
		m_vpAudioXmitA = (DMADescriptorChannelType *)
			VirtualAllocCopy(0x20, "AudioInitialize: VirtualAllocCopy failed XmitA", 
			(PVOID)(DMA_XMIT_A_DESCRIPTOR_BASE_VIRTUAL));

		if (m_vpAudioXmitA == NULL )
		{
			DEBUGMSG(ZONE_ERROR, (TEXT( "AudioInitialize: VirtualAllocCopy failed!\r\n" )) );
			//PddpAudioDeallocateVm();
			return ( FALSE );
		}

	}


	if (m_vpAudioXmitB==NULL)
	{
		m_vpAudioXmitB = (DMADescriptorChannelType *)
			VirtualAllocCopy(0x20, "AudioInitialize: VirtualAllocCopy failed XmitB", 
			(PVOID)(DMA_XMIT_B_DESCRIPTOR_BASE_VIRTUAL));

		if (m_vpAudioXmitB == NULL )
		{
			DEBUGMSG(ZONE_ERROR, (TEXT( "AudioInitialize: VirtualAllocCopy failed!\r\n" )) );
			//PddpAudioDeallocateVm();
			return ( FALSE );
		}

	}

	if (m_vpAudioRcvA==NULL)
	{
		m_vpAudioRcvA  = (DMADescriptorChannelType *)
			VirtualAllocCopy(0x20, "AudioInitialize: VirtualAllocCopy failed RecA", 
			(PVOID)(DMA_RCV_A_DESCRIPTOR_BASE_VIRTUAL));

		if (m_vpAudioRcvA  == NULL )
		{
			DEBUGMSG(ZONE_ERROR, (TEXT( "AudioInitialize: VirtualAllocCopy failed!\r\n" )) );
			//PddpAudioDeallocateVm();
			return ( FALSE );
		}

	}
	if (m_vpAudioRcvB==NULL)
	{
		m_vpAudioRcvB = (DMADescriptorChannelType *)
			VirtualAllocCopy(0x20, "AudioInitialize: VirtualAllocCopy failed RecB", 
			(PVOID)(DMA_RCV_B_DESCRIPTOR_BASE_VIRTUAL));

		if (m_vpAudioRcvB == NULL )
		{
			DEBUGMSG(ZONE_ERROR, (TEXT( "AudioInitialize: VirtualAllocCopy failed!\r\n" )) );
			//PddpAudioDeallocateVm();
			return ( FALSE );
		}

	}

/*
    m_vpAudioXmitA = (volatile DMADescriptorChannelType *)MapRegisters((PVOID)DMA_XMIT_A_BUFFER_BASE_VIRTUAL,sizeof(*m_vpAudioXmitA));
    m_vpAudioXmitB = (volatile DMADescriptorChannelType *)MapRegisters((PVOID)DMA_XMIT_B_BUFFER_BASE_VIRTUAL,sizeof(*m_vpAudioXmitB));
*/
/*volatile DMADescriptorChannelType *v_pAudioRcvB = NULL;  //	Audio recieve buffer B		128 bits (16 byte aligned)
volatile DMADescriptorChannelType *v_pAudioXmitA = NULL; //	Audio transmit buffer A		128 bits (16 byte aligned)
volatile DMADescriptorChannelType *v_pAudioXmitB = NULL; //	Audio transmit buffer B		128 bits (16 byte aligned)
volatile DMADescriptorChannelType *v_pAudioMicA = NULL;  //	Audio Microphone buffer A	128 bits (16 byte aligned)
volatile DMADescriptorChannelType *v_pAudioMicB = NULL;  //	Audio Microphone buffer B	128 bits (16 byte aligned)
*/

	// Map the DMA buffers (and fill the descriptors) into driver's virtual address space
    if (!MapDMABuffers())
    {
        goto Exit;
    }

	//m_vpBLReg->hex_led = 0x97ACFFFC;


    if (!InitInterruptThread())
    {
        goto Exit;
    }


    // Bring up AC-LINK Configure the Codec
    InitCodec();

	//do a quick diag--see if we can read and write registers
	TestAcLink();

	int i,j;
	for (j=0; j<10; j++)
	//	while(1)
	{
		for (i=0; i<=162; i+=2)
		{ 

			while ((m_pGPIORegisters->GPLR0 & (1 << 31)) != (1 << 31)); //freeze until it's high
			while ((m_pGPIORegisters->GPLR0 & (1 << 31)) != 0);        //freez until it goes low
			m_pAc97regs->pcdr = (MySineWave[i] << 16) | MySineWave[i+1] ;
	//		LocReadAC97(0x2,&Data, DEV_AUDIO);
	//		Data = Data | (unsigned short)(0xf << 6);  

	//		EdbgOutputDebugString(" %x ",Data);
		//LocWriteAC97(0x2,Data+1,DEV_AUDIO);  //hp enable

		}
	} 


    // Configure the DMA controller
    InitInputDMA();
    InitOutputDMA();

    m_Initialized=TRUE;

Exit: 

	FUNC_WPDD("-HardwareContext::Init");

	return m_Initialized;
}


BOOL HardwareContext::MapDMABuffers()
{

⌨️ 快捷键说明

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