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.

TMS320F28379D: calling a function with many arguments in CLA

Part Number: TMS320F28379D

Dear TI Hello,

 

I am using the CLA to compute the regulation loop using a function with many arguments. 

My function takes a structure input. I am trying to initialize (reference and enable) a part of the structure in the main.c interrupt service routine.

My function is an inline function:

static inline void RST_Regulor(float R_Input, float S_Input, float T_Input,
                               uint16_t Enable, float oldActu, float *Output)
{
    uint16_t i;
    /*******************************************
     *             Compute T polynome          *
     *******************************************/
     /* Shift the delay line to the right by 1 */
    for(i = SIZE_OF_T-1; i > 0; i--)
    {
        /*shift*/
        Poly_T[i] = Poly_T[i-1];

        /*Multiplication and Addition*/
        T  += coef_t[i] * Poly_T[i];
    }
    /* Get adc physical input into start of the delay line */
    /* note the adc input is simulated in software */
    if (Enable == 1)
    {
        Poly_T[0] = T_Input; //reference
    }
    else
    {
        Poly_T[0] = R_Input; //measured
    }
    
    /*Add the first param */
    T  += coef_t[0] * Poly_T[0];

    /*******************************************
     *             Compute R polynome          *
     *******************************************/
    /* Shift the delay line to the right by 1 */
    for(i = SIZE_OF_R-1; i > 0; i--)
    {
        /*shift*/
        Poly_R[i] = Poly_R[i-1];

        /*Multiplication and Addition*/
        R   += coef_r[i] * Poly_R[i];
    }
    /* Get adc physical input into start of the delay line */
    /* note the adc input is simulated in software */
    Poly_R[0] = R_Input;
    R  += coef_r[0] * Poly_R[0];

    /*******************************************
     *             Compute S polynome          *
     *******************************************/
     //Shift the delay line to the right by 1
    for(i = SIZE_OF_S-1; i > 0; i--)
    {
        /*shift*/
        Poly_S[i] = Poly_S[i-1];

        /*Multiplication and Addition*/
        S   += coef_s[i] * Poly_S[i];
    }
    /* Get adc physical input into start of the delay line */
    /* note the adc input is simulated in software */
    Poly_S[0] = oldActu;
    S  += coef_s[0] * Poly_S[0];

    /**** Result*****/

    if(Enable == 1)
    {
        /* Regulation output if enable*/
        *Output = (T - R - S) * INVERS_S0;
    }
    else
    {
        /* Old value if RST regulation is not enabled */
        *Output = oldActu;
    }
    
}

and I am using the following mapping:

    #pragma DATA_SECTION(coef_r,"RAMLS4")
    const float coef_r[SIZE_OF_R] = {0.2483687f, 0.03341229f, -0.2149564f};
    
    #pragma DATA_SECTION(Poly_R,"RAMLS4")
    float Poly_R[SIZE_OF_R];
    
    #pragma DATA_SECTION(coef_s,"RAMLS4")
    const float coef_s[SIZE_OF_S] = {0.1058185f, -0.06386142f, -0.01921073f, -0.02274637f};
    
    #pragma DATA_SECTION(Poly_S,"RAMLS4")
    float Poly_S[SIZE_OF_S];
    
    #pragma DATA_SECTION(coef_t,"RAMLS4")
    const float coef_t[SIZE_OF_T] = {0.06682458f};
    
    #pragma DATA_SECTION(Poly_T,"RAMLS4")
    float Poly_T[SIZE_OF_T];
    
    #pragma DATA_SECTION(R,"RAMLS4")
    float R;
    #pragma DATA_SECTION(S,"RAMLS4")
    float S;
    #pragma DATA_SECTION(T,"RAMLS4")
    float T;

The problem is that when I debug the CLA using ____mdebugstop()my polynoms Poly_R, Poly_S and Poly_T are empty.

By the way, this code is already executed in the C28 CPU and it works. my polynoms are note null.

2. Another thing that I couldn't understand that the structure is partially initialed.

for example, the reference variable is affected but not the enable variable.

 sDCDCConfig.CurrentRef    = Ref;   
 sDCDCConfig.EnableControl = Enable;
 

I am using the 21.6 C2000 compiler.

The CLA code is the following:

#pragma DATA_SECTION(sDCDCConfig,"CpuToCla1MsgRAM");
#pragma DATA_SECTION(DutyCycleMan,"Cla1ToCpuMsgRAM");
ST_DcDcConfiguration    sDCDCConfig;
float DutyCycleMan;

    //__mdebugstop();
    /* RST regulation */
    RST_Regulor(IDC_CLA,                    //R
                CLA_StaActu,                //S
                sDCDCConfig.CurrentRef,     //T
                sDCDCConfig.EnableControl,  //enable
                CLA_StaActu,                //old actuation
                &DutyCycleMan);             //RST output regulation

