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

📄 hwctxt.cpp

📁 Xcale270Bsp包,wince平台
💻 CPP
📖 第 1 页 / 共 4 页
字号:
	m_vpAudioRcvA-> dcmd = CmdBuff.DcmdDword ;						             // size and cmd values of the RcvA buffer

	//
	// fill RcvB Descriptor
	//

	m_vpAudioRcvB-> ddadr= DMA_RCV_A_DESCRIPTOR_BASE_PHYSICAL ;   // address of the next (RcvA) descriptor
	m_vpAudioRcvB-> dtadr= DMA_RCV_B_BUFFER_BASE_PHYSICAL;			 // source address of the AC97 RcvB buffer
	m_vpAudioRcvB-> dsadr= DMAC_AC97_AUDIO_RCV_FIFO; 			 // destination address of the RcvB buffer
	m_vpAudioRcvB-> dcmd = CmdBuff.DcmdDword ;						             // size and cmd values of the RcvB buffer

	return TRUE;
}
//------------------------------------------------------------------------------------------------------------
// Function: AC97SetSampleRate
// 
// Purpose: Write the sample rate value to the ac97 codec
//-------------------------------------------------------------------------------------------------------------
BOOL HardwareContext::AC97SetSampleRate(unsigned short int SampleRate, WAPI_INOUT apidir )
{
	short int RetVal=FALSE;

	switch(SampleRate)
	{
		case 8000:
		case 11025:
		case 16000:
		case 22050:
		case 32000:
		case 44100:
		case 48000:
		//	RETAILMSG(ZONE_ERROR, (TEXT( "Direction: %x  Sample Rate: %d \r\n" ),apidir,SampleRate ) );
			RetVal=TRUE;
			break;
		default:
			DEBUGCHK(0);  //we sent a bad rate
			RetVal=FALSE;
			return (RetVal);


	}

	//this write assumes that the 
	if (apidir == WAPI_IN)
		RetVal=SafeWriteAC97((BYTE)AUDIO_ADC_RATE,(unsigned short int)(SampleRate & 0xFFFF) , DEV_AUDIO); //set the input sample rate
	else
		RetVal=SafeWriteAC97((BYTE)AUDIO_DAC_RATE,(unsigned short int)(SampleRate & 0xFFFF) , DEV_AUDIO); //set the output sample rate
	
	return (RetVal);
}

//------------------------------------------------------------------------------------------------------------
// Function: StopDmac
// 
// Purpose: To stop DMA transmit
//-------------------------------------------------------------------------------------------------------------
BOOL  HardwareContext::StopDmac(int Channel)
{
	//TODO: Do I need to set the dma length to 0

	m_pDMARegisters->dcsr[Channel] &=  ~DCSR_RUN;  //clear the run but

	return TRUE;
}

