Main Content

Software-in-the-Loop Execution for MATLAB Function with Multiple Signatures

R2026b

For MATLAB® function with multiple signatures, software-in-the-loop (SIL) enables you to verify the generated C/C++ code by using a SIL MEX file that supports multiple signatures. This feature enables you to generate one SIL MEX file for verification instead of generating separate SIL MEX files for each signature.

Generate Multisignature SIL MEX File for an Entry-Point Function

  1. Copy the MATLAB code of one entry-point function myAdd, and save it in your working directory.

    The entry-point function, myAdd, returns the sum of two values.

    function y = myAdd(a,b)
    %#codegen
    y = a+b;
    end
    
  2. Create a coder.EmbeddedCodeConfig object and configure the object for SIL.

    cfg = coder.config('lib');
    cfg.VerificationMode = "SIL";

  3. The codegen command generates a SIL MEX file myAdd_sil that works with three different data types: double, int8, and vector of doubles. You specify the entry-point function followed by -args for each signature of the entry-point function.

    codegen -config cfg myAdd -args {1,2} -args {int8(2),int8(3)} -args {1:10,1:10} -report

  4. At the command prompt, call the generated SIL MEX file myAdd_sil. Make sure that the values you pass to myAdd_sil match the input properties that you specified in the codegen command.

    myAdd_sil(3,4)
    ans =
    
         7
    myAdd_sil(int8(5),int8(6))
    ans =
    
      int8
    
       11
    myAdd_sil(1:10,2:11)
    ans =
    
         3     5     7     9    11    13    15    17    19    21

    Running the MATLAB function myAdd with these input values produces the same output. These test cases verify that myAdd and myAdd_sil have the same behavior.

  5. Terminate the SIL execution process.

    clear myAdd_sil;

    You can also use the command clear mex, which clears MEX files from memory.

  6. In the generated code, different signatures are mapped to versioned entry-point functions myAdd1, myAdd2, and myAdd3 as shown in the figure.

    Entry point summary shows mapping of signatures to entry-point function versions.

Generate Multisignature SIL MEX File for Multiple Entry-Point Functions

  1. Copy the MATLAB codes of two entry-point functions, myAdd and myMul and save it in your working directory.

    The first entry-point function, myAdd, returns the sum of two values:

    function y = myAdd(a,b)
    %#codegen
    y = a+b;
    end
    

    The second entry-point function, myMul, returns the multiplication of two values:

    function y = myMul(a,b)
    %#codegen
    y = a*b;
    end
    
  2. Create a coder.EmbeddedCodeConfig object and configure the object for SIL.

    cfg = coder.config('lib');
    cfg.VerificationMode = "SIL";

  3. The codegen command generates a SIL MEX file myMath_sil for the signatures that you specified in the codegen command. The SIL MEX file myMath_sil works for myAdd and myMul with two different data types: double, and int8. You specify the entry-point function followed by -args for each signature of the entry-point function.

    codegen -config cfg myAdd.m -args {1,2} -args {int8(1),int8(2)} myMul.m -args {1,2} -args {int8(1),int8(2)} -o 'myMath' -report

  4. At the command prompt, call the generated SIL MEX file myMath_sil. Make sure that the values you pass to myMath_sil match the input properties that you specified in the codegen command.

    myMath_sil("myAdd",3,4)
    ans =
    
         7
    myMath_sil("myAdd",int8(5),int8(6))
    ans =
    
       int8 
    
       11
    myMath_sil("myMul",3,4)
    ans =
    
         12
    myMath_sil("myMul",int8(5),int8(6))
    ans =
    
        int8
    
        30

    Running the MATLAB function myAdd and myMul with these input values produces the same output. These test cases verify that myAdd, myMul and the generated SIL MEX file myMath_sil have the same behavior.

  5. Terminate the SIL execution process.

    clear myMath_sil;

    You can also use the command clear mex, which clears MEX files from memory.

  6. In the generated code, different signatures are mapped to versioned entry-point functions myAdd1, myAdd2, myMul1 and myMul2 as shown in the figure.

    Entry point summary shows mapping of signatures to entry-point function versions.

Example main file provides information about how to use entry-points in your application. Incorporate Generated Code Using an Example Main Function, helps to generate example main.c file.

Note

You can implement the multisignature PIL MEX for an entry-point function and multiple entry-point functions in the same way that the multisignature SIL MEX is implemented.

Limitations

The multisignature SIL MEX and PIL MEX generation does not have graphical user interface (GUI) support.

See Also

|

Topics