Code Generation: Static local variables

I would like the "Block signals" and "Block states" in the generated c-code to be of the type "static".
Example:
static BlockIO_model B;
How do I get there? thx

 Respuesta aceptada

Kaustubha Govind
Kaustubha Govind el 22 de Nov. de 2011

1 voto

I don't think there is currently a simple solution for this (I would recommend putting in an enhancement request with MathWorks Tech Support if this is important for your use-case).
However, this is certainly possible with use of Custom Storage Classes. You can create your own storage class to declare data as "static" in the generated code. This storage class can then be applied to data in your model by the use of Simulink.Signal (or mpt.Signal) and Simulink.Parameter (or mpt.Parameter) objects that use this as their storage class. There are some usage examples in the documentation section Types, Operators, and Expressions.

6 comentarios

Steg
Steg el 22 de Nov. de 2011
thanks for your answert.
I'm already working with custom storage classes. It works well for signals which are linked to these storage classes.
My current problem is, that all other variables (like block outputs or states), which are generated automatically and are not related to a storage class, are of a global typ. In general, I want all variables in the code to be of a "static local" type.
Any idea how to make these "intermediate" variables of static type?
Kaustubha Govind
Kaustubha Govind el 23 de Nov. de 2011
Steg: In general, you can assign custom storage classes to all signals by creating a signal object or assigning it a name (right click on signal and select "Signal Properties ..."). Regarding states - I think this is currently possible only for blocks that have the "State Attributes" tab in the dialog window like the Delay and Unit Delay block. You can select a storage class in this tab.
Fang Li
Fang Li el 22 de Dic. de 2016
Editada: Fang Li el 22 de Dic. de 2016
I come across this problem too. The Answer here does no help.
Jean
Jean el 9 de En. de 2017
Hello Fang, do you manage to fix this issue?
Sai Manga Reddy Karri
Sai Manga Reddy Karri el 30 de Jul. de 2021
I am trying to generate it for unit delay block..it is generated as global static.. but i am unable to generate it as local static..
sai ganesh
sai ganesh el 26 de Abr. de 2024
Any solution for this scenario? Even in MATLAB 2022b we are unable to generate the Block states as local static variables.

Iniciar sesión para comentar.

Más respuestas (1)

Fan BU
Fan BU el 26 de Mayo de 2017

0 votos

Please try using the block delay, the delayed signal will be one from last cycle, this corresponds to static in C code, see the picture, the signal rpmDir in generated C code will be static.
Maybe custom storage class is better solution, I never used this.

Productos

Etiquetas

Preguntada:

el 21 de Nov. de 2011

Comentada:

el 26 de Abr. de 2024

Community Treasure Hunt

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

Start Hunting!

Translated by