Optional Input Ports - 2020.2 English

Vivado Design Suite User Guide: Model-Based DSP Design Using System Generator (UG897)

Document ID
UG897
Release Date
2020-11-18
Version
2020.2 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 Generated by Your Tool

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.