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.

TMS320F28377D: Launching the assembly code for FIR32 example from an already existing CLA code

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

Hi All,

I have been messing around with the concept of applying some FIR digital filtering to the outputs of my ADC's as I need to have a very accurate and low-noise reading of the analogue input pin.

I already use task 1 and task 8 in my CLA to perform a 2P2Z controller calculation from the DCL library, and to initialize all the DCL variables, respectively. 

I found the FIR32 example in C2000Ware, called: cla_adc_fir32_cpu01. This is an assembly language implementation of an FIR32 filter. Because it is wrote in assembly language, it is different to my current CLA format where I have what is a file with the extension ".cla". 

I would like to know whether there is a way to combine these two types of CLA code into the one I already have wrote, where the DCL is called through functions and the assembly language is simply kept in the directory of the project and executes when the functions are called.

For example, should the following work:

__interrupt void Cla1Task7 ( void ) {
    asm("fir32.asm");
}

My CLA7 is triggered by an ADCINT, but I am not sure whether this code is correct for entering the .asm file and executing it, placing the filtered voltage as an output. I planned to have one ".asm" file that actually executes the assembly file FIR32, and filters the voltage, and then creating a second ".asm" file that is for initialization of the filter coefficients and delays, and calling that in a separate CLA task as follows:

__interrupt void Cla1Task3 ( void ) {
    asm"fir32_init.asm";
}

And just triggering this one via software in main() before the ISR's begin to ensure that the filter coefficients and delays are initialized before the program begins looping. I am thinking to do this because as it stands I have what is technically two CLA's (The one that holds the .asm, and my DCL CLA file) which may clash in memory if they are called at the same time -- really hope that makes sense.

As a side note, there are some other errors that I get with this code example: 

    MUI16TOF32 MR2,  @_AdcaResultRegs.ADCRESULT0  ;8 Read ADCRESULT0 and convert to float

Throws the error E0009 - Missing struct/union member or tag and E0300 - The following symbols are undefined.

extern float  X[FILTER_LEN];   // Filter sample delay line
extern float  A[FILTER_LEN];   // A - Filter Coefficients

Throws three errors:

#17 expected a "]"
#171 expected a declaration 
#29 expected an expression

I put these in my CLA code where the DCL is held so it might be to do with that not being correct. 

When I try to compile the code, the compiler actually doesn't seem to have an issue with me attempting to call assembly files from the CLA. No errors there whatsoever, so maybe that is correct?

If so, then would one define these variables and buffers in the normal way one would when communicating between the CLA and the CPU? Is there anything inherently wrong with this approach?

I am really confused how the "CLA" has been coded as an "ASM" file, that doesn't seem to make much sense. I've always seen a separate ".cla" file in the explorer when the CLA of the C2000 family of devices is used, but that does not seem to be the case here.

As a final note, I've had this problem for a long time now but again the linker command file for this project is completely missing from the files in C2000Ware I am looking at. I assume there needs to be a modification in my linker command file to define some additional memory in RAM for this assembly language file, but I cannot discern a thing without being able to look at it!

A complicated question, I know -- but any help or a push in the right direction with some documents/study material for why this example was coded the way it was would be more than appreciated.

Best regards,

Joel

File location: C:\ti\controlSUITE\device_support\F2837xD\v210\F2837xD_examples_Cpu1\cla_adc_fir32\cpu01

  • Hi,

    I would like to know whether there is a way to combine these two types of CLA code into the one I already have wrote, where the DCL is called through functions and the assembly language is simply kept in the directory of the project and executes when the functions are called.

    Yes, this is possible. The .asm can hold just the 2 tasks related to FIR and the .cla file defines the other tasks. So in your case, Task 1 and Task 8 will reside in .cla file. And Task 7 and Task 3 will reside in ASM file.

    I am really confused how the "CLA" has been coded as an "ASM" file, that doesn't seem to make much sense. I've always seen a separate ".cla" file in the explorer when the CLA of the C2000 family of devices is used, but that does not seem to be the case here.

    For CLA the programmer has the option to write C code which goes in the .cla file or hand created assembly which goes into assembly files. Either entire CLA task code can be written in assembly or even functions can be written in assembly that can then be called from C code. Example the CLAmath library functions are written in assembly and are called by C code in .cla files. See : <C2000Ware>libraries\math\CLAmath\c28\

    More information on assembly function calling conventions from C can be found here if you need more information.

    Compiler Guides  https://www.ti.com/lit/spru514

    Assembly Guide https://www.ti.com/lit/spru513

    As a final note, I've had this problem for a long time now but again the linker command file for this project is completely missing from the files in C2000Ware I am looking at. I assume there needs to be a modification in my linker command file to define some additional memory in RAM for this assembly language file, but I cannot discern a thing without being able to look at it!

    The application will need a linker command file. Is it that the linker command file does not show up in the CCS project? If so you can find the linker command file in Project Properties -> Build -> C2000 Linker  -> File Search Path

    As a side note, there are some other errors that I get with this code example: 

    I am able to build the example just fine. Can you compare the original example with your application and check if any header files were missed out?

    Thanks,
    Ashwini

  • Hello,

    Thanks for the reply. I have started looking and already have found a discrepancy with the comments regarding how claMath is wrote in assembly. The programs in the directory that you pointed me towards, use the header file "CLAmath.h", and all of the functions in this header file are wrote in C language, and there is no assembly language whatsoever, and definitely does not show any calls to any assembly language functions that perform mathematical operations on any of the variables defined in the code. 

    Have you suggested the wrong directory? Here's an example of what I see in the CLAmath directory header files you have told me to look at, for calculating a logarithm:

    //
    // CLAlogN_inline(float32_t fVal, float32_t N)
    //
    #pragma FUNC_ALWAYS_INLINE(CLAlogN_inline)
    static inline float32_t CLAlogN_inline(float32_t fVal, float32_t N)
    {
        float32_t ln_fVal;
        float32_t ln_N;
        float32_t result;
    
        //Step 1:   Calculate natural logarithm of fVal
        ln_fVal = CLAln_inline(fVal);
    
        //Step 2:   Calculate natural logarithm of N
        ln_N = CLAln_inline(N);
    
        //Step 3:   log_N(x) = ln(fVal)/ln(N)
        result = CLAdiv_inline(ln_fVal, ln_N);
    
        return(result);
    }
    

    Please do clarify if I am looking in the wrong location, but I cannot see any .asm mathematic functions in this directory. I also do not see, again, linker command files. Here is a screenshot:

    Looks very different to the project properties for my own project, so there is something wrong possibly with how the installer has set the directories?

    Best regards,

    Joel

  • Hi Joel,

    Consider the logN example:

    1. In <C2000Ware>\libraries\math\CLAmath\c28\examples\logN\cla_logN.cla CLA source file, Cla1task1 calls CLAlogN function.

    2. CLAlogN is an optimized assembly function which is defined in <C2000Ware>\libraries\math\CLAmath\c28\source\CLAlogN.asm and gets included in the CLAmath library which was linked with the logN example project.

    The code snippet you included above is an unoptimized C inline function which is a test function to verify that the assembly function is correct by comparing the output of both implementations.

    Thanks,
    Ashwini