Download Real-Time Workshop User's Guide

Transcript
9
Optimizing the Model for Code Generation
/* Gain: '<Root>/Gain1' incorporates:
*
Inport: '<Root>/In1'
*
* Regarding '<Root>/Gain':
*
Gain value: 2.0
*/
rtb_Gain1 = rtU.In1 * 2.0;
/* Outport: '<Root>/Out1' incorporates:
*
Abs: '<Root>/Abs'
*/
rtY.Out1 = rt_ABS(rtb_Gain1);
/* Outport: '<Root>/Out2' incorporates:
*
Trigonometry: '<Root>/Trigonometric Function'
*
Gain: '<Root>/Gain2'
*
Inport: '<Root>/In2'
*
* Regarding '<Root>/Gain2':
*
Gain value: 2.0
*/
rtY.Out2 = sin((2.0 * rtU.In2));
}
Using the S-Function API to Specify Input Expression Acceptance
The S-Function API provides macros that let you:
• Specify whether a block input should accept non-constant expressions (i.e.
trivial or generic expressions).
• Query whether a block input accepts non-constant expressions.
By default, block inputs do not accept non-constant expressions.
You should call the macros in your mdlSetWorkWidths function. The macros
have the following arguments:
• SimStruct *S: pointer to the block’s SimStruct.
• int idx: zero-based index of the input port.
• bool value: pass in TRUE if the port accepts input expressions; otherwise
pass in FALSE.
9-18