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.

Combining assembly and C with the CLA-C compiler for 28035

Other Parts Discussed in Thread: CONTROLSUITE

Hello,

   I'm using the CLA C Compiler for the 28035 and need to write a routine in assembly to be called at a certain line in my C code written in the .cla file. In other words I want to combine my C code for the CLA with assembly code written by myself.

   Could anyone please provide me with some help on how to do it?

   Thanks,

Lucas

  • Hi Lucas,

    I would urge you to take a look at the CLAmath library v400 in controlSUITE. The examples show how an asm routine(with C wrapper) is called in the C context.

    Another resource is the following wiki: pay close attention to the section on calling convention:

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

    Please let me know if this helps

  • Hi Vishal,

      Than you very much for your assistance. I did work with the CLAmath library v400 before. I have reviewed some of those examples. The same with the wiki, I've already read it.

       Unfortunately, none of those sources have the information I'm looking for. The methodology used by the examples is for calling asm routines from .c files and does not work for .cla files. The examples are created either writing assembly code and calling it from .c files, or writing c code and using the CLA-C compiler. But there is no example nor documentation that shows how to combine both methods. I am developing in C and using the CLA-C compiler and need to write in assembly some time critical sections of the code. Would you be able to provide me with any further suggestions/examples on how to do that?

       Thanks,

    Lucas 

  • Hi Lucas,

    Im not sure I understand. Do you want to do the following?

    1. trigger a CLA-C task (in .cla file)

    2. From this task you call a function written in assembly (This is what the CLAmath examples do)

    3. End task, CLA goes back to sleep

    or are you trying to write one CLA task in C and another in assembly?

    can you provide me a kind of call graph starting with CPU trigger->CLA task->asm function->end of task  etc?

  • Hi Vishal,

      Say I have a routing write in .cla and a routine written in assembly.

       I want to

    1. Trigger my CLA-C task, say Task1, that has my routine in CLA-C Code

    2. At a certain part of the code, say at the middle, I want to call a function written in assembly 

    3. When the function finishes, come back to my original routine in Task1

    4. End Task1, CLA goes back to sleep

       The CLAmath examples call a function written in assembly, that's right. The problem is that the function is called from a program in C with no restrictions. C for the CLA-C Compiler is not the same as regular C, it has several restrictions, so the examples do not apply.

  • How closely does this example illustrate what you'd like to do with Task 1?

      

  • Hi Jason,

      If the function foo(y) is written in assembly, the example does illustrate what I need to do. 

      

  • Hi Lucas,

    The CLAmath examples do call the assembly routines from a CLA task. For e.g. I pulled this snippet from the EXP10 example.

    If you look at the file 2806x_exp10.cla(CLA-C code), I have defined task 1 as follows: (trigger task 1 in whatever manner you like, Im using a software trigger)

    //Task 1 : Calculate exp10(X)
    interrupt void Cla1Task1 ( void )
    {
        __mdebugstop();
        fResult = CLAexp10(fVal);          // Here i call CLAexp10 which is an assembly routine called in the CLA-C not ANSI-C context
    }

    This is identical to the function foo in the previous post. These routines are NOT being called by the CPU...they are being called from within CLA task 1.

  • Thanks you for your help. The code was a good example and I could implement what I was trying to.

    Cheers,

    Lucas

  • Figure I would ask a question in this post instead of creating a new one since it deals with this issue. I've created an assembly function that I will call from my Clatask which is written in C.

    My question is during the context restore portion of the exp10 example why can't I do something like the following to save cycles and store registers? Will the values of MR0 and MR1 from the function get saved? and when the function returns, will their values before the function call get restored properly?

    ; Context Restore

    MRCNDD UNC

    MMOV32 MR3,@_save_MR3

    MMOV32 *MAR0[2]++, MR0

    MMOV32 *MAR0[0]++, MR1

    Thanks, Joe

  • You certainly can do that. The three instructions after the MRCNDD will be executed. I do have to point out that if you do this you need to make sure that the instruction (or C code) following the function doesnt immediately try to read *MAR0[0] or you will have a read-after-write conflict. If would be better to do the following:

    MMOV32 MR3,@_save_MR3

    MRCNDD UNC

    MMOV32 *MAR0[2]++, MR0

    MMOV32 *MAR0[0]++, MR1

    MNOP          ;; Allows the write phase of the previous instruction to complete

  • Thanks for the reply.

    I have a couple more questions though.

    Why can't the MMOV32 MR3, @_save_MR3 be after teh MRCNDD UNC?

    I follow your example and have the last MNOP after the MMOV32 *MAR0[0]++, MR1 and I use the value of *MAR0 in the first line of code after the asm function jumps back to my C code, will *MAR0 have the updated value?

    Hopefully my second question makes sense.

    Thanks, Joe

  • Joseph Ares said:
    Why can't the MMOV32 MR3, @_save_MR3 be after teh MRCNDD UNC?

    I only moved it before the MRCNDD so that the MNOP at the end is executed. You can certainly rearrange the order of the instructions (provided you account for pipeline conflicts) so that the MMOV32 falls after the MRCNDD

    Joseph Ares said:
    I follow your example and have the last MNOP after the MMOV32 *MAR0[0]++, MR1 and I use the value of *MAR0 in the first line of code after the asm function jumps back to my C code, will *MAR0 have the updated value?

    Yep, it should have the updated value. MNOP in between ensures that the new MR1 value is written to memory before the read occurs, if you fail to put the NOP in between, the Read and Write happen on the same clock (due to pipelining) but the read happens on the rising edge, write on the falling edge and you end up with the wrong value. The CLA pipeline is unprotected so it wont automatically stall when it runs into these kind of things.