📄 dma4.c
字号:
DMA_DMMCR_DIND_NOMOD,
DMA_DMMCR_DMD_DATA
), /* DMMCR */
DMA_DMSFC_RMK(
DMA_DMSFC_DSYN_XEVT0,
DMA_DMSFC_DBLW_ON, /*32bit Mode*/
DMA_DMSFC_FRAMECNT_OF(0)
), /* DMSFC */
(DMA_AdrPtr)&src[0], /* DMSRC */
(DMA_AdrPtr)MCBSP_ADDR(DXR20), /* DMDST */
(Uint16)(Nm2) /* DMCTR = buffsize */
};
/* Create configuration structure for DMA channel 4 using */
/* predefined CSL macros and symbolic constants */
DMA_Config my_dmaConfigCha4 = {
0, /* Set Priority */
DMA_DMMCR_RMK(
DMA_DMMCR_AUTOINIT_OFF,
DMA_DMMCR_DINM_ON,
DMA_DMMCR_IMOD_HALF_AND_FULL,
DMA_DMMCR_CTMOD_ABU,
// DMA_DMMCR_CTMOD_MULTIFRAME,
DMA_DMMCR_SLAXS_OFF,
DMA_DMMCR_SIND_NOMOD,
DMA_DMMCR_DMS_DATA,
DMA_DMMCR_DLAXS_OFF,
DMA_DMMCR_DIND_DMIDX0,
DMA_DMMCR_DMD_DATA
), /* DMMCR */
DMA_DMSFC_RMK(
DMA_DMSFC_DSYN_REVT0,
DMA_DMSFC_DBLW_ON,
DMA_DMSFC_FRAMECNT_OF(0)
), /* DMSFC */
(DMA_AdrPtr)MCBSP_ADDR(DRR20), /* DMSRC */
(DMA_AdrPtr)&dst[0], /* DMDST */
(Uint16)(Nm2) /* DMCTR = buffsize */
};
/* Global declarations */
DMA_Handle myhDmaCha4;
DMA_Handle myhDmaCha5;
MCBSP_Handle myhMcbsp1;
volatile Uint16 WaitForDmaRec = TRUE;
volatile Uint16 WaitForDmaSend= TRUE;
interrupt void hMcbsp1RcvIsr(void);
interrupt void hMcbsp1XmtIsr(void);
interrupt void dmaCha5Isr(void);
interrupt void dmaCha4Isr(void);
void taskFunc(void);
Uint16 SendNum;
Uint16 StartSend=1;
Uint16 ConverDat=1;
void DelayModule(Uint16 DelayNum)
{
Uint16 i,j;
for(i=0;i<100;i++)
{
for(j=0;j<DelayNum;j++);
}
}
/*----------------------------------------------------------------------------*/
void main() {
Uint16 InitNum;
asm(" RSBX XF");
/* Initialize CSL library, this step is required */
CSL_init();
/* Initialize IVPTR to start of vector table */
IRQ_setVecs((Uint16)(&VECSTART));
*SWWSR=0x0400;
//asm(" STM #0a8H,PMST");
/* Initialize send and receive buffers */
for(InitNum=0;InitNum<N;InitNum++)
{
src[InitNum]=0;dst[InitNum]=0;
}
/* Call example function */
taskFunc();
}
unsigned int sqrt32(unsigned long M)
{
unsigned int Ntmp, i;
unsigned long tmp, ttp; // 结果、循环计数
if (M == 0) // 被开方数,开方结果也为0
return 0;
Ntmp = 0;
tmp = (M >> 30); // 获取最高位:B[m-1]
M <<= 2;
if (tmp >=1) // 最高位为1
{
Ntmp ++; // 结果当前位为1,否则为默认的0
tmp -= Ntmp;
}
for (i=15; i>0; i--) // 求剩余的15位
{
Ntmp <<= 1; // 左移一位
tmp <<= 2;
tmp += (M >> 30); // 假设
ttp = Ntmp;
ttp = (ttp<<1)+1;
M <<= 2;
if (tmp >= ttp) // 假设成立
{
tmp -= ttp;
Ntmp ++;
}
}
return Ntmp;
}
/*----------------------------------------------------------------------------*/
void ProcessSub(void)
{
Uint16 pCnt,i,j;
//************************************//
for(pCnt=0;pCnt<Nd4;pCnt++)
{
dsttemp=(Dis[pCnt*2+1]&0x80000000);
if(dsttemp==0x80000000)
{
dsttemp=Dis[pCnt*2+1];
dsttemp=(~dsttemp)+1>>16;
LchIn[pCnt]=~dsttemp+1;
}
else
{
dsttemp=Dis[pCnt*2+1];
LchIn[pCnt]=(dsttemp)>>16;
}
}
/* compute */
cbrev(LchIn,LchIn,Nd8);
rfft(LchIn,Nd4,1);
for(i=0;i<Nd8;i++)
{Ly[i]=0x00;}
j=0;
for(i=0;i<Nd4;)
{
Ly[j]=LchIn[i]*LchIn[i];
Ly[j]+=LchIn[i+1]*LchIn[i+1];
Ly[j]=sqrt32(Ly[j]);
i=i+2;
j++;
}
////////////*****************////////////////
for(pCnt=0;pCnt<Nd4;pCnt++)
{
dsttemp=(Dis[pCnt*2]&0x80000000);
if(dsttemp==0x80000000)
{
dsttemp=Dis[pCnt*2];
dsttemp=(~dsttemp)>>16;
RchIn[pCnt]=~dsttemp;
}
else
{
dsttemp=Dis[pCnt*2];
RchIn[pCnt]=(dsttemp)>>16;
}
}
/* compute */
cbrev(RchIn,RchIn,Nd8);
rfft(RchIn,Nd4,1);
for(i=0;i<Nd8;i++)
{Ry[i]=0x00;}
j=0;
for(i=0;i<Nd4;)
{
Ry[j]=RchIn[i]*RchIn[i];
Ry[j]+=RchIn[i+1]*RchIn[i+1];
Ry[j]=sqrt32(Ry[j]);
i=i+2;
j++;
}
//****************************************//
}
void DisDatSend(void)
{
Uint16 ii,jj;
if(ConverDat==2)
{
jj=0;
for(ii=0;ii<64;)
{
LySend[jj]=(Ly[ii]<<16)+Ly[ii+1];
ii+=2;
jj++;
}
ConverDat=1;
MCBSP_write32(myhMcbsp1,0xfff0fff0);
}
}
void taskFunc() {
MCBSP_Handle myhMcbsp;
Uint16 hMcbsp1RcvId,hMcbsp1XmtId;
Uint16 cha4EventId, cha5EventId;
Uint16 CopyCnt;
/* Temporarily disable all maskable interrupts */
/* keeping old status of INTM bit */
IRQ_globalDisable();
/* Open MCBSP channel 0 */
myhMcbsp = MCBSP_open(MCBSP_PORT0, MCBSP_OPEN_RESET);
/* Open MCBSP channel 1 */
myhMcbsp1= MCBSP_open(MCBSP_PORT1, MCBSP_OPEN_RESET);
/* Write configuration values to MCBSP 0 control registers */
MCBSP_config(myhMcbsp, &my_mcbspConfig);
/* Write configuration values to MCBSP 1 control registers */
MCBSP_config(myhMcbsp1, &my_mcbspConfig1);
hMcbsp1RcvId=MCBSP_getRcvEventId(myhMcbsp1);
hMcbsp1XmtId=MCBSP_getXmtEventId(myhMcbsp1);
/* Open DMA channels 4 & 5*/
myhDmaCha4 = DMA_open(DMA_CHA4, DMA_OPEN_RESET);
myhDmaCha5 = DMA_open(DMA_CHA5, DMA_OPEN_RESET);
/* Write configuration structure values to DMa control registers */
DMA_config(myhDmaCha4, &my_dmaConfigCha4);
DMA_config(myhDmaCha5, &my_dmaConfigCha5);
/* Get Event ID's associated with DMA channels */
cha4EventId = DMA_getEventId(myhDmaCha4);
cha5EventId = DMA_getEventId(myhDmaCha5);
/* the interrupt selector value in DMA priority and enable */
/* register, DMPREC */
DMA_FSET(DMPREC,INTOSEL,0);
/* Set FREE bit in DMPREC to enable free run on DMA */
DMA_FSET(DMPREC,FREE,1);
/* Clear all pending maskable interrupts */
CHIP_RSET(IFR,0xFFFFu);
/* Enable interrupts for DMA channels 4 & 5*/
IRQ_enable(cha4EventId);
IRQ_enable(cha5EventId);
/* Map DMA interrupts for use with dispatcher */
IRQ_plug(cha4EventId,&dmaCha4Isr);
IRQ_plug(cha5EventId,&dmaCha5Isr);
/* Set value of Global Index Register , DMIDX0 */
DMA_RSET(DMIDX0,1);
/* Enable all maskable interrupts, INTM = 0 */
//IRQ_globalEnable();
/* Start DMA */
DMA_start(myhDmaCha5);
DMA_start(myhDmaCha4);
IRQ_enable(hMcbsp1RcvId);
IRQ_enable(hMcbsp1XmtId);
IRQ_plug(hMcbsp1RcvId,&hMcbsp1RcvIsr);
IRQ_plug(hMcbsp1XmtId,&hMcbsp1XmtIsr);
/* Start Sample Rate Generator and Enable Frame Sync */
MCBSP_start(myhMcbsp,
MCBSP_SRGR_START|MCBSP_SRGR_FRAMESYNC ,
0x200
);
/* Take MCBSP transmit and receive out of reset */
MCBSP_start(myhMcbsp,
MCBSP_RCV_START|MCBSP_XMIT_START,
0x200
);
/* Start Sample Rate Generator and Enable Frame Sync */
MCBSP_start(myhMcbsp1,
MCBSP_SRGR_START|MCBSP_SRGR_FRAMESYNC , //
0x200
);
/* Take MCBSP transmit and receive out of reset */
MCBSP_start(myhMcbsp1,
MCBSP_RCV_START|MCBSP_XMIT_START,
0x200
);
/* Enable all maskable interrupts, INTM = 0 */
IRQ_globalEnable();
/* Wait for Transfer to Complete */
while(1)
{
if(WaitForDmaRec==0)
{
WaitForDmaRec=1;
PingPong=(PingPong+1)&0x01; /*PingPong=0,Ping Status;PingPong=1,Pong*/
if(PingPong==0)
{
for(CopyCnt=0;CopyCnt<Nd2;CopyCnt++)
{
Dis[CopyCnt]=dst[CopyCnt];
}
}
else
{
for(CopyCnt=Nd2;CopyCnt<N;CopyCnt++)
{
Dis[CopyCnt-Nd2]=dst[CopyCnt];
}
}
//DelayModule(240);
ProcessSub();
DisDatSend();
if(PingPong==0)
{
for(CopyCnt=0;CopyCnt<Nd2;CopyCnt++)
{
src[CopyCnt]=Dis[CopyCnt];
}
}
else
{
for(CopyCnt=Nd2;CopyCnt<N;CopyCnt++)
{
src[CopyCnt]=Dis[CopyCnt-Nd2];
}
}
}
}
}
/* DMA Channel ISRs, these functions will be called by DSP/BIOS dispatcher */
/*----------------------------------------------------------------------------*/
interrupt void dmaCha5Isr(void){
WaitForDmaSend= 0;
}
/*----------------------------------------------------------------------------*/
interrupt void dmaCha4Isr(void) {
WaitForDmaRec = 0;
}
Uint16 CmdRcv;
interrupt void hMcbsp1RcvIsr(void){
CmdRcv=MCBSP_read16(myhMcbsp1);
if(CmdRcv==0x0805)
{
ConverDat=2;
}
else if(CmdRcv==0x0806)
{
MCBSP_write32(myhMcbsp1,LySend[0]);
SendNum=0;
StartSend=2;
}
}
interrupt void hMcbsp1XmtIsr(void){
if(StartSend==2)
{
SendNum++;
if(SendNum<32)
{
MCBSP_write32(myhMcbsp1,LySend[SendNum]);
if(SendNum==31)
{
StartSend=1;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -