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

📄 codec.c

📁 主要测试USB 连接并通过USB 接口控制SEED-DEC6713 上各种资源进行工作。由CY7C68001 兼容USB1.1 与USB2.0 标准
💻 C
字号:
/********************************************************************************\
\*DEC6713_AIC23_CODEC.C	V1.00
* Copyright	2003 by SEED Electronic Technology Ltd.
* All rights reserved. Property of SEED Electronic Technology Ltd.			                
* Designed by:	Hongshuai.Li								                                
*********************************************************************************/ 
/*DEC6713_AIC23_CEDEC.C	-CODEC appled functions.*/
#include <csl.h>
#include <csl_i2c.h>
#include <csl_mcasp.h>
#include <DEC6713.h>
#include <codec_iis.h>

//MCASP_Handle DEC6713_AIC23_DATAHANDLE;
/********************************************************************************/
	/* Configure MCASP. */
	MCASP_ConfigGbl MyMCASPcfgGbl = {
		0x00000000, /* PFUNC -     All pins as McASP */
    	0x00000080, /* PDIR  -     XMT DATA output, rest are inputs */
    	0x00000000, /* DITCTL -    DIT mode disable */
    	0x00000000, /* DLBCTL -    Loopback disabled */
    	0x00000000  /* AMUTE  -    Never drive AMUTE */
	};
	
	//Set receive registers.
	MCASP_ConfigRcv MyMCASPcfgRcv = {
		/* RMASK */
		0xffffffff, /* RMASK -     Use all 32 bits */
    	0x000180f8, /* RFMT -      MSB first, 32-bit slots, CPU bus, 0 bit delay */
    	0x00000000, /* AFSRCTL -   burst, single bit frame sync, ext FS */
    	0x00000080, /* ACLKRCTL -  Sample on rising CLK, divide by 1, ext CLK */
    	0x00000000, /* AHCLKRCTL - External HCLK */
    	0x00000001, /* RTDM -      Slots 0-31 are active */
    	0x00000000, /* RINTCTL -   No interrupts */
    	0x00000000  /* RCLKCHK -   Not used */ 
	};
	//Set serial control.
	MCASP_ConfigSrctl MyMCASPcfgSrctl = {
		0x00000000, /* SRCTL0 -    Inactive */
    	0x00000000, /* SRCTL1 -    Inactive */
    	0x00000000, /* SRCTL2 -    Inactive */
    	0x00000000, /* SRCTL3 -    Inactive */
    	0x00000000, /* SRCTL4 -    Inactive */
    	0x00000000, /* SRCTL5 -    Inactive */
    	0x0000000E, /* SRCTL6 -    Receive, active high */
    	0x0000000D  /* SRCTL7 -    Transmit, active high */
	};
	
	//Set transmit registers.
	MCASP_ConfigXmt MyMCASPcfgXmt = {
		/* XMASK */
		0xffffffff, /* XMASK -     Use all 32 bits */
    	0x000180f8, /* XFMT -      MSB first, 32-bit slots, CPU bus, 0 bit delay */
    	0x00000000, /* AFSXCTL -   burst, single bit frame sync, ext FS */
    	0x000000C0, /* ACLKXCTL -  Sample on falling CLK, divide by 1, ext CLK */
    	0x00000000, /* AHCLKXCTL - External HCLK */
    	0x00000001, /* XTDM -      Slots 0-31 are active */
    	0x00000000, /* XINTCTL -   No interrupts */
    	0x00000000  /* XCLKCHK -   Not used */
	};
	MCASP_Config MyMCASPConfig = {
		&MyMCASPcfgGbl,
		&MyMCASPcfgRcv,
		&MyMCASPcfgXmt,
		&MyMCASPcfgSrctl,
	};
