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.

OMAP memTab[] in codec engine framework?

Dear Experts,

It is urgent to know how to deal with the following case:

=========

 

1. data struct definition:

typedef struct datatype

{

  int     (*f) (int *a, char *b);

} DataType;

 

 

2. Functions definition:

int  f1 (int *a, char *b)

{

int c;

d=a+b;

return c;

}

int  f2 (int *a, char *b)

{

int c;

d=a-b;

return c;

}

 

int  f3 (int *a, char *b)

{

int c;

d=a*b;

return c;

}

 

3. Use of the struct

main()

DataTyppe *dP;

int i;

int output;

if (i==1) dP->f=f1;

else if (i==2) dP->f=f2;

else dP->f=f3;

}

 

Question: how to memTab[] for the dP->f ?

I found the problem: if I allocates memory for "dP" with "memTab[]", it is able to be used for some variables inside "dP", but if a function inside, the OMAP DSP side have no idea where is the "dP->f"? and the program will crash sometimes, or give wrong result.

 

How to deal with this thing? thanks

 

Dave

 

  • It's not clear what you're asking.

    Making a giant assumption... but if your algorithm needs to call different functions depending on something like a creation param, and that's why you're initializing a fxn pointer, maybe the simple G.711 XDAIS example would be a good reference.

    The following is stolen from that example (examples/ti/xdais/dm/examples/g711/g711dec_sun_ialg.c).  Here's that alg's initObj() where the function pointer is initialized based on input params - I highlighted code associated with the input params in red, and the handle/alg object in green:

    Int G711DEC_SUN_initObj(IALG_Handle handle, const IALG_MemRec memTab[],
        IALG_Handle p, const IALG_Params *algParams)
    {
        G711DEC_SUN_Obj *g711Dec = (Void *)handle;
        const ISPHDEC1_Params *params = (ISPHDEC1_Params *)algParams;
        Int status = IALG_EOK;

        /* ... snip! ... */

        switch (params->compandingLaw) {
            case ISPEECH1_PCM_COMPAND_ALAW:
                g711Dec->fxn = G711_SUN_alaw2linear;
                g711Dec->compandingLaw = ISPEECH1_PCM_COMPAND_ALAW;
                break;

            case ISPEECH1_PCM_COMPAND_ULAW:
                g711Dec->fxn = G711_SUN_ulaw2linear;
                g711Dec->compandingLaw = ISPEECH1_PCM_COMPAND_ULAW;
                break;

            default:
                status = IALG_EFAIL;
                break;
        }

        return (status);
    }

    ... and then in the process() method, you'll see a call to "whichever function is correct - alaw or ulaw - based on the create params" - remember, the 'handle' arg passed in is really the object you initialized in initObj above:

    XDAS_Int32 G711DEC_SUN_decode(ISPHDEC1_Handle handle,
        XDM1_SingleBufDesc *inBuf, XDM1_SingleBufDesc *outBuf,
        ISPHDEC1_InArgs *inArgs, ISPHDEC1_OutArgs *outArgs)
    {
        G711DEC_SUN_Obj *g711Dec = (Void *)handle;
        Int i;

        short * out        = (short *)outBuf->buf;
        unsigned char * in = (unsigned char *)inBuf->buf;

        /* ... snip! ... */

        /* process the data: read input, produce output */
        for (i = 0; i < frameLen; i++) {
            *out++ = g711Dec->fxn(*in++);
        }

        /* ... snip! ... */

        return (ISPHDEC1_EOK);
    }

    Maybe that helps?

    Chris

  • Thank Chris,

    Your answer is appreciated, and very helpful. It is what I am eager to know.

     

    So, it is pretty much I can say:

    In CE, a data structure is assigned a memory in "_initObj()" by "memTab[]", but a "function" should not be defined inside this data structure.

    am I right?

     

     

    I found if a function is defined inside the data structure, program will be crashed sometimes, but also, wrong results sometimes are given. because the DSP image executable can not locate the function. right?

     

    All bests,

     

    DAVE 

  • dave li said:

    In CE, a data structure is assigned a memory in "_initObj()" by "memTab[]", but a "function" should not be defined inside this data structure.

    am I right?

    I wouldn't make that blanket statement.  Memory is memory is memory.  There's nothing special about CE-granted memory than any other.  If you ask for 4 bytes of memory, you can store whatever you want in there - a 32-bit integer, 4 8-bit ANSI characters, a 32-bit pointer, whatever you want.

    If you were storing a pointer in there, and were observing failures to call that fxn, some things that might cause problems:

    • Programming error.  Pointers can be tricky, maybe it was just a user bug?
    • Depending on what that fxn does, maybe you were blowing your stack?
    • Alignment(unlikely) - some ISAs don't like to call functions on "mis-aligned" boundaries.  If your fxn pointer was, for example, stored in a tightly packed struct and it wasn't aligned on a 32-bit boundary, some processors could get upset at that.

    If the fxn pointer was passed from the ARM to the DSP, here are a few more things could go wrong:

    • Address translation - gotta be careful about the fxn location from the ARM's POV and the DSP's POV.
    • MMU config (unlikely).  Some DSP's have MMUs between the CPU and the memory.  If the fxn was located in a block of memory that was inaccessible to the CPU because of the MMU config, you may get an MMU fault.

    It's hard to say without looking at code what the issue is, but you should be able to store a fxn ptr in that memory if you want.

    Chris

  • Dear Chris

    I am using Codec engine for my project,  H.264/avc decoder, which is now running on GPP side without any problem. The problem is that I want to speed up it with DSP side.  So I am planning to port part of the code running on GPP side into DSP side. 

    Here is a data structure involved in porting:

    ===========================================

    typedef struct slice

    {

      struct video_par    *p_Vid;

      struct inp_par      *p_Inp;

       struct decoded_picture_buffer *p_Dpb;

      int idr_flag;

      int idr_pic_id;

       short        current_slice_nr;

       int                 mb_aff_frame_flag;

        int                 qp;

       Boolean is_reset_coeff;

      imgpel  ***mb_pred;

      imgpel  ***mb_rec;

      int     ***mb_rres;

      int     ***cof;

      int     ***fcf;

    ;
    ;
    }
    =============================================

    My question is:

    1. How can I pass a data structure (or a parameter) from GPP side into DSP side ?  using VIDDEC_COPY handle? Outargs? or sth else and how to use it

    2. How to pas by a buffer, I know to use inBuffer or OutBuffer inside "TI_Process()" function, need I use DMA to pass, and How?

     

    Many thanks,

     

    David