Simulink Embedded Coder: need to define code generation storage class for a block that is part of a library

16 次查看(过去 30 天)
Hello experts,
I am reorganizing an existing Simulink model and would like to move parts of it to a library file so it can be reused.
The model is used to generate C code that runs on a TI C2000 microcontroller. We make use of C2000 Control Law Accelerator (CLA), which requires that variables be placed in certain memory sections - otherwise they are not accessible by the CLA. Note that by default, all variables go in to main microcontroller RAM, which is NOT accessible by the CLA.
My main problem is with "Unit Delay" blocks in the model, which have an internal state variable. Currently, for each Unit Delay block in the project, a "State name" is defined in block parameters. Once "State name" is defined, "Signal object class" and "Code generation storage class" dropdowns become enabled, and it's possible to select a CLA-accessible memory section for the state variable. Everything compiles and works properly this way.
However, some parts of our models are duplicated, and making them part of a library would really help with managing complexity. Once block becomes part of the library, it is no longer possible to define a state name, as they are required to be unique.
We do define a custom storage class, but it has multiple memory sections. To place state variable where it needs to be, it needs to go to a specific memory section within our custom storage class (i.e., "Code generation storage class"). But once I leave "State name" textbox blank, "Code generation storage class" resets to "Auto", and the state variable is not placed in CLA-accessible section of RAM.
Is there a recommended way for handling these situations? Should I define a custom storage class with only one memory section?
Thanks in advance!
  1 个评论
Matthew Englehart
编辑:Matthew Englehart 2025-7-7
Hi Pavel, once you place an instance of the library block in the model, you can define a code mapping in the model (not in the library) for that Unit Delay state, specifying both the identifier and storage class for that state.

请先登录,再进行评论。

回答(1 个)

Mark McBroom
Mark McBroom 2025-5-17
You could try putting a mask on the library block and adding a mask argument for the State. Then, create a Simuilnk.Signal to represent the state, and set the appropriate storage class settings. Use this new Simulink.Signal as the argument for your newly created masked subsystem.
Thanks.
Mark.

类别

Help CenterFile Exchange 中查找有关 Deployment, Integration, and Supported Hardware 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by