Real-Time Workshop    

Acceptance or Denial of Requests for
Input Expressions

A block can request that its output be represented in code as an expression. Such a request may be denied if the destination block cannot accept expressions at its input port. Furthermore, conditions independent of the requesting block and its destination block(s) can prevent acceptance of expressions.

In this section, we will discuss block-specific conditions under which requests for input expressions are denied. For information on other conditions that prevent acceptance of expressions, see Generic Conditions for Denial of Requests to Output Expressions.

A block should not be configured to accept expressions at its input port under the following conditions:

If a block refuses to accept expressions at an input port, then no block that is connected to that input port is permitted to output a generic or trivial expression.

A request to output a constant expression is never denied, because there is no performance penalty for a constant expression, and it is always possible to take the parameter's address.

Example: Acceptance and Denial of Expressions at Block Inputs

This example illustrates how various built-in blocks handle requests to accept different categories of expressions at their inputs.

The sample model of Figure 9-5 contains:

Figure 9-5: Two Gain Blocks Requesting to Output an Expression

The Gain1 block's request to output an expression is denied by the Abs block. The Gain2 block's request to output an expression is accepted by the Trigonometric Function block.

The generated code is shown in the code excerpt below. Note that the output of the Gain1 block is stored in the temporary variable rtb_Gain1, rather than generating an input expression to the Abs block.

Using the S-Function API to Specify Input Expression Acceptance

The S-Function API provides macros that let you:

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:

The macro available for specifying whether or not a block input should accept a non-constant expression is as follows:

The corresponding macro available for querying the status set by any prior calls to ssSetInputPortAcceptExprInRTW is as follows:

Generic Conditions for Denial of Requests to Output Expressions

Even after a specific block requests that it be allowed to generate an output expression, that request may be denied, for generic reasons. These reasons include, but are not limited to:

You do not need to consider these generic factors when deciding whether or not to utilize expression folding for a particular block. However, these rules may be helpful when examining generated code, and analyzing cases where the expression folding optimization is suppressed.


  Categories of Output Expressions Utilizing Expression Folding in Your TLC Block Implementation