TI中文支持网
TI专业的中文技术问题搜集分享网站

mcbsp dma

各位有谁有相关经历,给点意见,或给个想关代码

现在我的项目,是e1 pcm 连到 mcbsp, 然后通过dma 存到 buf里 

我用汇编写的代码是可以,代码如下

;————————————-
; MCBSP复位
;————————————-
MCBSP_RST:
ST #0,WORKLIGHT_TIMER
STM #0,SPSA0 ; 对MCBSP0进行初始化
STM #0h,SPCR10 ; 接收复位
STM #1,SPSA0
STM #0c0h,SPCR20 ; 发送复位

STM #0,SPSA1 ; 对MCBSP1进行初始化
STM #0h,SPCR11 ; 接收复位
STM #1,SPSA1
STM #0C0h,SPCR21 ; 发送复位

;;————————————-
; DMA的初始化
;————————————-
STM #0080h,DMPREC ; 所有通道禁用
;***通道1初始化,用于串口0的发送
DMA_CH1:
STM DMSRC1,DMSA
STM #TRA10,DMSDN ; 源地址为#TRA10
STM DMDST1,DMSA ; 目的地址为DXR10
STM DXR10,DMSDN
STM DMCTR1,DMSA
STM #31,DMSDN ; 每帧元素个数为32个
STM DMSFC1,DMSA ; McBSP0 transmit event,单字传输方式,帧数为8
STM #2007h,DMSDN
STM DMMCR1,DMSA ; DMA自动初始关,块发送完产生中断,复帧方式,目的地址不变,位于数据存储器
STM #4541h,DMSDN ; 源地址指针根据DMIDX0 and DMFRI0改变,处于数据存储器
; STM #4141h,DMSDN ; 源地址指针自增1,处于数据存储器

STM DMIDX0,DMSA
STM #8,DMSDN ; set element address index to +8
STM DMFRI0,DMSA
STM #0FF09h,DMSDN ; set frame address index to -(31*8-1)

;***通道0初始化,用于串口0的接收
DMA_CH0:
STM DMSRC0,DMSA
STM DRR10,DMSDN ; 设置DMA通道0的源地址为DRR10
STM DMDST0,DMSA
STM #RCV10,DMSDN ; 设置DMA通道0的目的地址为RCV10
STM DMCTR0,DMSA
STM #(16-1),DMSDN ; DMA通道0:1帧16字
STM DMSFC0,DMSA
STM #105Fh,DMSDN ; 接收由MCBSP1的接收事件触发,1字16位,1模块含N帧
STM DMMCR0,DMSA
STM #4059h,DMSDN ; 不自动初始化,1模块传输完产生中断,工作于多帧模式
; 源地址不变,目的地址根据DMIDX1和DMFRI1变化
STM DMIDX1,DMSA ; set element address index to +N
STM #N,DMSDN
STM DMFRI1,DMSA ; set frame address index to -(N*15-1)
STM #0FA61h,DMSDN

;***通道3初始化,用于串口1的发送
DMA_CH3:
STM DMSRC3,DMSA
STM #TRA11,DMSDN ; 源地址为#TRA11
STM DMDST3,DMSA ; 目的地址为DXR11
STM DXR11,DMSDN
STM DMCTR3,DMSA
STM #31,DMSDN ; 每帧元素个数为32个
STM DMSFC3,DMSA ; McBSP1 transmit event,单字传输方式,帧数为8
STM #6007h,DMSDN
STM DMMCR3,DMSA ; DMA自动初始关,块发送完不产生中断,复帧方式,目的地址不变,位于数据存储器
STM #0541h,DMSDN ; 源地址指针根据DMIDX0 and DMFRI0改变,处于数据存储器

STM DMIDX0,DMSA
STM #8,DMSDN ; set element address index to +8
STM DMFRI0,DMSA
STM #0FF09h,DMSDN ; set frame address index to -(31*8-1)

