Simulink: How to make built-in boolean a 32-bit type?

9 ビュー (過去 30 日間)
Kai Harth
Kai Harth 2017 年 2 月 6 日
編集済み: Kai Harth 2017 年 2 月 10 日
How can I configure Simulink to consider its built-in 'boolean' type to be unsigned int 32 bit?
My scenario is Simulink-only (no code-generation etc), but using utility library blocks that we create using the legacy code tool...
lct_spec.OutputFcnSpec = 'void GetBoolean(uint8 u1[], uint32 u2, uint32 u3, uint32 u4, boolean y1[1])'
On the legacy code side that y1 return-by-reference value uses a boolean typedef that uses a 32-bit representation. This compiles fine, but as one would expect leads to some nasty run-time problems, because presumably the simulink boolean type is mapped to a single byte.
The two things I cannot/don't want to do: - change my legacy code to use an 8-bit boolean type - change my Simulink models to use an AliasType for boolean
I have read the documentation on data type replacement and Simulink.AliasType, but those seem to be only available to solve the problem if the Coder product is involved.
Thank you!

採用された回答

Kai Harth
Kai Harth 2017 年 2 月 10 日
編集済み: Kai Harth 2017 年 2 月 10 日
Ok, I dind't find out how to change the size of the Simulink underlying type... but I found a work-around.
I have a file DataAccess.c/.h, containing the problem function DataAccess_GetBoolean(...)
The legacy code tool then generated a separate wrapper file for each function, in that case DataAccess_GetBoolean.c/.h, which containts the s-function API functions, and in mdlOutputs(..) calls the hand-code function DataAccess_GetBoolean(...)
In our case, that is where I had to adjust the code by hand and then rebuild:
This is the generated code:
[...]
boolean_T *y1 = (boolean_T *) ssGetOutputPortSignal(S, 0); // this is where the pointer size mismatch caused the problem, because boolean_T is 8-bit and my boolean type is uint32
/* Call the legacy code function */
DataAccess_GetBoolean( u1, *u2, *u3, *u4, y1);
And this is the code with manual modification:
[...]
boolean_T *y1= (boolean_T *) ssGetOutputPortSignal(S, 0);
uint32_T TmpBoolean;
/* Call the legacy code function, using the uint32 pointer */
DataAccess_GetBoolean( u1, *u2, *u3, *u4, &TmpBoolean);
// map boolean value over from uint32 pointer to boolean_T(8 bit) pointer
if (TmpBoolean)
*y1 = 1;
else
*y1 = 0;
After the modification I had to rebuild the legacy code and the wrapper code. The easiest way to do that was to copy the output from the previous legacy code tool run and run them again on the command line... Just looked for ### Start Compiling DataAccess_GetBoolean and grabbed the next two mex calls

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeString についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by