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

c6678用 EDMA CC0 坐pingpong 搬运 为什么有时成功有时不成功

用的开发平台式6678L,用edma 从一个固定地址搬运数据,固定地址src_addr中数据位*(src_addr)=0x5555。代码如下,编译成功之后运行发现有时候pingInBuff和pongInBuff中有数据,有时候没有,不知道是不是哪里没有配置好。

 

#include <stdio.h>
#include <ti/csl/csl_edma3.h>
#include <ti/csl/csl_edma3Aux.h>
#include <ti/csl/csl_cacheAux.h>

#define BUFF_SZ  256
#define TRANS_SZ 256

#define ELEMENT_WID_8BIT   1
#define ELEMENT_WID_16BIT   2        //acnt

CSL_TpccRegs*  gEDMACC0Regs  = (CSL_TpccRegs*)CSL_EDMA0CC_REGS;
CSL_TpccRegs*  gEDMACC1Regs  = (CSL_TpccRegs*)CSL_EDMA1CC_REGS;
CSL_TpccRegs*  gEDMACC2Regs  = (CSL_TpccRegs*)CSL_EDMA2CC_REGS;

    Uint16 *src_addr=(Uint16*)0x0C000000;
    Uint16 *dst_addr=(Uint16*)0x0C000010;
    Uint16 src_val=2;

 

    Uint16 srcBuff[BUFF_SZ];
    Uint16 pingInBuff[BUFF_SZ];
    Uint16 pongInBuff[BUFF_SZ];
    Uint16 pingOutBuff[BUFF_SZ];
    Uint16 pongOutBuff[BUFF_SZ];

 

int main()
{
    CACHE_invL1d ((void *)srcBuff, 2*BUFF_SZ, CACHE_WAIT);
    CACHE_invL2 ((void *)srcBuff, 2*BUFF_SZ, CACHE_WAIT);

    CACHE_invL1d ((void *)pingInBuff,2*BUFF_SZ , CACHE_WAIT);
    CACHE_invL2 ((void *)pingInBuff, 2*BUFF_SZ, CACHE_WAIT);

    CACHE_invL1d ((void *)pongInBuff,2*BUFF_SZ , CACHE_WAIT);
    CACHE_invL2 ((void *)pongInBuff, 2*BUFF_SZ, CACHE_WAIT);

    CACHE_invL1d ((void *)pingOutBuff,2*BUFF_SZ , CACHE_WAIT);
    CACHE_invL2 ((void *)pingOutBuff, 2*BUFF_SZ, CACHE_WAIT);

    CACHE_invL1d ((void *)pongOutBuff,2*BUFF_SZ , CACHE_WAIT);
    CACHE_invL2 ((void *)pongOutBuff, 2*BUFF_SZ, CACHE_WAIT);

    _mfence();

 

 

 

 

 

    Int32                           instNum=0;
 CSL_Edma3Handle                 hModule;
    CSL_Edma3Obj                    edmaObj;

    Uint8                           channelNum_in=0;
    CSL_Edma3ChannelObj             chObj_in;
    CSL_Edma3ChannelHandle          hChannel_in;
    CSL_Edma3ChannelAttr            chAttr_in;

    Uint8                           channelNum_out=1;
    CSL_Edma3ChannelObj             chObj_out;
    CSL_Edma3ChannelHandle          hChannel_out;
    CSL_Edma3ChannelAttr            chAttr_out;

 

    CSL_Edma3ParamSetup             pingInParam;
    CSL_Edma3ParamSetup             pongInParam;
    CSL_Edma3ParamHandle            hPingInParam;
    CSL_Edma3ParamHandle            hPongInParam;

    CSL_Edma3ParamSetup             pingOutParam;
    CSL_Edma3ParamSetup             pongOutParam;
    CSL_Edma3ParamHandle            hPingOutParam;
    CSL_Edma3ParamHandle            hPongOutParam;

 

 

    CSL_Edma3CmdIntr                regionIntr;
    CSL_Edma3Context                context;

    CSL_Status                      status;

    int i;
    for(i=0;i<BUFF_SZ;i++)
    {
     srcBuff[i]=src_val;
     pingInBuff[i]=0;
     pongInBuff[i]=0;
     pingOutBuff[i]=2;
     pongOutBuff[i]=2;
    }

    printf ("init is finished。。。。\n");

    *(src_addr)=0x5555;//src_val;

/***************************init the edma moudle*****************************************************/

    if (CSL_edma3Init(&context) != CSL_SOK)
        {
            printf ("Error: EDMA module initialization failed\n");
            return -1;
        }

    hModule = CSL_edma3Open(&edmaObj, instNum, NULL, &status);
        if ( (hModule == NULL) || (status != CSL_SOK))
        {
            printf ("Error: EDMA module open failed\n");
            return -1;
        }

     printf("step 1 is done !!!\n");

/************************************init the channel_in and channel_out of the edma moudle**********/

    chAttr_in.regionNum = CSL_EDMA3_REGION_GLOBAL;
    chAttr_in.chaNum    = channelNum_in;
    hChannel_in = CSL_edma3ChannelOpen(&chObj_in, instNum, &chAttr_in, &status);
    if ((hChannel_in == NULL) || (status != CSL_SOK))
        {
            printf ("Error: Unable to open EDMA Channel_in:%d\n", channelNum_in);
          return -1;
      }
    else
     printf ("EDMA channel_in open success !\n");

    chAttr_out.regionNum = CSL_EDMA3_REGION_GLOBAL;
    chAttr_out.chaNum    = channelNum_out;
    hChannel_out = CSL_edma3ChannelOpen(&chObj_out, instNum, &chAttr_out, &status);
    if ((hChannel_out == NULL) || (status != CSL_SOK))
        {
            printf ("Error: Unable to open EDMA Channel_out:%d\n", channelNum_in);
          return -1;
      }
    else
     printf ("EDMA channel_out open success !\n");

 

    printf("step 2 is done !!!\n");

/********************************* map the channel to the param set and build the handle to the param structure********/

    CSL_edma3MapDMAChannelToParamBlock (hModule, channelNum_in, 2);

    hPingInParam = CSL_edma3GetParamHandle(hChannel_in, 2, &status);
      if (hPingInParam == NULL)
      {
          printf ("Error: EDMA Get Parameter Entry failed for 2.\n");
          return -1;
      }

   hPongInParam = CSL_edma3GetParamHandle(hChannel_in, 1, &status);
    if (hPongInParam == NULL)
      {
         printf ("Error: EDMA Get Parameter Entry failed for 1.\n");
         return -1;
    }

      CSL_edma3MapDMAChannelToParamBlock (hModule, channelNum_out, 4);

   hPingOutParam = CSL_edma3GetParamHandle(hChannel_out, 4, &status);
    if (hPingInParam == NULL)
    {
         printf ("Error: EDMA Get Parameter Entry failed for 4.\n");
         return -1;
    }

   hPongOutParam = CSL_edma3GetParamHandle(hChannel_out, 3, &status);
    if (hPongInParam == NULL)
    {
       printf ("Error: EDMA Get Parameter Entry failed for 3.\n");
       return -1;
    }

 

       printf("step 3 is done !!!\n");
/******************************************set the param structure in the memory***********************************************************/

      /**********  pingInParam  **************************************************************************************/
           pingInParam.option = CSL_EDMA3_OPT_MAKE(CSL_EDMA3_ITCCH_DIS, \
                                                        CSL_EDMA3_TCCH_DIS, \
                                                        CSL_EDMA3_ITCINT_DIS, \
                                                        CSL_EDMA3_TCINT_EN, \
                                                        0, CSL_EDMA3_TCC_NORMAL,\
                                                        CSL_EDMA3_FIFOWIDTH_NONE, \
                                                        CSL_EDMA3_STATIC_DIS, \
                                                        CSL_EDMA3_SYNC_A, \
                                                        CSL_EDMA3_ADDRMODE_INCR, \
                                                        CSL_EDMA3_ADDRMODE_INCR );//  上半部分不用修改,全当成incr来做,只不过修改acntbcnt
           pingInParam.srcAddr    = (Uint32)src_addr;//srcBuff;
              pingInParam.aCntbCnt   = CSL_EDMA3_CNT_MAKE(2,TRANS_SZ);//(2*TRANS_SZ,1);
              pingInParam.dstAddr    = (Uint32)pingInBuff;
           pingInParam.srcDstBidx = CSL_EDMA3_BIDX_MAKE(0,2);//(1,1);   //?????????????????
           pingInParam.linkBcntrld= CSL_EDMA3_LINKBCNTRLD_MAKE(hPongInParam,0);
           pingInParam.srcDstCidx = CSL_EDMA3_CIDX_MAKE(0,1);
           pingInParam.cCnt = 1;

/**********  pongInParam  **************************************************************************************/
                pongInParam.option = CSL_EDMA3_OPT_MAKE(CSL_EDMA3_ITCCH_DIS, \
                                                             CSL_EDMA3_TCCH_DIS, \
                                                             CSL_EDMA3_ITCINT_DIS, \
                                                             CSL_EDMA3_TCINT_EN, \
                                                             0, CSL_EDMA3_TCC_NORMAL,\
                                                             CSL_EDMA3_FIFOWIDTH_NONE, \
                                                             CSL_EDMA3_STATIC_DIS, \
                                                             CSL_EDMA3_SYNC_A, \
                                                             CSL_EDMA3_ADDRMODE_INCR, \
                                                             CSL_EDMA3_ADDRMODE_INCR );
                pongInParam.srcAddr    = (Uint32)src_addr;//srcBuff;
                pongInParam.aCntbCnt   = CSL_EDMA3_CNT_MAKE(2,TRANS_SZ);//(2*TRANS_SZ,1);
                pongInParam.dstAddr    = (Uint32)pongInBuff;
                pongInParam.srcDstBidx = CSL_EDMA3_BIDX_MAKE(0,2);//(1,1);   //?????????????????
                pongInParam.linkBcntrld= CSL_EDMA3_LINKBCNTRLD_MAKE(hPingInParam,0);
                pongInParam.srcDstCidx = CSL_EDMA3_CIDX_MAKE(0,1);
                pongInParam.cCnt = 1;

 /**********    pingOutParam**************************************************************************************/
                pingOutParam.option = CSL_EDMA3_OPT_MAKE(CSL_EDMA3_ITCCH_DIS, \
                                                             CSL_EDMA3_TCCH_DIS, \
                                                             CSL_EDMA3_ITCINT_DIS, \
                                                             CSL_EDMA3_TCINT_EN, \
                                                             0, CSL_EDMA3_TCC_NORMAL,\
                                                             CSL_EDMA3_FIFOWIDTH_NONE, \
                                                             CSL_EDMA3_STATIC_DIS, \
                                                             CSL_EDMA3_SYNC_A, \
                                                             CSL_EDMA3_ADDRMODE_INCR, \
                                                             CSL_EDMA3_ADDRMODE_INCR );
                pingOutParam.srcAddr    = (Uint32)pingOutBuff;//srcBuff;
                pingOutParam.aCntbCnt   = CSL_EDMA3_CNT_MAKE(2,TRANS_SZ);//(2*TRANS_SZ,1);
                pingOutParam.dstAddr    = (Uint32)dst_addr;
                pingOutParam.srcDstBidx = CSL_EDMA3_BIDX_MAKE(2,0);//(1,1);   //?????????????????
                pingOutParam.linkBcntrld= CSL_EDMA3_LINKBCNTRLD_MAKE(hPongOutParam,0);
                pingOutParam.srcDstCidx = CSL_EDMA3_CIDX_MAKE(0,1);
                pingOutParam.cCnt = 1;
 /**********    pongOutParam**************************************************************************************/
                pongOutParam.option = CSL_EDMA3_OPT_MAKE(CSL_EDMA3_ITCCH_DIS, \
                                                            CSL_EDMA3_TCCH_DIS, \
                                                            CSL_EDMA3_ITCINT_DIS, \
                                                            CSL_EDMA3_TCINT_EN, \
                                                            0, CSL_EDMA3_TCC_NORMAL,\
                                                            CSL_EDMA3_FIFOWIDTH_NONE, \
                                                             CSL_EDMA3_STATIC_DIS, \
                                                             CSL_EDMA3_SYNC_A, \
                                                             CSL_EDMA3_ADDRMODE_INCR, \
                                                              CSL_EDMA3_ADDRMODE_INCR );
                pongOutParam.srcAddr    = (Uint32)pongOutBuff;//srcBuff;
                pongOutParam.aCntbCnt   = CSL_EDMA3_CNT_MAKE(2,TRANS_SZ);//(2*TRANS_SZ,1);
                pongOutParam.dstAddr    = (Uint32)dst_addr;
                pongOutParam.srcDstBidx = CSL_EDMA3_BIDX_MAKE(2,0);//(1,1);   //?????????????????
                pongOutParam.linkBcntrld= CSL_EDMA3_LINKBCNTRLD_MAKE(hPingOutParam,0);
                pongOutParam.srcDstCidx = CSL_EDMA3_CIDX_MAKE(0,1);
                pongOutParam.cCnt = 1;
/************************set up the param set with the param structure******************/

     if (CSL_edma3ParamSetup(hPingInParam,&pingInParam) != CSL_SOK)
         {
             printf ("Error: EDMA Parameter Entry Setup failed\n");
             return -1;
         }

     if (CSL_edma3ParamSetup(hPongInParam,&pongInParam) != CSL_SOK)
         {
             printf ("Error: EDMA Parameter Entry Setup failed\n");
             return -1;
         }

     if (CSL_edma3ParamSetup(hPingOutParam,&pingOutParam) != CSL_SOK)
         {
             printf ("Error: EDMA Parameter Entry Setup failed\n");
             return -1;
         }

     if (CSL_edma3ParamSetup(hPongOutParam,&pongOutParam) != CSL_SOK)
         {
             printf ("Error: EDMA Parameter Entry Setup failed\n");
             return -1;
         }

       printf("step 4 is done !!!\n");

    regionIntr.region = CSL_EDMA3_REGION_GLOBAL;
    regionIntr.intr   = 0x3;
    regionIntr.intrh  = 0x0000;
    CSL_edma3HwControl(hModule,CSL_EDMA3_CMD_INTR_ENABLE,&regionIntr);

        /* Trigger channel */

   int cnt;
   for(cnt=0;cnt<2*TRANS_SZ;cnt++)
   {

     CSL_edma3HwChannelControl(hChannel_in,CSL_EDMA3_CMD_CHANNEL_SET,NULL);
    CSL_edma3HwChannelControl(hChannel_out,CSL_EDMA3_CMD_CHANNEL_SET,NULL);
   
   }

    printf("step 5 is done !!!\n");

 

 

   /* Close channel */
       if (CSL_edma3ChannelClose(hChannel_in) != CSL_SOK)
       {
           printf("Error: EDMA Channel_in Close failed\n");
           return -1;
       }
       if (CSL_edma3ChannelClose(hChannel_out) != CSL_SOK)
       {
           printf("Error: EDMA Channel_out Close failed\n");
           return -1;
       }

       /* Close EDMA module */
       if (CSL_edma3Close(hModule) != CSL_SOK)
       {
           printf("Error: EDMA Module Close failed\n");
           return -1;
       }

       /* The test passed. */

 

       printf("the test passed !!!\n");
       return 0;

 

}

Andy Yin1:

EDMA源及目的buffer是在LL2还是SL2,如果是LL2注意需要转换成全局地址赋给EDMA,如果是SL2则在初始化写数据之后需要cache flush。如果还有问题,建议查看一下触发前后PaRAM set相关的参数变化,确认参数配置配置没有问题,及启动后channel有进行数据搬移。

赞(0)
未经允许不得转载:TI中文支持网 » c6678用 EDMA CC0 坐pingpong 搬运 为什么有时成功有时不成功
分享到: 更多 (0)