;***通道2初始化,用于串口1的接收
DMA_CH2:
STM DMSRC2,DMSA
STM DRR11,DMSDN ; 设置DMA通道2的源地址为DRR11
STM DMDST2,DMSA
STM #RCV11,DMSDN ; 设置DMA通道2的目的地址为RCV11
STM DMCTR2,DMSA
STM #(16-1),DMSDN ; DMA通道2:1帧16字
STM DMSFC2,DMSA
STM #505Fh,DMSDN ; 接收由MCBSP1的接收事件触发,1字16位,1模块含N帧
STM DMMCR2,DMSA
STM #0059h,DMSDN ; 不自动初始化,1模块传输完不产生中断,工作于多帧模式
; 源地址不变,目的地址根据DMIDX1和DMFRI1变化
STM DMIDX1,DMSA ; set element address index to +N
STM #N,DMSDN
STM DMFRI1,DMSA ; set frame address index to -(N*15-1)
STM #0FA61h,DMSDN

STM #0F8Fh,DMPREC ; 通道0,1,2,3使能,并高优先,中断复用
;————————————-
; 变量的初始化
;————————————-
ST #0h,DXTPT
ST #0h,XFLAG ; XFLAG清零
ST #0h,RFLAG ; RFLAG清零
ST #0h,XFRAMECT ; XFRAMECT清零
ST #0h,TRAINT ; TRAINT清零
ST #0h,TRAINT1
ST #0h,RCVINT ; RCVINT清零
ST #0h,RCVINT1
ST #0h,XTCOUNT ;发送缓冲区时隙计算计数清零
ST #0h,RTCOUNT
ST #0h,FLAG1mS ; 1mS定时标志
ST #0h,GROUPNUM ; GROUPNUM清零
ST #0h,SYNC_FLAG
ST #0h,TEMP

ST #0h,RSHTFLAG ;接收移位标志
ST #0h,RSHTBAK ;接收移位标志备份
ST #0h,RSDCT ;接收移位检测计数

ST #0h,FSKBUFFADDR ;FSK发送相应时隙数据包的首地址
ST #0h,SAMCOUNT ;采样点计数
ST #0h,COUNT2
; ST #40,TIMEINTERVAL
;————CONFERENCE CALL所需初始化的数据———————
LD #0h,A
STM #CCVALUE,AR1 ; CCVALUE区清零
RPT #(MEMNUM-1)
STL A,*AR1+
STM #CVALSTAT,AR1 ; CVALSTAT区清零
RPT #(MEMNUM-1)
STL A,*AR1+
STM #SAMS,AR1 ; SAMS区清零
RPT #(MEMNUM*8-1)
STL A,*AR1+

ST #0h,CCBSAMCT ; CCBSAMCT清零
; ST #RCV11,CCRBADDR ; CCRBADDR初始化
ST #(RCV21+8*N),CCRBADDR ; CCRBADDR初始化
; ST #RCV20,CCRBADDR ; CCRBADDR初始化(也可以)

;********** 串口检测帧同步子程序 *****************
;帧同步高电平有效,串口在检测到帧同步下降沿后才能开始发送和接收数据
;初始化也在第一个帧同步到来后再做
;*************************************************************************
;
FrameSYN_Detect:
STM #0,SPSA0
STM #00h,SPCR10 ; 配置串口控制寄存器10(SPCR10):非数字环回;右对齐,高位补0;非SPI正常时钟模式;
; 接收复位;值为01h时启动接收
STM #1,SPSA0
STM #00h,SPCR20 ; 配置串口控制寄存器200(SPCR20),发送复位
; FREE模式,值为201h时启动发送
STM #0Eh,SPSA0
STM #3000h,PCR0 ; 把FSR FSX设置成通用IO输入口,帧同步高电平有效,时钟上升沿触发
; 00h时引脚设置成串口模式,FSR FSX只有在接收和发送处于复位状态时
; 才能配置成通用IO输入口
FrameSYN_Wait:
STM #0Eh,SPSA0 ; 检测帧同步,若检测到帧同步就启动发送和接收
LDM PCR0,A ; 若没有则继续检测等待
AND #08h,A
SUB #08h,A
BC FrameSYN_Wait,ANEQ
FSDown_Wait:
STM #0Eh,SPSA0 ; 检测到下降沿时跳出检测
LDM PCR0,A
AND #08h,A
BC FSDown_Wait,ANEQ

