📄 ad535.c
字号:
/* ***********************************************************
* THIS PROGRAM IS PROVIDED "AS IS". TI MAKES NO WARRANTIES OR
* REPRESENTATIONS, EITHER EXPRESS, IMPLIED OR STATUTORY,
* INCLUDING ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE, LACK OF VIRUSES, ACCURACY OR
* COMPLETENESS OF RESPONSES, RESULTS AND LACK OF NEGLIGENCE.
* TI DISCLAIMS ANY WARRANTY OF TITLE, QUIET ENJOYMENT, QUIET
* POSSESSION, AND NON-INFRINGEMENT OF ANY THIRD PARTY
* INTELLECTUAL PROPERTY RIGHTS WITH REGARD TO THE PROGRAM OR
* YOUR USE OF THE PROGRAM.
*
* IN NO EVENT SHALL TI BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
* CONSEQUENTIAL OR INDIRECT DAMAGES, HOWEVER CAUSED, ON ANY
* THEORY OF LIABILITY AND WHETHER OR NOT TI HAS BEEN ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGES, ARISING IN ANY WAY OUT
* OF THIS AGREEMENT, THE PROGRAM, OR YOUR USE OF THE PROGRAM.
* EXCLUDED DAMAGES INCLUDE, BUT ARE NOT LIMITED TO, COST OF
* REMOVAL OR REINSTALLATION, COMPUTER TIME, LABOR COSTS, LOSS
* OF GOODWILL, LOSS OF PROFITS, LOSS OF SAVINGS, OR LOSS OF
* USE OR INTERRUPTION OF BUSINESS. IN NO EVENT WILL TI'S
* AGGREGATE LIABILITY UNDER THIS AGREEMENT OR ARISING OUT OF
* YOUR USE OF THE PROGRAM EXCEED FIVE HUNDRED DOLLARS
* (U.S.$500).
*
* Unless otherwise stated, the Program written and copyrighted
* by Texas Instruments is distributed as "freeware". You may,
* only under TI's copyright in the Program, use and modify the
* Program without any charge or restriction. You may
* distribute to third parties, provided that you transfer a
* copy of this license to the third party and the third party
* agrees to these terms by its first use of the Program. You
* must reproduce the copyright notice and any other legend of
* ownership on each copy or partial copy, of the Program.
*
* You acknowledge and agree that the Program contains
* copyrighted material, trade secrets and other TI proprietary
* information and is protected by copyright laws,
* international copyright treaties, and trade secret laws, as
* well as other intellectual property laws. To protect TI's
* rights in the Program, you agree not to decompile, reverse
* engineer, disassemble or otherwise translate any object code
* versions of the Program to a human-readable form. You agree
* that in no event will you alter, remove or destroy any
* copyright notice included in the Program. TI reserves all
* rights not specifically granted under this license. Except
* as specifically provided herein, nothing in this agreement
* shall be construed as conferring by implication, estoppel,
* or otherwise, upon you, any license or other right under any
* TI patents, copyrights or trade secrets.
*
* You may not use the Program in non-TI devices.
* ********************************************************* */
/*
* ======== ad535.c ========
*/
#include <std.h>
#include <log.h>
#include <csl.h>
#include <mcbsp.h>
/* local function prototypes ... */
static Void codec_init(MCBSP_HANDLE);
static Void codec_error(Int id);
static Void mcbsp_init(MCBSP_HANDLE);
static Uns mcbsp_read(MCBSP_HANDLE);
static Void mcbsp_write(MCBSP_HANDLE hMcbsp, Uns out_data);
/*
* ======== codec_error ========
*/
static Void codec_error(id)
{
LOG_error("Error setting up register %d", id);
for (;;) {
/* loop forever */
}
}
/*
* ======== codec_init ========
*/
static Void codec_init(MCBSP_HANDLE hMcbsp)
{
volatile Uns temp;
/* For more details on the setup for the TLC320AD535 Analog Interface,
refer to Appendix A of SLAS202a.pdf. To use Code Composer Studio Help:
Help->General Help, then in Contents tab double click TMS320C6211 DSK,
double click Hardware, double click Analog Interface, then
double click 'C6211 DSK Analog Interface Configuration, at the bottom
is a link to the data manual.
*/
/* set up control register 3 for S/W reset */
mcbsp_read(hMcbsp);
mcbsp_write(hMcbsp,0);
mcbsp_read(hMcbsp);
mcbsp_write(hMcbsp,0);
mcbsp_read(hMcbsp);
mcbsp_write(hMcbsp,0);
mcbsp_read(hMcbsp);
mcbsp_write(hMcbsp,1);
mcbsp_read(hMcbsp);
mcbsp_write(hMcbsp,0x0386);
mcbsp_read(hMcbsp);
mcbsp_write(hMcbsp,0);
mcbsp_read(hMcbsp);
/* set up control register 3 for mic input */
mcbsp_write(hMcbsp,0);
mcbsp_read(hMcbsp);
mcbsp_write(hMcbsp,0);
mcbsp_read(hMcbsp);
mcbsp_write(hMcbsp,1);
mcbsp_read(hMcbsp);
mcbsp_write(hMcbsp,0x0306);
mcbsp_read(hMcbsp);
mcbsp_write(hMcbsp,0);
mcbsp_read(hMcbsp);
/* read control register 3 to verify mic input */
mcbsp_write(hMcbsp,0);
mcbsp_read(hMcbsp);
mcbsp_write(hMcbsp,1);
mcbsp_read(hMcbsp);
mcbsp_write(hMcbsp,0x2330);
temp = mcbsp_read(hMcbsp);
mcbsp_write(hMcbsp,0x0);
mcbsp_read(hMcbsp);
mcbsp_write(hMcbsp,0x0);
mcbsp_read(hMcbsp);
if((temp & 0xff) != 0x06) {
codec_error(3);
}
/* set up control register 4 to select Voice Channel Input 0db gain */
mcbsp_write(hMcbsp,0);
mcbsp_read(hMcbsp);
mcbsp_write(hMcbsp,0);
mcbsp_read(hMcbsp);
mcbsp_write(hMcbsp,1);
mcbsp_read(hMcbsp);
mcbsp_write(hMcbsp,0x0400);
mcbsp_read(hMcbsp);
mcbsp_write(hMcbsp,0);
mcbsp_read(hMcbsp);
/* read and verify control register 4 */
mcbsp_write(hMcbsp,0);
mcbsp_read(hMcbsp);
mcbsp_write(hMcbsp,1);
mcbsp_read(hMcbsp);
mcbsp_write(hMcbsp,0x2430);
temp = mcbsp_read(hMcbsp);
mcbsp_write(hMcbsp,0x0);
mcbsp_read(hMcbsp);
mcbsp_write(hMcbsp,0x0);
mcbsp_read(hMcbsp);
if((temp & 0xff) != 0x00) {
codec_error(4);
}
/* set up control register 5 to select Voice Channel Output 0db gain */
mcbsp_write(hMcbsp,0);
mcbsp_read(hMcbsp);
mcbsp_write(hMcbsp,0);
mcbsp_read(hMcbsp);
mcbsp_write(hMcbsp,1);
mcbsp_read(hMcbsp);
mcbsp_write(hMcbsp,0x0502);
mcbsp_read(hMcbsp);
mcbsp_write(hMcbsp,0);
mcbsp_read(hMcbsp);
/* read and verify control register 5 */
mcbsp_write(hMcbsp,0);
mcbsp_read(hMcbsp);
mcbsp_write(hMcbsp,1);
mcbsp_read(hMcbsp);
mcbsp_write(hMcbsp,0x2530);
temp = mcbsp_read(hMcbsp);
mcbsp_write(hMcbsp,0x0);
mcbsp_read(hMcbsp);
mcbsp_write(hMcbsp,0x0);
mcbsp_read(hMcbsp);
if((temp & 0xfe) != 0x2) {
codec_error(5);
}
}
/*
* ======== mcbsp_init ========
*/
static Void mcbsp_init(MCBSP_HANDLE hMcbsp)
{
/* CSL McBSP configure function */
MCBSP_ConfigB(hMcbsp,
/* Configure both RINT and XINT events */
MCBSP_MK_SPCR(MCBSP_SPCR_RRST_NO,
MCBSP_SPCR_RINTM_RRDY,
MCBSP_SPCR_DXENA_OFF,
MCBSP_SPCR_CLKSTP_DISABLE,
MCBSP_SPCR_RJUST_RZF,
MCBSP_SPCR_DLB_OFF,
MCBSP_SPCR_XRST_NO,
MCBSP_SPCR_XINTM_XRDY,
MCBSP_SPCR_GRST_NO,
MCBSP_SPCR_FRST_NO),
/* set RX and TX control registers to 16 bit data */
MCBSP_MK_RCR(MCBSP_RCR_RWDREVRS_NA,
MCBSP_RCR_RWDLEN1_16BIT,
MCBSP_RCR_RFRLEN1_OF(0),
MCBSP_RCR_RPHASE2_NA,
MCBSP_RCR_RDATDLY_1BIT,
MCBSP_RCR_RFIG_NO,
MCBSP_RCR_RCOMPAND_MSB,
MCBSP_RCR_RWDLEN2_16BIT,
MCBSP_RCR_RFRLEN2_OF(0),
MCBSP_RCR_RPHASE_SINGLE),
MCBSP_MK_XCR(MCBSP_XCR_XWDREVRS_NA,
MCBSP_XCR_XWDLEN1_16BIT,
MCBSP_XCR_XFRLEN1_OF(0),
MCBSP_XCR_XPHASE2_NA,
MCBSP_XCR_XDATDLY_1BIT,
MCBSP_XCR_XFIG_NO,
MCBSP_XCR_XCOMPAND_MSB,
MCBSP_XCR_XWDLEN2_16BIT,
MCBSP_XCR_XFRLEN2_OF(0),
MCBSP_XCR_XPHASE_SINGLE),
1, /* Default SRGR value */
0, /* Default MCR value */
0, /* Default RCER value */
0, /* Default XCER value */
0 /* Default PCR value */
);
}
/*
* ======== mcbsp_read ========
*/
static Uns mcbsp_read(MCBSP_HANDLE hMcbsp)
{
/* Monitor RRDY, wait until data ready */
while (!MCBSP_Rrdy(hMcbsp));
return MCBSP_Read(hMcbsp);
}
/*
* ======== mcbsp_write ========
*/
static Void mcbsp_write(MCBSP_HANDLE hMcbsp, Uns out_data)
{
/* Monitor XRDY, wait until ready before writing */
while (!MCBSP_Xrdy(hMcbsp));
MCBSP_Write(hMcbsp, out_data);
}
/*
* ======== DSS_init ========
*/
Void ad535_init(MCBSP_HANDLE hMcbsp)
{
mcbsp_init(hMcbsp);
codec_init(hMcbsp);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -