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.

TMS320F280049: Question about how to use math.h with CLA enabling

Part Number: TMS320F280049
Other Parts Discussed in Thread: CONTROLSUITE, C2000WARE

Dear Champs,

Help customer to post the problem, his problem as below:

------------------------------------------------------------------------------

I have question about a lot of “long long” definitions in math.h.

I ‘d like to enable CLA feature and use sqrt() function.

The sqrt() function is defined in math.h file.

But CLA doesn’t support “long long”.

Do you know how to solve this problem? Thank you.

------------------------------------------------------------------------------

If you have any suggestion, please feel free to let me know.

Thanks a lot.

  • Hi,

    Though linker may link functions compiled for CPU to CLA, but they won't work! Every function defined in standard headers like math.h, stdlib.h, etc are compiled for CPU, not for CLA.
    You should check what's available for CLA in libs/math/ CLAmath library from controlSUITE / cware2000. CLAsqrt() is there

    Edward
  • Dear Edward,

    Thanks for your reminder.
    Yes, I find it on CLAmath library, the online link as below and C2000Ware path as you said:
    dev.ti.com/.../

    Then see 7 Revision History, we could know "Added function mappings from math.h functions to CLA math functions in CLAmath.h".
    Hence, sqrt() --> CLAsqrt().

    Thanks a lot.
  • Dear Edward,

    CLAsqrt() can be used both CLA and CPU?

    Best Regards,

    Johnson

  • Hi Janet,

    Of course not. CLA and CPU have different instructions sets. This means you can't call sqrt() in the same project from both CPU and CLA, you also can't call CLAsqrt() in the same project from both CPU and CLA. If you want sqrt() in CLA as well, then you should use preprocessor to replace sqrt with CLAsqrt on CLA. You may do it like this, not verified

    #ifdef __TMS320C28XX_CLA__
    #define sqrt CLAsqrt
    #else
    //#define sqrt sqrt
    #endif

    These lines should be put in your code sooner than you make a call to sqrt().

    Edward
  • Hi Edward,

    In currently CLAmath.h library, CLA function always put "CLA" prepositions.

    So the designer can easily distinguish which one is for the CPU and which one is for the CLA.

    Why the CCS compiler is fail to put CLAmath.h and math.h together in the same project?

    If these two libraries can put together, then the designer can put sqrt() in CPU procedure and put CLAsqrt in CLA procedure separately.

    Best Regards,
    Johnson
  • Hi Johnson,

    Hm, looks like we have here some misunderstanding. Of course you can use both CLAmath.h and math.h in the same project. The problem is you can't misuse functions declared in these headers. Developer should care not to call CLAxxx functions from CPU and non-CLAxxx functions from CLA.

    Regards,
    Edward
  • Hi Edward,

    Thanks for your quickly reply.

    I would like to enable CLA for handling CLA interrupt routine only (without CLAmath.h function).
    CPU will use math.h for some calculation.

    I just used sqrt() in CPU code not CLA.
    But CCS always shows the error message for type define error (for example: "long long" is not support).

    Because the preprocessor "__TMS320C28XX_CLA__" will be set when "--cla_support = cla2".
    So some type definitions for math.h will be eliminated.

    Could you please help me how to solve this problem? Thank you.

    Best Regards,
    Johnson
  • Hi,


    __TMS320C28XX_CLA__ is defined only compiling CLA code. Compiling CPU code this is not defined.
    You shouldn't include math.h and perhaps any other standard headers in your CLA code, because no function compiled for CPU will work for CLA.

    BTW, are you sure you have cla2 in your derivative?

    Edward
  • Hi Edward,

    I got it.
    Thank you for your help.

    Best Regards,
    Johnson
  • These #defines have been added to CLAmath.h in the latest release.

    sal
  • In CLAmath.h sqrt() has been redefined to CLAsqrt() so that the function call to sqrt() will be mapped to the CLA Math LIbrary implementation.

    Hope this helps.

    sal
  • Dear Sal,

    Do you mean the latest CLA math library that will redefine CLAsqrt() to sqrt() in CLAmath.h?

    If yes, it is good for use when customer migrate the code from F2803x to F28004x.

    Thanks for your sharing.

  • Please take a look at the latest header file. It should answer your questions.

    The latest header defines sqrt() to CLAsqrt() if the compiler CLA macro is defined. So when the C28x runs, it will use sqrt() from math.h and when the CLA runs, it will use CLAsqrt() from the CLA math library.

    Hope this helps,
    sal