?? codectest.c
字號:
while(!MCBSP_RRDY((unsigned int*)hDevice));
temp=REG_READ(DRR1_ADDR((unsigned int*)hDevice));
clr_fc1();
asm(" nop ");
asm(" nop ");
asm(" nop ");
asm(" nop ");
return temp;
}
/*
codec_write_reg(ANDLE hDevice,CodecReg reg,unsigned int value)--寫AD50 CODEC的控制寄存器
參數:
hDevice--控制codec的句柄
reg--控制寄存器的地址
value--要寫入的寄存器的數據
*/
u16 codec_write_reg(HANDLE hDevice,CodecReg reg,u16 value,u16 mask)
{
u16 output;
output=(reg<<0x08)+value;
//清空接收緩沖區及RRDY標志
REG_READ(DRR1_ADDR((unsigned int*)hDevice));
while(!MCBSP_RRDY((unsigned int*)hDevice));
REG_READ(DRR1_ADDR((unsigned int*)hDevice));
while(!MCBSP_XRDY((unsigned int*)hDevice));
set_fc1();
asm(" nop ");
asm(" nop ");
asm(" nop ");
asm(" nop ");
REG_WRITE(DXR1_ADDR((unsigned int*)hDevice), output);
while(!MCBSP_RRDY((unsigned int*)hDevice));
REG_READ(DRR1_ADDR((unsigned int*)hDevice));
clr_fc1();
return OK;
}
/******************************************************************************/
/* codec_open() - Acquire a handle to a specific codec and connect codec to */
/* respective McBSP. */
/* */
/* Parameters - */
/* codec - an element of an enumeration indicating the codec to open . */
/* */
/* Returns - a handle to the codec or -1 on failure */
/* */
/******************************************************************************/
HANDLE codec_open(CodecId codec)
{
init_mcbsp(codec);
return (HANDLE) codec;
}
/******************************************************************************/
/* codec_close() - Closes codec connection to the McBSP and releases a */
/* previously acquired handle */
/* */
/* Parameters - */
/* hDevice - a handle to a specific instance of codec. */
/* */
/* Returns - */
/* */
/******************************************************************************/
int codec_close(HANDLE hDevice)
{
MCBSP_TX_RESET((u16 *)hDevice);
MCBSP_RX_RESET((u16 *)hDevice);
return True;
}
/******************************************************************************/
/* codec_reset() - Reset chip to Power On Reset Configuration */
/* */
/* This function resets the AD50 codec by asserting then de-asserting */
/* the PWDN pin. All registers are configured to their POR values. */
/* */
/* Parameters - */
/* hDevice - a handle to a specific instance of codec. . */
/* */
/* Returns - */
/* */
/******************************************************************************/
int codec_reset(HANDLE hDevice)
{
codec_write_reg((u16 *)hDevice,Cntrl1,0x80,0);
codec_write_reg((u16 *)hDevice,Cntrl1,0,0);
return True;
}
/******************************************************************************/
/* codec_monitor_gain() - Set monitor amplifier gain */
/* */
/* Parameters - */
/* hDevice - a handle to a specific instance of codec. . */
/* gain - member of an enumeration indicating gain for monitor amp */
/* */
/* Returns - */
/* */
/* */
/******************************************************************************/
int codec_monitor_gain(HANDLE hDevice, CodecMonGain gain)
{
CR1=CR1&0xf3|(gain<<2);
codec_write_reg((u16 *)hDevice,Cntrl1,CR1,0);
return True;
}
/******************************************************************************/
/* codec_dac_mode() - Sets 16-bit or 15-bit+1 mode for the DAC portion of the */
/* codec. */
/* */
/* Parameters - */
/* hDevice - a handle to a specific instance of codec. . */
/* mode - a member of an enumeration indicating 16 bit or 15+1 bit */
/* serial communications protocol. */
/* */
/* Returns - */
/* */
/* */
/******************************************************************************/
int codec_dac_mode(HANDLE hDevice, CodecDacMode mode)
{
CR1=CR1&0xfe|mode;
codec_write_reg((u16 *)hDevice,Cntrl1,CR1,0);
return True;
}
/******************************************************************************/
/* codec_adc_mode() - Sets 16-bit or 15-bit+1 mode for the ADC portion of the */
/* codec. */
/* */
/* Parameters - */
/* hDevice - a handle to a specific instance of codec. . */
/* mode - a member of an enumeration indicating 16 bit or 15+1 bit */
/* serial communications protocol. */
/* */
/* Returns - */
/* */
/* */
/******************************************************************************/
int codec_adc_mode(HANDLE hDevice, CodecAdcMode mode)
{
CR2=CR2&0xef|(mode ? 0x10:0x00);
codec_write_reg((u16 *)hDevice,Cntrl2,CR2,0);
return True;
}
/******************************************************************************/
/* codec_ain_gain() - Set the analog input gain */
/* */
/* Parameters - */
/* hDevice - a handle to a specific instance of codec. . */
/* gain - member of an enumeration indicating gain for analog input */
/* */
/* Returns - */
/* */
/* */
/******************************************************************************/
int codec_ain_gain(HANDLE hDevice, CodecAinGain gain)
{
CR4=CR4&0xf3|(gain<<2);
codec_write_reg((u16 *)hDevice,Cntrl4,CR4,0);
return True;
}
/******************************************************************************/
/* codec_aout_gain() - Set the analog output gain */
/* */
/* Parameters - */
/* hDevice - a handle to a specific instance of codec. . */
/* gain - member of an enumeration indicating gain for analog output */
/* */
/* Returns - */
/* */
/* */
/******************************************************************************/
int codec_aout_gain(HANDLE hDevice, CodecAoutGain gain)
{
CR4=CR4&0xfc|gain;
codec_write_reg((u16 *)hDevice,Cntrl4,CR4,0);
return True;
}
/******************************************************************************/
/* codec_sample_rate() - Sets the code sample rate. The specified sample rate */
/* Fs (Hz) is used to choose the value N in the equation: */
/* */
/* fs = MCLK/(128*N) or MCLK/(512*N) MCLK=8.192Mhz */
/* */
/* both the value of N, and the selection of 128 or 512 is made automatically */
/* by this routine. */
/* */
/* */
/* Parameters - */
/* hDevice - a handle to a specific instance of codec. . */
/* sample_rate - desired number of samples per second */
/* */
/* Returns - */
/* */
/* */
/******************************************************************************/
int codec_sample_rate(HANDLE hDevice, CodecSampleRate sample_rate)
{
CR4=CR4&0x0f|sample_rate;
codec_write_reg((u16 *)hDevice,Cntrl4,CR4,0);
return True;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -