Main Content

target.MainFunction Class

Namespace: target

Provide C and C++ dependencies for main function of target hardware application

Since R2020b

Description

Use the target.MainFunction class to provide main function dependencies for an application main function that runs on your target hardware. For example, C and C++ initialization and termination code, include preprocessor directives, and specification of main function arguments for the application.

To create a target.MainFunction object, use the target.create function.

Properties

expand all

Name of the collection of main dependencies.

Attributes:

GetAccess
public
SetAccess
public

Compiler build tool dependencies of the main function, which include header files, source files, and libraries.

Attributes:

GetAccess
public
SetAccess
public

Capture run-time command-line argument dependencies.

Attributes:

GetAccess
public
SetAccess
public

Array of header files that must be included in a target main function by using the preprocessor directive #include "path-spec".

Attributes:

GetAccess
public
SetAccess
public

Array of header files that must be included in a target main function by using the preprocessor directive #include <path-spec>.

Attributes:

GetAccess
public
SetAccess
protected

Formatted string of C or C++ code that the main function uses to initialize target resources.

Attributes:

GetAccess
public
SetAccess
public

Formatted string of C or C++ code that the main function uses to terminate target resources.

Attributes:

GetAccess
public
SetAccess
public

Examples

collapse all

Create a target.MainFunction object and associate it with a target.Board object, which captures the main function dependencies for an Arduino® board. Workflows, such as processor-in-the-loop (PIL), can use this information when generating a main function for an application that runs on the target hardware.

board = target.create('Board', 'Name', 'Arduino Board')
mainFunction = target.create('MainFunction');
mainFunction.Name = 'Arduino Main Dependencies';

mainFunction.IncludeFiles = { 'Arduino.h' };
mainFunction.InitializationCode = fileread('arduino_main_initialization.c');

board.MainFunctions = mainFunction;

In the code snippet, arduino_main_initialization.c contains C code. For example:

/* Initialize system */
init();

This code snippet from Set Up PIL Connectivity by Using Target Framework shows how you can create and use a target.MainFunction object to specify main function arguments that are required for an API implementation.

comms = target.create('CommunicationInterface');
comms.Name = 'Linux TCP Interface';
comms.Channel = 'TCPChannel';
comms.APIImplementations = target.create('APIImplementation', ...
                                         'Name', 'x86 rtiostream Implementation');
comms.APIImplementations.API = target.create('API', 'Name', 'rtiostream');
comms.APIImplementations.BuildDependencies = target.create('BuildDependencies');
comms.APIImplementations.BuildDependencies.SourceFiles = ...
                                                        {fullfile('$(MATLABROOT)', ...
                                                        'toolbox', ...
                                                        'coder', ...
                                                        'rtiostream', ...
                                                        'src', ...
                                                        'rtiostreamtcpip', ...
                                                        'rtiostream_tcpip.c')};
comms.APIImplementations.MainFunction = target.create('MainFunction', ...
                                                      'Name', 'TCP RtIOStream Main');
comms.APIImplementations.MainFunction.Arguments = {'-blocking', '1', '-port', '0'};
hostTarget.CommunicationInterfaces = comms;

Version History

Introduced in R2020b