I have some level 2 sfunctions in my system to wrap my C/C++ functions. All of these functions are fixed and I don't change them. Is it possible to avoid code generation of these function each time that I build an application for the xpctarget?

Hello,
I am trying to compile and a build a Simulink system as an xpctarget application. My system has some level-2 Sfunctions that I use to wrap some of my C/C++ functions. One of these functions is huge and each time that I change my system and try to build the application it takes a long time to do code generation for that sfunction. (compilationa and linking are pretty fast since I use static libraries of my functions.)
Is there a possibility that once the code is generated for the sfunction, the next time somehow avoid code generation for that sfunction. Or, I separately generate code for the sfunction once and each time just using the generated code.
Thanks for your help,
Reza

Answers (3)

I think the only way to bypass code-generation for one part of the model is to using a Model Reference block. Try putting your S-function is a separate model and reference that model from the main model. I think if the generated code for the referenced model already exists, Simulink Coder won't attempt to generate code again.
Hello,
I used the Model Reference Block and I set my reference model as inline and also added this to the mdlInitializeSizes of my Sfuncion:
>> ssSetOptions(S,(SS_OPTION_WORKS_WITH_CODE_REUSE));
to activate reusable code. But I still get this error
>>'Configuration Parameters > Model Referencing > Total number of instances allowed per top model' is set to 'Multiple' for model 'FCN_LEFT_ATRIAS_B_BLK'. S-Function block 'FCN_LEFT_ATRIAS_B_BLK/FCN_LEFT_ATRIAS_B' of this model does not support code reuse. This is not allowed in a model configured to be referenced multiple times. To enable code reuse, the block must have a TLC implementation and the S-function's mdlInitializeSizes function must set the option 'SS_OPTION_WORKS_WITH_CODE_REUSE'. To configure the model to be referenced only once, change the configuration parameter 'Total number of instances allowed per top model' to 'One'"
Thanks, Reza
Here what I tried:
I wrapped my C function with Sfunction level-2 and saved the Sfunction block in a simulink library. Then I opened two new models in simulink. In model1, I copied one instance of my sfunction from the library. I implemented a TLC file for my Sfunction to inline my C function. Then I compiled and built model1 as grt.tlc . I compiled it and built it as grt.tlc.
Then I used "Model Reference" block in simulink in the second model (model2) to reference to model1. When I tried to build model2 with ctrlB the previous error appears. Interesting thing is, when I check the code generation report for model1 it says the "code reuse" is failed because TLC is not implemented for the Sfunction and the option 'SS_OPTION_WORKS_WITH_CODE_REUSE' is not set inside the Sfunction.
I don't know what shall I try next.
Thanks, Reza

1 Comment

Have you already written a TLC file for your S-function? From the error message, it looks like you need to do so. Please see S-Function Inlining.

Sign in to comment.

Categories

Find more on Simulink Coder in Help Center and File Exchange

Asked:

on 2 Nov 2012

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!