?? dec5502_codec.c
字號:
/******************************************************************************/
/* Copyright 2004 by SEED Electronic Technology LTD. */
/* All rights reserved. SEED Electronic Technology LTD. */
/* Restricted rights to use, duplicate or disclose this code are */
/* granted through contract. */
/* */
/* */
/******************************************************************************/
/* DESCRIPTION: */
/* */
/* This is an audio signal sample and play example for CODEC of C5502 */
/*----------------------------------------------------------------------------*/
/* MODULE NAME... IIC and Mcbsp */
/* FILENAME...... 5502_CODEC.c */
/* DATE CREATED.. Mon 6/20/2004 */
/* COMPONENT..... */
/* PREREQUISITS.. */
/*----------------------------------------------------------------------------*/
/* DESCRIPTION: */
/* */
/* This example is that the codec is controled by the IIC and Mcbsp */
/*----------------------------------------------------------------------------*/
#include <csl.h>
#include <csl_chip.h>
#include <csl_i2c.h>
#include <csl_pll.h>
#include <csl_mcbsp.h>
#include <csl_emif.h>
#include <csl_emifBhal.h>
#include "CODEC.h"
#undef CODEC_ADDR
#define CODEC_ADDR 0x1A
/*------------------------------------------------------------------------------------*/
//
// Config McBSP: Use McBSP to send and receive the data between DSP and AIC23B
//
/*------------------------------------------------------------------------------------*/
MCBSP_Config Mcbsp1Config = {
MCBSP_SPCR1_RMK(
MCBSP_SPCR1_DLB_OFF, // DLB = 0
MCBSP_SPCR1_RJUST_LZF, // RJUST = 0,right justify the data and zero fill the MSBs
MCBSP_SPCR1_CLKSTP_DISABLE, // CLKSTP = 0
MCBSP_SPCR1_DXENA_ON, // DXENA = 1,DX delay enabler on
0, // Reserved = 0
MCBSP_SPCR1_RINTM_RRDY, // RINTM = 0
MCBSP_SPCR1_RSYNCERR_NO, // RSYNCER = 0
MCBSP_SPCR1_RFULL_NO, // RFULL = 0
MCBSP_SPCR1_RRDY_NO, // RRDY = 0
MCBSP_SPCR1_RRST_DISABLE // RRST = 0; Disable receiver
),
MCBSP_SPCR2_RMK(
MCBSP_SPCR2_FREE_NO, // FREE = 0
MCBSP_SPCR2_SOFT_NO, // SOFT = 0
MCBSP_SPCR2_FRST_FSG, // FRST = 1 ; Enable the frame-sync logic
MCBSP_SPCR2_GRST_CLKG, // GRST = 1 ; The sample rate generator is take out of its reset state
MCBSP_SPCR2_XINTM_XRDY, // XINTM = 0
MCBSP_SPCR2_XSYNCERR_NO, // XSYNCER =0
MCBSP_SPCR2_XEMPTY_NO, // XEMPTY = 0
MCBSP_SPCR2_XRDY_NO, // XRDY = 0
MCBSP_SPCR2_XRST_DISABLE // XRST = 0 Disable transimitter
),
// 單數(shù)據(jù)相,接受數(shù)據(jù)長度為16位,每相2個數(shù)據(jù)
MCBSP_RCR1_RMK(
MCBSP_RCR1_RFRLEN1_OF(1), // RFRLEN1 = 1
MCBSP_RCR1_RWDLEN1_16BIT // RWDLEN1 = 2
),
MCBSP_RCR2_RMK(
MCBSP_RCR2_RPHASE_SINGLE, // RPHASE = 0
MCBSP_RCR2_RFRLEN2_OF(0), // RFRLEN2 = 0
MCBSP_RCR2_RWDLEN2_8BIT, // RWDLEN2 = 0
MCBSP_RCR2_RCOMPAND_MSB, // RCOMPAND = 0 No companding,any size data, MSB received first
MCBSP_RCR2_RFIG_YES, // RFIG = 1 Frame-sync ignore
MCBSP_RCR2_RDATDLY_1BIT // RDATDLY = 1 1-bit data delay
),
MCBSP_XCR1_RMK(
MCBSP_XCR1_XFRLEN1_OF(1), // XFRLEN1 = 1
MCBSP_XCR1_XWDLEN1_16BIT // XWDLEN1 = 2
),
MCBSP_XCR2_RMK(
MCBSP_XCR2_XPHASE_SINGLE, // XPHASE = 0
MCBSP_XCR2_XFRLEN2_OF(1), // XFRLEN2 = 0
MCBSP_XCR2_XWDLEN2_8BIT, // XWDLEN2 = 0
MCBSP_XCR2_XCOMPAND_MSB, // XCOMPAND = 0
MCBSP_XCR2_XFIG_YES, // XFIG = 1 Unexpected Frame-sync ignore
MCBSP_XCR2_XDATDLY_1BIT // XDATDLY = 1 1-bit data delay
),
MCBSP_SRGR1_DEFAULT,
MCBSP_SRGR2_DEFAULT,
MCBSP_MCR1_DEFAULT,
MCBSP_MCR2_DEFAULT,
MCBSP_PCR_RMK(
MCBSP_PCR_IDLEEN_RESET, // IDLEEN = 0
MCBSP_PCR_XIOEN_SP, // XIOEN = 0
MCBSP_PCR_RIOEN_SP, // RIOEN = 0
MCBSP_PCR_FSXM_EXTERNAL, // FSXM = 0 Tranmit frame-syn is provided by AIC23B
MCBSP_PCR_FSRM_EXTERNAL, // FSRM = 0 Receive frame-syn is provided by AIC23B
MCBSP_PCR_CLKXM_INPUT, // CLKR is input
MCBSP_PCR_CLKRM_INPUT, // CLKX is input
MCBSP_PCR_SCLKME_NO, // SCLKME=0 CLKG is taken from the McBSP internal input clock
MCBSP_PCR_CLKSSTAT_0, // The signal on the CLKS pin is low
MCBSP_PCR_DXSTAT_0, // Drive the signal on the DX pin low
MCBSP_PCR_DRSTAT_0, // The signal on the DR pin is low
MCBSP_PCR_FSXP_ACTIVEHIGH, // FSXP = 1 Because a falling edge on LRCIN or LRCOUT starts data transfer
MCBSP_PCR_FSRP_ACTIVELOW, // FSRP = 1
MCBSP_PCR_CLKXP_FALLING, // CLKXP = 1 The falling edge of BCLK starts data transfer
MCBSP_PCR_CLKRP_RISING // CLKRP = 1
),
MCBSP_RCERA_DEFAULT,
MCBSP_RCERB_DEFAULT,
MCBSP_RCERC_DEFAULT,
MCBSP_RCERD_DEFAULT,
MCBSP_RCERE_DEFAULT,
MCBSP_RCERF_DEFAULT,
MCBSP_RCERG_DEFAULT,
MCBSP_RCERH_DEFAULT,
MCBSP_XCERA_DEFAULT,
MCBSP_XCERB_DEFAULT,
MCBSP_XCERC_DEFAULT,
MCBSP_XCERD_DEFAULT,
MCBSP_XCERE_DEFAULT,
MCBSP_XCERF_DEFAULT,
MCBSP_XCERG_DEFAULT,
MCBSP_XCERH_DEFAULT
};
// 定義McBSP的句柄
MCBSP_Handle hMcbsp;
/*------------------------------------------------------------------------------------*/
//
// Config I2C: Use I2C to interface CODEC control interface
//
/*------------------------------------------------------------------------------------*/
I2C_Setup Setup = {
0, // 7 bit address mode
0x0000, // own address
150, // clkout value (Mhz)
400, // a number between 10 and 400
0, // 8 bits/byte to be received or transmitted
0, // DLB mode off
0 // FREE mode on
};
/*------------------------------------------------------------------------------------*/
//
// Config CODEC control registers
//
/*------------------------------------------------------------------------------------*/
// 數(shù)字音頻接口格式設(shè)置
// AIC23為主模式,數(shù)據(jù)為DSP模式,數(shù)據(jù)長度16位
Uint16 Digital_Audio_Inteface_Format[2]={
Codec_DAIF_REV,
DAIF_MS(1)+DAIF_LRSWAP(0)+DAIF_LRP(1)+DAIF_IWL(0)+DAIF_FOR(3)};
// AIC23的波特率設(shè)置,采樣率為48k,CLKIN=CLKOUT=MCLK
// 時鐘模式設(shè)為普通模式,基過采樣率為250Fs
Uint16 Sample_Rate_Control[2] = {
Codec_SRC_REV,
SRC_CLKIN(0)+SRC_CLKOUT(0)+SRC_SR(6)+SRC_BOSR(0)+SRC_USB(0)};
// AIC23寄存器復(fù)位
Uint16 Reset[2] ={
Codec_RST_REV,
RST_RES};
// AIC23節(jié)電方式設(shè)置,所有部分均處于工作狀態(tài)
Uint16 Power_Down_Control[2] ={
Codec_PDC_REV,
PDC_DEFAULT};
// AIC23模擬音頻的控制:關(guān)掉側(cè)音
// DAC使能,ADC輸入選擇為音頻輸入
Uint16 Analog_Aduio_Path_Control[2] = {
Codec_AAPC_STA2(0),
AAPC_STA10(0)+AAPC_STE(0)+AAPC_DAC(1)+AAPC_BYP(0)+AAPC_INSEL(0)+AAPC_MICM(0)+AAPC_MICB(0)};
// AIC23數(shù)字音頻通路的控制
// 使能ADC高通濾波
Uint16 Digital_Audio_Path_Control[2] ={
Codec_DAPC_REV,
DAPC_DACM(0)+DAPC_DEEMP(0)+DAPC_ADCHP(1)};
// AIC23數(shù)字接口的使能
Uint16 Digital_Interface_Activation[2] ={
Codec_DIA_REV,
DIA_ACT(1)};
// AIC23左通路音頻調(diào)節(jié)
Uint16 Left_Line_Input_Volume_Control[2] ={
Codec_LLIVC_LPS(1),
LLIVC_LIM(0)+LLIVC_LIV(23)};
// AIC23右通路音頻調(diào)節(jié)
Uint16 Right_Line_Input_Volume_Control[2] = {
Codec_RLIVC_RLS(1),
RLIVC_RIM(0)+RLIVC_RIV(23)};
// AIC23耳機(jī)左通路音頻調(diào)節(jié)
Uint16 Left_Headphone_Volume_Control[2] = {
Codec_LHPVC_LRS(1),
LHPVC_LZC(1)+LHPVC_LHV(127)};
// AIC23耳機(jī)右通路音頻調(diào)節(jié)
Uint16 Right_Headphone_Volume_Control[2] = {
Codec_RHPVC_RLS(1),
LHPVC_RZC(1)+LHPVC_RHV(127)};
/*------------------------------------------------------------------------------------*/
//
// FUNCTION: MAIN
//
/*------------------------------------------------------------------------------------*/
void main(void)
{
Uint16 DataTempLeft = 0; // 暫存采樣數(shù)據(jù)
Uint16 DataTempRight = 0;
// Initialize CSL library - This is REQUIRED !!!
CSL_init();
// The main frequency of system is 300MHz
PLL_setFreq(1, 0xa, 0, 1, 3, 3, 0);
// Initialize I2C, Using parameters in I2C_Setup structure
I2C_setup(&Setup);
// Open McBSP port 1 and get a McBSP type handle
hMcbsp = MCBSP_open(MCBSP_PORT1,MCBSP_OPEN_RESET);
// Config McBSP port 1 by use previously defined structure
MCBSP_config(hMcbsp,&Mcbsp1Config);
// Start McBSP1
MCBSP_start(hMcbsp,
MCBSP_RCV_START | MCBSP_XMIT_START,
0);
/*設(shè)置AIC23各部分均工作*/
I2C_write( Power_Down_Control,//pointer to data array
2, //length of data to be transmitted
1, //master or slaver
CODEC_ADDR, //slave address to transmit to
1, //transfer mode of operation
30000 //time out for bus busy
);
/*設(shè)置AIC23的數(shù)字接口*/
I2C_write( Digital_Audio_Inteface_Format,//pointer to data array
2, //length of data to be transmitted
1, //master or slaver
CODEC_ADDR, //slave address to transmit to
1, //transfer mode of operation
30000 //time out for bus busy
);
/*設(shè)置AIC23模擬通路*/
I2C_write( Analog_Aduio_Path_Control,//pointer to data array
2, //length of data to be transmitted
1, //master or slaver
CODEC_ADDR, //slave address to transmit to
1, //transfer mode of operation
30000 //time out for bus busy
);
/*設(shè)置數(shù)字通路*/
I2C_write( Digital_Audio_Path_Control,//pointer to data array
2, //length of data to be transmitted
1, //master or slaver
CODEC_ADDR, //slave address to transmit to
1, //transfer mode of operation
30000 //time out for bus busy
);
/*設(shè)置AIC23的采樣率*/
I2C_write( Sample_Rate_Control,//pointer to data array
2, //length of data to be transmitted
1, //master or slaver
CODEC_ADDR, //slave address to transmit to
1, //transfer mode of operation
30000 //time out for bus busy
);
/*設(shè)置耳機(jī)音量*/
I2C_write( Left_Headphone_Volume_Control,//pointer to data array
2, //length of data to be transmitted
1, //master or slaver
CODEC_ADDR, //slave address to transmit to
1, //transfer mode of operation
30000 //time out for bus busy
);
/*設(shè)置Line輸入的音量*/
I2C_write( Left_Line_Input_Volume_Control,//pointer to data array
2, //length of data to be transmitted
1, //master or slaver
CODEC_ADDR, //slave address to transmit to
1, //transfer mode of operation
30000 //time out for bus busy
);
/*啟動AIC23*/
I2C_write( Digital_Interface_Activation,//pointer to data array
2, //length of data to be transmitted
1, //master or slaver
CODEC_ADDR, //slave address to transmit to
1, //transfer mode of operation
30000 //time out for bus busy
);
/*------------------------------------------------------------------------------------*/
// Receive the ADC output data of CODEC
// Then output the received data to DAC of CODEC
/*------------------------------------------------------------------------------------*/
while(TRUE)
{
/* 左通路數(shù)據(jù) */
while(!MCBSP_rrdy(hMcbsp)){};
DataTempLeft = MCBSP_read16(hMcbsp);
/* 右通路數(shù)據(jù) */
while(!MCBSP_rrdy(hMcbsp)){};
DataTempRight = MCBSP_read16(hMcbsp);
/* 左聲道耳機(jī)輸出 */
while(!MCBSP_xrdy(hMcbsp)) {};
MCBSP_write16(hMcbsp,DataTempLeft);
/* 右聲道耳機(jī)輸出 */
while(!MCBSP_xrdy(hMcbsp)) {};
MCBSP_write16(hMcbsp,DataTempRight);
};
}
/******************************************************************************/
// No more
/******************************************************************************/
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -