This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Why I can't put the Physical Address from ARM to DSP

hello, everyone,

my development platform is Devkit8500 (DM3700), and I use the xdctools to develop my code,

it by dvsdk_dm3730-evm_4_02_00_06_setuplinux and use dvsdk's Codec Engine GenCodecPkg Wizard,

 

According to this developers guide,

http://processors.wiki.ti.com/index.php/Codec_Engine_Application_Developers_Guide

and at "Reconfiguring the Server's Algorithm Heap"

I following this step, to write my code at ARM, but not successful,

/**********************************************************/

Engine_Handle hEngine;
Server_Handle hServer;
XDAS_Int8  *buf;
Uint32 physAddr; 
 
/*
 * Open the Engine and get Server handle. Note, the
 * Engine_open() call will load and start the DSP.
 */
hEngine = Engine_open("audio_copy", NULL, NULL);
hServer = Engine_getServer(hEngine); 
 
/* Allocate a large block of physically contiguous memory for our "alg heap" */
buf = (XDAS_Int8 *)Memory_contigAlloc(BUFSIZE, ALIGNMENT); 
 
/* Convert virtual address to physical address. */
physAddr = Memory_getBufferPhysicalAddress(buf, BUFSIZE, NULL); 
 
/* Reconfigure the algorithm heap */
Server_redefineHeap(hServer, "DDRALGHEAP", physAddr, BUFSIZE); 
 
/* ...Create, run and delete codecs... */
 
/* Reconfigure alg heap back to its original state. */
Server_restoreHeap(hServer, "DDRALGHEAP"); 
 
/* Free the "alg heap" buffer */
Memory_contigFree(buf, BUFSIZE);


/**********************************************************/

My code is as follows:

At ARM code:

4064.main.c

At DSP code:

8585.myfacedetection.c

 

My idea is that, in the ARM side, first with fopen to read a txt file (this is an image buffer) and then name number_array matrix, then get number_array's physical location, and location to the DSP, and let DSP to do arithmetic.

So, I use Memory_contigAlloc to creat a space for buf, and use memcpy copy the number_array value to buf,
and use Memory_getBufferPhysicalAddress to get physical address to DSP, but not successful,

I have three questions:

1. how I can send Physical Address from the ARM to DSP , and DSP can receive the image buffer address, and do something

2. if DSP receive the Physical Address, how to use the physical address to get the image buffer

3. and where my code was wrong?

Thank you, I rellay need help, it confuse me a long time, please help me

 




  • Hi Steven,

    I don't think you need to be re-defining the Server's heap.  Your DDRALGHEAP size is probably already sufficient.  I recommend starting with the Codec Engine Image1_copy or universal_copy example and incorporating your algorithm into it.  Codec Engine will handle the address translation for you.  You can run these examples with CE_DEBUG=2 to see better how this all works.

    Best regards,

        Janet

  • Dear Janet,

    Thank you for your suggestion, 

    according to your suggestions, I found this two Codec Engine Image1_copy and universal_copy example,

    Is this it ?

    But when I in this location to make the app, but not successful,

    Which is not set yet completed?

    Thank you so much

    Best Regards,
    Steven

     

  • Hi Steven,

    Yes, those were the examples I was referring to.  You will need to set up some variables for product and tools locations in your <CE_INSTALL_DIR>/examples/xdcpaths.mak file.  Please see the Codec Engine instructions for building the examples in <CE_INSTALL_DIR>/examples/build_instructions.html.  That should get you through the build problem you are having.

    Best regards,

        Janet

  • Dear Janet,

    OK, Thank you so much, I'm very grateful for your help,

    I will try do my best,

    Best regards,

        Steven

  • Dear Janet,

    I just completed the Codec Engine Image1_copy, and can make

    But I have a question,

    Can I see the contents inside in.dat ?

  • Hi Steven,

    You can use 'od -x' to dump the .dat file.  You can also run 'diff in.dat out.dat' to make sure the contents of out.dat is the same as in.dat.

    Best regards,

        Janet

  • Dear Janet,

    Thank you for your answer, 
    But as I following your suggestions, then I modified my code, but it just unsuccessful 

    ******* The red word is code**********

    At my main.c code (this is ARM)

    I put the value 1~10 in the number_array, 

    and look the number_array address :
              physAddr = Memory_getBufferPhysicalAddress(number_array, 10, NULL); 
              printf("physAddr = %x\n", physAddr);

    it show the 81837008

    and put the number_array to the DSP :
             
    /* Run MYFACEDETECTION */
             if (MYFACEDETECTION_process(hMYFACEDETECTION, number_array, hMYFACEDETECTION_DstBuf) < 0) {
                       printf("Failed to encode video buffer(MYFACEDETECTION)\n");
                       exit(-1);
              }

    The complete code is as follows:

    65143.main.c

    And at my useMYFACEDETECTION.c code

    It will call the MYFACEDETECTION_process function, and I want use Memory_getBufferPhysicalAddress function with number_array's address to inPtr :
              XDM1_BufDesc            inBufDesc;
              inPtr = Memory_getBufferPhysicalAddress(number_array, 10, NULL) + offset ; 
              inBufDesc.numBufs = 1;
              inBufDesc.descs[0].buf = inPtr;
              //inBufDesc.descs[0].bufSize = Buffer_getSize(hInBuf);
              inBufDesc.descs[0].bufSize = 10;
              status = IMGENC1_process(hIe->hEncode, &inBufDesc, &outBufDesc, &inArgs, &outArgs);

    The complete code is as follows:

    4377.useMYFACEDETECTION.c

    And at my myfacedetection.c code(this is DSP)

    I just want it will add the value 1 :      

             aaa = temp_input[0];
             bbb = temp_input[1];
             ccc = temp_input[2];
             ddd = temp_input[3];
             eee = temp_input[4];
             fff = temp_input[5];
             ggg = temp_input[6];
             hhh = temp_input[7];
              iii = temp_input[8];
              jjj = temp_input[9];


             temp_output[0] = aaa + 1;
             temp_output[1] = bbb + 1;
             temp_output[2] = ccc + 1 ;
             temp_output[3] = ddd + 1 ;
             temp_output[4] = eee + 1;
             temp_output[5] = fff + 1 ;
             temp_output[6] = ggg + 1;
             temp_output[7] = hhh + 1;
             temp_output[8] = iii + 1 ;
             temp_output[9] = jjj + 1;

    The complete code is as follows:

    8422.myfacedetection.c

    And I run my code, it shows the error :

    I would like to ask which lines of code is wrong ?

    Thank you so much,

    Best regards,

        Steven

  • Hi Steven,

    Could you try using Memory_alloc() to allocate the buffer instead of malloc()?  Please look at image1_copy app.c to see how this is done.  If you were allocating a large buffer with malloc(), the buffer may not even be contiguous in physical memory.

    Thanks,

        Janet

  • Dear Janet,

    Thank you for your answer, 

    As I following the app.c to use Memory_alloc() ,it will show  "Segmentation fault"

    My main.c code is  add: (I just show another add code)

    /*
    * If an XDAIS algorithm _may_ use DMA, buffers provided to it need to be
    * aligned on a cache boundary.
    */

    #ifdef CACHE_ENABLED

    /*
    * If buffer alignment isn't set on the compiler's command line, set it here
    * to a default value.
    */
    #ifndef BUFALIGN
    #define BUFALIGN 128
    #endif
    #else

    /* Not a cached system, no buffer alignment constraints */
    #define BUFALIGN Memory_DEFAULTALIGNMENT

    #endif


    #define NSAMPLES 10
    #define IFRAMESIZE (NSAMPLES * sizeof(Int8)) /* raw frame (input) */
    #define OFRAMESIZE (NSAMPLES * sizeof(Int8)) /* decoded frame (output) */

    static String engineName = "encode";

    int main()
    {

    Memory_AllocParams allocParams;

    static XDAS_Int8 *testcode;

    /* allocate input, encoded, and output buffers */

    allocParams.type = Memory_CONTIGPOOL;
    allocParams.flags = Memory_NONCACHED;
    allocParams.align = BUFALIGN;
    allocParams.seg = 0;


    printf("step1\n");
    //number_array = (int *)malloc(10*sizeof(int));
    testcode = (XDAS_Int8 *)Memory_alloc(IFRAMESIZE, &allocParams);
    printf("OK\n");

    .........

    }

    I would like to ask which lines of code is wrong ?

    Thank you so much,

    Best regards,

        Steven

     

     

     

     

     

  • Hi Steven,
    Sorry, but I should have mentioned that the call to Memory_alloc() must go after the call to CERuntime_init().  That should fix the seg fault.

    Best regards,

        Janet

  • Dear Janet,

    Thank you so much, you are my angel, I love you so much, you save my life~~~~

    thank you, thank you

    and I will share my code to everyone

    At main.c (for ARM)

    4578.main.c

    At useMYFACEDETECTION.c (for ARM to DSP)

    8203.useMYFACEDETECTION.c

    At  myfacedetection.c (for DSP)

    5327.myfacedetection.c

    Best regards,

        Steven

  • Dear Janet,

    Sorry, I found I was wrong, because I use the memcpy function at main.c,

    this is not successful, because it copy the value, but I want copy the physical address,

    inPtr = Buffer_getUserPtr(hMYFACEDETECTION_InBuf);
    memcpy(inPtr, number_array, 10);

    /* Run MYFACEDETECTION */
    if (MYFACEDETECTION_process(hMYFACEDETECTION, hMYFACEDETECTION_InBuf, hMYFACEDETECTION_DstBuf) < 0) {
           printf("Failed to encode video buffer(MYFACEDETECTION)\n");
           exit(-1);
    }

    So, I use this method,

    inPtr = Buffer_getUserPtr(hMYFACEDETECTION_InBuf);
    inPtr = number_array

    /* Run MYFACEDETECTION */
    if (MYFACEDETECTION_process(hMYFACEDETECTION, hMYFACEDETECTION_InBuf, hMYFACEDETECTION_DstBuf) < 0) {
           printf("Failed to encode video buffer(MYFACEDETECTION)\n");
           exit(-1);
    }

     

    But it not unsucessful again :(

    So, is that any way to give the physical address to DSP ?

    Thank you so much,

    Best regards,

        Steven

     

  • Hi Steven,

    I think you are pretty close to solving your problem, actually.  Looking at your code more closely, I don't see why you even need number_array.  In main(), you create a buffer object with Buffer_create():

        hMYFACEDETECTION_InBuf = Buffer_create(bufSize, &myfacedetection_bufAttrs);

    I checked in the dvsdk code, and Buffer_create() creates a buffer with Memory_alloc(), so this should be contiguous physical memory.  So why don't you copy your data into hMYFACEDETECTION_InBuf and pass that to your process() function?  You can get the address to copy the data to with Buffer_getUserPtr()  (Look at your code in MYFACEDETECTION_process() to see an example of Buffer_getUserPtr()).

    Your call to IMGENC1_process() in MYFACEDETECTION_process() will handle getting the physical address to the DSP.

    Best regards,

        Janet

  • Dear Janet

    I'm so sorry, I am too late to respond to you,

    so did you mean that, when I use Buffer_create to create a buffer,

    /* Create an input buffer*/
    bufSize = 10;
    hMYFACEDETECTION_InBuf = Buffer_create(bufSize, &myfacedetection_bufAttrs);

    then use Buffer_getUserPtr to put my vaule with out number_array,

    inPtr = Buffer_getUserPtr(hMYFACEDETECTION_InBuf);
    for(temp=0; temp<10; temp++)
    {
          inPtr[temp] = number_array[temp];
    }

    /* Run MYFACEDETECTION */
    if (MYFACEDETECTION_process(hMYFACEDETECTION, hMYFACEDETECTION_InBuf, hMYFACEDETECTION_DstBuf) < 0) {
          printf("Failed to encode video buffer(MYFACEDETECTION)\n");
          exit(-1);
    }

    is that right ?

    Thank you so much,

    Best regards,

        Steven

     

     

     

  • Hi Steven,

    Yes, could you please try that?

    Best regards,

        Janet

  • Dear Janet,

    Thank you so much,

    I finally solved this problem from your suggestion,

    XDDD

    Best regards,

        Steven

     

  • Hi Steven,

    I am really glad to hear it is working now.

    Best regards,

        Janet