How to influence order of automatic generated C-Code from Simulink Model

Hallo,
I have a simulink-model containing normal math operations and s-functions as input and outputs to hardware.
Lets say two s-funtions give in1 and in2, a multiplication calculates mult1 = in1 * in2, a s-function writes the value of mult1.
I would expect the following c-code from my model:
/* S-Function (nios_mm_read) Block: <Root>/in1 */
MEM_FAST_READ(simulink_model.in1, short, IN1_BASE);
/* S-Function (nios_mm_read) Block: <Root>/in2 */
MEM_FAST_READ(simulink_model.in2, short, IN2_BASE);
/* product */
simulink_model.Product = simulink_model.in1 *
simulink_model.in2 ;
/* S-Function (nios_mm_write) Block: <Root>/Product */
MEM_FAST_WRITE(simulink_model.Product, short, OUT_BASE);
Unfortunately the order functions is mixed up after generating the c-code from the model, so that, in my minimal example, the multiplication is caclulated, before the actual values are read via the s-functions.
Is there any possibility to influence the order appearance of the blocks in the generated code?
Thanks and regards

 채택된 답변

Sebastian Castro
Sebastian Castro 2015년 4월 14일

0 개 추천

Yes, there is a block sorted order in all blocks in Simulink. This documentation link talks about block sorted order at great length.
If Simulink "doesn't care" which blocks runs first, i.e., if there are no real dependencies and the order of blocks is arbitrary, you can modify the priority of each block which MAY affect its sorted order. The "Priority" section in this link discusses this.
When you generate code from a model, the lines of code should directly match the block sorted order. So, you can enable the sorted order display in your model to verify how your code will be arranged.
- Sebastian

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Simulink Coder에 대해 자세히 알아보기

질문:

2015년 4월 14일

답변:

2015년 4월 14일

Community Treasure Hunt

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

Start Hunting!

Translated by