void HardwareContext::DumpDmacRegs()
{
	int i;

	DEBUGMSG(ZONE_ERROR, (TEXT( "gsr %x, posr %x, pocr %x, pisr %x, picr %x\r\n" ),
		m_pAc97regs->gsr,
		m_pAc97regs->posr,
		m_pAc97regs->pocr,
		m_pAc97regs->pisr,
		m_pAc97regs->picr
		) );

	
	for (i=0; i< 16; i++)
		DEBUGMSG(ZONE_ERROR, (TEXT( "m_pDMARegisters->dcsr[%d]	   %x \r\n" ),i,m_pDMARegisters->dcsr[i] ) );
   
	//skip rsvd section rsvd0[44];
	DEBUGMSG(ZONE_ERROR, (TEXT( "m_pDMARegisters->dint	   %x \r\n" ),m_pDMARegisters->dint ) );

    //skip rsvd seciton rsvd1[3];

	for (i=0; i< 39; i++)
		DEBUGMSG(ZONE_ERROR, (TEXT( "m_pDMARegisters->drcmr[%d]	   %x \r\n" ),i,m_pDMARegisters->drcmr[i] ) );

	for (i=0; i<16; i++)
	{

		DEBUGMSG(ZONE_ERROR, (TEXT( "m_pDMARegisters->ddg[%d].ddadr  %x \r\n" ),i,m_pDMARegisters->ddg[i].ddadr ) );
		DEBUGMSG(ZONE_ERROR, (TEXT( "m_pDMARegisters->ddg[%d].dsadr  %x \r\n" ),i,m_pDMARegisters->ddg[i].dsadr ) );
		DEBUGMSG(ZONE_ERROR, (TEXT( "m_pDMARegisters->ddg[%d].dtadr  %x \r\n" ),i,m_pDMARegisters->ddg[i].dtadr ) );
		DEBUGMSG(ZONE_ERROR, (TEXT( "m_pDMARegisters->ddg[%d].dcmd   %x \r\n" ),i,m_pDMARegisters->ddg[i].dcmd ) );


	}

}
void  HardwareContext::PowerDown()
{
	m_Sleeping=TRUE;
//	if (AC97GpioUnConfigure(m_pGPIORegisters,FALSE,DEV_AUDIO)!=SUCCESS)
	if (AC97CtrlUnConfigure(m_InPowerHandler, DEV_AUDIO)!=SUCCESS)
		DEBUGCHK(0);
	
} // PowerDown()

