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
Name
— Dependency collection
character vector | string
Name of the collection of main
dependencies.
Attributes:
GetAccess | public |
SetAccess | public |
Dependencies
— Build dependencies
target.BuildDependencies
object
Compiler build tool dependencies of the main
function, which
include header files, source files, and libraries.
Attributes:
GetAccess | public |
SetAccess | public |
Arguments
— Command-line arguments
string array
Capture run-time command-line argument dependencies.
Attributes:
GetAccess | public |
SetAccess | public |
IncludeFiles
— #include
files
string array
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 |
SystemIncludeFiles
— System #include
files
string array
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 |
InitializationCode
— Target main
initialization
character vector | string
Formatted string of C or C++ code that the main
function uses to
initialize target resources.
Attributes:
GetAccess | public |
SetAccess | public |
TerminationCode
— Target main
termination
character vector | string
Formatted string of C or C++ code that the main
function uses to
terminate target resources.
Attributes:
GetAccess | public |
SetAccess | public |
Examples
Specify Target-Specific main
Function Dependencies
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();
Specify main
Function Run-Time Arguments
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
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)