Adds a custom section to a source file. You must associate a custom section with one of
the built-in sections: Includes, Defines, Types, Enums, Definitions, Declarations,
Functions, or Documentation. Nothing happens if the section already exists, except to report
an error if a inconsistent built-in section association is attempted.
LibAddSourceFileCustomSection
is available only with the Embedded Coder® product.
file
— Source file reference
builtInSection
— Name of the associated built-in
section
newSection
— Name of the new (custom) section
See LibAddSourceFileCustomSection
in codetemplatelib.tlc
.
Adds items to a list of #include /package
specification items. Each
member of the list is unique. Attempting to add a duplicate member does nothing.
LibAddToCommonIncludes
should be called from block TLC methods to
specify generation of #include
statements in
. Specify the names of files on the
include path inside angle brackets, e.g., model
.h<sysinclude.h>
. Specify
the names of local files without angle brackets, e.g., myinclude.h
. Each
call to LibAddToCommonIncludes
adds the specified file to the list only
if it is not already there. Filenames with and without angle brackets (e.g.,
<math.h>
and math.h
) are considered different.
The #include
statements are placed inside
.model
.h
LibAddToCommonIncludes("tpu332lib.h")
See LibAddToCommonIncludes
in cachelib.tlc
.
LibAddToModelSources
serves two purposes:
To notify the build process that it must build with the specified source file
To update the SOURCES: file1.c file2.c ...
comment in the
generated code.
For inlined S-functions, LibAddToModelSources
is generally called
from BlockTypeSetup
. LibAddToModelSources
adds a
filename to the list of sources for building this model.
LibAddToModelSources
returns 1
if the filename
passed in was a duplicate (i.e., it was already in the sources list) and
0
if it was not a duplicate.
You can use the LibAddToModelSources
function for other purposes in
TLC aside from writing S-functions. If you write your own S-functions, use the
SFunctionModules
block parameter instead of
LibAddToModelSources
. See LibAddToModelSources
in
utillib.tlc
.
Each call to LibCacheDefine
appends your buffer to the existing cache
buffer. For blocks, LibCacheDefine
is generally called from
BlockTypeSetup
.
LibCacheDefine
caches #define
statements for
inclusion in
or
model
_private.h
. Call
model
.cLibCacheDefine
from inside BlockTypeSetup
to cache a
#define
statement. Each call to LibCacheDefine
appends your buffer to the existing cache buffer. The #define
statements
are placed inside
or
model
_private.h
.model
.c
%openfile buffer #define INTERP(x,x1,x2,y1,y2) ( y1+((y2 - y1)/(x2 - x1))*(x-x1)) #define this that %closefile buffer %<LibCacheDefine(buffer)>
See LibCacheDefine
in cachelib.tlc
.
LibCacheExtern
should be called from inside
BlockTypeSetup
to cache an extern
statement. Each
call to LibCacheExtern
appends your buffer to the existing cache buffer.
The extern
statements are placed in
.model
_private.h
%openfile buffer extern real_T mydata; %closefile buffer %<LibCacheExtern(buffer)>
See LibCacheExtern
in cachelib.tlc
.
LibCacheFunctionPrototype
should be called from inside
BlockTypeSetup
to cache a function prototype. Each call to
LibCacheFunctionPrototype
appends your buffer to the existing cache
buffer. The prototypes are placed inside
.model
_private.h
%openfile buffer extern int_T fun1(real_T x); extern real_T fun2(real_T y, int_T i); %closefile buffer %<LibCacheFunctionPrototype(buffer)>
See LibCacheFunctionPrototype
in cachelib.tlc
.
LibCacheTypedefs
should be called from inside
BlockTypeSetup
to cache typedef
declarations. Each
call to LibCacheTypedefs
appends your buffer to the existing cache
buffer. The typedef
statements are placed inside
(or
model
.h
).model
_common.h
%openfile buffer typedef foo bar; %closefile buffer %<LibCacheTypedefs(buffer)>
See LibCacheTypedefs
in cachelib.tlc
.
Returns code for calling the model's initialize function (valid for ERT only).
See LibCallModelInitialize
in
.codetemplatelib.tlc
Returns code for calling the model's step function (valid for ERT only).
See LibCallModelStep
in codetemplatelib.tlc
.
Returns code for calling the model's terminate function (valid for ERT only).
See LibCallModelTerminate
in codetemplatelib.tlc
.
Returns code for calling the model's set events function (valid for ERT only).
buffername
— Name of the variable used to buffer the events.
For the example ert_main.c
, this is
eventFlags
.
See LibCallSetEventForThisBaseStep
in codetemplatelib.tlc
.
Before writing file to disk, clear file sections with custom values.
fileIdx
(scope or number) — File index
attrib
(string) — Name of model attribute
See LibGetSourceFileAttribute
in codetemplatelib.tlc
.
Creates a new C or C++ file and returns its reference. If the file already exists,
LibCreateSourceFile
returns the existing file's reference.
%assign fileH = LibCreateSourceFile ("Source", "Custom", "foofile")
type
(string) — Valid values are "Source"
and "Header"
for .c
and .h
files,
respectively.
creator
(string) — Who is creating the file? An error is
reported if different creators attempt to create the same file.
name
(string) — Base name of the file (i.e., without the
extension). Note that files are not written to disk if they are empty.
Reference to the model file (scope).
See LibCreateSourceFile
in codetemplatelib.tlc
.
Returns model file name (including the path) without the file extension. To retrieve the
file name (including the path) with the file extension, use
LibGetSourceFileSection
.
file
— Source file reference
See LibGetFileRecordName
in codetemplatelib.tlc
.
Returns the base name of the model's private header file, for example,
.model
_private.h
See LibGetMdlPrvHdrBaseName
in codetemplatelib.tlc
.
Returns the base name of the model's public header file, for example,
.model
.h
See LibGetMdlPubHdrBaseName
in codetemplatelib.tlc
.
Returns the base name of the model's main source file, for example,
.model
.c
See LibGetMdlSrcBaseName
in codetemplatelib.tlc
.
Returns the base name of the model's data file, for example,
.model
_data.c
See LibGetMdlDataSrcBaseName
in codetemplatelib.tlc
.
Returns the base name of the model types file, for example,
.model
_types.h
See LibGetMdlTypesHdrBaseName
in codetemplatelib.tlc
.
Returns the base name of the model capi header file, for example,
.model
_capi.h
See LibGetMdlCapiHdrBaseName
in codetemplatelib.tlc
.
Returns the base name of the model capi source file, for example,
.model
_capi.c
See LibGetMdlCapiSrcBaseName
in codetemplatelib.tlc
.
Returns the base name of the model capi host header file, for example,
.model
_host_capi.h
See LibGetMdlCapiHostHdrBaseName
in codetemplatelib.tlc
.
Returns the base name of the model testinterface header file, for example,
.model
_testinterface.h
See LibGetMdlTestIfHdrBaseName
in codetemplatelib.tlc
.
Returns the base name of the model testinterface source file, for example,
.model
_testinterface.c
See LibGetMdlTestIfSrcBaseName
in codetemplatelib.tlc
.
Returns the base name of the data type transition file, for example,
for code generation's Real-Time
and Embedded-C code formats.model
_dt.h
See LibGetDataTypeTransHdrBaseName
in codetemplatelib.tlc
.
Returns a reference to the
or
model
.c.cpp
source file. You can then cache additional code using
LibSetSourceFileSection
.
%assign srcFile = LibGetModelDotCFile() %<LibSetSourceFileSection(srcFile, "Functions", mybuf)>
Returns a reference to the
or
model
.c.cpp
source file.
See LibGetModelDotCFile
in codetemplatelib.tlc
.
Returns a reference to the
source
file. You can then cache additional code using
model
.hLibSetSourceFileSection
.
%assign hdrFile = LibGetModelDotHFile() %<LibSetSourceFileSection(hdrFile, "Functions", mybuf)>
Returns a reference to the
source file.model
.h
See LibGetModelDotHFile
in codetemplatelib.tlc
.
Returns the name of the model (without an extension).
See LibGetModelName
in codetemplatelib.tlc
.
Returns the number of source files (.c
or .cpp
and
.h
) that have been created.
%assign numFiles = LibGetNumSourceFiles()
Returns the number of files (number).
See LibGetNumSourceFiles
in codetemplatelib.tlc
.
Returns the code required to get the model error status.
%<LibGetRTModelErrorStatus()>;
See LibGetRTModelErrorStatus
in codetemplatelib.tlc
.
Returns the specified attribute of a file. The table lists the valid attributes.
Attribute | |||
---|---|---|---|
Name (with file extension) | SystemsInFile | IsEmpty | SharedType |
BaseName | RequiredIncludes | Indent | CodeTemplate |
Type | UtilityIncludes | WrittenToDisk | OutputDirectory |
Creator | Filter | Shared | Group |
fileIdx
(scope or number) — File index
attrib
(string) — Name of model attribute
See LibGetSourceFileAttribute
in codetemplatelib.tlc
.
Returns a model file reference based on its index. This reference can be useful for a common operation on all files, for example, to set the leading file banner of all files.
%assign fileH = LibGetSourceFileFromIdx(fileIdx)
fileIdx
(number) — Index of model file
Reference (scope) to the model file.
See LibGetSourceFileFromIdx
in
.codetemplatelib.tlc
Returns the contents of a file. See LibSetSourceFileSection(fileH, section, value) for a list of valid sections.
fileIdx
(scope or number) — File index
section
(string) — File section of interest
See LibGetSourceFileSection
in codetemplatelib.tlc
.
Returns
and
fileName
_h
for header and source files,
respectively, where fileName
_c
is the name of
the model file.fileName
%assign tag = LibGetSourceFileTag(fileIdx)
fileIndex
(number) — File index
Returns the tag (string).
See LibGetSourceFileTag
in
.codetemplatelib.tlc
Places declaration statements and executable code inside the
function.model
_initialize
buffer
— String buffer containing text to append to the internal
cache buffer.
location
— String specifying where to place the buffer's
contents. Possible values are
"header"
— Place buffer at top of function
"declaration"
— Place buffer at top of function
"execution"
— Place buffer at top of function, but after
header
"trailer"
— Place buffer at bottom of function
Nothing
See LibMdlRegCustomCode
in hookslib.tlc
.
Places declaration statements and executable code inside the start function. Start code is executed once, during the model initialization phase.
LibMdlStartCustomCode(buffer, location)
buffer
— String buffer containing text to append to the
internal cache buffer.
location
— String specifying where to place the buffer's
contents. Possible values are
"header"
— Place buffer at top of function
"declaration"
— Place buffer at top of function
"execution"
— Place buffer at top of function, but after
header
"trailer"
— Place buffer at bottom of function
Nothing
LibMdlStartCustomCode
places declaration statements and executable
code inside the start function. This code is output into the following functions,
depending on the current value for the CodeFormat
TLC variable:
Function Name | Value of CodeFormat TLC variable |
---|---|
|
|
|
|
|
|
|
|
Each call to LibMdlStartCustomCode
appends your buffer to the
internal cache buffer.
See LibMdlStartCustomCode
in hookslib.tlc
.
Places declaration statements and executable code inside the terminate function.
LibMdlTerminateCustomCode(buffer, location)
buffer
— String buffer containing text to append to the
internal cache buffer.
location
— String specifying where to place the buffer's
contents. Possible values are
"header"
— Place buffer at top of function
"declaration"
— Place buffer at top of function
"execution"
— Place buffer at top of function, but after
header
"trailer"
— Place buffer at bottom of function
Nothing
LibMdlTerminateCustomCode
places declaration statements and
executable code inside the terminate function. This code is output into the following
functions, depending on the current value of the CodeFormat
TLC
variable:
Function Name | Value of CodeFormat TLC variable |
---|---|
|
|
|
|
|
|
Each call to LibMdlTerminateCustomCode
appends your buffer to the
internal cache buffer.
See LibMdlTerminateCustomCode
in hookslib.tlc
.
Returns the code required to set the model error status.
LibSetRTModelErrorStatus("\"Overrun\"")
str
(string) — char * to a C string
See LibSetRTModelErrorStatus
in
.codetemplatelib.tlc
By default, *.c
and *.h
files are generated with
the code templates specified in the Code Generation > Templates pane
of the Configuration Parameters dialog box. LibSetSourceFileCodeTemplate
allows you to change the template for a file.
Note
Custom templates are a feature of the Embedded Coder product.
%assign tag = LibSetSourceFileCodeTemplate(opFile,name)
opFile
(scope) — Reference to file
name
(string) — Name of the desired template
Nothing
See LibSetSourceFileCodeTemplate
in
.codetemplatelib.tlc
Adds to the contents of a custom section previously created with
LibAddSourceFileCustomSection
. Available only with Embedded Coder software.
file
(scope or number) — Source file reference or
index
attrib
(string) — Name of custom section
value
(string) — Value to be appended to section
See LibSetSourceFileCustomSection
in codetemplatelib.tlc
.
By default, *.c
and *.h
files are generated into a
build folder at the current location. LibSetSourceFileOutputDirectory
allows you to change the folder into which a specified source file is to be generated. Note
that the caller is responsible for specifying a valid folder.
%assign tag = LibSetSourceFileOutputDirectory(opFile,dirName)
opFile
(scope) — Reference to file
dirName
(string) — Name of the desired output folder
Nothing
See LibSetSourceFileOutputDirectory
in codetemplatelib.tlc
.
Adds to the contents of a specified section within a specified file. Valid file sections include
File Section | Description |
---|---|
| Set the file banner (comment) at the top of the file. |
| Append to the |
| Append to the |
| Append to the intrinsic |
| Append to the primitive |
| Append to the User Top section. |
| Append to the |
| Append to the enumerated types section. |
| Append to the data definition section. |
| (Reserved) Code generator |
| (Reserved) Code generator |
| (Reserved) Code generator function prototypes. |
| Append to the data declaration section. |
| Append to the C functions section. |
| Append to the |
| Append to the |
| Append to the documentation (comment) section. |
| Append to the User Bottom section. |
The code generator orders the code as listed above.
Example (iterating over the files):
%openfile tmpBuf whatever %closefile tmpBuf %foreach fileIdx = LibGetNumSourceFiles() %assign fileH = LibGetSourceFileFromIdx(fileIdx) %<LibSetSourceFileSection(fileH,"SectionOfInterest",tmpBuf)> %endforeach %assign fileH = LibCreateSourceFile("Header","Custom","foofile") %<LibSetSourceFileSection(fileH,"Defines","#define FOO 5.0\n")>
fileH
(scope or number) — Reference or index to a file
section
(string) — File section of interest
value
(string) — Value
See LibSetSourceFileSection
in codetemplatelib.tlc
.
Places declaration statements and executable code inside a subsystem's derivative function.
LibSystemDerivativeCustomCode(system, buffer, location)
system
— Reference to the subsystem whose derivative
function is to be modified.
buffer
— String buffer containing text to append to the
internal cache buffer.
location
— String specifying where to place the buffer's
contents. Possible values are
"header"
— Place buffer at top of function
"declaration"
— Place buffer at top of function
"execution"
— Place buffer at top of function, but after
header
"trailer"
— Place buffer at bottom of function
Nothing
LibSystemDerivativeCustomCode
places declaration statements and
executable code inside the derivative function for the subsystem specified by
system
. This code is output into the following functions, depending
on the current value of the CodeFormat
TLC variable:
Function Name | Value of CodeFormat TLC variable |
---|---|
|
|
|
|
LibSystemDerivativeCustomCode
is not relevant when the value of the
CodeFormat
TLC variable is Embedded-C
, because
blocks with continuous states cannot be used.
Each call to LibSystemDerivativeCustomCode
appends your buffer to
the internal cache buffer. An error is generated if you attempt to add code to a subsystem
that does not have continuous states.
See LibSystemDerivativeCustomCode
in hookslib.tlc
.
Note
To avoid a potential mismatch between simulation and code generation results, do not
use LibSystemDerivativeCustomCode
to read from and write to global
Simulink data (signals, states, and block parameters). Instead, use the proper modeling
pattern (for example, Data Store Read, Data Store Write, State Reader, and State Writer blocks.)
Places declaration statements and executable code inside a subsystem's disable function.
LibSystemDisableCustomCode(system, buffer, location)
system
— Reference to the subsystem whose disable function
is to be modified.
buffer
— String buffer containing text to append to the
internal cache buffer.
location
— String specifying where to place the buffer's
contents. Possible values are
"header"
— Place buffer at top of function
"declaration"
— Place buffer at top of function
"execution"
— Place buffer at top of function, but after
header
"trailer"
— Place buffer at bottom of function
Nothing
LibSystemDisableCustomCode
places declaration statements and
executable code inside the disable function for the subsystem specified by
system
. Each call to LibSystemDisableCustomCode
appends your buffer to the internal cache buffer.
An error is generated if you attempt to add code to a subsystem that does not have a disable function.
See LibSystemDisableCustomCode
in hookslib.tlc
.
Note
To avoid a potential mismatch between simulation and code generation results, do not
use LibSystemDisableCustomCode
to read from and write to global
Simulink data (signals, states, and block parameters). Instead, use the proper modeling
pattern (for example, Data Store Read, Data Store Write, State Reader, and State Writer blocks.)
Places declaration statements and executable code inside a subsystem's enable function.
LibSystemEnableCustomCode(system, buffer, location)
system
— Reference to the subsystem whose enable function is
to be modified.
buffer
— String buffer containing text to append to the
internal cache buffer.
location
— String specifying where to place the buffer's
contents. Possible values are
"header"
— Place buffer at top of function
"declaration"
— Place buffer at top of function
"execution"
— Place buffer at top of function, but after
header
"trailer"
— Place buffer at bottom of function
Nothing
LibSystemEnableCustomCode
places declaration statements and
executable code inside the enable function for the subsystem specified by
system
. Each call to LibSystemEnableCustomCode
appends your buffer to the internal cache buffer.
An error is generated if you attempt to add code to a subsystem that does not have an enable function.
See LibSystemEnableCustomCode
in hookslib.tlc
.
Note
To avoid a potential mismatch between simulation and code generation results, do not
use LibSystemEnableCustomCode
to read from and write to global
Simulink data (signals, states, and block parameters). Instead, use the proper modeling
pattern (for example, Data Store Read, Data Store Write, State Reader, and State Writer blocks.)
Places declaration statements and executable code inside a subsystem's initialize function.
LibSystemInitializeCustomCode(system, buffer, location)
system
— Reference to the subsystem whose initialize
function is to be modified.
buffer
— String buffer containing text to append to the
internal cache buffer.
location
— String specifying where to place the buffer's
contents. Possible values are
"header"
— Place buffer at top of function
"declaration"
— Place buffer at top of function
"execution"
— Place buffer at top of function, but after
header
"trailer"
— Place buffer at bottom of function
Nothing
LibSystemInitializeCustomCode
places declaration statements and
executable code inside the initialize function for the subsystem specified by
system
. This code is output into the following functions, depending
on the current value of the CodeFormat
TLC variable:
Function Name | Value of CodeFormat TLC variable |
---|---|
|
|
|
|
|
|
Code for a subsystem is output into the subsystem's initialization function. Each call
to LibSystemInitializeCustomCode
appends your buffer to the internal
cache buffer.
Note
Enable systems that are not configured to reset on enable are inlined into
MdlStart
. For this case, the subsystem's custom code is found in
MdlStart
above and below the enable subsystem's initialization
code.
See LibSystemInitializeCustomCode
in hookslib.tlc
.
Note
To avoid a potential mismatch between simulation and code generation results, do not
use LibSystemInitializeCustomCode
to read from and write to global
Simulink data (signals, states, and block parameters). Instead, use the proper modeling
pattern (for example, Data Store Read, Data Store Write, State Reader, and State Writer blocks.)
Places declaration statements and executable code inside a subsystem's output function.
LibSystemOutputCustomCode(system, buffer, location)
system
— Reference to the subsystem whose output function is
to be modified.
buffer
— String buffer containing text to append to the
internal cache buffer.
location
— String specifying where to place the buffer's
contents. Possible values are
"header"
— Place buffer at top of function
"declaration"
— Place buffer at top of function
"execution"
— Place buffer at top of function, but after
header
"trailer"
— Place buffer at bottom of function
Nothing
LibSystemOutputCustomCode
places declaration statements and
executable code inside the output function for the subsystem specified by
system
. This code is output into the following functions, depending
on the current value of the CodeFormat
TLC variable:
Function Name | Value of CodeFormat TLC variable |
---|---|
|
|
|
|
|
|
|
|
Each call to LibSystemOutputCustomCode
appends your buffer to the
internal cache buffer.
See LibSystemOutputCustomCode
in
.hookslib.tlc
Note
To avoid a potential mismatch between simulation and code generation results, do not
use LibSystemOutputCustomCode
to read from and write to global
Simulink data (signals, states, and block parameters). Instead, use the proper modeling
pattern (for example, Data Store Read, Data Store Write, State Reader, and State Writer blocks.)
Places code inside a subsystem's update function.
LibSystemUpdateCustomCode(system, buffer, location)
system
— Reference to the subsystem whose update function is
to be modified.
buffer
— String buffer containing text to append to the
internal cache buffer.
location
— String specifying where to place the buffer's
contents. Possible values are
"header"
— Place buffer at top of function
"declaration"
— Place buffer at top of function
"execution"
— Place buffer at top of function, but after
header
"trailer"
— Place buffer at bottom of function
Nothing
LibSystemUpdateCustomCode
places declaration statements and
executable code inside the update function for the subsystem specified by
system
. This code is output into the following functions, depending
on the current value of the CodeFormat
TLC variable:
Function Name | Value of CodeFormat TLC variable |
---|---|
|
|
| Embedded-C ( |
|
|
| RealTime |
Each call to LibSystemUpdateCustomCode
appends your buffer to the
internal cache buffer.
See LibSystemUpdateCustomCode
in hookslib.tlc
.
Note
To avoid a potential mismatch between simulation and code generation results, do not
use LibSystemUpdateCustomCode
to read from and write to global
Simulink data (signals, states, and block parameters). Instead, use the proper modeling
pattern (for example, Data Store Read, Data Store Write, State Reader, and State Writer blocks.)
Returns data for the model (valid for ERT only).
See LibWriteModelData
in codetemplatelib.tlc
.
Returns the code for writing to a specified root input (that is, a model inport block). This function is valid for ERT only, and not valid for referenced models.
tid
(number) — Task identifier (0
is
fastest rate and n
is the slowest)
rollThreshold
— Width of signal before wrapping in a
for
loop.
See LibWriteModelInput
in codetemplatelib.tlc
.
Returns code that writes to all root inputs (that is, the model inport blocks). This function is valid for ERT only, and is not valid for referenced models.
See LibWriteModelInputs
in codetemplatelib.tlc
.
Returns code that writes to a specified root output (that is, a model outport block). This function is valid for ERT only, and not valid for referenced models.
tid
(number) — Task identifier (0
is
fastest rate and n
is the slowest)
rollThreshold
— Width of signal before wrapping in a
for
loop.
See LibWriteModelOutput
in codetemplatelib.tlc
.
Returns code that writes to all root outputs (that is, the model outport blocks). This function is valid for ERT only, and not valid for referenced models.
See LibWriteModelOutputs
in codetemplatelib.tlc
.