📄 ac97.c
字号:
/*******************************************************************************
File Name: AC97.c
Description: S3C2440A AC97 Controller Function Test Code
Version: 0.2
History:
0.0: First draft
0.1: 2003. 12. 22, Following test codes were modified by Yoh-Han Lee
- AC97 PCM Out in DMA mode
- AC97 PCM In in DMA mode
0.2: 2004. 02. 12, Programmed and tested by Yoh-Han Lee
- Volume up/down and Mute on/off are available, when codec plays PCM data.
- AC97 power down mode test is supported.
- AC97 reset timing check is added.
- Variable ADC/DAC Selection is supported.
- AC97 PCM Out in the interrupt mode is supported. Thanks to Y. M. Lee.
- AC97 PCM In using interrupt mode is supported.
- AC97 MIC In using interrupt or DMA is added.
********************************************************************************/
#include <stdlib.h>
#include <string.h>
#include "option.h"
#include "2440addr.h"
#include "2440lib.h"
#include "def.h"
#include "ac97.h"
#define AC97_REC_LEN 0xfffff*4
#define DOWN_BUF _NONCACHE_STARTADDRESS
#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 save_rGPBCON,save_rGPBUP,save_rGPBDAT;
U32 AC97_size, AC97_fs;
U32 Output_Volume,Input_Volume;
U32 *Rec_AC97_BUF, *Play_AC97_BUF, *End_AC97_BUF;
static int delayLoopCount;
S16 PCM_Out_INT_Exit = 0;
S16 PCM_In_INT_Exit =0;
U8 *AC97_BUF,*AC97_temp;
U8 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( U8 Up_Down_Volume);
void PCM_Out_Volume( U8 Up_Down_Volume);
void AC97_Controller_State(void);
void Delay_After_CommandWrite(int time);
U16 AC97_Select_SamplingRate(void);
U16 AC97_Codec_Cmd(U8 CMD_Read, U8 CMD_Offset, U16 CMD_Data);
void Speak_PowerUp(unsigned char ON_OFF);
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);
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 ",
(void *)Read_AC97_CPU_Register, "AC97 CPU Registers' value",
0,0
};
void Speak_PowerUp(unsigned char ON_OFF)
{
rGPBCON &=0x33ffff;
rGPBCON |=(1<<18); //Amplifer Enable
rGPBUP |=(1<<9);
if(ON_OFF)
{
rGPBDAT |=(1<<9); //GPB5=1
}
else
{
rGPBDAT &=~(1<<9); //GPB5=0
}
}
void AC97_Test(void)
{
int i;
AC97_Port_Init();
while(1)
{
i=0;
Uart_Printf("\n\n==================== AC97 Function Test ====================\n\n");
while(1)
{ //display menu
Uart_Printf("%2d:%s",i,func_ac97_test[i][1]);
i++;
if((int)(func_ac97_test[i][0])==0)
{
Uart_Printf("\n");
break;
}
if((i%2)==0)
Uart_Printf("\n");
}
Uart_Printf("\n============================================================");
Uart_Printf("\nSelect #Item or Press enter key to exit:");
i = Uart_GetIntNum();
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 Read_AC97_CPU_Register(void)
{
}
void PCMout_Test_AC97(void)
{
int i;
//U8 Char;
AC97_Port_Init();
Speak_PowerUp(1);//YOYO
Delay(1000);
//Uart_Printf("Download PCM Wave File? (y/n)");
//Char=Uart_Getch();
//if( (Char == 'y') | (Char == 'Y') )
Download_PCM_File();
AC97_Init();
if(Codec_Ready)
{
Uart_Printf("\nSelect PCM Out Operation Mode\n");
Uart_Printf("0: Interrupt, 1: DMA\n");
i = Uart_GetIntNum();
AC97_CodecInit_PCMOut(AC97_fs);
switch(i)
{
case 0:
AC97_PCMout_INT(AC97_size);
break;
case 1:
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;
Speak_PowerUp(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)
{
Uart_Printf("\nSelect PCM In/Out Operation Mode\n");
Uart_Printf("0: Interrupt, 1: DMA\n");
i = Uart_GetIntNum();
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)
{
Uart_Printf("\nSelect MIC In Operation Mode\n");
Uart_Printf("0: Interrupt, 1: DMA\n");
i = Uart_GetIntNum();
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
Uart_Printf("\nNormal\n");
AC97_Controller_State();
Uart_Printf("AC97 Codec Powerdown Ctrl/Stat Reg. Value (at 0x26): 0x%x\n", AC97_Codec_Cmd(1,0x26,0x0000));
//ADCs off
Uart_Printf("\n=>ADCs off PR0\n");
AC97_Codec_Cmd(0,0x26,(1<<8));
AC97_Controller_State();
Uart_Printf("AC97 Codec Powerdown Ctrl/Stat Reg. Value (at 0x26): 0x%x\n", AC97_Codec_Cmd(1,0x26,0x0000));
//DACs off
Uart_Printf("\n=>DACs off PR1\n");
AC97_Codec_Cmd(0,0x26,(1<<8)|(1<<9));
AC97_Controller_State();
Uart_Printf("AC97 Codec Powerdown Ctrl/Stat Reg. Value (at 0x26): 0x%x\n", AC97_Codec_Cmd(1,0x26,0x0000));
//Analog off
Uart_Printf("\n=>Analog off PR2\n");
AC97_Codec_Cmd(0,0x26,(1<<8)|(1<<9)|(1<<10));
AC97_Controller_State();
Uart_Printf("AC97 Codec Powerdown Ctrl/Stat Reg. Value (at 0x26): 0x%x\n", AC97_Codec_Cmd(1,0x26,0x0000));
//Digital I/F off
Uart_Printf("\n=>Digital I/F off PR4\n");
AC97_Codec_Cmd(0,0x26,(1<<8)|(1<<9)|(1<<10)|(1<<12));
AC97_Controller_State();
//Uart_Printf("AC97 Codec Powerdown Ctrl/Stat 0x26 Reg.: 0x%x\n", AC97_Codec_Cmd(1,0x26,0x0000));
//Shut off AC-Link
Uart_Printf("\n=>Shut off AC-Link\n");
rAC_GLBCTRL &= ~(1<<2);
AC97_Controller_State();
//Uart_Printf("AC97 Codec Powerdown Ctrl/Stat 0x26 Reg.: 0x%x\n", AC97_Codec_Cmd(1,0x26,0x0000));
while(1)
{
Uart_Printf("\nPress enter key for Warm Reset");
i = Uart_GetIntNum();
if(i==-1) break;
}
//Warm Reset
Uart_Printf("\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);
Uart_Printf("AC97 Codec Powerdown Ctrl/Stat Reg. Value (at 0x26): 0x%x\n", AC97_Codec_Cmd(1,0x26,0x0000));
//Cold Reset
Uart_Printf("\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();
Uart_Printf("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
Uart_Printf("\nNormal\n");
AC97_Controller_State();
Uart_Printf("AC97 Codec Powerdown Ctrl/Stat Reg. Value (at 0x26): 0x%x\n", AC97_Codec_Cmd(1,0x26,0x0000));
//ADCs off
Uart_Printf("\n=>ADCs off PR0\n");
AC97_Codec_Cmd(0,0x26,(1<<8));
AC97_Controller_State();
Uart_Printf("AC97 Codec Powerdown Ctrl/Stat Reg. Value (at 0x26): 0x%x\n", AC97_Codec_Cmd(1,0x26,0x0000));
//DACs off
Uart_Printf("\n=>DACs off PR1\n");
AC97_Codec_Cmd(0,0x26,(1<<8)|(1<<9));
AC97_Controller_State();
Uart_Printf("AC97 Codec Powerdown Ctrl/Stat Reg. Value (at 0x26): 0x%x\n", AC97_Codec_Cmd(1,0x26,0x0000));
//Analog off
Uart_Printf("\n=>Analog off PR2\n");
AC97_Codec_Cmd(0,0x26,(1<<8)|(1<<9)|(1<<10));
AC97_Controller_State();
Uart_Printf("AC97 Codec Powerdown Ctrl/Stat Reg. Value (at 0x26): 0x%x\n", AC97_Codec_Cmd(1,0x26,0x0000));
//Digital I/F off
Uart_Printf("\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
Uart_Printf("\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
Uart_Printf("\nWarm Reset Timing Check...");
Uart_Printf("\n Probe SYNC and BIT_CLK.");
Uart_Printf("\n Trigger SYNC Rising Edge.");
while(1)
{
Uart_Printf("\nPress enter key for Warm Reset Timing Check...");
i = Uart_GetIntNum();
if(i==-1) break;
}
Uart_Printf("\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);
Uart_Printf("AC97 Codec Powerdown Ctrl/Stat Reg. Value (at 0x26): 0x%x\n", AC97_Codec_Cmd(1,0x26,0x0000));
Uart_Printf("\nPress any key.\n");
Uart_Getch();
//Cold Reset Timing Check
Uart_Printf("\nCold Reset Timing Check...");
Uart_Printf("\n Probe RESET#, BIT_CLK and SDATA_IN.");
Uart_Printf("\n Trigger RESET# Rising Edge.");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -