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
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;
endConfigure SIL execution
Create a coder.EmbeddedCodeConfig object and configure the object for SIL.
cfg = coder.config('lib');
cfg.VerificationMode = "SIL";Generate code using codegen command
Thecodegen
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} -reportRun 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 thecodegen
command.
myAdd_sil(int8(5),int8(6))
ans =
3 5 7 9 11 13 15 17 19 21
Running the MATLAB functionmyAdd
with these input values produces the same output. These test cases verify thatmyAdd
andmyAdd_sil
have the same behavior.Terminate SIL execution
Terminate the SIL execution process.
You can also use the commandclear mex
, which clears MEX files from memory.Entry Point Summary Report
In the generated code, different signatures are mapped to versioned entry-point functionsmyAdd1
,myAdd2
, andmyAdd3
as shown in the figure.
Generate Multisignature SIL MEX File for Multiple Entry-Point Functions
MATLAB code for myAdd andmyMul functions
Copy the MATLAB codes of two entry-point functions,myAdd
andmyMul
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;
endConfigure SIL execution
Create a coder.EmbeddedCodeConfig object and configure the object for SIL.
cfg = coder.config('lib');
cfg.VerificationMode = "SIL";Generate code using codegen command
Thecodegen
command generates a SIL MEX filemyMath_sil
for the signatures that you specified in thecodegen
command. The SIL MEX filemyMath_sil
works formyAdd
andmyMul
with two different data types:double
, andint8
. 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' -reportRun 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 thecodegen
command.
myMath_sil("myAdd",int8(5),int8(6))
myMath_sil("myMul",int8(5),int8(6))
Running the MATLAB functionmyAdd
andmyMul
with these input values produces the same output. These test cases verify thatmyAdd
,myMul
and the generated SIL MEX filemyMath_sil
have the same behavior.Terminate SIL execution
Terminate the SIL execution process.
You can also use the commandclear mex
, which clears MEX files from memory.Entry Point Summary Report
In the generated code, different signatures are mapped to versioned entry-point functionsmyAdd1
,myAdd2
,myMul1
andmyMul2
as shown in the figure.
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.