The software described in this document is furnished under a license agreement. The software may be used
or copied only under the terms of the license agreement. No part of this manual may be photocopied or
reproduced in any form without prior written consent from The MathW orks, Inc.
FEDERAL ACQUISITION: This provision applies to all acquisitions of the Program and Documentation
by, for, or through the federal government of the United States. By accepting delivery of the Program
or Documentation, the government hereby agrees that this software or documentation qualifies as
commercial computer software or commercial computer software documentation as such terms are used
or defined in FAR 12.212, DFARS Part 227.72, and DFARS 252.227-7014. Accordingly, the terms and
conditions of this Agreement and only those rights specified in this Agreement, shall pertain to and govern
theuse,modification,reproduction,release,performance,display,anddisclosureoftheProgramand
Documentation by the federal government (or other entity acquiring for or through the federal government)
and shall supersede any conflicting contractual terms or conditions. If this License fails to meet the
government’s needs or is inconsistent in any respect with federal procurement law, the government agrees
to return the Program and Docu mentation, unused, to The MathWorks, Inc.
Trademarks
MATLAB and Simulink are registered trademarks of The MathWorks, Inc. See
www.mathworks.com/trademarks for a list of additional trademarks. Other product or brand
names may be trademarks or registered trademarks of their respective holders.
Patents
The MathWorks products are protected by one or more U.S. patents. Please see
www.mathworks.com/patents for more information.
Reference
Revision History
March 2006Online onlyNew for Version 6.4
September 2006 Online onlyRevised for Version 6.5 (Release 2006b)
March 2007Online onlyRevised for Version 6.6 (Release 2007a)
September 2007 Online onlyRevised for Version 7.0 (Release 2007b)
March 2008Online onlyRevised for Version 7.1 (Release 2008a)
October 2008Online onlyRevised for Version 7.2 (Release 2008b)
March 2009Online onlyRevised for Version 7.3 (Release 2009a)
September 2009 Online onlyRevised for Version 7.4 (Release 2009b)
March 2010Online onlyRevised for Version 7.5 (Release 2010a)
Product Limitations Summary
1
Function Reference
2
Build Information .................................2-2
Real-Time Workshop Pane: General .................6-2
Real-Time W orkshop: General Tab Overview
System targ et file
Language
Compiler optimization level
Custom co mpiler optimization flags
TLC options
Generate makefile
Make command
Template makefile
Ignore custom storage classes
Ignore test point signals
Prioritized objectives
Set objectives
Set Objectiv es — Code Generation Adv isor Dialog Box
Check model
Check model before generating code
Generate code only
Build/Generate code
Real-Time W orkshop: Comments Tab Overview
Include comments
Simulink block / Stateflow object comments
Show eliminated blocks
Verbose comm ents for SimulinkGlobal storage class
Simulink block descriptions
Simulink data object descriptions
Custom comments (MPT objects only)
Custom comments function
Stateflow object descriptions
Requirements in block comments
....................................6-45
.....................................6-47
........................................6-49
.................................6-61
........................ 6-43
.......................... 6-50
.......................... 6-52
......................... 6-54
............................ 6-63
......................... 6-65
......................... 6-71
........................ 6-73
.................. 6-37
....................... 6-40
.............. 6-56
.............. 6-58
.................... 6-67
................. 6-69
.................... 6-75
............ 6-39
........ 6-60
............ 6-62
..... 6-64
Real-Time Workshop Pane: Symbols
Real-Time W orkshop: Symbols Tab Overview
Global variables
Global types
Field n ame of global types
Subsystem methods
Subsystem method arguments
Local temporary variables
Local block output variables
Minimum mangle length
Maximum identifier length
Generate scalar inlined parameter as
Signal naming
M-function
Parameter naming
#define naming
Use the same reserved names as Simulation Target
Reserved names
.................................... 6-108
....................................... 6-110
................................... 6-114
................................... 6-117
........................... 6-103
.......................... 6-105
................. 6-107
................................ 6-112
..... 6-116
Real-Time Workshop Pane: Custom Code
Real-Time W orkshop: Custom Code Tab Overview
Use the same custom code settings as Simulation Target
Use local custom code settings (do not inherit from main
model)
Source file
Header file
Initialize function
Terminate function
Include directories
Source files
Libraries
Multiword type definitions
Maximum word length
GRT compatible call interface
Single output/update function
Terminate function required
Generate reusable code
Reusable code error diagnostic
Pass root-level I/O as
Block parameter visibility
Internal data visibility
Block parameter access
Internal data access
External I/O access
Generate destructor
Use operator new for referenced model object
registration
Generate preprocessor conditionals
Suppress error status in real-time model data structure
Configure Model Functions
Configure C++ Encapsulation Interface
MAT-file logging
MAT-file variable name modifier
Interface
Generate C API for: signals
Generate C API for: parameters
Generate C API for: states
Transport layer
MEX-file arguments
Static memory allocation
Static memory buffer size
......................................... 6-207
................................ 6-191
.................................... 6-195
.................................. 6-203
................................... 6-213
.......................... 6-166
............................. 6-168
....................... 6-170
....................... 6-172
........................ 6-174
............................. 6-176
....................... 6-179
.............................. 6-181
.......................... 6-183
............................. 6-185
............................. 6-187
............................... 6-189
............................... 6-193
................... 6-197
.. 6-199
.......................... 6-201
............... 6-202
..................... 6-205
......................... 6-210
..................... 6-211
.......................... 6-212
............................... 6-215
........................... 6-217
........................... 6-219
Real-Time Workshop Pane: RSim Target
Real-Time W orkshop: RSim Target Tab O ve rview
Enable RSim executa bl e to load parameters from a
MAT-file
Solver selection
Force storage classes to AUTO
Real-Time Workshop Overview
Check so lver for code generation
Identify questionable blocks within the specified system
Check the hardware implementation
Identify questionable software environment
specifications
Identify questionable code instrumentation (data I/O)
Check for blocks that have constraints on tunable
parameters
Check for blocks not recommended for MISRA-C:2004
compliance
Check configuration parameters for MISRA-C:2004
compliance
Check for model refe rence configuration mismatch
...................................8-8
....................................8-11
.....................................8-13
.....................................8-14
......................8-3
.....................8-4
..................8-7
...... 8-17
..... 7-55
..8-6
.... 8-10
xi
Disable signal logging .............................. 8-18
Identify blocks that generate expensive saturation and
rounding code
Check sample times and tasking mode
Identify questionable subsystem settings
Identify questionable fixed-point operations
Check model configuration settings against code generation
objectives
Check for efficiency optimization parameters
..................................8-19
................ 8-20
.............. 8-21
............ 8-22
......................................8-31
........... 8-33
Index
xiiContents
ProductLimitations
Summary
The f ollow ing topics identify Real-Time Workshop®feature limitations:
• “C++ Target Language Limitations”
• “packNGo Function Limitations”
• “Tunable Expression Limitations”
• “Limitations on Specifying Data Types in the Workspace Explicitly”
1
• “Code Reuse Limitations”
• “Real-Time Workshop Model Referencing Limitations”
• “External Mode Limitations”
• “Noninlined S-Function Parameter Type Limitations”
• “S-Function Target Limitations”
• “Rapid Simulation Target Limitations”
• “Asynchronous Support Limitations”
• “C API Limitations”
• “Block Support Considerations”
1 Product Limitations Summary
1-2
Glossary
Glossary
application modules
With respect to Real-Time W orkshop program architecture, these are
collections o f programs that implement functions carried out by the
system-dependent, system-independent, and application components.
atomic subsystem
Subsystem whose blocks are executed as a unit before moving on.
Conditionally executed subsystems are atomic, and atomic subsystems
are nonvirtual. Unconditionally executed subsystems are virtual by
default, but can be designated as atomic. The Real-Time Workshop
build process can generate reusable code only for nonvirtual subsystems.
base sample rate
Fundamental sample time of a model; in practice, limited by the fastest
rate at which a processor’s timer can generate interrupts. All sample
times must be integer multiples of the base rate.
block I/O structure (model_B)
Global data structure for storing block output signals. The number of
block output signals is the sum of the widths of the data output ports
of all nonvirtual blocks in your model. By default, Simulink
Real-Time Workshop build process try to reduce the size of the
structure by reusing the entries in the model_B structure and making
other entries local variables.
®
and the
model_B
block target file
File that describes how a specific Simulink block is to be transformed to
a language such as C, based on the block’s description in the Real-Time
Workshop file (
model.rtw). Typically, there is one block target file for
each Simulink block.
code reuse
Optimization whereby code generated for ide ntical no nv irtual
subsystems is collapsed into one function that is called for each
subsystem instance with appropriate parameters. Code reuse, along
with expression folding, can dramatically reduce the amount of
generated code.
Glossary-1
Glossary
configuration
Set of attributes for a model which defines parameters governing how a
model simulates and generates code. A model can have one or more such
configuration sets, and users can switch between them to change code
generation targets or to modify the behavior of models in other ways.
configuration component
Named element of a configuration set. Configuration components
encapsulate settings associated with the Solver, Data Import/Export,
Optimization, Diagnostics, Hardware Implementation, Model
Referencing,andReal-Time Workshop panes in the Configuration
Parameters dialog box. A component may contain subcomponents.
embedded real-time (ERT) target
Target configuration that generates model code for execution on
an independent e mbe dded real-time system. R equires a Real-Time
Workshop
®
Embedded Coder™ license.
expression folding
Code optimization technique that minimizes the computation of
intermediate results at block outputs and the storage of such results
in temporary buffers or variables. It can dramatically improve the
efficiency of generated code, achie v ing results that compare favorably
with hand-optimized code.
Glossary-2
file extensions
The table below lis ts the Simulink, Target Language Compiler, and
Real-Time Workshop file extensions.
ExtensionCreated byDescription
.c or .cpp
.h
Target Language
Compiler
Target Language
Compiler
The generated C or
C++ code
C/C++ include header
file used by the
.cpp program
.c or
ExtensionCreated byDescription
.mdl
SimulinkContains structures
associated with
Simulink block
diagrams
.mk
Real-Time Workshop
Makefile specific to
your model that is
derived from the
template makefile
.rtw
Real-Time WorkshopIntermediate
compilation
(
model.rtw)ofa
.mdl file used in
generating C or C++
code
.tlc
The MathWorks and
Real-Time Workshop
users
Target Language
Compiler script files
that the Real-Time
Workshop build
process uses to
generate code for
targets and blocks
.tmf
Supplied with
Template makefiles
Real-Time Workshop
.tmw
Real-Time WorkshopProject marker
file inside a build
directory that
identifies the date
and product version
of g enerated code
Glossary
generic real-time (GRT) target
Target configuration that generates model code for a real-time system,
with the resulting code executed on your workstation. (Execution is
not tied to a real-time clock.) You can use GRT as a starting point for
targeting custom hardware.
Glossary-3
Glossary
host system
Computer sy stem on which you create and may compile your real-time
application. Also referred to as emulation hardware.
inline
Generally, this means to place something directly in the generated
source code. You can inline parameters and S-functions using the
Real-Time Workshop software and the Target Language Compiler.
inlined parameters
(Target Language Compiler Boolean global variable:
InlineParameters)
The numerical values of the block parameters are hard-coded into the
generated code. Advantages include faster execution and less memory
use, but you lose the ability to change the block parameter values at
run time.
inlined S-function
An S-function can be inlined into the gen erate d code by implementing it
as a
.tlc file. The code for this S-function is placed in the generated
model code itself. In contrast, noninlined S-functions require a function
call to an S-function residing in an external MEX -file.
Glossary-4
interrupt service routine (ISR)
Piece of code that your processor executes when an external event, such
as a timer, occurs.
loop rolling
(Target Language Compiler global variable:
RollThreshold) Depending
on the block’s operation and the width of the input/output ports, the
generated code uses a
for statement (rolled code) instead of repeating
identical lines of code (flat code) over the signal width.
make
Utility to maintain, update, and regenerate related programs and files.
Thecommandstobeexecutedareplacedinamakefile.
makefiles
Files that contain a collection of commands that allow groups of
programs, object files, libraries, and so on, to interact. Makefiles are
executed by your development system’s make utility.
model.rtw
Intermediate record file into which the Real-Time Workshop build
process compiles the blocks, signals, states, and parameters a model,
which the Target Language Compiler reads to generate code to
represent the model.
multitasking
Process by which a microprocessor schedules the handling of multiple
tasks. In generated code, the number of tasks is equal to the number of
sample times in your model. See also pseudo multitasking.
noninlined S-function
In the context of the Real-Time Workshop build process, this is any C
MEX S-function that is not implemented using a customized
If you create a C MEX S-function as part of a Simulink model, it is by
default noninlined unless you write your o wn
.tlc file that inlines it.
nonreal-time
Simulation environment of a block diagram provided for high-speed
simulation of your model. Execution is not tied to a real-time clock.
Glossary
.tlc file.
nonvirtual block
Any block that performs some algorithm, such as a Gain block. The
Real-Time Workshop build process generates code for all nonvirtual
blocks, either inline or as separate functions and files, as directed by
users.
pseudo multitasking
On processors that do not offer multitasking support, you can perform
pseudo multitasking by scheduling events on a fixed time sh aring b asis.
real-time model data structure
The Real-Time Workshop build process encapsulates information about
the root model in the real-time model data structure, often abbreviated
as rtM. rtM contains global information related to timing, solvers, and
logging, and model data such as inputs, outputs, states, and parameters.
real-time system
Computer that processes real-world events as they happen, under the
constraint of a real-time clock, and that can implement algorithms in
Glossary-5
Glossary
dedicated hardware. Examples include m obile telephones, test and
measurement devices, and avionic and automotive control systems.
Real-Time Workshop target
Set of code files generated by the Real-Time Workshop build process
for a standard or custom target, specified by a Real-Time Workshop
configuration component. These source files can be built into an
executable program that will run independently of Simulink. See also
simulation target, configuration.
run-time interface
Wrapper around the generated code that can be built into a stand-alone
executable. The run-time interface consists of routines to move the time
forward, save logged variables at the appropriate time steps, and so on
The run-time interface is responsible for managing the execution of the
real-time program created from your Simulink block diagram.
S-function
Customized Simulink block written in C, Fortran, or MATLAB
The Real-Time Workshop build process can target C code S-functions
as is or users can inline C code S-functions by preparing TLC scripts
for them.
simstruct
Simulink data structure and associated application program interface
(API) that enables S-functions to communicate with other entities in
models. Simstructs are included in code generated by the Real-Time
Workshop build process for noninlined S-functions.
simulation target
Set of code files generated for a model which is referenced by a Model
block. Simulation target code is generated into
/slprj/sim project
directory in the working directory. Also an executable library compiled
from these codes that implements a Model block. See also Real-Time
Workshop target.
single-tasking
Mode in which a model runs in one task, regardless of the number of
sample rates it contains.
®
code.
Glossary-6
stiffness
Property of a problem that forces a numerical method, in one or more
intervals of integration, to use a step length that is excessively small in
relation to the smoothness of the exact solution in that interval.
system tar get file
Entry point to the Target Language Compiler program, used to
transformtheReal-TimeWorkshopfileintotarget-specificcode.
target file
File that is compiled and executed by the Target Language Compiler.
The block and system target TLC files used specify how to transform
the Real-Time Workshop file (
model.rtw) i n t o target-specific code.
Target Language Compiler (TLC)
Program that compiles and executes system and target files by
translating a
model.rtw file into a target language by means of TLC
scripts and tem plate makefiles.
Glossary
Tar get Language Compiler program
One or more TLC script files that describe how to convert a
file into generated code. There is one TLC file for the target, plus one
for each built-in block. Users can provide their own TLC files to inline
S-functionsortowrapexistingusercode.
target system
Specific or generic computer system on which your real-time application
is intended to execute. Also referred to as embedded hardware.
targeting
Process of creating software modules appropriate for execution on your
target system.
task id en tifier (tid)
In generated code, each sample rate in a multirate model is assigned a
task identifier (
tid). The tid is used by the model output and update
routines to control the portion of your model that should execute at
a given time step. Single-rate systems ignore the
tid. See also base
sample rate.
model.rtw
Glossary-7
Glossary
template makefile
Line-for-linemakefileusedbyamakeutility. TheReal-TimeWorkshop
build process converts the templatemakefiletoamakefilebycopying
the contents of the template makefile (usually
makefile (usually
system.mk) replacing tokens describing your model’s
system.tmf)toa
configuration.
virtual block
Connection or graphical block, for example a Mux block, that has no
algorithmic functionality. Virtual blocks incur no real-time overhead
as no code is generated for them.
work vector
Data structures for saving internal states or similar information,
accessible to blocks that may require such work areas. These include
state work (
pointer work (
rtDWork), real work (rtRWork ), integer work (rtIWork), and
rtPWork) structures. For example, the Memory block uses
a real work element for each signal.
Glossary-8
Function Reference
Build Information (p. 2-2)Set up and manage model’s build
Target Language Compiler and
Function Library (p. 2-8)
Generate embeddable C code or MEX
code from MATLAB language file
Document generated code
Optimize code generated for model’s
blocks
2 Function Reference
Build Information
addCompileFlagsAdd compiler options to model’s
build information
addDefinesAdd preprocessor macro definitions
to model’s build information
addIncludeFiles
addIncludePaths
addLinkFlags
addLinkObjectsAdd link objects to model’s build
addNonBuildFiles
addSourceFilesAdd source files to model’s build
addSourcePathsAdd source paths to model’s build
addTMFTokens
findIncludeFilesFind and add include (header) files
getCompileFlagsCompiler options from model’s build
Add include files to model’s build
information
Add include paths to model’s build
information
Add link options to model’s build
information
information
Add nonbuild-related files to model’s
build information
information
information
Addtemplatemakefile(TMF)tokens
that provide build-time information
for m akefile generation
to build information object
information
2-2
getDefinesPreprocessor macro definitions from
model’s b uild information
getFullFileList
getIncludeFiles
All files from model’s build
information
Include files from model’s build
information
Build Information
getIncludePaths
Include paths from model’s build
information
getLinkFlags
Link options from model’s build
information
getNonBuildFiles
Nonbuild-related files from model’s
build information
getSourceFilesSource files from model’s build
information
getSourcePathsSource paths from model’s build
information
packNGoPackage model code in zip file for
relocation
updateFilePathsAndExtensionsUpdate files in model’s build
information with mis sing paths and
file extensions
updateFileSeparatorChange file separator used in
model’s b uild information
2-3
2 Function Reference
Build Process
RTW.getBuildDir
rtwbuildInitiate build process
rtwrebuildRebuild gener
rtw_precompile_libsBuild libraries within model without
switchTarget
Build directory informa t ion for
specified model
ated code
building model
Specify target for configuration set
2-4
Embedded MATLAB Code Generation
Embedded MATLAB®Code Generation
emlc
Generate embeddable C/C++ code
from MATLAB code
2-5
2 Function Reference
Project Documentation
rtwreport
rtwtrace
Generate report documenting
generated code for model
Trace block to generated code
2-6
Rapid Simulation
Rapid Simulation
rsimgetrtp
rsimsetrtpparam
Global model parameter structure
Set parameters of
parameter structure
rtP model
2-7
2 Function Reference
Target Language Compiler and Function Library
tlc
See the “TLC Function Library Reference” in the Real-Time Workshop Target
Language Compiler documentation for a list of Target Language Compiler
functions.
Invoke Target Language Compiler
to convert model description file to
generated code
2-8
Alphabetical List
3
addCompileFlags
PurposeAdd compiler options to model’s build information
SyntaxaddCompileFlags(buildinfo, options, groups)
groups
is optional.
Argumentsbuildinfo
Build information returned by RTW.BuildInfo.
options
A character array or cell array of character arrays that specifies
the compiler options to be added to the build information. The
function adds each option to the end of a compiler option vector. If
you specify m ultiple options within a single character array, for
example
as a single element. For example, if you add
then
'-Zi -Wall''-O3'
groups
(optional)
A character array or cell array of character arrays that groups
specified compiler options. You can use groups to
• Document the use of specific compiler op tions
• Retrieve or apply collections of compiler options
You can apply
• Asinglegroupnametooneormorecompileroptions
'-Zi -Wall', the function adds the string to the vector
'-Zi -Wall' and
'-O3', the vector cons ists of two elements, as shown below.
3-2
• Multiple group names to collections of compiler options
(available for nonmakefile build environments only)
addCompileFlags
To ...
Apply one group
Specify
groups as a...
Character array.
name to all compiler
options
Apply different group
names to compiler
options
Cell array of character arrays such that
the number of group names matches
the number of elements you specify for
options.
Note
• To specify compiler options to be used in the standard
Real-Time Workshop makefile build process, specify
either
'OPTS' or 'OPT_OPT S'.
groups as
• To control compiler optimizations for your Real-Time Workshop
makefile build at Simulink GUI level, use the Compileroptimization level parameter on the Real-Time Workshop
pane of the Simulink Configuration Parameters dialog box. The
Compiler optimization level parameter provides
— Target-independent values
runs)
and Optimizations off (faster builds),which
Optimizations on (faster
allow you to easily toggle compiler optimizations on and off
during code development
— The value
Custom for entering custom compiler optimization
flags at Simulink GUI level (rather than at other levels of
the build process)
If you use the configuration parameter Make command to
specify compiler options for your Real-Time Workshop makefile
build using
MEX_OPT_FILE,thevalueofCompiler optimization level is
OPT_OPTS, MEX_OPTS (except MEX_OPTS="-v"), or
ignored and a warning is issued about the ignored parameter.
3-3
addCompileFlags
DescriptionThe addCom pile Flags function adds specified compiler options to the
model’s build information. Real-Time Workshop stores the compiler
options i n a vector. The function adds options to the end of the vector
based on the order in which you specify them.
In addition to the required
use a n optional
groups argument to group your options.
buildinfo and options arguments, you can
Examples• Add the compiler option -O3 to build information myModelBuildInfo
“Customizing Post Code Generation Build Processing”
3-4
addDefines
PurposeAdd preprocessor macro definitions to m odel’s build information
SyntaxaddDefines(buildinfo, macrodefs, groups)
groups
is optional.
Argumentsbuildinfo
Build information returned by RTW.BuildInfo.
macrodefs
A character array or cell array of character arrays that specifies
thepreprocessormacrodefinitionstobeaddedtotheobject.
The function adds each definition to the end of a comp il er
option vector. If you specify multiple definitions within a single
character array, for exam ple
thestringtothevectorasasingleelement. Forexample,ifyou
add
consists of two elements, as shown below.
'-DPROTO -DDEBUG''-DPRODUCTION'
groups
(optional)
A character array or cell array of character arrays that groups
specified definitions. You can use groups to
• Document the use of specific macro definitions
• Retrieve or apply groups of macro definitions
You can apply
'-DRT -DDEBUG',thefunctionadds
'-DPROTO -DDEBUG' and then '-DPRODUCTION',thevector
• Asinglegroupnametooneormoremacrodefinitions
• Multiple group names to collections of macro definitions
(available for nonmakefile build environments only)
3-5
addDefines
To ...
Apply one group
name to all macro
definitions
Apply different group
names to macro
definitions
Note To specify macro definitions to be u sed in the standard
Real-Time Workshop m ake file build process, specify
either
'OPTS' or 'OPT_OPTS'.
Specify
Character array.
Cell array of character arrays such that
the number of group names matches
the number elements you specify for
macrodefs.
groups as a...
groups as
DescriptionThe addDefines function adds specified preprocessor macro definitions
to the model’s build information. The Real-Time Workshop software
stores the definitions in a vector. The function adds definitions to the
end of the vector based on the order in which you specify them.
In addition to the required
can use an optional
groups argument to group your options.
buildinfo and macrodefs arguments, you
Examples• Add the macro definition -DPRODUCTION to build information
myModelBuildInfo and place the definition in the group OPTS.
A character array or cell array of character arrays that specifies
names of include files to be added to the build information.
Thefilenamestringscanincludewildcard characters, provided
that the dot delimiter (
and
The function adds the filenames to the end of a vector in the order
that you specify them.
The function removes duplicate include file entries that
• You specify as input
• Already exist in th e include file vector
• Have a path that matches the path of a matching filename
A duplicate entry consists of an exact match of a path string and
corresponding filename.
.)ispresent. Examplesare'*.*', '*.h',
'*.h*'.
3-8
paths (optional)
A character array or cell array of character arrays that specifies
paths to the include files. The function adds the paths to the end of
a vector in the order that you specify them. If you specify a single
path as a character array, the function uses that path for all files.
groups (optional)
A character array or cell array of character arrays that groups
specified include files. You can use groups to
addIncludeFiles
• Document the u se of specific include files
• Retrieve or apply group s of include files
You can apply
• A single g roup name to an include file
• A single group name to multiple include files
• Multiple group names to collections of multiple include files
To ...
Apply o ne group name
to all include files
Apply different group
names to include files
Specify
Character array.
Cell array of chara cter arrays such
that the number of group names that
you specify matches the number of
elements you specify for
groups as a...
filenames.
DescriptionThe addIncludeFiles function adds specified include files to the
model’s build information. The Real-Time Workshop software stores the
include files in a vector. The function adds the filenames to the end of
the vector in the order that you specify them.
In addition to the required
can specify optional
each optional argument as a character array or a cell array of character
arrays.
If You Specify an Optional
Argument as a...
Character arrayApplies the character array to all include files it adds to
Cell array of character arrays Pairs each character array with a spe c if ied include file.
The Func tion ...
the build information
Thus, the length of the cell array must match the length of
the ce ll array you specify for
paths and groups arguments. You can specify
buildinfo and filenames arguments, you
filenames.
3-9
addIncludeFiles
If you choose to s pecify groups,butomitpaths, specify a null string
(
'')forpaths.
Note The packNGo function also can add include files to a model’s build
information. If you call the
packNGo finds include files from all source and include paths recorded in
the model’s build information and adds them to the build information.
Examples• Add the include file mytypes.h to build information
myModelBuildInfo and place the fil e in the group SysFiles.
“Customizing Post Code Generation Build Processing”
3-11
addIncludePaths
PurposeAdd include paths to model’s build information
SyntaxaddIncludePaths(buildinfo, paths, groups)
groups
is optional.
Argumentsbuildinfo
Build information returned by RTW.BuildInfo.
paths
A character array or cell array of character arrays that specifies
include file paths to be added to the build information. The
function adds the paths to the end of a vector in the order that
you specify them.
The function removes duplicate include file entries that
• You specify as input
• Already exist in the include path vector
• Have a path that matches the path of a matching filename
A duplicate entry consists of an exact match of a path string and
corresponding filename.
groups (optional)
A character array or cell array of character arrays that groups
specified include paths. You can use groups to
• Document the use of specific include paths
3-12
• Retrieve or apply groups of include paths
You can apply
• A single group name to an include path
• A single group name to multiple inclu de paths
• Multiple group names to collections of multiple include paths
addIncludePaths
To ...
Apply one group
name to all include
paths
Apply different group
names to include
paths
Specify
Character array.
Cell array of character arrays such that
the number of group names that you
specify matches the number of elements
you specify for
groups as a...
paths.
DescriptionThe addIncludePaths function adds specified include paths to the
model’s build information. The Real-Time Workshop software stores
the include paths in a vector. The function adds the paths to the end of
the vector in the order that you specify them.
In addition to the required
specify an optional
character array or a cell array of character arrays.
If You Specify an Optional
Argument as a...
Character arrayApplies the character array to all
groups argument. You can specify groups as a
buildinfo and paths arguments, you can
The Fun ction...
include paths it adds to the build
information.
Cell array of character arrays
Pairs each character array with a
specified include path. Thus, the
length of the cell array m us t match
the length of the cell array you specify
for
paths.
3-13
addIncludePaths
Examples• Add the include path /etcproj/etc/etc_build to build information
“Customizing Post Code Generation Build Processing”
3-14
PurposeAdd link op tions to mode l’s build information
SyntaxaddLinkFlags(buildinfo, options, groups)
addLinkFlags
groups
is optional.
Argumentsbuildinfo
Build information returned by RTW.BuildInfo.
options
A character array or cell array of character arrays that specifies
the linker options to be added to the build information. The
function adds each option to the e nd of a linker option v ector. If
you specify m ultiple options within a single character array, for
example
a single element. For example, if you add
'-T', the vector consists of two elements, as shown below.
'-MD -Gy''-T'
groups
(optional)
A character array or cell array of character arrays that groups
specified linker options. You can use group s to
• Document the u se of specific linker options
• Retrieve or apply groups of linker options
You can apply
• A single group name to one or more linker options
'-MD -Gy', the function adds the string to the vector as
'-MD -Gy' and then
• Multiple group names to collections of linker options (avail able
for nonmakefile build environments only)
3-15
addLinkFlags
To ...
Apply one group
name to all linker
options
Apply different
group names to
linker options
Note To specify linker options to be used in the standard
Real-Time Workshop m ake file build process, specify
either
'OPTS' or 'OPT_OPTS'.
Specify
Character array.
Cell array of character arrays s uch that
the number of group names matches
the number of elements you specify for
options.
groups as a...
groups as
DescriptionThe addLinkFlags function adds specified linker options to the model’s
build information. The Real-Time Workshop software stores the linker
options i n a vector. The function adds options to the end of the vector
based on the order in which you specify them.
In addition to the required
use a n optional
groups argument to group your options.
buildinfo and options arguments, you can
Examples• Add the linker -T option to build information myModelBuildInfo and
All arguments except buildinfo , l inko bjs,andpaths are optional. If
you specify an optional argument, you must specify all of the optional
arguments preceding it.
Argumentsbuildinfo
Build information returned by RTW.BuildInfo.
linkobjs
A character array or cell array of character arrays that specifies
the filenames of linkable objectstobeaddedtothebuild
information. The function adds the filenames that you specify
in the function call to a vector that stores the object filenames
in priority order. If you specify multiple objects that have the
same priority (see
the vector based on the order in which you specify the object
filenames in the cell array.
priority below), the function adds them to
3-18
The function removes duplicate link objects that
• You specify as input
• Already exist in the linkable object filename vector
• Have a path that matches the path of a matching linkable
object filename
A duplicate entry consists of an exact match of a path string and
corresponding linkable object filename.
paths
A character array or cell array of character arrays that specifies
paths to the linkable objects. If you specify a character array, the
path string applies to all linkable objects.
addLinkObjects
priority (optional)
A numeric value or vector of numeric values that indicates the
relative priority of each specified link object. Lower values have
higher priority. The default priority is 1000.
precompiled (optional)
The logical value
indicates whether each specified link object is precompiled.
true or false or a vector of logical values that
Specify
true if the link object has been prebuilt for faster
compiling and linkin g and exists in a specified location.
If precompiled is
false (the default), the Real-Time Workshop
build process creates the link object in the build directory.
This argument is ignored if
linkonly (optional)
The logical value
true or false or a vector of logical values that
linkonly equals true.
indicates whether each specified link object is to be used only
for linking.
Specify
true if the Real-Tim e Workshop build process should
not build, nor generate rules in the makefile for building, the
specified link object, but should include it when linking the final
executable. F or example, you can u se this to incorporate link
objects for which source files are not available. If
true, the value of
If
linkonly is false (the default), rules for building the link
precompiled is ignored.
linkonly is
objects are added to the makefile. In this case, the value
of
precompiled determines which subsection of the added
rulesisexpanded,
START_EXPAND_LIBRARIES (false).
START_PRECOMP_LIBRARIES (true)or
groups (optional)
A character array or cell array of character arrays that groups
specified link objects. You can use groups to
3-19
addLinkObjects
• Document the use of specific link objects
• Retrieve or apply groups of link objects
You can apply
• Asinglegroupnametoalinkableobject
• A single group name to multiple linkable objects
• Multiple group name to collections of multiple linkable objects
To ...
Apply one group
name to all link
objects
Apply different group
names to link objects
The default value of groups is {''}.
Specify
Character array.
Cell array of character arrays such that
the number of group names matches
the number elements you specify for
linkobjs.
groups as a...
DescriptionThe addLinkObjects function adds specified link objects to the model’s
build information. The Real-Time Workshop software stores the link
objects in a vector in relative priority order. If multiple objects have the
same priority or you do not specify prioritie s, the function adds the
objects to the vector based on the order in which you specify them.
In addition to the required
you can specify the optional arguments
linkonly,andgroups. You can specify paths and groups as a character
array or a cell array of character arrays.
buildinfo, linkobjs,andpaths arguments,
priority, precompiled,
3-20
addLinkObjects
If You Specify paths or
groups as a...
The Fun ction...
Character arrayApplies the character array to
all objects it adds to the build
information.
Cell array of character arrays
Pairs each character array with a
specified object. Thus, the length
of the cell array must match the
length of the cell array you specify for
linkobjs.
Similarly, you can specify priority, p recompiled,andlinkonly as a
valueorvectorofvalues.
If You Specify priority,
precompiled,orlinkonly
The Fun ction...
as a. ..
Value
Appliesthevaluetoallobjectsitadds
to the build information.
Vector of valuesPairs each value with a specified
object. Thus, the length of the vector
must match the length of the cell
array you specify for
linkobjs.
If you choose to specify an optional argument, you must specify all of
the optional arguments preceding it. For example, to specify that all
objects are precompiled using the
specify the
priority argument that precedes precompiled.Youcould
precompiled argument, you must
pass the default priority value 1000, as shown below.
A character array or cell array of character arrays that specifies
names of nonbuild-related files to be added to the build
information.
Thefilenamestringscanincludewildcard characters, provided
that the dot delimiter (
'*.DLL',and'*.D*'.
The function adds the filenames to the end of a vector in the order
that you specify them.
The function removes duplicate nonbuild file entries that
• Already exist in the nonbuild file v ector
• Have a path that matches the path of a matching filename
A duplicate entry consists of an exact match of a path string and
corresponding filename.
paths (optional)
A character array or cell array of character arrays that specifies
paths to the nonbuild files. The function adds the paths to the
end of a vector in the order that you specify them. If you s pecify
a single path as a character array, the function uses that path
for all files.
.) is present. Examples are '*.*',
groups (optional)
A character array or cell array of character arrays that groups
specified nonbuild files. You can use groups to
3-23
addNonBuildFiles
• Document the use of specific nonbuild files
• Retrieve or apply groups of nonbuild files
You can apply
• A single g roup name to a nonbuild file
• A single group name to multiple nonbuild files
• Multiple group na mes to collections of multiple nonbuild files
To ...
Apply o ne group name
to all nonbuild files
Apply different group
names to nonbuild files
Specify
Character array.
Cell array of chara cter arrays such
that the number of group names that
you specify matches the number of
elements you specify for
groups as a...
filenames.
DescriptionThe addNonBu ild Files function adds specified nonbuild-related files,
such as DLL files required for a final executable, or a README file, to
the model’s build information. The Real-Time Workshop software stores
the nonbuild files in a vector. The function adds the filenames to the
end of the vector in the order that you specify them.
In addition to the required
can specify optional
each optional argument as a character array or a cell array of character
arrays.
paths and groups arguments. You can specify
buildinfo and filenames arguments, you
3-24
addNonBuildFiles
If You Specify an Option al
The Function...
Argument as a...
Character arrayApplies the character array to all nonbuild files it adds
to the build information.
Cell array of character arraysPairs each character array with a specified nonbuild file.
Thus, t h e length of the cell array must match the length
of the cell array you specify for
filenames.
If you choose to s pecify groups,butomitpaths, specify a null string
(
'')forpaths.
Examples• Add the nonbuild file readme.txt to build information
myModelBuildInfo and place the fil e in the group DocFiles.
A character array or cell array of character arrays that specifies
names of the source files to be added to the build information.
Thefilenamestringscanincludewildcard characters, provided
that the dot delimiter (
and
The function adds the filenames to the end of a vector in the order
that you specify them.
The function removes duplicate source file entries that
• You specify as input
• Already exist in the source file vector
• Have a path that matches the path of a matching filename
A duplicate entry consists of an exact match of a path string and
corresponding filename.
.)ispresent. Examplesare'*.*', '*.c',
'*.c*'.
3-26
paths (optional)
A character array or cell array of character arrays that specifies
paths to the source files. T he function adds the paths to the end of
a vector in the order that you specify them. If you specify a single
path as a character array, the function uses that path for all files.
groups (optional)
A character array or cell array of character arrays that groups
specified source files. You can use groups to
addSourceFiles
• Document the use of specific source files
• Retrieve or apply groups of source files
You can apply
• A single group name to a source file
• A single group name to multiple source files
• Multiple group names to collections of multiple source files
To ...
Apply one group name
to all source files
Apply different group
names to source files
Specify
Character array.
Cell array of character arrays such
that the number of group names that
you specify matches the number of
elements you specify for
group as a...
filenames.
DescriptionThe addSourceFiles function adds specified source files to the model’s
build information. The Real-Time Workshop software stores the source
files in a vector. The function adds the filenames to the end of the vector
in the order that you specify them.
In addition to the required
can specify optional
each optional argument as a character array or a cell array of character
arrays.
If You Specify an Optional
Argument as a...
Character arrayApplies the character array to all source files it adds to the
Cell array of character
arrays
The Function...
build information.
Pairs each character array with a specified source file.
Thus, th e length of the cell array must match the length of
the cell array you specify for
paths and groups arguments. You can specify
buildinfo and filenames arguments, you
filenames.
3-27
addSourceFiles
If you choose to s pecify groups,butomitpaths, specify a null string
(
'')forpaths.
Examples• Add the source file driver.c to build information myModelBuildInfo
See AlsoaddIncludeFiles, addIncludePaths, addSourcePaths,
getSourceFiles, updateFilePathsAndExtensions,
3-28
addSourceFiles
updateFileSeparator
“Customizing Post Code Generation Build Processing”
3-29
addSourcePaths
PurposeAdd source paths to model’s build information
SyntaxaddSourcePaths(buildinfo, paths, groups)
groups
is optional.
Argumentsbuildinfo
Build information returned by RTW.BuildInfo.
paths
A character array or cell array of character arrays that specifies
source file paths to be added to the build information. The
function adds the paths to the end of a vector in the order that
you specify them.
The function removes duplicate source file entries that
• You specify as input
• Already exist in the source path vector
• Have a path that matches the path of a matching filename
A duplicate entry consists of an exact match of a path string and
corresponding filename.
Note The Real-Time Workshop software does not check whether
a specified path string is valid.
3-30
groups (optional)
A character array or cell array of character arrays that groups
specified source paths. You can use groups to
• Document the use of specific source paths
• Retrieve or apply groups of source paths
addSourcePaths
You can apply
• A single group name to a source path
• A single group name to multiple source paths
• Multiple group n ames to collections of multiple source paths
To ...
Apply one group name
to all source paths
Apply different group
names to source paths
Specify
Character array.
Cell array of character arrays such
that the number of group names that
you specify matches the number of
elements you specify for
groups as a...
paths.
DescriptionThe addSourcePaths function adds specified source paths to the model’s
build information. The Real-Time Workshop software stores the source
paths in a vector. The function adds the paths to the end of the vector in
the order that you specify them.
In addition to the required
specify an optional
character array or a cell array of character arrays.
If You Specify an Optional
Argument as a...
Character arrayApplies the character array to all
Cell array of character arrays
groups argument . You can specify groups as a
buildinfo and paths arguments, you can
The Fun ction...
source paths it adds to the build
information.
Pairs each character array with a
specified source path. Thus, the
length of the character array o r cell
array must match the length of the
cell array you specify for
paths.
3-31
addSourcePaths
Note The Real-Time Workshop software does not check whether a
specified path string is valid.
Examples• Add the source path /etcproj/etc/etc_build to build information
A character array or cell array of character arrays that specifies
names of TMF tokens (for example,
be added to the build information. The function adds the token
names to the end of a vector in the order that you specify them.
If y ou specify a token name that already exists in the vector, the
first instance takes precedence and its value used for replacement.
tokenvalues
A character array or cell array of character arrays that specifies
TMF token values corresponding to the previously-specified TMF
token names. The function adds the token values to the end of a
vector in the order that you specify them.
groups (optional)
A character array or cell array of character arrays that groups
specified TMF token s. You can use groups to
• Document the use of specific TMF tokens
• Retrieve or apply groups of TMF tokens
'|>CUSTOM_OUTNAME<|')to
You can apply
• A single group name to a TMF token
• A single group name to multiple TMF tokens
• Multiple group n a mes to collections of multiple TMF tokens
3-33
addTMFTokens
To ...
Apply o ne group name
to all TMF tokens
Apply different group
names to TMF tokens
Specify
Character array.
Cell array of chara cter arrays such
that the number of group names that
you specify matches the number of
elements you specify for
groups as a...
tokennames.
DescriptionCall the addTMFTokens function inside a post code generation command
to provide build-time information to help customize makefile generation.
The tokens specified in the
appropriately in the template makefile (TMF) for the target selected
for your model. For example, if your post code generation comm and
calls
addTMFTokens to add a TMF token named |>CUSTOM_OUTNAME<|
that specifies an output file name for the build, the TMF m ust take
appropriate action with the value of
the desired result. (See “Example” on page 3-35.)
The
addTMFTokens function adds specified TMF token names and
values to the model’s build information. The Real-Time Workshop
software stores the TMF tokens in a vector. The function adds the
tokens to the end of the vector in the order that you specify them.
In addition to the required
arguments, you can specify an optional groups argument. You can
specify
groups as a character array or a cell array of character arrays.
addTMFTokens function call must be handled
|>CUSTOM_OUTNAME<| to achieve
buildinfo, tokennames,andtoken valu es
If You Specify an Option al
Argument as a...
Character arrayApplies the character array to all TMF tokens it adds to
Cell array of character arraysPairs each character array with a specified TMF token.
The Function...
the build information.
Thus, t h e length of the cell array must match the length
of the cell array you specify for
tokennames.
3-34
addTMFTokens
ExampleInside a post code generation command, add the TMF token
|>CUSTOM_OUTNAME<| and its value to build information
myModelBuildInfo, and place the token in the group LINK_INFO.
to an embeddable C/C++ library or executable or to a MEX function.
Optionally, you can specify custom
global_options applies to all functions fcn_1 through fcn_n.
options_n applies only to the preceding function, fcn_n.
translates the MATLAB functions fcn_1 through fcn_n
files to include in the build.
Input
Arguments
fcn_1 ...fcn_n
MATLAB functions from which to generate a MEX function,
C/C++ library, or C/C++ executable code.
comply with the correct syntax and semantics for Embedded
MATLAB
files
Space-separated list of custom files to include in generated code.
You can include the following types of files:
• Cfile(
• C++ file (
• Header file (
• Object file (
• Library (
• Template makefile (
global_options
Choice of compiler options. emlc resolves options from left to right.
If you specify conflicting options, the rightmost option prevails.
®
, a subset of the MATLAB language.
.c)
.cpp)
.h)
.o or .o bj)
.a, .so,or.lib)
.tmf)
fcn_1 ... fcn_n must
3-36
emlc
-c
-d out_folder
Generate C/C++ code, but do
not invoke the
Use only with
and
rtw:lib targets.
make command.
rtw, rtw:exe,
Store generated files in the
absolute or relative path
specified by
out_folder.
If the folder specified by
out_folder does not exist,
emlc creates it for you.
If you do not specify the folder
location,
emlc generates files
in the default folder:
emcprj/target/fcn1.
target
•
•
can be:
mexfcn for MEX functions
rtwexe for embeddable
C/C++ executables
•
rtwlib for embeddable
C/C++ libraries
fcn1 is the name of the first
MATLAB function specified at
the command line.
The function does not support
the following characters in
folder names: asterisk (*),
question-mark (?), dollar ($),
and pound (#).
3-37
emlc
-F fimath_obj
-g
-global global_values
Specify fimath_obj as the
default
fimath object for
all fixed-point inputs to the
primary function.
You can define
fimath_obj
using the fimath function.
If not specified,
the MATLAB default
emlc uses
fimath
value.
Compiles MEX functions in
debug mode, with optimization
turned off. Us e only for
mex
targets. If not specified, emlc
generates MEX functions in
optimized mode.
Specify initial values for
global variables in Embedded
MATLAB files. Use the values
in cell array
global_values
to init ialize gl obal va ria bles in
the function you compile. The
cell array should provide the
name and initial value of each
global variable. You must
initialize global variables
before compiling with
emlc.
Ifyoudonotprovideinitial
values for global variables
using the
emlc checks for the variable
-global option,
in the MATLAB global
workspace. If you do not
supply an initial value,
emlc
generates an error.
3-38
-I include_path
-launchreport
-N numerictype_obj
The Embedded MATLAB
subset and MATLAB each
have their o wn copies of global
data. To ensure consistency,
you must synchronize their
global data whenever the
two interact. If you do not
synchronize the data, their
global variables might differ.
Add include_path to the
beginning of the Embedded
MATLAB path.
emlc searches the Embedded
MATLAB path first when
converting MATLAB code to
C/C++ code.
Generate and open a
compilation report. If you
do not specify this option,
emlc
generates a report only error
or warning messages occur
or you specify the
-report
option.
Specify numerictype_obj
as the default numerictype
object for all fixed-point inputs
to the MATLAB function.
emlc
You can define
numerictype_obj using
the
numerictype function.
If you do not specify the object,
you must define fixed-point
inputs using the
-eg option.
3-39
emlc
-o output_file_name
-O optimization_option
Generate the ME X function,
C/C++ library, or C/C++
executable file with the base
name
output_file_name plus
an extension:
•
.a or .lib for C/C++
libraries
•
.exe or no extension for
C/C++ executables
• Platform-dependent
extension for generated
MEX functions
output_file_name can be
afilenameorincludean
existing path.
If you do not specify an output
file name, the base name is
fcn_1,wherefcn_1 is the
name of the first MA TLAB
function specified at the
command line.
Optimize generated code,
based on the value of
optimization_option:
3-40
•
enable:inline —Enable
function inlining
•
disable:inline — Disable
function inlining
•
enable:blas — Use BLAS
library, if available
• disable:blas —Donot
use BLAS library
emlc
-report
-s config_obj
If not specified,
emlc uses
inlining and BLAS library
functions for optimization.
Generate a compilation report.
If you do not specify this
option,
emlc generates a
report only if error or warning
messages occur or you specify
the
-launchreport option.
Specify code generation
parameters, based on
config_obj, defined as
one of these objects:
•
emlcoder.HardwareImplementation
— Parameters of the
target hardware for
embeddable C/C++ code.
Use with
rtw:exe targets. If not
specified,
rtw, rtw:lib,or
emlc generates
code compatible with the
MATLAB host computer.
•
emlcoder.MEXConfig —
Parameters for M EX code
generation. Use with
target.
emlcoder.RTWConfig —
•
Parameters for embeddable
C/C++ code generation. Use
mex
3-41
emlc
with rtw, rtw:lib,and
rtw:exe targets.
-T target_option
-v
-?
Define
config_obj as a
MATLAB variable. For
example:
rtw_config = emlcoder.RTWConfig
Specify target for generated
code, based on value of
target_option:
•
mex —GenerateaMEX
function (default)
•
rtw or rtw:lib —Generate
embeddable C/C++ library
file
•
rtw:exe —Generate
embeddable C/C++ code
executable file. You must
provide a
main function to
include in the build.
If not specified,
emlc generates
a MEX function.
Enable verbose mode to show
compilation steps. Use with
rtw, rtw:lib,andrtw:exe
targets.
Display help for emlc
command.
3-42
options_1 .. .options_n
emlc
-eg example_inputs
Define the size, class, and
complexity of all MATLAB
function inputs. Use the
values in
example_inputs
to define these properties.
example_inputs must be
a cell array that specifies
thesamenumberandorder
of inputs as the MATLAB
function.
Specify the example inputs
immediately after the function
to which they apply.
ExamplesGenerate a MEX function from an Embedded MATLAB compliant
function:
1 Write a MATLAB function emcrand that generates a random scalar
value drawn from the standard uniform distribution on the open
interval (0,1):
function r = emcrand() %#eml
% The directive %#eml decl are s the function
%to be Embedded MATLAB compliant
r = rand();
2 Generate and run the MEX function:
emlc emcrand
emcrand
Generate C executable files from an Embedded MATLAB compliant
function. Specify the main C function as a configuration parameter:
3-43
emlc
1 Write a MATLAB function emcrand that generates a random scalar
value drawn from the standard uniform distribution on the open
interval (0,1):
function r = emcrand() %#eml
r = rand();
2 Write a main C function c:\myfiles\main.c that calls emcrand:
generates C executables and supporting files in the default
emlc
folder
emcprj/rtwexe/emcrand.
emlc
This example shows how to specify a main function as a parameter in
the configuration object
specify the file containing
You can use a source, object, or library file.
Generate C library files in a custom folder from an Embedded MATLAB
compliant function with inputs of different classes and sizes. The first
input is a 1-by-4 vector of unsigned 16-bit integers; the second input is
a double-precision scalar:
1 Write a MATLAB function emcadd that returns the sum of tw o values:
function y = emcadd(u,v) %#eml
y=u+v;
2 Generate the C library files in a custom folder emcaddlib:
'ProductFractionLength',23)
% Define a fixed-point variable with these
%numerictype and fimath properties
myfiprops = {fi(4.0,T,F)}
emlc -T rtw:lib emcsqrtfi -eg myfipro ps
generates C library and supporting files in the default folder
emlc
emcprj/rtwlib/emcsqrtfi.
Specify global data at the command line.
1 Write a MATLAB function use_globals that takes one input
parameter
u and uses two global variables AR and B:
3-46
function y = use_globals( u)
%#eml
% Turn off inlining to make
% generated code easier to read
eml.inline('never');
global AR;
global B;
AR(1) = u(1) + B(1);
y=AR*2;
2 Generate a MEX function named use_globalsx in the current folder.
Specify the properties of the global variables at the command line
using the
emlc -global {'AR', ones(4), 'B', [1 2 3 4]}
-global option:
... -o use_globalsx use_globals
emlc
Alternatively, you can initialize the global data in the MATLAB
workspace. At the M ATLA B prompt, enter:
global AR B;
AR = ones(4);
B=[1 2 3];
Compile the function to generate a MEX file named use_globalsx.
emlmex -o use_globalsx use_globals
AlternativesYou can use a GUI to modify parameters for code generation with emlc:
• To modify hardware implementation parameters using a dialog box:
hw_config = emlcoder.HardwareImplementation
open hw_config
• To modify C/C++ code generation parameters using a dialog box:
rtw_config = emlcoder.RTWConfig
open rtw_config
• To modify MEX code generation parameters using a dialog box:
mex_config = emlcoder.MEXConfig
open mex_config
See Alsofimath | numerictype | emlmex | mex | fi
Tutorials• “Tutorial: Generating C Code from MATLAB Code”
• Generating Code for Embedded MATLAB
How To• “Making MATLAB Code Compliant with the Embedded MATLAB
Subset”
• “Converting MATLAB Code to C/C++ Code”
• “Specifying Properties of Primary Function Inputs”
3-47
emlc
• “Configuring Your Environment for Code Generation”
• “Specifying a Language for Embeddable Code Generation”
• “File Paths and Naming Conventions”
• “Generating C/C++ Code from MATLAB Code That Uses Global Data”
• “Synchronizing Global Data with MATLAB”
• “Compiling More Than One Entry-Point MATLAB Function”
3-48
findIncludeFiles
PurposeFind and add include (header) files to build information object
SyntaxfindIncludeFiles(buildinfo, extPatterns)
extPatterns
is optional.
Argumentsbuildinfo
Build information returned by RTW.BuildInfo.
extPatterns (optional)
A cell array of character arrays that specify patterns of file name
extensions for which the function is to search. Each pattern
• Must start with
• Can include any combination of alphanumeric and underscore
(_) characters
The default pattern is
Examples of valid patterns include
*.h
*.hpp
*.x*
*.
*.h.
DescriptionThe findIncludeFiles function
• Searches for include files, based on specifie d file name extension
patterns, in all source and include paths recorded in a model’s build
information object
• Adds the files found, along with their full pa th s, to the build
information object
• Deletes duplicate entries
3-49
findIncludeFiles
ExamplesFind all include files with filename extension .h that are in build
Concatenates and returns each filename
with its corresponding path.
Returns only filenames.
The Function ...
Replaces the token $(MATLAB_ROOT)
withtheabsolutepathstringforyour
MATLAB installation directory.
Does not replace the token
$(MATLAB_ROOT).
includeGroups (optional)
A character array or cell array of character arrays that specifies
groups of include files you want the function to return.
excludeGroups (optional)
A character array or cell array of character arrays that specifies
groups of include files you do not want the function to return.
3-59
getIncludeFiles
ReturnsNames of include files stored in the model’s build information. The
names include any files you added using the
and, if you called the
packNGo function, any files packNGo found and
added while packaging model code.
DescriptionThe getIncludeFiles function returns the names of include files
stored in the model’s build information. Use the
replaceMatlabroot arguments to control whether the function includes
paths and your MATLAB roo t definition in the output it returns.
Using optional
can selectively include or exclude groups of include files the function
returns.
includeGroups and excludeGroups arguments, you
addIncludeFiles function
concatenatePaths and
Ifyouchoosetospecify
specify a null string (
excludeGroups and omit incl udeGroups,
'')forincludeGroups.
Examples• Get all include paths and filenames stored in build information
A character array or cell array of character arrays that specifies
groups of include paths you want the function to return.
excludeGroups (optional)
A character array or cell array of character arrays that specifies
groups of include paths you do not want the function to return.
The Function ...
Replaces the token $(MATLAB_ROOT)
withtheabsolutepathstringforyour
MATLAB installation dire ctory.
Does not replace the token
$(MATLAB_ROOT).
ReturnsPaths of include files stored in the model’s build information.
DescriptionThe getIncludePaths function returns the names of include file paths
stored in the model’s build information. Use the
argument to control w hether the function includes your MATLAB root
definition in the output it returns. Using optional
and ex clud eGroups arguments, you can selectively include or exclude
groups of include file paths the function returns.
3-62
replaceMatlabroot
includeGroups
getIncludePaths
IfyouchoosetospecifyexcludeGroups and omit includeGroups,
specify a null string (
Examples• Get all include paths stored in build information m yMod elBuildInfo.
A character array or cell array that specifies groups of linker flags
you want the function to return.
excludeGroups (optional)
A character array or cell array that specifies groups of linker
flags you do not want the function to return. To exclude groups
and not include specific groups, specify an empty cell array (
for
includeGroups.
'')
ReturnsLinker options stored in the model’s build information.
DescriptionThe getLinkFlags function returns linker options stored in the model’s
build information. Using optional
arguments, you can selectively include or exclude groups of options
the function returns.
Ifyouchoosetospecify
specify a null string (
excludeGroups and omit incl udeGroups,
'')forincludeGroups.
includeGroups and excludeGroups
3-64
getLinkFlags
Examples• Get all linker options stored in buil d information myModelBuildInfo.
Concatenates and returns each filename
with its corresponding path.
Returns only filenames.
The Function ...
Replaces the token $(MATLAB_ROOT)
withtheabsolutepathstringforyour
MATLAB installation directory.
Does not replace the token
$(MATLAB_ROOT).
includeGroups (optional)
A character array or cell array of character arrays that specifies
groups of nonbuild files you want the function to return.
excludeGroups (optional)
A character array or cell array of character arrays that specifies
groups of nonbuild files you do not want the function to return.
3-67
getNonBuildFiles
ReturnsNames of nonbuild files stored in the model’s build information.
DescriptionThe getNonBuildFiles function returns the nam es of nonbuild-related
files, such as DLL files required for a final executable, or a README
file, stored in the m od el ’s build information. Use th e
and replaceMatlabroot arguments to control whether the function
includes paths and your MATLAB root definition in the output it
returns. Using optional
includeGroups and excludeG roups arguments,
you can selectively include or excl ude groups of nonbuild files the
function returns.
concatenatePaths
Ifyouchoosetospecify
specify a null string (
excludeGroups and omit incl udeGroups,
'')forincludeGroups.
ExamplesGet all nonbuild filenames stored in build information
Concatenates and returns each filename
with its corresponding path.
Returns only filenames.
The Function ...
Replaces the token $(MATLAB_ROOT)
withtheabsolutepathstringforyour
MATLAB installation directory.
Does not replace the token
$(MATLAB_ROOT).
includeGroups (optional)
A character array or cell array of character arrays that specifies
groups of source files you want the function to return.
excludeGroups (optional)
A character array or cell array of character arrays that specifies
groups of source files you do not want the function to return.
3-69
getSourceFiles
ReturnsNames of source files stored in the model’s build information.
DescriptionThe getSourceFiles function returns the names of source files stored
in the model’s build information. Use the
replaceMatlabroot arguments to control whether the function includes
paths and your MATLAB root definition in the output it returns. Using
optional
selectively include or exclude groups of source files the function returns.
includeGroups and excludeGroups arguments, you can
concatenatePaths and
Ifyouchoosetospecify
specify a null string (
excludeGroups and omit incl udeGroups,
'')forincludeGroups.
Examples• Get all source paths and filenames stored in build information