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

📄 ha_ac97.c

📁 MP3的代码很实用 MP3的代码很实用
💻 C
字号:
/********************************************************************************************
*filename:		HA_AC97.c						
*author:		JIE.XU	
*create date:		2003-7-1 14:17                                                                      
*description:	    	The file consists of the function used to config AC97                                                               
*modify history:	                                                                      
*misc:           
********************************************************************************************/
#include "HA_typedef.h"
#include "HA_AC97.h"
#include "hardware.h"
extern 	char decbuf[];

extern int base;

U32 ii=0;
extern nframe;
short frame10[BUFFRAMENUM];
int frame11[BUFFRAMENUM];
int outbyte;

/*配置CODEC*/
void ConfigurationCodec(int type)
{

//_________________________________________________________________
//**********open Master Volume Register,ADDR: 02H
	 *(RP)AC97_CRAC=WRITE+ 0x20000 + 0x0000;		//0dB attenuation
	do{}while(!OVER_WRITE);

//_________________________________________________________________
//**********open Master Volume MONO,ADDR:06H
//	 *(RP)AC97_CRAC=WRITE + 0x60000 + 0x0;		//0dB attenuation
//	do{}while(!OVER_WRITE);


//_________________________________________________________________
//*********open MIC Volume,ADDR:0eH
	*(RP)AC97_CRAC=WRITE + 0xe0000 + 0x8;		//0dB attenuation
	do{}while(!OVER_WRITE);


//_________________________________________________________________
//*********open AUX Volume,ADDR:16H
//	 *(RP)AC97_CRAC=WRITE + 0x160000 + 0x808;		//0dB attenuation	
//	do{}while(!OVER_WRITE);

//________________________________________________________________
//********open PCM Out Volume,ADDR:18H
//	 *(RP)AC97_CRAC=WRITE + 0x180000 + 0x808;		//0dB attenuation	
//	do{}while(!OVER_WRITE);
*(RP)AC97_CRAC=WRITE + 0x6a0000 + 0x50;		//0dB attenuation
	do{}while(!OVER_WRITE);

//________________________________________________________________
//********open Extend Audio Status and Control Register,ADDR:2AH
	if(type)
		{
		*(RP)AC97_CRAC=WRITE + 0x2a0000 + 0x0;		//	fixed sample
		do{}while(!OVER_WRITE);
		}
	else
		{
		*(RP)AC97_CRAC=WRITE + 0x2a0000 + 0x1;		//	VRA sample
		do{}while(!OVER_WRITE);
		

		*(RP)AC97_CRAC=WRITE +0x2c0000 + 0xac44;//配置D/A采样率,用于输出播放
		do{}while(!OVER_WRITE);

		*(RP)AC97_CRAC=WRITE +0x320000 + 0xac44;//配置A/D采样率,用于采样录音
		do{}while(!OVER_WRITE);
		}

}

/*配置AC97*/
void ConfigurationAC97(int i)
{
	if (i)
		{
	
		*(RP)AC97_OCR=0x00010001;	//open L/R channel,and set fixed sample rate	
		*(RP)AC97_ICR=0x00000000;		//open Input channel,and set fixed sample rate	
		}
	else
		{
		*(RP)AC97_OCR=0x00030003;	//open L/R channel,and set variable sample rate	
		*(RP)AC97_ICR=0x00000000;		//open Input channel,and set variable sample rate	
		}

	//_________________________________________________________________
	//**********configure the register INT_ENABLE
	*(RP)AC97_INT_ENABLE=0xbf;	//open all the interrupt

	//_________________________________________________________________
	//**********configure the register AC97_ENABLE for open modual AC97
	*(RP)AC97_ENABLE=0x1;
	
}

/*配置DMA*/
void ConfigureDMA_Output()
{
	*(RP)DMA_SA=(int)(base);
	*(RP)DMA_DA=AC97_OUT_FIFOADDR;
	*(RP)DMA_CTRL=0x0120d4ad;
	*(RP)DMA_ENABLE=0x2003;
}

/*初始化AC97*/
void InitAC97(void)
{
//_________________________________________________________________
//*********Reset AC97

	*(RP)AC97_CONR=0X13;	
	
	
//_________________________________________________________________
//**********Reset Codec 
	*(RP)AC97_CRAC=WRITE + 0x0 + 0x1;
	do{}while(!OVER_WRITE);

//_________________________________________________________________
//************configure Codec,	
//Note: first configure Codec,then AC97;

	ConfigurationCodec(VRA_SAMPLE);
	ConfigurationAC97(VRA_SAMPLE);


//_________________________________________________________________
//**********configure the register INT_CLEAR
		if (*(RP)AC97_INT_STATUS!=0x0)
		{
		*(RP)AC97_INT_CLEAR=0x1;	//after writing in INT_CLEAR,INT_STATUS must be zero
		}
}

/*初始化DMA函数*/
void InitDMA()
{
	U32 Input_Output=1;
//_________________________________________________________________
//*********configure DMA

	if (Input_Output)
		{
		ConfigureDMA_Output();
		}
	else
		{
		ConfigureDMA_Input();
		}
}

/*用于AC97播放的DMA中断处理函数*/
void ac97_handler(void)
{
	
		
	*(RP)DMACIntTCClear=0X01;
	*(RP)DMACIntTCClear=0X0;

	ii++;

	*(RP)DMA_SA=(int)base+0x1200*ii;
	*(RP)DMA_DA=AC97_OUT_FIFOADDR;
	*(RP)DMA_CTRL=0x0120d4ad;
	*(RP)DMA_ENABLE=0x2003;

	#if 1
	if(ii==1300)
	{
		irq_disable(INT_DMA);
		*(RP)DMA_ENABLE=0x2002;
		
		ii=0;

		irq_enable(INT_DMA);
		unmask_irq(INT_DMA);
		InitDMA();
		InitAC97();
	}
	#endif
			
}







⌨️ 快捷键说明

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