Thank you in advance,

S.Tarik

//Edited by tarik le 21/01/2022

  • Hi S.Tarik,

    Have you configured those LS RAM ownership to CLA? Are the variables/struct initialized in a .c file or .cla file?

    Regards,

    Veena

  • Hi Veena,

    I clicked on "this resolved my issue" by error, my issue is already remaining.

    could you open the thread, please?

  • Have you configured those LS RAM ownership to CLA?

    Yes I did it:

           MemCfgRegs.LSxMSEL.bit.MSEL_LS4 = 1;
           MemCfgRegs.LSxCLAPGM.bit.CLAPGM_LS4 = 1;
    
           MemCfgRegs.LSxMSEL.bit.MSEL_LS3 = 1;
           MemCfgRegs.LSxCLAPGM.bit.CLAPGM_LS3 = 0;

    I am using the LS4RAm for prog and the LS3RAM for data.

    Are the variables/struct initialized in a .c file or .cla file?

    The structure is partially initialized in the .c and resides in Cpu1ToCla1MSG

    One more question:

    My function is an Inline function, should I add the memcpy like this?

    //       memcpy((uint32_t *)&Cla1ConstRunStart, (uint32_t *)&Cla1ConstLoadStart,
    //           (uint32_t)&Cla1ConstLoadSize );

    I don't have the Cla1ConstRunStart, Cla1ConstLoadStart and Cla1ConstLoadSize variviable in my .cmd file.

  • Hi,

    could you open the thread, please?

    The thread will be reopened automatically when you reply to the thread.

    should I add the memcpy like this?

    This is required if you want to run the code standalone from Flash. If you have constants in your  CLA code, you need to load them in Flash and run from RAM. This is because CLA does not have access to Flash memory.

       .const_cla       :   LOAD = FLASH2,
                            RUN = RAMLS1,
                            RUN_START(Cla1ConstRunStart),
                            LOAD_START(Cla1ConstLoadStart),
                            LOAD_SIZE(Cla1ConstLoadSize)

    Memcpy is required to copy the contents from Flash to RAM. It is not done by default. You can check the .map file to see if there are any bytes allocated to const_cla section. It is possible that the init values of the variables are stored in the const_cla section.

    Note that you cannot initialize global variables in .cla file. You can initialize them only inside a task

    Regards,

    Veena

  • I am using a const float tab[] which resides in the LSRAM4, I do it this way because I don't know where the const variables are by default on the project I am working on. 

        #pragma DATA_SECTION(coef_r,"CpuClaData")
        const float coef_r[SIZE_OF_R] = {0.2483687f, 0.03341229f, -0.2149564f};
        
        #pragma DATA_SECTION(Poly_R,"CpuClaData")
        float Poly_R[SIZE_OF_R];
        
        #pragma DATA_SECTION(coef_s,"CpuClaData")
        const float coef_s[SIZE_OF_S] = {0.1058185f, -0.06386142f, -0.01921073f, -0.02274637f};
        
        #pragma DATA_SECTION(Poly_S,"CpuClaData")
        float Poly_S[SIZE_OF_S];
        
        #pragma DATA_SECTION(coef_t,"CpuClaData")
        const float coef_t[SIZE_OF_T] = {0.06682458f};
        
        #pragma DATA_SECTION(Poly_T,"CpuClaData")
        float Poly_T[SIZE_OF_T];
        
        #pragma DATA_SECTION(R,"Cla1ToCpuMsgRAM")
        float R;
        #pragma DATA_SECTION(S,"Cla1ToCpuMsgRAM")
        float S;
        #pragma DATA_SECTION(T,"Cla1ToCpuMsgRAM")
        float T;
        
    #endif

    CpuClaData = LS4RAM

  • Hi,

    Is the issue present in const arrays as well, or just with the Poly_R, Poly_S, Poly_T?

    Can you share the linker command file used?

    Regards,

    Veena

  • when I add the float const tables like coef to the watch window, I could see the content but the Poly_R S ant T there are always null.

    The code must shift the input values in the Poly_R S and T. When I add manually values to the Poly_R  S and T the buffer does not move, it looks like the code is not running. 

    I have another inline functions that read the ADC, computes the physical values, and makes a saturation on the output, these functions are well executed in the CLA, but the regulation does not work and poly R S and T are always null.

    Can you share the linker command file used?

    I wish I could do it!

  • In the const_cla section, the LOAD must be from FLASH2,

    The choice is based on what?

    I don't know why I have to put FLASH2 or FLASH3...

  • Hi,

    You can change the memory regions as required. But note that, if you are putting cla_const in Flash, you need to copy that to RAM location using memcpy and LOAD_RUN feature in cmd file

    Regards,

    Veena