Why are 2D arrays in Simulink represented as 1D arrays in the generated C code in Real-Time Workshop 5.6 (R2010b)?

9 次查看(过去 30 天)
I am attempting to generate C code from my Simulink model. I have a parameter (external variable with direct access) defined in a hand-coded header file as:
SInt16_T EOLFillTimeLookup[2][2];
This parameter is a 2x2 matrix in Simulink but when I generate code, the generated code is expecting a 1D array instead of a 2D array.
For example, when passing a pointer to this parameter to an interpolate function the code uses:
&(EOLFillTimeLookup[0])
I would expect it to be:
&(EOLFillTimeLookup[0][0])
I realize these are functionally equivalent, but this is causing compiler warnings. Is there a way to tell Real-Time Workshop to treat my parameter as a 2D array?

采纳的回答

MathWorks Support Team
编辑:MathWorks Support Team 2020-6-15
Real-Time Workshop 5.6 (R2010b) treats multidimensional data as 1-D and it serializes it such that when you access x[0], x[1], x[2] in the generated code, the generated code expects to be moving down columns and then moving to the next column. Thus multidimensional arrays are ordered in a column-major format and not a row-major format in the generated code.
To work around this issue, there are two options:
1. One option is to re-order the 2D variable definition in the hand code so that it is ordered correctly in the generated code.
2. The second option is to use the custom storage class with the data. The custom storage classes replace variable reads and writes with user-specified function calls. The user has to implement those function calls, but in this case, that provides a perfect place for the user to do the array access the way that he wants it.
For more information on Custom Storage Class refer to the following documentation link:
<https://in.mathworks.com/help/ecoder/ug/design-custom-storage-classes-and-memory-sections.html>
On embedded systems, the overhead of the extra function call might be unacceptable to the user in which case the first option may be used instead.
  1 个评论
TAB
TAB 2018-7-20
Is this true in Matlab R2015b. I have simulink output or [8x12] array. But in generated generated output is 96 array.
All the work around suggested above are not useful for me. My software is based on AUTOSAR and Simulink output goes to code which is also generated by other tool.

请先登录,再进行评论。

更多回答(0 个)

类别

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

产品


版本

R2010b

Community Treasure Hunt

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

Start Hunting!

Translated by