void  HardwareContext::PowerUp()
{

 	//Basic Outline:
	// configue the GPIO registers
	// Set hardcoded values like variable rate audio
	// Set the BCR values (for sandgate)
	//	 set volume 
	//	 set record select
	//	 set EQ values (bass, treble, and mode
	//   Clear Audio Mute (output & input)

	unsigned short int Ac97RegisterData=0;
	unsigned short int FeatureCrs1Data=0;

	static DWORD VendorId=0;
    unsigned short int VidTemp=0;

    DelayInit();
	//m_vpBLReg->hex_led = 0xAC970000;

	m_vpBLReg->misc_wr2 &= ~(0x1 << 2);   // switch on the amplifier


/*	if (AllocAcLink(DEV_AUDIO)!=SUCCESS)		// Allocate virtual addresses for AC97 controller and associated registers.
		ASSERT(FALSE);
*/
	//m_vpBLReg->hex_led = 0xAC970010;
	if (InitAcLink(FALSE,DEV_AUDIO)!=SUCCESS)		// Allocate virtual addresses for AC97 controller and associated registers.
			ASSERT(FALSE),m_vpBLReg->hex_led = 0xfeceface;;

/*	if (AC97GpioConfigure(m_pGPIORegisters,FALSE,DEV_AUDIO)!=SUCCESS)
		DEBUGCHK(0);
*/
		if (AC97CtrlConfigure(m_InPowerHandler, DEV_AUDIO)!=SUCCESS)
				ASSERT(FALSE),m_vpBLReg->hex_led = 0xdeadac97;

	//m_vpBLReg->hex_led = 0xAC970020;

	//m_vpBLReg->hex_led = 0xAC970030;

	//Force VRA (variable rate audio) to be on 
	if( !SafeWriteAC97( EXTENDED_AUDIO_CTRL, VRA_ENABLED_MASK , DEV_AUDIO)  )  // Enable Variable Rate Audio
		RETAILMSG(ZONE_ERROR, (TEXT( "-- Bad VRA Value \r\n")   ) );

	if( !SafeWriteAC97( RECORD_SELECT, 0x0, DEV_AUDIO )  )  // default is AUDIO_MIC_INPUT_MONO
		RETAILMSG(ZONE_ERROR, (TEXT( "-- Bad RECORD_SELECT \r\n")   ) );	

	//Set the output volume from the OS 

	SafeWriteAC97(MASTER_VOLUME, 0, DEV_AUDIO); //full volume for now

	//Set the record gain value
	if( !SafeWriteAC97( RECORD_GAIN, 0x0f0f, DEV_AUDIO )  )  //set to a well working value
		RETAILMSG(3, (TEXT( "-- Bad RECORD_GAIN \r\n")   ) );	

	//m_vpBLReg->hex_led = 0xAC970040;

	//Set the record gain value
	if( !SafeWriteAC97( FEATURE_CSR1, 0x5400, DEV_AUDIO )  )  //set bass & treble to a good sounding value
		RETAILMSG(3, (TEXT( "-- Bad FEATURE_CSR1 \r\n")   ) );	

	
	//
	//compliant codecs such as Crystal require the PCM volume
	//if it's a ucb1400 then don't write the PCM volume (although it shouldn't hurt)
	//
	//m_vpBLReg->hex_led = 0xAC970050;
	SafeReadAC97(VENDOR_ID1, &VidTemp, DEV_AUDIO);  //ucb1400 doesn't use an ascii (that I can tell)
	VendorId= (VidTemp <<16); //ffffffffssssssss // f=first ascii s = second ascii
	SafeReadAC97(VENDOR_ID2, &VidTemp, DEV_AUDIO);  
	VendorId |=VidTemp;       //ttttttttrrrrrrrr //t = third ascii, r=rev #
	VendorId &= 0xfffffff0;//trim of version number

	//m_vpBLReg->hex_led = 0xAC970060;

	//vendor specific 
	switch (VendorId)
	{
		case 0x50534300: //philips UCB1400
			SafeWriteAC97( FEATURE_CSR2, PWR_SMART_CODEC, DEV_AUDIO );  //enable smart mode

			SafeReadAC97(RESET, (unsigned short *) &m_ResetCaps, DEV_TOUCH); // if it returns 0x2a it's rev 1b, if 0x2a0 it 2a

			//
			//CAREFULL, writing the FEATURE_CSR1 could mess up the touch screen
			//

			SafeReadAC97( FEATURE_CSR1,&Ac97RegisterData,DEV_AUDIO);  

			Ac97RegisterData = Ac97RegisterData & EQ_MASK;				//get just EQ data

			SafeReadAC97( FEATURE_CSR1,&FeatureCrs1Data,DEV_AUDIO);         //get the real codec register value
			//mask off eq data

			FeatureCrs1Data = FeatureCrs1Data &  0x8000;				// lob off reserved bit (must be 0)
			FeatureCrs1Data = FeatureCrs1Data & ~EQ_MASK;				// lob off eq data
			FeatureCrs1Data = FeatureCrs1Data | Ac97RegisterData;	// stored EQ data with actual Feature data 
			
			//comment out headphone enable to save power, use an app to turn it on instead
			if (m_ResetCaps==REV_2A)
			{
				FeatureCrs1Data = FeatureCrs1Data | (unsigned short) HPEN_MASK; //turn on head phone
				m_CodecType=UCB14002A;
				RETAILMSG(ZONE_ERROR, (TEXT( "-- UCB14002A \r\n")   ) );	
			}
			else
			{
				m_CodecType=UCB14001B;
 				RETAILMSG(ZONE_ERROR, (TEXT( "-- UCB14001b \r\n")   ) );	

			}
			if( !SafeWriteAC97( FEATURE_CSR1, FeatureCrs1Data, DEV_AUDIO )  )  //write out the result
				RETAILMSG(ZONE_ERROR, (TEXT( "-- Bad FEATURE_CRS1 \r\n")   ) );	
			
			break;



		default:  //vanilla AC97
			SafeWriteAC97( PCM_OUT_VOL, 0x1f1f, DEV_AUDIO );  //AC97 set the PCM out value (not used on ucb1400)
			RETAILMSG(ZONE_ERROR, (TEXT( "-- vanilla AC97 \r\n")   ) );	
			break;


	}

//	m_vpBLReg->hex_led = 0xAC97600D;

	m_OutputDMARunning=FALSE;
	m_Sleeping=FALSE;

}
// Control the hardware speaker enable
void HardwareContext::SetSpeakerEnable(BOOL bEnable)
{
    // Code to turn speaker on/off here
    return;
}

