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 Real-Time Workshop® 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 matlabroot/rtw/c/tlc/mw/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 matlabroot/rtw/c/tlc/lib/cachelib.tlc.

LibAddToModelSources(newFile)

LibAddToModelSources serves two purposes:

For inlined S-functions, LibAddToModelSources is generally called from BlockTypeSetup. LibAddToModelSources adds a filename to the list of sources needed to build 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.

The MathWorks recommends using the SFunctionModules block parameter instead of LibAddToModelSources when writing S-functions. See Writing S-Functions.

See LibAddToModelSources in matlabroot/rtw/c/tlc/lib/utillib.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.h (or model_private.h). 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.h (or model_private.h).

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 matlabroot/rtw/c/tlc/lib/cachelib.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 matlabroot/rtw/c/tlc/lib/cachelib.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.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 matlabroot/rtw/c/tlc/lib/cachelib.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 matlabroot/rtw/c/tlc/lib/cachelib.tlc.

LibCallModelInitialize()

Example

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

See LibCallModelInitialize in matlabroot/rtw/c/tlc/mw/codetemplatelib.tlc.

LibCallModelStep(tid)

Example

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

See LibCallModelStep in matlabroot/rtw/c/tlc/mw/codetemplatelib.tlc.

LibCallModelTerminate()

Example

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

See LibCallModelTerminate in matlabroot/rtw/c/tlc/mw/codetemplatelib.tlc.

LibCallSetEventForThisBaseStep(buffername)

Returns necessary 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 matlabroot/rtw/c/tlc/mw/codetemplatelib.tlc.

LibCreateSourceFile(type, creator, name)

LibCreateSourceFile creates a new C file and returns its reference. If the file already exists, no error occurs and 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 matlabroot/rtw/c/tlc/mw/codetemplatelib.tlc.

LibGetMdlPrvHdrBaseName()

Returns the base name of the model's private header file, e.g., model_private.h.

See LibGetMdlPrvHdrBaseName in matlabroot/rtw/c/tlc/mw/codetemplatelib.tlc.

LibGetMdlPubHdrBaseName()

Returns the base name of the model's public header file, e.g., model.h).

See LibGetMdlPubHdrBaseName in matlabroot/rtw/c/tlc/mw/codetemplatelib.tlc.

LibGetMdlSrcBaseName()

Return the base name of the model's main source file, e.g., model.c.

See LibGetMdlSrcBaseName in matlabroot/rtw/c/tlc/mw/codetemplatelib.tlc.

LibGetModelDotCFile()

Gets the record for the model.c file. You can then cache additional code using LibSetSourceFileSection.

Syntax

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

Returns

Returns the model.c source file record.

See LibGetModelDotCFile in matlabroot/rtw/c/tlc/mw/codetemplatelib.tlc.

LibGetModelDotHFile()

Get the record for the model.h file. You can then cache additional code using LibSetSourceFileSection.

Syntax

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

Returns

Returns the model.h source file record.

See LibGetModelDotHFile in matlabroot/rtw/c/tlc/mw/codetemplatelib.tlc.

LibGetModelName()

Return the name of the model (no extension).

See LibGetModelName in matlabroot/rtw/c/tlc/mw/codetemplatelib.tlc.

LibGetNumSourceFiles()

Gets the number of source files (.c and .h) that have been created.

Syntax

%assign numFiles = LibGetNumSourceFiles()

Returns

Returns the number of files (number).

See LibGetNumSourceFiles in matlabroot/rtw/c/tlc/mw/codetemplatelib.tlc.

LibGetRTModelErrorStatus()

Returns the code required to get the model error status.

Syntax

%<LibGetRTModelErrorStatus()>;

See LibGetRTModelErrorStatus in matlabroot/rtw/c/tlc/mw/codetemplatelib.tlc.

LibGetSourceFileCustomSection(file, attrib)

Gets a custom section previously created with LibAddSourceFileCustomSection.

Arguments

file (scope or number) — Source file reference or index

attrib (string) — Name of custom section

See LibGetSourceFileCustomSection in matlabroot/rtw/c/tlc/mw/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 matlabroot/rtw/c/tlc/mw/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 matlabroot/rtw/c/tlc/mw/codetemplatelib.tlc.

LibMdlRegCustomCode(buffer, location)

Place declaration statements and executable code inside the model_initialize function.

Argument

buffer — String buffer to append to internal cache buffer

location — Where to place the buffer's contents

"header"

To place buffer at top of function

"declaration"

Same as specifying header

"execution"

To place buffer at top of function, but after header

"trailer"

To place buffer at bottom of function

Returns

Nothing

See LibMdlRegCustomCode in matlabroot/rtw/c/tlc/mw/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 to append to internal cache buffer

location — Where to place the buffer's contents

"header"

To place buffer at top of function

"declaration"

Same as specifying header

"execution"

To place buffer at top of function, but after header

"trailer"

To 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 code format:

Function NameCode Format

model_initialize

Embedded-C

mdlStart

S-function

MdlStart

RealTime, RealTimeMalloc

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

See LibMdlStartCustomCode in matlabroot/rtw/c/tlc/mw/hookslib.tlc.

LibMdlTerminateCustomCode(buffer, location)

Purpose

Places declaration statements and executable code inside the terminate function.

Syntax

LibMdlTerminateCustomCode(buffer, location)

Arguments

buffer — String buffer to append to internal cache buffer

location — Where to place the buffer's contents

"header"

To place buffer at top of function

"declaration"

Same as specifying header

"execution"

To place buffer at top of function, but after header

"trailer"

To 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 code format:

Function NameCode Format

model_terminate

Embedded-C

mdlTerminate

S-function

MdlTerminate

RealTime, RealTimeMalloc

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

See LibMdlTerminateCustomCode in matlabroot/rtw/c/tlc/mw/hookslib.tlc.

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 matlabroot/rtw/c/tlc/mw/codetemplatelib.tlc.

LibSetSourceFileCodeTemplate(opFile, name)

By default, *.c and *.h files are generated with the code templates specified in the Configuration Parameters > Real-Time Workshop > Templates pane. LibSetSourceFileCodeTemplate allows you to change the template for a file. The function uses the code templates entered into the Configuration Parameters > Real-Time Workshop > Templates pane.

Syntax

%assign tag = LibSetSourceFileCodeTemplate(opFile,name)

Arguments

opFile (scope) — Reference to file

name (string) — Name of the desired template

Returns

Nothing

See LibSetSourceFileCodeTemplate in matlabroot/rtw/c/tlc/mw/codetemplatelib.tlc.

LibSetSourceFileCustomSection(file, attrib, value)

Sets a custom section previously created with LibAddSourceFileCustomSection. Available only with the Real-Time Workshop 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 matlabroot/rtw/c/tlc/mw/codetemplatelib.tlc.

LibSetSourceFileOutputDirectory(opFile, name)

By default, *.c and *.h files are generated into the Real-Time Workshop build directory. LibSetSourceFileOutputDirectory allows you to change the default location. Note that the caller is responsible for specifying a valid directory.

Syntax

%assign tag = LibSetSourceFileOutputDirectory(opFile,dirName)

Arguments

opFile (scope) — Reference to file

dirName (string) — Name of the desired output directory

Returns

Nothing

See LibSetSourceFileOutputDirectory in matlabroot/rtw/c/tlc/mw/codetemplatelib.tlc.

LibSetSourceFileSection(fileH, section, value)

Adds to the contents of a 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 any 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 any previously defined type.

Enums

Append to the enumerated types section.

Definitions

Append to the data definition section.

ExternData

(Reserved) Real-Time Workshop extern data.

ExternFcns

(Reserved) Real-Time Workshop extern functions.

FcnPrototypes

(Reserved) Real-Time Workshop function prototypes.

Declarations

Append to the data declaration section.

Functions

Append to the C functions section.

CompilerErrors

Append to the #warning section.

CompilerWarnings

Append to the #error 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 all 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 matlabroot/rtw/c/tlc/mw/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 to append to internal cache buffer

location — (string) Where to place the buffer

"header"

To place buffer at top of function

"declaration"

Same as specifying header

"execution"

To place buffer at top of function, but after header

"trailer"

To 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 code format:

Function NameCode Format

mdlDerivatives

S-function

MdlDerivatives

RealTimeMalloc

model_derivatives

RealTime

LibSystemDerivativeCustomCode is not relevant for the Embedded-C code format, 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 any continuous states.

See LibSystemDerivativeCustomCode in matlabroot/rtw/c/tlc/mw/hookslib.tlc.

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 to append to internal cache buffer

location — (string) Where to place the buffer

"header"

To place buffer at top of function

"declaration"

Same as specifying header

"execution"

To place buffer at top of function, but after header

"trailer"

To 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 matlabroot/rtw/c/tlc/mw/hookslib.tlc.

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 to append to internal cache buffer

location — (String) Where to place the buffer

"header"

To place buffer at top of function

"declaration"

Same as specifying header

"execution"

To place buffer at top of function, but after header

"trailer"

To 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 matlabroot/rtw/c/tlc/mw/hookslib.tlc.

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 to append to internal cache buffer

location — (string) Where to place the buffer

"header"

To place buffer at top of function

"declaration"

Same as specifying header

"execution"

To place buffer at top of function, but after header

"trailer"

To 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 code format:

Function NameCode Format

model_initialize

Embedded-C

mdlInitializeConditions

S-function

MdlStart

RealTime, RealTimeMalloc

Code for a subsystem is output into the subsystem's initialization function. Each call to LibSystemInitializeCustomCode appends your buffer to the internal cache buffer.

See LibSystemInitializeCustomCode in matlabroot/rtw/c/tlc/mw/hookslib.tlc.

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 to append to internal cache buffer

location — (string) Where to place the buffer

"header"

To place buffer before the complete subsystem's output code.

"declaration"

Same as specifying header

"execution"

To place buffer at top of function, but after header

"trailer"

To 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 code format:

Function NameCode Format

model_step

Embedded-C (CombineOutputUpdateFcns is 1)

model_output

Embedded-C (CombineOutputUpdateFcns is 0)

mdlOutputs

S-function

MdlOutputs

RealTime, RealTimeMalloc

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

See LibSystemOutputCustomCode in matlabroot/rtw/c/tlc/mw/hookslib.tlc.

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) A buffer containing text to append to the internal cache buffer

location — (String) Where to place the buffer in the function:

"header"

Place the buffer at the top of the function

"declaration"

Same as specifying "header"

"execution"

Place the buffer at the top of function, but after the header

"trailer"

Place the buffer at the bottom of the 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 code format:

Function NameCode Format

model_step

Embedded-C (CombineOutputUpdateFcns is 1)

model_update

Embedded-C (CombineOutputUpdateFcns is 0)

mdlUpdate

S-function

MdlUpdate

RealTime, RealTimeMalloc

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

See LibSystemUpdateCustomCode in matlabroot/rtw/c/tlc/mw/hookslib.tlc.

LibWriteModelData()

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

See LibWriteModelData in matlabroot/rtw/c/tlc/mw/codetemplatelib.tlc.

LibWriteModelInput(tid, rollThreshold)

Returns the code necessary to write to a particular root input (i.e., a model inport block). Valid for ERT only.

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 matlabroot/rtw/c/tlc/mw/codetemplatelib.tlc.

LibWriteModelInputs()

Returns the code necessary to write to root inputs (i.e., all the model inport blocks). Valid for ERT only.

See LibWriteModelInputs in matlabroot/rtw/c/tlc/mw/codetemplatelib.tlc.

LibWriteModelOutput(tid, rollThreshold)

Returns the code necessary to write to a particular root output (i.e., a model outport block). Valid for ERT only.

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 matlabroot/rtw/c/tlc/mw/codetemplatelib.tlc.

LibWriteModelOutputs()

Returns the code necessary to write to root outputs (i.e., all the model outport blocks). Valid for ERT only.

See LibWriteModelOutputs in matlabroot/rtw/c/tlc/mw/codetemplatelib.tlc.

  


 © 1984-2008- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS