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

📄 wdt_ac97.c

📁 2440超级bios(ads1.2 rvds2.2)通用
💻 C
📖 第 1 页 / 共 3 页
字号:
/*
*******************************************************************************
* file name:	rtc.c
* description:	rtc driver
* author:		xzChen(chxzh123@163.com)
* QQ / msn:		36725175 / chxzh123@hotmail.com
*******************************************************************************
*/

#ifndef __WDT_AC97_C__
#define __WDT_AC97_C__

#include "Includes.h"

void wdt_func(void)
{
	rWTCON = (255<<8) + (1<<5) + 3<<3 + 4;
	rWTDAT = 1;
	rWTCNT = 1;
}


#define AC97_REC_LEN			0xfffff*4
#define DOWN_BUF				0x31000000
#define PCM_OUT_TRIGGER 		8
#define PCM_IN_TRIGGER			8
#define AC97_PCM_OUT_THRESHOLD	(1<<18)
#define AC97_PCM_IN_THRESHOLD	(1<<17)
#define AC97_MIC_IN_THRESHOLD	(1<<16)

U32 save_AC97_rGPECON, save_AC97_rGPEDAT, save_AC97_rGPEUP;
U32 AC97_size, AC97_fs;
U32 Output_Volume,Input_Volume;
U32 *Rec_AC97_BUF, *Play_AC97_BUF, *End_AC97_BUF;

S16 PCM_Out_INT_Exit = 0;
S16 PCM_In_INT_Exit	= 0;

U08 *AC97_BUF,*AC97_temp;
U08 Up_Down_Volume;

char AC97_Rec_Done = 0;
char Codec_Ready_Irq;
char AC97_mute = 1;
char Codec_Ready = 1;

void AC97_Port_Init(void);
void AC97_Port_Return(void);
void AC97_Init(void);
void Download_PCM_File(void);
void AC97_CodecInit_PCMOut(U16 AC97_fs);
void AC97_CodecInit_PCMIn(U16 AC97_fs);
void AC97_CodecInit_MICIn(U16 AC97_fs);
void AC97_CodecInit_PD(void);
void AC97_CodecExit_PCMOut(void);
void AC97_CodecExit_PCMIn(U16 DACs_off);
void AC97_CodecExit_MICIn(U16 DACs_off);
void AC97_PCMout_DMA1(U32 PCM_Size);
void AC97_PCMout_INT(U32 PCM_Size);
void AC97_PCMin_DMA2(U32 PCM_Size);
void AC97_PCMin_INT(U32 PCM_Size);
void AC97_MICin_DMA3(U32 MIC_Size);
void AC97_MICin_INT(U32 PCM_Size);
void Delay_Init(void);

void PCM_In_Volume( U08 Up_Down_Volume);
void PCM_Out_Volume( U08 Up_Down_Volume);

void AC97_Controller_State(void);
void Delay_After_CommandWrite(int time);
U16 AC97_Select_SamplingRate(void);
U16 AC97_Codec_Cmd(U08 CMD_Read, U08 CMD_Offset, U16 CMD_Data);


static void __irq DMA1_Play_Done(void);
static void __irq DMA2_Rec_Done(void);
static void __irq DMA3_Rec_Done(void);
static void __irq RxInt(void);
static void __irq Muting(void);
void __irq AC97_Codec_Ready(void);
void __irq Irq_AC97_PCMout(void);
void __irq Irq_AC97_PCMin(void);
void __irq Irq_AC97_MICin(void);

extern void PCMout_Test_AC97(void);
extern void PCMin_Test_AC97(void);
extern void MICin_Test_AC97(void);
extern void Powerdown_Test_AC97(void);
extern void Reset_Test_AC97(void);

void * func_ac97_test[][2]=
{
	//AC97 Function Test Item
	(void *)PCMout_Test_AC97,   		"Play Wave File    ",
	(void *)PCMin_Test_AC97,     		"Record Sound via LineIn and Play it  ",
	(void *)MICin_Test_AC97,      		"Record Voice via MIC and Play it      ",
	(void *)Powerdown_Test_AC97,    	"AC97 Power Down   ",
	(void *)Reset_Test_AC97,      		"AC97 Reset Timing Check ",
	0,0
};

void AC97_Test(void)
{
	int i;

	AC97_Port_Init();
	Delay(1000);
	while(1)
	{
		i = 0;
		UartPrintf(SHL_PRT,"\n\n==================== AC97 Function Test ====================\n\n");
		while(1)
		{
		   //display menu
			UartPrintf(SHL_PRT,"%2d:%s",i,func_ac97_test[i][1]);
			i++;
			if((int)(func_ac97_test[i][0])==0)
			{
				UartPrintf(SHL_PRT,"\n");
				break;
			}
			if((i%2)==0)
			UartPrintf(SHL_PRT,"\n");
		}
		UartPrintf(SHL_PRT,"\n============================================================");
		UartPrintf(SHL_PRT,"\nSelect #Item or Press enter key to exit:");
//		i = Uart_GetIntNum(SHL_PRT);
i=0;
		if(i==-1)
			break;		// return.
		if(i>=0 && (i<((sizeof(func_ac97_test)-1)/8)) )	// select and execute...
			( (void (*)(void)) (func_ac97_test[i][0]) )();
	}
	 rAC_GLBCTRL = 0;
}
void PCMout_Test_AC97(void)
{
	int i;

    Download_PCM_File();
    AC97_Init();
	if(Codec_Ready)
	{
       	UartPrintf(SHL_PRT,"\nSelect PCM Out Operation Mode\n");
		UartPrintf(SHL_PRT,"0: Interrupt, 1: DMA\n");
		i = Uart_GetIntNum(SHL_PRT);
		AC97_CodecInit_PCMOut(AC97_fs);

       	switch(i)
       	{
   			case 0:
		UartPrintf(SHL_PRT,"0: Interrupt\n");
//			AC97_PCMout_INT(AC97_size);
   			AC97_PCMout_DMA1(AC97_size);
   			break;

   			case 1:
		UartPrintf(SHL_PRT,"1: DMA\n");
   			AC97_PCMout_DMA1(AC97_size);
   			break;

   			default:
   			AC97_PCMout_DMA1(AC97_size);
   			break;
       	}

     		AC97_CodecExit_PCMOut();
	}

       AC97_mute = 1;
       Codec_Ready =1;
       PCM_Out_INT_Exit = 0;

       AC97_Port_Return();
}


void PCMin_Test_AC97(void)
{
	int i;
	U32 Sampling_Rate;
	AC97_Rec_Done = 0;

	AC97_Port_Init();
	Sampling_Rate = AC97_Select_SamplingRate();
	AC97_Init();

	if(Codec_Ready)
	{
		UartPrintf(SHL_PRT,"\nSelect PCM In/Out Operation Mode\n");
		UartPrintf(SHL_PRT,"0: Interrupt, 1: DMA\n");
		i = Uart_GetIntNum(SHL_PRT);
       	AC97_CodecInit_PCMIn(Sampling_Rate);
		switch(i)
       	{
   			case 0:
				AC97_PCMin_INT(AC97_REC_LEN);
				//Play Recorded Data
	    		AC97_CodecInit_PCMOut(Sampling_Rate);
				AC97_PCMout_INT(AC97_REC_LEN);
       		break;

			case 1:
         		AC97_PCMin_DMA2(AC97_REC_LEN);
         		//Play Recorded Data
	    		AC97_CodecInit_PCMOut(Sampling_Rate);
	   			AC97_PCMout_DMA1(AC97_REC_LEN);
	   		break;

			default:
				AC97_PCMin_DMA2(AC97_REC_LEN);
	    		//Play Recorded Data
	    		AC97_CodecInit_PCMOut(Sampling_Rate);
	   			AC97_PCMout_DMA1(AC97_REC_LEN);
   			break;
		}
		AC97_CodecExit_PCMIn(1);
	}
   	Codec_Ready =1;
	AC97_mute = 1;
	PCM_Out_INT_Exit = 0;
	PCM_In_INT_Exit = 0;
   	AC97_Port_Return();
}

void MICin_Test_AC97(void)
{
	U16 i, Sampling_Rate;
	AC97_Rec_Done = 0;

	AC97_Port_Init();
	Delay(1000);
    Sampling_Rate = AC97_Select_SamplingRate();
	AC97_Init();
	if(Codec_Ready)
	{
		UartPrintf(SHL_PRT,"\nSelect MIC In Operation Mode\n");
		UartPrintf(SHL_PRT,"0: Interrupt, 1: DMA\n");
		i = Uart_GetIntNum(SHL_PRT);
       	AC97_CodecInit_MICIn(Sampling_Rate);
		switch(i)
       	{
			case 0:
				AC97_MICin_INT(AC97_REC_LEN/2);
				//Play Recorded Data
	    		AC97_CodecInit_PCMOut(Sampling_Rate);
		   		AC97_PCMout_DMA1(AC97_REC_LEN/2);
			break;

			case 1:
				AC97_MICin_DMA3(AC97_REC_LEN/2);
         		//Play Recorded Data
	    		AC97_CodecInit_PCMOut(Sampling_Rate);
	   			AC97_PCMout_DMA1(AC97_REC_LEN/2);
			break;

			default:
				AC97_MICin_DMA3(AC97_REC_LEN/2);
         		//Play Recorded Data
	    		AC97_CodecInit_PCMOut(Sampling_Rate);
		   		AC97_PCMout_DMA1(AC97_REC_LEN/2);
			break;
 		}
  		AC97_CodecExit_MICIn(1);
	}
	Codec_Ready =1;
	AC97_mute = 1;
    PCM_In_INT_Exit = 0;
	AC97_Port_Return();
}
void Powerdown_Test_AC97(void)
{
	int i;

	AC97_Port_Init();
	Delay(1000);
	AC97_Init();
	if(Codec_Ready)
	{
	  	AC97_CodecInit_PD();
	 	//Normal
	 	UartPrintf(SHL_PRT,"\nNormal\n");
	 	AC97_Controller_State();
	 	UartPrintf(SHL_PRT,"AC97 Codec Powerdown Ctrl/Stat Reg. Value (at 0x26): 0x%x\n", AC97_Codec_Cmd(1,0x26,0x0000));
	 	//ADCs off
	 	UartPrintf(SHL_PRT,"\n=>ADCs off PR0\n");
	 	AC97_Codec_Cmd(0,0x26,(1<<8));
	 	AC97_Controller_State();
	 	UartPrintf(SHL_PRT,"AC97 Codec Powerdown Ctrl/Stat Reg. Value (at 0x26): 0x%x\n", AC97_Codec_Cmd(1,0x26,0x0000));
	 	//DACs off
	 	UartPrintf(SHL_PRT,"\n=>DACs off PR1\n");
	 	AC97_Codec_Cmd(0,0x26,(1<<8)|(1<<9));
	 	AC97_Controller_State();
	 	UartPrintf(SHL_PRT,"AC97 Codec Powerdown Ctrl/Stat Reg. Value (at 0x26): 0x%x\n", AC97_Codec_Cmd(1,0x26,0x0000));
	 	//Analog off
	 	UartPrintf(SHL_PRT,"\n=>Analog off PR2\n");
	 	AC97_Codec_Cmd(0,0x26,(1<<8)|(1<<9)|(1<<10));
	 	AC97_Controller_State();
	 	UartPrintf(SHL_PRT,"AC97 Codec Powerdown Ctrl/Stat Reg. Value (at 0x26): 0x%x\n", AC97_Codec_Cmd(1,0x26,0x0000));
	 	//Digital I/F off
	 	UartPrintf(SHL_PRT,"\n=>Digital I/F off PR4\n");
	 	AC97_Codec_Cmd(0,0x26,(1<<8)|(1<<9)|(1<<10)|(1<<12));
	 	AC97_Controller_State();
	 	//UartPrintf(SHL_PRT,"AC97 Codec Powerdown Ctrl/Stat 0x26 Reg.: 0x%x\n", AC97_Codec_Cmd(1,0x26,0x0000));
	 	//Shut off AC-Link
	 	UartPrintf(SHL_PRT,"\n=>Shut off AC-Link\n");
	 	rAC_GLBCTRL &= ~(1<<2);
	 	AC97_Controller_State();
	 	//UartPrintf(SHL_PRT,"AC97 Codec Powerdown Ctrl/Stat 0x26 Reg.: 0x%x\n", AC97_Codec_Cmd(1,0x26,0x0000));
	 	while(1)
	 	{
	 		UartPrintf(SHL_PRT,"\nPress enter key for Warm Reset");
			i = Uart_GetIntNum(SHL_PRT);
	 		if(i==-1)
	 			break;
	 	}
	 	//Warm Reset
	 	UartPrintf(SHL_PRT,"\n=>Warm Reset\n");
	 	rAC_GLBCTRL = (1<<1);
	 	AC97_Controller_State();
	 	rAC_GLBCTRL &= ~(1<<1);

	 	rAC_GLBCTRL |= (1<<2);
	 	AC97_Controller_State();
	 	rAC_GLBCTRL |= (1<<3);
	 	UartPrintf(SHL_PRT,"AC97 Codec Powerdown Ctrl/Stat Reg. Value (at 0x26): 0x%x\n", AC97_Codec_Cmd(1,0x26,0x0000));

	 	//Cold Reset
	 	UartPrintf(SHL_PRT,"\n=>Cold Reset\n");
	 	rAC_GLBCTRL |= (1<<0);
	 	AC97_Controller_State();
	 	rAC_GLBCTRL &= ~(1<<0);

	 	rAC_GLBCTRL |= (1<<2);
	 	AC97_Controller_State();
	 	rAC_GLBCTRL |= (1<<3);
	 	AC97_Controller_State();
	 	UartPrintf(SHL_PRT,"AC97 Codec Powerdown Ctrl/Stat Reg. Value (at 0x26): 0x%x\n", AC97_Codec_Cmd(1,0x26,0x0000));
	}
	Codec_Ready =1;
	AC97_Port_Return();
}
void Reset_Test_AC97(void)
{
	int i;

	AC97_Port_Init();
	Delay(1000);
	AC97_Init();
	if(Codec_Ready)
	{
	 	AC97_CodecInit_PD();
		//Normal
		UartPrintf(SHL_PRT,"\nNormal\n");
		AC97_Controller_State();
		UartPrintf(SHL_PRT,"AC97 Codec Powerdown Ctrl/Stat Reg. Value (at 0x26): 0x%x\n", AC97_Codec_Cmd(1,0x26,0x0000));
		//ADCs off
		UartPrintf(SHL_PRT,"\n=>ADCs off PR0\n");
		AC97_Codec_Cmd(0,0x26,(1<<8));
		AC97_Controller_State();
		UartPrintf(SHL_PRT,"AC97 Codec Powerdown Ctrl/Stat Reg. Value (at 0x26): 0x%x\n", AC97_Codec_Cmd(1,0x26,0x0000));
		//DACs off
		UartPrintf(SHL_PRT,"\n=>DACs off PR1\n");
		AC97_Codec_Cmd(0,0x26,(1<<8)|(1<<9));
		AC97_Controller_State();
		UartPrintf(SHL_PRT,"AC97 Codec Powerdown Ctrl/Stat Reg. Value (at 0x26): 0x%x\n", AC97_Codec_Cmd(1,0x26,0x0000));
		//Analog off
		UartPrintf(SHL_PRT,"\n=>Analog off PR2\n");
		AC97_Codec_Cmd(0,0x26,(1<<8)|(1<<9)|(1<<10));
		AC97_Controller_State();
		UartPrintf(SHL_PRT,"AC97 Codec Powerdown Ctrl/Stat Reg. Value (at 0x26): 0x%x\n", AC97_Codec_Cmd(1,0x26,0x0000));
		//Digital I/F off
		UartPrintf(SHL_PRT,"\n=>Digital I/F off PR4\n");
		AC97_Codec_Cmd(0,0x26,(1<<8)|(1<<9)|(1<<10)|(1<<12));
		AC97_Controller_State();
		//Shut off AC-Link
		UartPrintf(SHL_PRT,"\n=>Shut off AC-Link\n");
		rAC_GLBCTRL &= ~(1<<2);
		//AC97_Codec_Cmd(0,0x26,(1<<8)|(1<<9)|(1<<10)|(1<<12));
		AC97_Controller_State();
		//Warm Reset Timing Check
		UartPrintf(SHL_PRT,"\nWarm Reset Timing Check...");
		UartPrintf(SHL_PRT,"\n	Probe SYNC and BIT_CLK.");
		UartPrintf(SHL_PRT,"\n	Trigger SYNC Rising Edge.");
		while(1)
		{
			UartPrintf(SHL_PRT,"\nPress enter key for Warm Reset Timing Check...");
			i = Uart_GetIntNum(SHL_PRT);
			if(i==-1) break;
		}
		UartPrintf(SHL_PRT,"\n=>Warm Reset\n");
		rAC_GLBCTRL = (1<<1);
		AC97_Controller_State();
		rAC_GLBCTRL &= ~(1<<1);

		rAC_GLBCTRL |= (1<<2);
		AC97_Controller_State();
		rAC_GLBCTRL |= (1<<3);
		UartPrintf(SHL_PRT,"AC97 Codec Powerdown Ctrl/Stat Reg. Value (at 0x26): 0x%x\n", AC97_Codec_Cmd(1,0x26,0x0000));

		UartPrintf(SHL_PRT,"\nPress any key.\n");
		UartGetByte(SHL_PRT);

		//Cold Reset Timing Check
		UartPrintf(SHL_PRT,"\nCold Reset Timing Check...");
		UartPrintf(SHL_PRT,"\n	Probe RESET#, BIT_CLK and SDATA_IN.");
		UartPrintf(SHL_PRT,"\n	Trigger RESET# Rising Edge.");
		while(1)
		{
			UartPrintf(SHL_PRT,"\nPress enter key for Cold Reset Timing Check...");
		i = Uart_GetIntNum(SHL_PRT);
			if(i==-1) break;
		}

		rAC_GLBCTRL = 0x1;
		Delay(1000);
		rAC_GLBCTRL = 0x0;
		Delay(1000);

⌨️ 快捷键说明

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