Clear Filters
Clear Filters

how to turn off "ConstCode" optimization

4 views (last 30 days)
Paul
Paul on 20 Jun 2023
Answered: Paul on 20 Jun 2023
I'm using Embedded Coder to generate code from a system that contains some custom S-Functions written in C. They are fully inlined, so I have .mex64 files and .tlc files.
If the s-function blocks have constant inputs, Simulink is emitting my code in a function called ModelName_Const() which is called only once at initialization. There's a comment saying "ConstCode for S-Function (my_sfunction)" followed by my custom code.
Why is it doing that, and how do I make it stop? My code has side effects, so I don't want it called only once. I want it called in the main ModelName_step() block. Is there a way to tell Simulink that the s-function has side effects, so it doesn't get moved?
In some cases, the s-function block is in a triggered subsystem. I don't want the code to get run at all until the subsystem is triggered, but Simulink doesn't care. It calls it once at initialization time whether the subsystem gets triggered or not.

Accepted Answer

Paul
Paul on 20 Jun 2023
I figured this out. I needed this flag passed to ssSetOptions(): SS_OPTION_DISALLOW_CONSTANT_SAMPLE_TIME

More Answers (0)

Categories

Find more on Simulink Coder in Help Center and File Exchange

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!