Software-in-the-Loop Execution for MATLAB Function with Multiple Signatures - MATLAB & Simulink (original) (raw)

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. MATLAB code for myAdd function
    Copy the MATLAB code of one entry-point functionmyAdd, 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. Configure SIL execution
    Create a coder.EmbeddedCodeConfig object and configure the object for SIL.
    cfg = coder.config('lib');
    cfg.VerificationMode = "SIL";
  3. Generate code using codegen command
    The codegen command generates a SIL MEX filemyAdd_sil that works with three different data types: double, int8, andvector 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. Run generated SIL MEX file myAdd_sil
    At the command prompt, call the generated SIL MEX filemyAdd_sil. Make sure that the values you pass tomyAdd_sil match the input properties that you specified in the codegen command.
    myAdd_sil(int8(5),int8(6))
    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 thatmyAdd and myAdd_sil have the same behavior.
  5. Terminate SIL execution
    Terminate the SIL execution process.
    You can also use the command clear mex, which clears MEX files from memory.
  6. Entry Point Summary Report
    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. MATLAB code for myAdd andmyMul functions
    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. Configure SIL execution
    Create a coder.EmbeddedCodeConfig object and configure the object for SIL.
    cfg = coder.config('lib');
    cfg.VerificationMode = "SIL";
  3. Generate code using codegen command
    The codegen command generates a SIL MEX filemyMath_sil for the signatures that you specified in the codegen command. The SIL MEX filemyMath_sil works for myAdd andmyMul 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. Run generated SIL MEX file myMath_sil
    At the command prompt, call the generated SIL MEX filemyMath_sil. Make sure that the values you pass tomyMath_sil match the input properties that you specified in the codegen command.
    myMath_sil("myAdd",int8(5),int8(6))
    myMath_sil("myMul",int8(5),int8(6))
    Running the MATLAB function myAdd andmyMul with these input values produces the same output. These test cases verify that myAdd,myMul and the generated SIL MEX filemyMath_sil have the same behavior.
  5. Terminate SIL execution
    Terminate the SIL execution process.
    You can also use the command clear mex, which clears MEX files from memory.
  6. Entry Point Summary Report
    In the generated code, different signatures are mapped to versioned entry-point functions myAdd1,myAdd2, myMul1 andmyMul2 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

codegen | coder.config

Topics