/********************************************************************************\
\*DEC6713_AIC23_OpenCodec()	-Open the codec AIC23.
\*							Configure AXR1[7] as transmit port and AXR1[6] as 
\*							receive port.
\*Parameters:
\*
\*
\*Return:
\********************************************************************************/
MCASP_Handle DEC6713_AIC23_OpenCodec()
{
	MCASP_Handle DEC6713_AIC23_DATAHANDLE;
	Uint32 gblctl;
//	Uint32 RegAddr;
		
	DEC6713_AIC23_DATAHANDLE = MCASP_open(MCASP_DEV1,MCASP_OPEN_RESET);
	
	/* Reset MCASP to default values by setting GBLCTL = 0.*/
	MCASP_reset(DEC6713_AIC23_DATAHANDLE);
	
	
	MCASP_config(DEC6713_AIC23_DATAHANDLE,&MyMCASPConfig);
	
	/* Clear transmit and receive status ,清除发送与接收状态*/
	MCASP_RSETH(DEC6713_AIC23_DATAHANDLE,XSTAT,0xFFFF);
	MCASP_RSETH(DEC6713_AIC23_DATAHANDLE,RSTAT,0xFFFF);
	
	gblctl = 0;
    MCASP_RSETH(DEC6713_AIC23_DATAHANDLE, GBLCTL, gblctl);
    gblctl = 0x404;
    /*使能发送与接收的串行寄存器*/    
    MCASP_RSETH(DEC6713_AIC23_DATAHANDLE, GBLCTL, 0x404);
            
	
	/* Enable transmit/receive state machines */
    MCASP_RSETH(DEC6713_AIC23_DATAHANDLE, XBUF7, 0);
    gblctl = 0x0c0c;
    MCASP_RSETH(DEC6713_AIC23_DATAHANDLE, GBLCTL, gblctl);
	

	return(DEC6713_AIC23_DATAHANDLE);
}

/********************************************************************************/
/********************************************************************************\
\*DEC6713_AIC23_CloseCodec()
\*Parameters:
\*Return:
\********************************************************************************/
void DEC6713_AIC23_CloseCodec(MCASP_Handle HMcASP)
{
	MCASP_close(HMcASP);
}
/********************************************************************************\
\* CODEC_config()	*\
\* Parameters:
\* Return:
\********************************************************************************/
Uint16 CODEC_config()
{
	I2C_Handle hI2C;
	/* Open I2C0. */
	hI2C = I2C_open(I2C_DEV0,I2C_OPEN_RESET);
		
		/* If i2c model clock frequency is lower, perhaps timer delay should be 
		   added between aic23 registers writting */
		/* Set all parts of AIC23 begin to work. */
		I2C_write16(hI2C,Power_Down_Control,0x00);
		//DEC6713_wait(100);
		/* Set digital interface for AIC23. */
		I2C_write16(hI2C,Digital_Audio_Interface_Format,0x53);//0x52
		//DEC6713_wait(100);
		/* Set analog channel for AIC23. */
		I2C_write16(hI2C,Analog_Audio_Path_Control,0x10);
		//DEC6713_wait(100);
		/* Set digital channel for AIC23. */
		I2C_write16(hI2C,Digital_Audio_Path_Control,0x01);
		//DEC6713_wait(100);
		/* Set sample rate for AIC23. */
		I2C_write16(hI2C,Sample_Rate_Control,0x00);
		//DEC6713_wait(100);
		/* Set volume for headphone. */
		I2C_write16(hI2C,Left_Channel_Headphone_Volume_Control,0xF9);
		//DEC6713_wait(100);
		/* Set volume for line in. */
		I2C_write16(hI2C,Left_Line_Input_Channel_Volume_Control,0x17);
		//DEC6713_wait(100);
		I2C_write16(hI2C,Right_Line_Input_Channel_Volume_Control,0x17);
		//DEC6713_wait(100);
		/* Start AIC23. */
		I2C_write16(hI2C,Digital_Interface_Activation,0x01);
		DEC6713_wait(1000);
		I2C_close(hI2C);
	return(TRUE); 
}
/********************************************************************************\
\* CODEC_close()	*\
\* Parameters:
\* Return:
\********************************************************************************/
void CODEC_close()
{
	I2C_Handle hI2C;
	/* Open I2C0. */
	hI2C = I2C_open(I2C_DEV0,I2C_OPEN_RESET);
	I2C_write16(hI2C,Reset_Register,0x00);
	DEC6713_wait(1000);
	I2C_close(hI2C);
}
/********************************************************************************/
/* End of CODEC.C */
/********************************************************************************/




⌨️ 快捷键说明

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