Main Content

setFunction

Set code mapping information for model function

    Description

    example

    setFunction(myCodeMappingObj,function,Name,Value) sets code mapping information for the specified model function. Use this function to set the function customization template, memory section, or function name for a model function. For single-tasking periodic functions and Simulink® functions, you can use this function to set the argument specification, including argument names, type qualifiers, and argument order.

    Examples

    collapse all

    In the model code mappings for model myConfigModel, configure the name of the generated C initialize function as myInitFunction.

    cm = coder.mapping.api.get('myConfigModel');
    setFunction(cm,'Initialize','FunctionName','myInitFunction');
    

    In the model code mappings for model myInitFunction, configure the memory section for the periodic single-tasking function as None.

    cm = coder.mapping.api.get('myInitFunction');
    setFunction(cm,'Periodic','MemorySection','None');
    

    In the model code mappings for model myInitFunction, configure the function customization template for the periodic multitasking function for sample time D2 as FastFcn.

    cm = coder.mapping.api.get('myInitFunction');
    setFunction(cm,'Periodic:D2','FunctionCustomizationTemplate','FastFcn');
    

    In the model code mappings for model myInitFunction, configure the argument specification for Simulink function mySLFunc as y=(u1, const *u2).

    cm = coder.mapping.api.get('myInitFunction');
    setFunction(cm,'mySLFunc','Arguments','y=(u1, const *u2)');
    

    Input Arguments

    collapse all

    Code mapping object (model code mappings) returned by a call to function coder.mapping.api.get.

    Example: myCM

    Model function for which to set code mapping property value. Specify one of the values listed in this table.

    Type of Model FunctionValue
    Exported functionExportedFunction:slIdentifier, where slIdentifier is the name of the function-call Inport block in the model
    Initialize functionInitialize
    Partition functionPartition:slIdentifier, where slIdentifier is a partition name for an exported function or a function for the model that you explicitly partition in the Simulink Schedule Editor. For example, P1.
    Partition update function (model configuration parameter Single output/update function is cleared) PartitionUpdate:slIdentifier, is a partition name for an exported function or a function for the model that you explicitly partition in the Simulink Schedule Editor (for example, P1)
    Periodic, multitasking functionPeriodic:slIdentifier, where slIdentifier is an annotation that corresponds the sample time period associated with a function for a periodic partition of a multi-tasking model (for example, D1)
    Periodic, multitasking update function (model configuration parameter Single output/update function is cleared) PeriodicUpdate:slIdentifier, where slIdentifier is an annotation that corresponds the sample time period associated with a function for a periodic partition of a multi-tasking model (for example, D1)
    Periodic, single-tasking functionPeriodic
    Periodic, single-tasking update function a (model configuration parameter Single output/update function is cleared)PeriodicUpdate
    Reset functionReset:slIdentifier, where slIdentifier is the name of the reset function in the model
    Simulink functionSimulinkFunction:slIdentifier, where slIdentifier is the name of the Simulink function in the model
    Terminate functionTerminate

    Model function for which to return a code mapping property value. Specify one of the values listed in this table. If model configuration parameter Single output/update function is cleared, you can specify the update version of a partition, periodic multi-tasking, or periodic singletasking function.

    Type of Model FunctionValue
    Exported functionExportedFunction:slIdentifier, where slIdentifier is the name of the function-call Inport block in the model
    Initialize functionInitialize
    Partition functionPartition:slIdentifier, where slIdentifier is a partition that was created explicitly from a block in the model and shown in the Simulink Schedule Editor (for example, P1)
    Partition update function PartitionUpdate:slIdentifier, is a partition that was created explicitly from a block in the model and shown in the Simulink Schedule Editor (for example, P1)
    Periodic multitasking functionPeriodic:slIdentifier, where slIdentifier is an annotation that corresponds to the sample time period for a periodic or continuous rate of a multi-tasking model (for example, D1)
    Periodic multitasking update functionPeriodicUpdate:slIdentifier, where slIdentifier is an annotation that corresponds to the sample time period for a periodic or continuous rate of a multi-tasking model (for example, D1)
    Periodic single-tasking functionPeriodic
    Periodic single-tasking update functionPeriodicUpdate
    Reset functionReset:slIdentifier, where slIdentifier is the name of the reset function in the model
    Simulink functionSimulinkFunction:slIdentifier, where slIdentifier is the name of the Simulink function in the model
    Terminate functionTerminate

    For information about model partitioning, see Create Partitions.

    Example: 'Periodic:D1'

    Name-Value Pair Arguments

    Example: 'FunctionCustomizationTemplate' 'exFastFunction'

    Specify comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside quotes. You can specify several name and value pair arguments as Name1,Value1,…,NameN,ValueN. The order of the name and value pair arguments does not matter.

    Name of a function customization template defined in the Embedded Coder Dictionary associated with the model, specified as a character vector or string scalar. If you set the default function customization template for a category of functions to Default, you can specify a memory section for the functions category.

    Data Types: char | string

    Name of a memory section that is defined in the Embedded Coder Dictionary associated with the model, specified as a character vector or string scalar.

    Data Types: char | string

    Name for the entry-point function in the generated C code, specified as a character vector or string scalar.

    Data Types: char | string

    Argument specification for the entry-point function in the generated C code, specified as a character vector or string scalar. The specification is a function prototype that shows argument names, type qualifiers, and argument order (for example, y=(u1, const *u2) .

    Data Types: char | string

    Introduced in R2020b