#include <stdio.h> #define IMR (volatile unsigned int *) 0x0000 #define DMPREC (volatile unsigned int *) 0x0054 #define SWWSR (volatile unsigned int *) 0x0028 #define BSCR (volatile unsigned int *) 0x0029 #define ST0 (volatile unsigned int *) 0x0006 #define ST1 (volatile unsigned int *) 0x0007 #define PMST (volatile unsigned int *) 0x001D #define IFR (volatile unsigned int *) 0x0001 #define DRR11 (volatile unsigned int *) 0x0041 #define DXR11 (volatile unsigned int *) 0x0043
#define SPSA1 (volatile unsigned int *) 0x0048 //McBSP1 #define SPSD1 (volatile unsigned int *) 0x0049 //sub_address register #define SPCR11 0x0000 #define SPCR21 0x0001 #define RCR11 0x0002 #define RCR21 0x0003 #define XCR11 0x0004 #define XCR21 0x0005 #define PCR1 0x000E
void inline disable(void); void inline enable(void); void interrupt essp_rx(void); void init_core(void); void init_bsp(void); void init_codec(void);
main() { init_core(); init_codec(); enable(); while(1); }
void init_core() { /*设置外部存储器的等待周期为0,I/O等待周期为2*/ *SWWSR=0x2000; *BSCR=0x0000; *ST0=0x1800; *ST1=0x2900; /*设置中断向量表的首地址为0X0080*/ *PMST=0x00A0; *IMR=0x0000; *IFR=0xffff;/*有的中断标志*/ }
void init_bsp() { *SPSA1=SPCR11; *SPSD1=0x0020; /*发送中断由帧同步信号产生,McBSP0 Tx=FREE*/ *SPSA1=SPCR21; *SPSD1=0x0201;
*SPSA1=RCR11; *SPSD1=0x0040;
*SPSA1=RCR21; *SPSD1=0x0000;
*SPSA1=XCR11; *SPSD1=0x0040; *SPSA1=XCR21; *SPSD1=0x0000;
*SPSA1=PCR1; *SPSD1=0x000C;
asm("NOP"); asm("NOP"); }
/*初始化TLC320AD50*/ void init_codec() { int i; disable(); init_bsp(); /*初始化MBSP0*/
*DMPREC=*DMPREC&0xFF3F; /*设置中断为串口发出*/ *DXR11=0x0000;
*SPSA1=SPCR11; /*接收数据*/ *SPSD1=0x0001;
*SPSA1=SPCR21; /*发送数据*/ *SPSD1=0x0001;
*DXR11=0x0003; /*用软件方式配置AD50寄存器*/ *SPSA1=SPCR21; while(!(*SPSD1&0x0002));
*DXR11=0x0181; /*复位AD50*/ while(!(*SPSD1&0x0002)); for(i=0;i<4000;i++); *DXR11=0x0003; while(!(*SPSD1&0x0002));
*DXR11=0x0101; while(!(*SPSD1&0x0002));
*DXR11=0x0003; while(!(*SPSD1&0x0002)); *DXR11=0x0210; while(!(*SPSD1&0x0002));
*DXR11=0x0003; while(!(*SPSD1&0x0002));
*DXR11=0x0300; while(!(*SPSD1&0x0002));
*DXR11=0x0003; while(!(*SPSD1&0x0002));
*DXR11=0x0450; while(!(*SPSD1&0x0002));
asm("NOP"); asm("NOP"); *IMR=0x0400; *IFR=0x0400; enable(); *DXR11=*DRR11; }
void inline disable() {
asm("SSBX INTM"); }
void inline enable() {
asm("RSBX INTM"); }
void interrupt essp_rx() { int sample_in; /*读入采样数据*/ sample_in=*DRR11; /*传回AD50*/ *DXR11=sample_in; }
|