Main Content

Code Configuration Functions

LibAddSourceFileCustomSection
(file, builtInSection, newSection)

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.

Arguments

file — Source file reference

builtInSection — Name of the associated built-in section

newSection — Name of the new (custom) section

See LibAddSourceFileCustomSection in codetemplatelib.tlc.

LibAddToCommonIncludes(incFileName)

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 model.h. Specify the names of files on the include path inside angle brackets, e.g., <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.

Example

LibAddToCommonIncludes("tpu332lib.h")

See LibAddToCommonIncludes in cachelib.tlc.

LibAddToModelSources(newFile)

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 utils_api.tlc.

LibCacheDefine(buffer)

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 model_private.h or model.c. Call LibCacheDefine 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 model_private.h or model.c.

Example

%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 codecache_api.tlc.

LibCacheExtern(buffer)

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.

Example

%openfile buffer
 extern real_T mydata;
%closefile buffer
%<LibCacheExtern(buffer)>

See LibCacheExtern in codecache_api.tlc.

LibCacheFunctionPrototype(buffer)

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.

Example

%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 codecache_api.tlc.

LibCacheTypedefs(buffer)

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 model.h (or model_common.h).

Example

%openfile buffer
typedef foo bar;
%closefile buffer
%<LibCacheTypedefs(buffer)>

See LibCacheTypedefs in codecache_api.tlc.

LibCallModelInitialize()

Returns code for calling the model's initialize function (valid for ERT only).

See LibCallModelInitialize in codetemplatelib.tlc.

LibCallModelStep(tid)

Returns code for calling the model's step function (valid for ERT only).

See LibCallModelStep in codetemplatelib.tlc.

LibCallModelTerminate()

Returns code for calling the model's terminate function (valid for ERT only).

See LibCallModelTerminate in codetemplatelib.tlc.

LibCallSetEventForThisBaseStep(buffername)

Returns code for calling the model's set events function (valid for ERT only).

Argument

buffername — Name of the variable used to buffer the events. For the example ert_main.c, this is eventFlags.

See LibCallSetEventForThisBaseStep in codetemplatelib.tlc.

LibClearFileSectionContents(fileIdx, attrib)

Before writing file to disk, clear file sections with custom values.

Arguments

fileIdx (scope or number) — File index

attrib (string) — Name of model attribute

See LibGetSourceFileAttribute in codetemplatelib.tlc.

LibCreateSourceFile(type, creator, name)

Creates a new C or C++ file and returns its reference. If the file already exists, LibCreateSourceFile returns the existing file's reference.

Syntax

%assign fileH = LibCreateSourceFile
                ("Source", "Custom", "foofile")

Arguments

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.

Returns

Reference to the model file (scope).

See LibCreateSourceFile in codetemplatelib.tlc.

LibGetFileRecordName (file)

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.

Arguments

file — Source file reference

See LibGetFileRecordName in codetemplatelib.tlc.

LibGetMdlPrvHdrBaseName()

Returns the base name of the model's private header file, for example, model_private.h.

See LibGetMdlPrvHdrBaseName in codetemplatelib.tlc.

LibGetMdlPubHdrBaseName()

Returns the base name of the model's public header file, for example, model.h.

See LibGetMdlPubHdrBaseName in codetemplatelib.tlc.

LibGetMdlSrcBaseName()

Returns the base name of the model's main source file, for example, model.c.

See LibGetMdlSrcBaseName in codetemplatelib.tlc.

LibGetMdlDataSrcBaseName()

Returns the base name of the model's data file, for example, model_data.c.

See LibGetMdlDataSrcBaseName in codetemplatelib.tlc.

LibGetMdlTypesHdrBaseName()

Returns the base name of the model types file, for example, model_types.h.

See LibGetMdlTypesHdrBaseName in codetemplatelib.tlc.

LibGetMdlCapiHdrBaseName()

Returns the base name of the model capi header file, for example, model_capi.h.

See LibGetMdlCapiHdrBaseName in codetemplatelib.tlc.

LibGetMdlCapiSrcBaseName()

Returns the base name of the model capi source file, for example, model_capi.c.

See LibGetMdlCapiSrcBaseName in codetemplatelib.tlc.

LibGetMdlCapiHostHdrBaseName()

Returns the base name of the model capi host header file, for example, model_host_capi.h.

See LibGetMdlCapiHostHdrBaseName in codetemplatelib.tlc.

LibGetMdlTestIfHdrBaseName()

Returns the base name of the model testinterface header file, for example, model_testinterface.h.

See LibGetMdlTestIfHdrBaseName in codetemplatelib.tlc.

LibGetMdlTestIfSrcBaseName()

Returns the base name of the model testinterface source file, for example, model_testinterface.c.

See LibGetMdlTestIfSrcBaseName in codetemplatelib.tlc.

LibGetDataTypeTransHdrBaseName()

Returns the base name of the data type transition file, for example, model_dt.h for code generation's Real-Time and Embedded-C code formats.

See LibGetDataTypeTransHdrBaseName in codetemplatelib.tlc.

LibGetModelDotCFile()

Returns a reference to the model.c or .cpp source file. You can then cache additional code using LibSetSourceFileSection.

Syntax

%assign srcFile = LibGetModelDotCFile()
%<LibSetSourceFileSection(srcFile, "Functions", mybuf)>

Returns

Returns a reference to the model.c or .cpp source file.

See LibGetModelDotCFile in codetemplatelib.tlc.

LibGetModelDotHFile()

Returns a reference to the model.h source file. You can then cache additional code using LibSetSourceFileSection.

Syntax

%assign hdrFile = LibGetModelDotHFile()
%<LibSetSourceFileSection(hdrFile, "Functions", mybuf)>

Returns

Returns a reference to the model.h source file.

See LibGetModelDotHFile in codetemplatelib.tlc.

LibGetModelName()

Returns the name of the model (without an extension).

See LibGetModelName in codetemplatelib.tlc.

LibGetNumSourceFiles()

Returns the number of source files (.c or .cpp and .h) that have been created.

Syntax

%assign numFiles = LibGetNumSourceFiles()

Returns

Returns the number of files (number).

See LibGetNumSourceFiles in codetemplatelib.tlc.

LibGetRTModelErrorStatus()

Returns the code required to get the model error status.

Syntax

%<LibGetRTModelErrorStatus()>;

See LibGetRTModelErrorStatus in codetemplatelib.tlc.

LibGetSourceFileAttribute(fileIdx, attrib)

Returns the specified attribute of a file. The table lists the valid attributes.

Attribute
Name (with file extension)SystemsInFileIsEmptySharedType
BaseNameRequiredIncludesIndentCodeTemplate
TypeUtilityIncludesWrittenToDiskOutputDirectory
CreatorFilterSharedGroup

Arguments

fileIdx (scope or number) — File index

attrib (string) — Name of model attribute

See LibGetSourceFileAttribute in codetemplatelib.tlc.

LibGetSourceFileFromIdx(fileIdx)

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.

Syntax

%assign fileH = LibGetSourceFileFromIdx(fileIdx)

Argument

fileIdx (number) — Index of model file

Returns

Reference (scope) to the model file.

See LibGetSourceFileFromIdx in codetemplatelib.tlc.

LibGetSourceFileSection(fileIdx, section)

Returns the contents of a file. See LibSetSourceFileSection(fileH, section, value) for a list of valid sections.

Arguments

fileIdx (scope or number) — File index

section (string) — File section of interest

See LibGetSourceFileSection in codetemplatelib.tlc.

LibGetSourceFileTag(fileIdx)

Returns fileName_h and fileName_c for header and source files, respectively, where fileName is the name of the model file.

Syntax

%assign tag = LibGetSourceFileTag(fileIdx)

Argument

fileIndex (number) — File index

Returns

Returns the tag (string).

See LibGetSourceFileTag in codetemplatelib.tlc.

LibMdlRegCustomCode(buffer, location)

Places declaration statements and executable code inside the model_initialize function.

Arguments

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

Returns

Nothing

See LibMdlRegCustomCode in hookslib.tlc.

LibMdlStartCustomCode(buffer, location)

Places declaration statements and executable code inside the start function. Start code is executed once, during the model initialization phase.

Syntax

LibMdlStartCustomCode(buffer, location)

Arguments

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

Returns

Nothing

Description

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 NameValue of CodeFormat TLC variable

model_initialize

Embedded-C (if not ModelReferenceCoderTarget)

mdlStart

Embedded-C (if ModelReferenceCoderTarget)

mdlStart

S-Function

MdlStart

RealTime

Each call to LibMdlStartCustomCode appends your buffer to the internal cache buffer.

See LibMdlStartCustomCode in hookslib.tlc.

LibMdlTerminateCustomCode(buffer, location)

Purpose

Places declaration statements and executable code inside the terminate function.

Syntax

LibMdlTerminateCustomCode(buffer, location)

Arguments

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

Returns

Nothing

Description

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 NameValue of CodeFormat TLC variable

model_terminate

Embedded-C

mdlTerminate

S-Function

MdlTerminate

RealTime

Each call to LibMdlTerminateCustomCode appends your buffer to the internal cache buffer.

Note

Do not use the LibMdlTerminateCustomCode outside of the "case 'content' " section of the TLC code of a custom storage class.

See LibMdlTerminateCustomCode in hookslib.tlc.

LibNotifySymbolExportedFromFile

Notifies the code generation infrastructure that the symbol is being exported from the file.

This function is recommended for custom user symbols such as variable, type, macro, and function declarations. The function signals the code generation infrastructure to include appropriate headers when the passed symbol is used in auto generated files.

Arguments

symbol — Macro, variable, type, or function name, specified as a string.

fileNameWithExtension — File name with language extension, specified as a string. For example, <modelName>.h.

Example

%openfile myFcnDecl
  extern real_T myCustomFcn(void);
%closefile myFcnDecl
%<LibCacheFunctionPrototype(myFcnDecl)>
%assign modelPrivateFile = "%<LibGetMdlPrvHdrBaseName()>.h
%<LibNotifySymbolExportedFromFile("myCustomFcn",modelPrivateFile)>

LibNotifySymbolUsedByFile

Notifies the code generation infrastructure that the symbol is being used by the file.

This function is recommended for custom user symbols such as variable, type, macro, and function declarations. The function signals the code generation infrastructure to include headers for the symbol passed to the function.

Arguments

symbol — Macro, variable, type, or function name, specified as a string.

fileNameWithExtension — File name with language extension, specified as a string. For example, <modelName>.h.

Example

%% The following line is expanded and placed in <model>.c
%<y> = myCustomFcn();
%assign modelSrcFile = LibGetModelDotCFile()
%<LibNotifySymbolUsedByFile("myCustomFcn",modelSrcFile)>

LibSetRTModelErrorStatus(str)

Returns the code required to set the model error status.

Syntax

LibSetRTModelErrorStatus("\"Overrun\"")

Argument

str (string) — char * to a C string

See LibSetRTModelErrorStatus in codetemplatelib.tlc.

LibSetSourceFileCodeTemplate(opFile, name)

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.

Syntax

%assign tag = LibSetSourceFileCodeTemplate(opFile,name)

Arguments

opFile (scope) — Reference to file

name (string) — Name of the desired template

Returns

Nothing

See LibSetSourceFileCodeTemplate in codetemplatelib.tlc.

LibSetSourceFileCustomSection(file, attrib, value)

Adds to the contents of a custom section previously created with LibAddSourceFileCustomSection. Available only with Embedded Coder software.

Arguments

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.

LibSetSourceFileOutputDirectory(opFile, name)

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.

Syntax

%assign tag = LibSetSourceFileOutputDirectory(opFile,dirName)

Arguments

opFile (scope) — Reference to file

dirName (string) — Name of the desired output folder

Returns

Nothing

See LibSetSourceFileOutputDirectory in codetemplatelib.tlc.

LibSetSourceFileSection(fileH, section, value)

Adds to the contents of a specified section within a specified file. Valid file sections include

File Section

Description

Banner

Set the file banner (comment) at the top of the file.

Includes

Append to the #include section.

Defines

Append to the #define section.

IntrinsicTypes

Append to the intrinsic typedef section. Intrinsic types are those that depend only on intrinsic C types.

PrimitiveTypedefs

Append to the primitive typedef section. Primitive typedefs are those that depend only on intrinsic C types and typedefs previously defined in the IntrinsicTypes section.

UserTop

Append to the User Top section.

Typedefs

Append to the typedef section. The typedefs can depend on a previously defined type.

Enums

Append to the enumerated types section.

Definitions

Append to the data definition section.

ExternData

(Reserved) Code generator extern data.

ExternFcns

(Reserved) Code generator extern functions.

FcnPrototypes

(Reserved) Code generator function prototypes.

Declarations

Append to the data declaration section.

Functions

Append to the C functions section.

CompilerErrors

Append to the #error section.

CompilerWarnings

Append to the #warning section.

Documentation

Append to the documentation (comment) section.

UserBottom

Append to the User Bottom section.

The code generator orders the code as listed above.

Syntax

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")>

Arguments

fileH (scope or number) — Reference or index to a file

section (string) — File section of interest

value (string) — Value

See LibSetSourceFileSection in codetemplatelib.tlc.

LibSystemDerivativeCustomCode
(system, buffer, location)

Purpose

Places declaration statements and executable code inside a subsystem's derivative function.

Syntax

LibSystemDerivativeCustomCode(system, buffer, location)

Arguments

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

Returns

Nothing

Description

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 NameValue of CodeFormat TLC variable

mdlDerivatives

S-Function

model_derivatives

RealTime

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.)

LibSystemDisableCustomCode
(system, buffer, location)

Purpose

Places declaration statements and executable code inside a subsystem's disable function.

Syntax

LibSystemDisableCustomCode(system, buffer, location)

Arguments

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

Returns

Nothing

Description

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.)

LibSystemEnableCustomCode
(system, buffer, location)

Purpose

Places declaration statements and executable code inside a subsystem's enable function.

Syntax

LibSystemEnableCustomCode(system, buffer, location)

Arguments

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

Returns

Nothing

Description

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.)

LibSystemInitializeCustomCode
(system, buffer, location)

Purpose

Places declaration statements and executable code inside a subsystem's initialize function.

Syntax

LibSystemInitializeCustomCode(system, buffer, location)

Arguments

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

Returns

Nothing

Description

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 NameValue of CodeFormat TLC variable

model_initialize

Embedded-C

mdlInitializeConditions

S-Function

MdlStart

RealTime

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.)

LibSystemOutputCustomCode
(system, buffer, location)

Purpose

Places declaration statements and executable code inside a subsystem's output function.

Syntax

LibSystemOutputCustomCode(system, buffer, location)

Arguments

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

Returns

Nothing

Description

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 NameValue of CodeFormat TLC variable

model_step

Embedded-C (CombineOutputUpdateFcns is 1)

model_output

Embedded-C (CombineOutputUpdateFcns is 0)

mdlOutputs

S-Function

MdlOutputs

RealTime

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.)

LibSystemUpdateCustomCode
(system, buffer, location)

Purpose

Places code inside a subsystem's update function.

Syntax

LibSystemUpdateCustomCode(system, buffer, location)

Arguments

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

Returns

Nothing

Description

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 NameValue of CodeFormat TLC variable

model_step

Embedded-C (CombineOutputUpdateFcns is 1)

model_update

Embedded-C (CombineOutputUpdateFcns is 0)

mdlUpdate

S-Function

MdlUpdate

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.)

LibWriteModelData()

Returns data for the model (valid for ERT only).

See LibWriteModelData in codetemplatelib.tlc.

LibWriteModelInput(tid, rollThreshold)

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.

Arguments

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.

LibWriteModelInputs()

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.

LibWriteModelOutput(tid, rollThreshold)

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.

Arguments

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.

LibWriteModelOutputs()

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.

Related Topics