; ******** 串口初始化 ***********
;*************************************************************
;串口0初始化
STM #4,SPSA0
STM #1F00h,XCR10 ; 发送帧结构:1帧32字,1字8位
STM #5,SPSA0
.if SYNCDETECT0
STM #19h,XCR20 ; 发送单相,用A律压扩发送数据,延迟1Bit,每帧发送由帧同步启动
.else
STM #1Dh,XCR20 ; 发送单相,用A律压扩发送数据,延迟1Bit
.endif
STM #2,SPSA0
STM #0F40h,RCR10 ; 接收帧结构:1帧16字,1字16位
STM #3,SPSA0
.if SYNCDETECT0
STM #01h,RCR20 ; 接收单相,不压扩,延迟1Bit,每帧接收由帧同步启动
.else
STM #05h,RCR20 ; 接收单相,不压扩,延迟1Bit
.endif
;串口1初始化
STM #4,SPSA1
STM #1F00h,XCR11 ; 发送帧结构:1帧32字,1字8位
STM #5,SPSA1
STM #1Dh,XCR21 ; 发送单相,用A律压扩发送数据,延迟1Bit
STM #2,SPSA1
STM #0F40h,RCR11 ; 接收帧结构:1帧16字,1字16位
STM #3,SPSA1
STM #05h,RCR21 ; 接收单相,不压扩,延迟1Bit
;
; ******** 启动串口 ***********
;*************************************************************
;启动串口0
STM #0Eh,SPSA0
STM #00h,PCR0 ; 引脚设置成串口模式
STM #1,SPSA0
; STM #01h,SPCR20 ; 启动发送
STM #31h,SPCR20 ; 启动发送,发送失步产生中断
STM #0,SPSA0
; STM #01h,SPCR10 ; 启动接收
STM #31h,SPCR10 ; 启动接收,接收失步产生中断
;;启动串口1
STM #0Eh,SPSA1
STM #00h,PCR1 ; 引脚设置成串口模式
STM #1,SPSA1
STM #01h,SPCR21 ; 启动发送
STM #0,SPSA1
STM #01h,SPCR11 ; 启动接收

RSBX INTM ; 开中断z

中断程序

;———————————————————————————
; 接收中断服务子程序
;———————————————————————————
DMACH0_ISR: ; 接收(通道2)中断服务子程序
PSHM ST0
PSHM ST1
PSHM BRC
BC DMACH0_ISR3,NBIO
ST #0h,RSHTFLAG
B DMACH0_ISR4
DMACH0_ISR3:
ST #1h,RSHTFLAG
DMACH0_ISR4:
ST #1h,RCVINT
ST #1h,RCVINT1
CMPM RFLAG,#0h ; 若RFLAG为0,则转到DMACH0_ISR0
BC DMACH0_ISR1,NTC ; 若RFLAG为1,则转到DMACH0_ISR1
DMACH0_ISR0:
ST #1h,RFLAG
STM DMDST0,DMSA ; 目的地址为RCV20
STM #RCV20,DMSDN

ST #RCV10,RDBPTR
STM DMDST2,DMSA ; 目的地址为RCV21
STM #RCV21,DMSDN
B DMACH0_ISR2
DMACH0_ISR1:
ST #0h,RFLAG
STM DMDST0,DMSA ; 目的地址为#RCV10
STM #RCV10,DMSDN

ST #RCV20,RDBPTR
STM DMDST2,DMSA ; 目的地址为#RCV10
STM #RCV11,DMSDN
DMACH0_ISR2:
STM DMCTR0,DMSA ; 每帧元素个数为16个
STM #15,DMSDN
STM DMSFC0,DMSA
STM #105Fh,DMSDN ; McBSP1 receive event,单字传输方式,帧数为N
; ORM #01h,DMPREC

STM DMCTR2,DMSA ; 每帧元素个数为16个
STM #15,DMSDN
STM DMSFC2,DMSA
STM #505Fh,DMSDN ; McBSP1 receive event,单字传输方式,帧数为N
ORM #05h,DMPREC ; 通道0,2使能
; ORM #01h,DMPREC
POPM BRC
POPM ST1
POPM ST0
RETE

现在用c 直接翻译过来,怎么总是不对,有收到数据,可不是一个时隙放在一起

c 代码如下

