Optional Input Ports - 2022.1 English

Vitis Model Composer User Guide (UG1483)

Document ID
UG1483
Release Date
2022-05-26
Version
2022.1 English

This example shows how to use the parameter passing mechanism of MCode blocks to specify whether or not to use optional input ports on MCode blocks.

The following M-code, which defines M-function xl_m_addsub is contained in file xl_m_addsub.m:

function s = xl_m_addsub(a, b, sub)
  if sub
    s = a - b;
  else
    s = a + b;
  end

The following diagram shows a Subsystem containing two MCode blocks that use M-function xl_m_addsub.

Figure 1. Two MCode Blocks Using M-Function

The labeled add is shown in below.

Figure 2. Block Interface Editor of the MCode Block

As a result, the add block features two input ports a and b; it performs full precision addition. Input parameter sub of the MCode block labeled addsub is not bound with any value. Consequently, the addsub block features three input ports: a, b, and sub; it performs full precision addition or subtraction based on the value of input port sub.