1. 头文件
*=====================================================================
* FILENAME: Regs.h
*=====================================================================
.mmregs
*--------------------- McBSP0 Registers -------------------------
DRR20 .set0020h; McBSP0 Data Rx Reg2
DRR10 .set0021h; McBSP0 Data Rx Reg1
DXR20 .set0022h; McBSP0 Data Tx Reg2
DXR10 .set0023h; McBSP0 Data Tx Reg1
SPSA0 .set0038h; McBSP0 Sub Bank Addr Reg
SPSD0 .set0039h; McBSP0 Sub Bank Data Reg
*--------------------- McBSP1 Registers --------------------------
DRR21 .set0040h; McBSP1 Data Rx Reg2
DRR11 .set0041h; McBSP1 Data Rx Reg1
DXR21 .set0042h; McBSP1 Data Tx Reg2
DXR11 .set0043h; McBSP1 Data Tx Reg1
SPSA1 .set0048h; McBSP1 Sub Bank Addr Reg
SPSD1 .set0049h; McBSP1 Sub Bank Data Reg
*------- McBSP0 & McBSP1 Sub-Bank Addressed Registers -------------
SPCR1.set0000h ; McBSP Ser Port Ctrl Reg1
SPCR2.set0001h ; McBSP Ser Port Ctrl Reg2
RCR1.set0002h ; McBSP Rx Ctrl Reg1
RCR2.set0003h ; McBSP Rx Ctrl Reg2
XCR1.set0004h ; McBSP Tx Ctrl Reg1
XCR2.set0005h ; McBSP Tx Ctrl Reg2
SRGR1.set0006h ; McBSP Sample Rate Gen Reg1
SRGR2.set0007h ; McBSP Sample Rate Gen Reg2
MCR1.set0008h ; McBSP Multichan Reg1
MCR2.set0009h ; McBSP Multichan Reg2
RCERA.set000Ah ; McBSP Rx Chan Enable Reg Partition A
RCERB.set000Bh ; McBSP Rx Chan Enable Reg Partition B
XCERA.set000Ch ; McBSP Tx Chan Enable Reg Partition A
XCERB.set000Dh ; McBSP Tx Chan Enable Reg Partition B
PCR.set000Eh ; McBSP Pin Ctrl Reg
2. 中断向量表
.title "vectors.asm"
.ref start
.ref receive_int
.sect ".vectors"
RESET: B start ;复位矢量
NOP
NOP
NMI: RETE ;非屏蔽中断
NOP
NOP
NOP
SINT17 .space 4*16 ;软件中断
SINT18 .space 4*16
SINT19 .space 4*16
SINT20 .space 4*16
SINT21 .space 4*16
SINT22 .space 4*16
SINT23 .space 4*16
SINT24 .space 4*16
SINT25 .space 4*16
SINT26 .space 4*16
SINT27 .space 4*16
SINT28 .space 4*16
SINT29 .space 4*16
SINT30 .space 4*16
INT0: RETE ;外部用户中断0
NOP
NOP
NOP
INT1: RETE ;外部用户中断1
NOP
NOP
NOP
INT2: RETE ;外部用户中断2
NOP
NOP
NOP
TINT0: RETE ;定时器0中断
NOP
NOP
NOP
BRINT0: B receive_int ;McBSP0接收中断
NOP
NOP
NOP
BXINT0: RETE ;McBSP0发送中断
NOP
NOP
NOP
DMAC0: RETE ;DMA通道0中断
NOP
NOP
NOP
TINT1: RETE ;定时器1中断
NOP
NOP
NOP
INT3: RETE ;外部用户中断3
NOP
NOP
NOP
HPINT: RETE ;主机接口(HPI)中断
NOP
NOP
NOP
BRINT1: RETE ;McBSP1接收中断
NOP
NOP
NOP
BXINT1: RETE ;McBSP1发送中断
NOP
NOP
NOP
DMAC4: RETE ;DMA通道4中断
NOP
NOP
NOP
DMAC5: RETE ;DMA通道5中断
NOP
NOP
NOP
.end
3. CMD文件
vectors.obj
audio.obj
-o audio.out
-m audio.out
-e start
MEMORY
{
PAGE 0:
PFLASH: org=10000h,len=0C000h
VECS: org=0FF80h,len=0080h
PAGE 1:
DARAM: org=20000h,len=20000h
DFLASH: org=00000h,len=4000h
}
SECTIONS
{
.text :>PFLASH PAGE 0
.data :>PFLASH PAGE 0
.bss :>DARAM PAGE 1
STACK :>DFLASH PAGE 1
.vectors :>VECS PAGE 0
}
4. 主程序
.title "audio.asm"
.mmregs
.include "regs.h"
.def start
.def init_5402
.def init_mcbsp
.def init_codec
.def receive_int
STACK .usect "STACK",200h
.text
start: STM #STACK+200h,SP ;设置堆栈指针
B init_5402 ;TMS320VC5402初始化(STO,ST1,PMST,SWWSR,BSCR)
B init_mcbsp ;McBSP模块初始化
B init_codec ;TLV320AIC15初始化
STM #0 ,IMR ;中断屏蔽寄存器清0
ORM #0010h ,IMR ;使能BRINT0,BXINT0中断
STM #0FFFFh ,IFR ;中断标志寄存器清0
RSBX INTM ;中断使能
end: NOP
NOP
B end
;--------------------------------------------------------------------------------------
init_5402: STM #2492h ,SWWSR ;插入2个等待状态
STM #0002h ,BSCR ;块切换时插入0个等待状态
STM #1800h ,ST0 ;DP指针清0
STM #2940h ,ST1 ;相对寻址使用DP指针,中断禁止
STM #0FF88h ,PMST ;MP/MC=0,OVLY=0,DROM=1,CLKOUT输出使能
RET
;---------------------------------------------------------------------------------------
W_McBSP_REG .macro addr ,val ;定义一个宏,写McBSP寄存器
STM addr ,SPSA0 ;设置子地址寄存器的值
NOP
STM val ,SPSD0 ;设置子数据寄存器的值
NOP
NOP
.endm
R_McBSP_REG .macro addr ,acc ;定义一个宏,读McBSP寄存器
STM addr ,SPSA0 ;设置子地址寄存器的值
NOP
LDM SPSD0 ,acc ;将子数据寄存器的值传给累加器
NOP
.endm
WAIT_W .macro ;定义一个宏,等待
WAIT?: R_McBSP_REG SPCR2 ,A
AND #10 ,A ;发送RDY信号与A向与
BC WAIT? ,AEQ ;发送没准备好就继续等待
.endm
PROGREG .macro progword ;定义一个宏,向Codec写控制命令
STM #01h ,DXR10 ;通过向数据最低位写1,使Codec由连续数据模式
;转换为编程模式
WAIT_W
STM progword,DXR10 ;向数据发送寄存器写控制字
WAIT_W
.endm
;---------------------------------------------------------------------------------------
init_mcbsp: W_McBSP_REG SPCR1 ,#0000h ;数据右对齐,接收器复位
W_McBSP_REG SPCR2 ,#0000h ;帧同步发生器,采样率发生器,发送器复位
W_McBSP_REG PCR ,#000Ch ;DX,FSX,CLKX,DR,FSR,CLKR配置为串口,
;帧同步信号,发送时钟,接收时钟由外部器
;件驱动,发送,接收帧同步脉冲高电平有效,
;在CLKX的上升沿采样发送数据,CLKR的
;下降沿采样接收数据
W_McBSP_REG RCR1 ,#0040h ;接收数据每帧长度为1个字,字长为16位
W_McBSP_REG RCR2 ,#0004h ;接收数据为单相帧,无扩展,无延迟,第一
;个后的接收帧同步脉冲被忽略
W_McBSP_REG XCR1 ,#0040h ;发送数据每帧长度为1个字,字长为16位
W_McBSP_REG XCR2 ,#0004h ;发送数据为单相帧,无扩展,无延迟,第一
;个后的发送帧同步脉冲被忽略
NOP
NOP
STM #0 ,DRR10 ;数据接收寄存器清0
STM #0 ,DXR10 ;数据发送寄存器清0
W_McBSP_REG SPCR1 ,#0001h ;使能接收器
W_McBSP_REG SPCR2 ,#0001h ;使能发送器
RET
;----------------------------------------------------------------------------------------
init_codec: PROGREG #2740h ;设置控制寄存器1,选择连续数据模式,DAC
;输入数据长度为15bit
PROGREG #4720h ;设置控制寄存器2,
;SCLK=16*FS*#Device*mode
PROGREG #6701h ;设置控制寄存器3,FS/fs=1
PROGREG #8700h ;设置控制寄存器4,N=16,P=8
PROGREG #8719h ;设置控制寄存器4,M=9
PROGREG #0C704h ;设置控制寄存器6,模拟输入为MICIN的公
;共外部模式
;----------------------------------------------------------------------------------------
receive_int:
LDM DRR10 ,A ;将串口数据接收寄存器的值传给累加器A
STL A ,DXR10 ;将累加器A的值传给串口数据发送寄存器
RETE
.end