void Mcu_Reg_Init()
{
*CLKMD = 0;
while((*CLKMD)&(1<<CLKMD_PLLSTATUS));
*CLKMD = 0x40c7; //pllX5 bit15~bit12
*SWWSR = 0x4249; //wait stat i/o=4; data=1;program=1
*SWCR = 0x01;
*PMST = (1<<PMST_IPTR) | (1<<PMST_OVLY);
*BSCR = (1<<BSCR_BH) | (1<<BSCR_PSDS);
*IMR = 0;
*TCR = 0x10;
*PRD = 0xC34F;//0x186a;
*TCR = 0xc21;//0xC2f;
*IFR = 0xffff;
*IMR = 0xC000 | (1<<IMR_TINT0) | (1<<IMR_DMAC1);
// *IMR = 0xC000 | (1<<IMR_TINT0) | (1<<IMR_BRINT0) | (1<<IMR_BXINT0) | (1<<IMR_DMAC0) | (1<<IMR_DMAC1);
// *ST0 = 0;
// *ST1 = 0x800;
Disable();
}

void Mcbsp_Rst()
{
*SPSA0 = SPCR1;
*SPSD0 = 0; //接收复位
*SPSA0 = SPCR2;
*SPSD0 = 0xc0; //发送复位
*SPSA1 = SPCR1;
*SPSD1 = 0; //接收复位
*SPSA1 = SPCR2;
*SPSD1 = 0xc0; //发送复位}

void Mcbsp_Sync()
{
*SPSA0 = SPCR1;
*SPSD0 = 0; //引脚设置成串口模式
*SPSA0 = SPCR2;
*SPSD0 = 0; //启动发送,发送失步产生中断
*SPSA0 = PCR;
*SPSD0 = 0x3000; // 启动接收,接收失步产生中断
*SPSA0 = PCR;
while(((*SPSD0) & (1<<PCR_FSXP))==0);
while((*SPSD0) & (1<<PCR_FSXP)); //检测下降沿
}

void Mcbsp_Init()
{
*SPSA0 = XCR1;
//*SPSD = 0x1F00; //发送帧结构:1帧32字,1字8位
*SPSD0 = 0xF40; //发送帧结构:1帧16字,1字16位
*SPSA0 = XCR2;
*SPSD0 = 1; //发送单相,延迟1Bit,每帧发送由帧同步启动
*SPSA0 = RCR1;
//*SPSD = 0x1F00; // 接收帧结构:1帧32字,1字8位
*SPSD0 = 0xF40; //发送帧结构:1帧16字,1字16位
*SPSA0 = RCR2;
*SPSD0 = 1; //接收单相,不压扩,延迟1Bit,每帧接收由帧同步启动
*SPSA1 = XCR1;
//McBSP1->SPSD = 0x1F00; //发送帧结构:1帧32字,1字8位
*SPSD1 = 0xF40; //发送帧结构:1帧16字,1字16位
*SPSA1 = XCR2;
*SPSD1 = 5; //发送单相,延迟1Bit,
*SPSA1 = RCR1;
//*SPSD = 0x1F00; // 接收帧结构:1帧32字,1字8位
*SPSD1 = 0xF40; //发送帧结构:1帧16字,1字16位
*SPSA1 = RCR2;
*SPSD1 = 5; //接收单相,不压扩,延迟1Bit,
}

void Mcbsp_Start()
{
*SPSA0 = PCR;
*SPSD0 = 0; //引脚设置成串口模式
*SPSA0 = SPCR2;
*SPSD0 = 0x31; //启动发送,发送失步产生中断
*SPSA0 = SPCR1;
*SPSD0 = 0x31; // 启动接收,接收失步产生中断
*SPSA1 = PCR;
*SPSD1 = 0; //引脚设置成串口模式
*SPSA1 = SPCR2;
*SPSD1 = 0x1; //启动发送,
*SPSA1 = SPCR1;
*SPSD1 = 0x1; // 启动接收,
}

void Dma_Init()
{
*DMPREC = 0x80; // 所有通道禁用
//—–通道1初始化,用于串口0的发送——————
*DMSA = DMSRC1;
*DMSDN =(XB_U16)Tx_Mcbsp0_Buf0; //源地址为Tx_Mcbsp0_Buf0
*DMSA = DMDST1;
*DMSDN =(XB_U16)( DXR10); //目的地址为DXR10
*DMSA = DMCTR1;
*DMSDN = 16-1; //每帧元素个数为16个
*DMSA = DMSFC1;
*DMSDN = 0x2000+MCBSP0_DMA_TX_FRAME_NUM-1; //McBSP0 transmit event,单字传输方式,帧数为256
*DMSA = DMMCR1; //DMA自动初始关,块发送完产生中断,复帧方式,目的地址不变,位于数据存储器
*DMSDN = 0x4541; //源地址指针根据DMIDX0 and DMFRI0改变,处于数据存储器
*DMSA = DMIDX0;
*DMSDN = MCBSP0_DMA_TX_FRAME_NUM; //set element address index to +MCBSP0_DMA_TX_FRAME_NUM
*DMSA = DMFRI0;
*DMSDN = 0x10000-(MCBSP0_DMA_TX_FRAME_NUM*15-1); //set frame address index to -(MCBSP0_DMA_TX_FRAME_NUM*15-1)

//———通道0初始化,用于串口0的接收————–
*DMSA = DMSRC0;
*DMSDN =(XB_U16) (DRR10); //源地址为DRR10
*DMSA = DMDST0;
*DMSDN =(XB_U16) Rx_Mcbsp0_Buf0; //目的地址为Rx_Mcbsp0_Buf0
*DMSA = DMCTR0;
*DMSDN = 16-1; //每帧元素个数为16个
*DMSA = DMSFC0;
*DMSDN = 0x1000+MCBSP0_DMA_RX_FRAME_NUM-1; //McBSP0 transmit event,单字传输方式,帧数为256
*DMSA = DMMCR0; //不自动初始化,1模块传输完产生中断,工作于多帧模式
*DMSDN = 0x4059; //源地址不变,目的地址根据DMIDX1和DMFRI1变化
*DMSA = DMIDX1;
*DMSDN = MCBSP0_DMA_RX_FRAME_NUM; //set element address index to +MCBSP0_DMA_TX_FRAME_NUM
*DMSA = DMFRI1;
*DMSDN = 0x10000-(MCBSP0_DMA_RX_FRAME_NUM*15-1); //set frame address index to -(MCBSP0_DMA_TX_FRAME_NUM*15-1)
//—–通道3初始化,用于串口1的发送——————
*DMSA = DMSRC3;
*DMSDN = (XB_U16)Tx_Mcbsp1_Buf0; //源地址为Tx_Mcbsp1_Buf0
*DMSA = DMDST3;
*DMSDN = (XB_U16)(DXR11); //目的地址为DXR10
*DMSA = DMCTR3;
*DMSDN = 16-1; //每帧元素个数为16个
*DMSA = DMSFC3;
*DMSDN = 0x6000+MCBSP1_DMA_TX_FRAME_NUM-1; //McBSP0 transmit event,单字传输方式,帧数为256
*DMSA = DMMCR3; //DMA自动初始关,块发送完产生中断,复帧方式,目的地址不变,位于数据存储器
*DMSDN = 0x541; //源地址指针根据DMIDX0 and DMFRI0改变,处于数据存储器
//DMA->DMSA = DMIDX0;
//DMA->DMSDN = MCBSP0_DMA_TX_FRAME_NUM; //set element address index to +MCBSP0_DMA_TX_FRAME_NUM
//DMA->DMSA = DMFRI0;
//DMA->DMSDN = 0x10000-(MCBSP0_DMA_TX_FRAME_NUM*15-1); //set frame address index to -(MCBSP0_DMA_TX_FRAME_NUM*15-1)

//———通道2初始化,用于串口1的接收————–
*DMSA = DMSRC2;
*DMSDN = (XB_U16)(DRR11); //源地址为DRR10
*DMSA = DMDST2;
// *DMSDN = (XB_U16)Rx_Mcbsp1_Buf0; //目的地址为Rx_Mcbsp0_Buf0
*DMSA = DMCTR2;
*DMSDN = 16-1; //每帧元素个数为16个
*DMSA = DMSFC2;
*DMSDN = 0x5000+MCBSP1_DMA_RX_FRAME_NUM-1; //McBSP0 transmit event,单字传输方式,帧数为256
*DMSA = DMMCR2; //不自动初始化,1模块传输完产生中断,工作于多帧模式
*DMSDN = 0x59; //源地址不变,目的地址根据DMIDX1和DMFRI1变化
//DMA->DMSA = DMIDX1;
//DMA->DMSDN = MCBSP0_DMA_RX_FRAME_NUM; //set element address index to +MCBSP0_DMA_TX_FRAME_NUM
//DMA->DMSA = DMFRI1;
//DMA->DMSDN = 0x10000-(MCBSP0_DMA_RX_FRAME_NUM*15-1); //set frame address index to -(MCBSP0_DMA_TX_FRAME_NUM*15-1)
//————————————————–
*DMPREC = 0xF8F; // 通道0,1,2,3使能,并高优先,中断复用
}

void Peripheral_Init(void)
{
Mcbsp_Rst();
Dma_Init();
Mcbsp_Sync();
Mcbsp_Init();
Mcbsp_Start();
Enable();
Firm_Parm_Init();
}
void Firm_Parm_Init(void)
{
Tx_Flag=0;
Rx_Flag=0;
TxInt_Flag=0;
RxInt_Flag=0;
}

void main()
{
XB_U16 i,nret;
/*准备数据*/
Mcu_Reg_Init();
Peripheral_Init();
memset(Tx_Mcbsp0_Buf0, 0, 4096);
memset(Tx_Mcbsp0_Buf1, 0, 4096);
// Mute_Tx(0);
// Mute_Tx(1);
// Mute_Tx(3);
for(i=0; i<2112; i++)
szbuf[i] = i%16;
while(1)
{
// NANDFLASH_Block_Erase(0);
// nret = NANDFLASH_Page_WriteData(0x10,0, szbuf,2000); /*写第0页*/
// nret = NANDFLASH_Page_WriteData(1,1, szbuf,2000); // nret=NANDFLASH_ReadStatus(0x70);
// NANDFLASH_ReadIDOperation(ChipId);
nop();
// nret=FPGA_NAND_RB_;
// memset(szbuf, 0, 2112);
// nret = NANDFLASH_Page_ReadData(0,0×1, szbuf,2112);
// FPGA_NAND_CLE = 1;
// FPGA_NAND_CE_ = 1;
// FPGA_NAND_ALE = 1;
if(TxInt_Flag)
{
// Mute_tx(0);
TxInt_Flag=0;
}
if(MsFlag)
{
MsFlag=0;
ms++;
Led_Deal();
}
nop();
nop();
}
}

interrupt void DMACH0_ISR()
{
RxInt_Flag=1;
if(Rx_Flag)
{
Rx_Flag=0;
*DMSA = DMDST0;
*DMSDN =(XB_U16)Tx_Mcbsp0_Buf0;
*DMSA = DMDST2;
*DMSDN = (XB_U16)Tx_Mcbsp1_Buf0; //源地址为Tx_Mcbsp1_Buf0
}
else
{
Rx_Flag=1;
*DMSA = DMDST0;
*DMSDN =(XB_U16)Tx_Mcbsp0_Buf1;
*DMSA = DMDST2;
*DMSDN = (XB_U16)Tx_Mcbsp1_Buf1; //源地址为Tx_Mcbsp1_Buf0
}
*DMSA = DMCTR0;
*DMSDN = 16-1; //每帧元素个数为16个
*DMSA = DMSFC0;
*DMSDN = MCBSP0_DMA_RX_FRAME_NUM-1;

*DMSA = DMCTR2;
*DMSDN = 16-1; //每帧元素个数为16个
*DMSA = DMSFC2;
*DMSDN = 0x5000+MCBSP1_DMA_RX_FRAME_NUM-1; //McBSP0 transmit event,单字传输方式,帧数为256
*DMPREC |= 0x05;
}

Tony Tang:

anding xu

现在用c 直接翻译过来,怎么总是不对,有收到数据,可不是一个时隙放在一起

你能把正确的数据与接收到的不对的数据提供做一个对比吗?另外请描述一下你期望的McBSP的工作模式,比如一个时隙多少个数,内同步,还是外同步等。

赞(0)
未经允许不得转载:TI中文支持网 » mcbsp dma
分享到: 更多 (0)