Main Content

Validate Port Signals Among Ports of the Same Masked Block

This example shows how to create cross port constraints to validate compile-time signal attributes among ports of the same masked block. For example, you can set a constraint among the input and output port signals of the masked block to have the same data type. The rules for the cross port constraints are predefined. The available rules are Same Data Type and Same Dimension. Additionally, you can also set parameter conditions. Each port in the masked block is identified by port identifiers. The cross port constraint association is done through port identifiers.

Explore the Model

This example model multiplies the input signals and displays the product in the output. This models uses cross port constraint feature to check if the input and output port signals have same dimensions and datatypes. It has a subsystem block with two input ports and one output port. The input port identifiers are 1 and Input_2. The output port identifier is 1. The cross port constraints CheckDimensions and CheckDatatype are defined to validate the compile-time port signals of the input and output ports for same dimensions and same datatypes respectively.

open_system("slexMaskCrossPortConstraints")

Create Port Identifiers

First, create port identifiers to associate with the port constraint. To create port identifiers, right-click subsys_mask > Edit Mask > Constraints > Port Identifiers. The Port Identifiers pane lists the port identifiers for the masked Subsystem block subsys_mask.

1 Enter the Name for the port as Input_1, Input_2, and Output_1.

This name uniquely identifies the port identifier in the mask. Multiple ports can have the same port identifier.

2 Select the Type of the port as either Input or Output.

3 Select the Type of Identifier as name or index.

Select name if you want to identify the ports using names. Select index, if you want to identify the ports using numbers.

4 Enter 1, Input_2 in Identifier(s) as the Type of Identifier for these were selected as index. Enter 1 in Identifier(s) as the Type of Identifier for this was selected as name in the previous step, selecting the type of port is optional as the name for a port is unique. Each port name in a block is unique. You can map multiple ports to one port identifier when the identifier type is index.

Note: If you select name as the Identifier Type, then you do not need to select the Type of port, because each port name is unique.

Create Cross Port Constraints

Next, create cross port constraints for the masked block. Create cross port constraint CheckDimensions, to validate the input signals for the same dimension. To create cross port constraints, create mask on the block. Go to Constraints > Cross Port. The port constraint appears in the Constraint Browser.

1. Enter the Constraint Name for the constraint as CheckDimensions.

2. In Parameter Conditions, select the Parameter Name as checkCrossPortDimensions and enter the Parameter Values as on.

3. In Rule, select the Rule as Same Dimension.

4. In Associations, click add and select the Port Identifiers Input_1 and Input_2 to which the constraint needs to be associated.

5. In Diagnostic Level, select error or warning if the port constraint is not satisfied, you can display an error or a warning message during compile time.

6 Specify Diagnostic Message that will be displayed if the port constraint validation fails.

Similarly, create another cross port constraints CheckDataType to check for same datatype among all the ports Input_1, Input_2, and Output_1.

Validate Cross Port Constraints

Change the Dimension of the Input_1 and simulate the model. In the Diagnostic Viewer the following message is displayed.

The following two ports must have same dimensions. Caused by: Data at
port 1 of block
'slexMaskCrossPortConstraints/Mask_CrossPortConstraints', which is
'[1]' , must be the same as data at port 2 of block
'slexMaskCrossPortConstraints/Mask_CrossPortConstraints', which is
'[2]'. 'The inputs to the masked block must be of same dimensions'.