/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
// RecalcSpeakerEnable decides whether to enable the speaker or not.
// For now, it only looks at the m_bForceSpeaker variable, but it could
// also look at whether the headset is plugged in
// and/or whether we're in a voice call. Some mechanism would
// need to be implemented to inform the wave driver of changes in the state of
// these variables however.
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8

void HardwareContext::RecalcSpeakerEnable()
{
    SetSpeakerEnable(m_NumForcedSpeaker);
}

/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
// SetForceSpeaker is called from the device context to update the state of the
// m_bForceSpeaker variable.
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8

DWORD HardwareContext::ForceSpeaker( BOOL bForceSpeaker )
{
    // If m_NumForcedSpeaker is non-zero, audio should be routed to an
    // external speaker (if hw permits).
    if (bForceSpeaker)
    {
        m_NumForcedSpeaker++;
        if (m_NumForcedSpeaker==1)
        {
            RecalcSpeakerEnable();
        }
    }
    else
    {
        m_NumForcedSpeaker--;
        if (m_NumForcedSpeaker==0)
        {
            RecalcSpeakerEnable();
        }
    }

    return MMSYSERR_NOERROR;
}



short int HardwareContext::MsgWriteAC97(DWORD dwParam1,DWORD dwParam2)
{
	if (SafeWriteAC97( (BYTE) dwParam1,(unsigned short int)dwParam2 , DEV_AUDIO )!=SUCCESS)
		return(MMSYSERR_ERROR);

	DEBUGMSG(ZONE_ERROR, (TEXT( "write %x %x \r\n" ),dwParam1,dwParam2 ) ); 
	return (MMSYSERR_NOERROR);
}

short int HardwareContext::MsgReadAC97(DWORD dwParam1,DWORD dwParam2)
{
	unsigned short int MyData=0; 

	if (ReadAC97( (BYTE) dwParam1, &MyData , DEV_AUDIO )!=SUCCESS)
		return(MMSYSERR_ERROR);

	DEBUGMSG(ZONE_ERROR, (TEXT( "read %x %x \r\n" ),dwParam1,MyData ));
	if (dwParam2 != (unsigned short int) NULL)
		* (unsigned short int *) dwParam2 =  MyData;

	return (MMSYSERR_NOERROR);

}

short int HardwareContext::SafeWriteAC97(BYTE Offset, unsigned short int Data, BYTE DevId)
{


	if (m_InPowerHandler)
		return(RawAC97Write(Offset, Data, DevId));
	else
		return(WriteAC97(Offset,Data,DevId));
}

short int HardwareContext::SafeReadAC97(BYTE Offset, unsigned short int * Data, BYTE DevId)
{


	if (m_InPowerHandler)
		return(RawAC97Read(Offset, Data, DevId));
	else
		return(ReadAC97(Offset,Data,DevId));
}
/*
#define RIL_AUDIO_NONE                              (0x00000000)      // @constdefine No audio devices
#define RIL_AUDIO_HANDSET                           (0x00000001)      // @constdefine Handset
#define RIL_AUDIO_SPEAKERPHONE                      (0x00000002)      // @constdefine Speakerphone
#define RIL_AUDIO_HEADSET                           (0x00000003)      // @constdefine Headset
#define RIL_AUDIO_CARKIT                            (0x00000004)      // @constdefine Carkit
*/

BOOL HardwareContext::SetCfgHeadSet()
{
	return TRUE;
}
BOOL HardwareContext::SetCfgHandSet()
{
	return TRUE;
}
BOOL HardwareContext::SetCfgSpeakerPhone()
{
	return TRUE;
}
BOOL HardwareContext::SetCfgCarKit()
{
	return TRUE;
}
BOOL HardwareContext::SetCfgNone()
{
	return TRUE;
}

⌨️ 快捷键说明

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