| Real-Time Workshop® | ![]() |
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.
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.
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.
LibAddToCommonIncludes("tpu332lib.h")See LibAddToCommonIncludes in matlabroot/rtw/c/tlc/lib/cachelib.tlc.
LibAddToModelSources serves two purposes:
To notify the Real-Time Workshop® 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 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.
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).
%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 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 matlabroot/rtw/c/tlc/lib/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.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 matlabroot/rtw/c/tlc/lib/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 model.h (or model_common.h).
%openfile buffer typedef foo bar; %closefile buffer %<LibCacheTypedefs(buffer)>
See LibCacheTypedefs in matlabroot/rtw/c/tlc/lib/cachelib.tlc.
Returns necessary code for calling the model's initialize function (valid for ERT only).
See LibCallModelInitialize in matlabroot/rtw/c/tlc/mw/codetemplatelib.tlc.
Returns necessary code for calling the model's step function (valid for ERT only).
See LibCallModelStep in matlabroot/rtw/c/tlc/mw/codetemplatelib.tlc.
Returns necessary code for calling the model's terminate function (valid for ERT only).
See LibCallModelTerminate in matlabroot/rtw/c/tlc/mw/codetemplatelib.tlc.
Returns necessary 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 matlabroot/rtw/c/tlc/mw/codetemplatelib.tlc.
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.
%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 matlabroot/rtw/c/tlc/mw/codetemplatelib.tlc.
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.
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.
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.
Gets the record for the model.c file. You can then cache additional code using LibSetSourceFileSection.
%assign srcFile = LibGetModelDotCFile() %<LibSetSourceFileSection(srcFile, "Functions", mybuf)>
Returns the model.c source file record.
See LibGetModelDotCFile in matlabroot/rtw/c/tlc/mw/codetemplatelib.tlc.
Get the record for the model.h file. You can then cache additional code using LibSetSourceFileSection.
%assign hdrFile = LibGetModelDotHFile() %<LibSetSourceFileSection(hdrFile, "Functions", mybuf)>
Returns the model.h source file record.
See LibGetModelDotHFile in matlabroot/rtw/c/tlc/mw/codetemplatelib.tlc.
Return the name of the model (no extension).
See LibGetModelName in matlabroot/rtw/c/tlc/mw/codetemplatelib.tlc.
Gets the number of source files (.c and .h) that have been created.
%assign numFiles = LibGetNumSourceFiles()
Returns the number of files (number).
See LibGetNumSourceFiles in matlabroot/rtw/c/tlc/mw/codetemplatelib.tlc.
Returns the code required to get the model error status.
%<LibGetRTModelErrorStatus()>;
See LibGetRTModelErrorStatus in matlabroot/rtw/c/tlc/mw/codetemplatelib.tlc.
Gets a custom section previously created with LibAddSourceFileCustomSection.
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.
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 matlabroot/rtw/c/tlc/mw/codetemplatelib.tlc.
Returns fileName_h and fileName_c for header and source files, respectively, where fileName is the name of the model file.
%assign tag = LibGetSourceFileTag(fileIdx)
fileIndex (number) — File index
Returns the tag (string).
See LibGetSourceFileTag in matlabroot/rtw/c/tlc/mw/codetemplatelib.tlc.
Place declaration statements and executable code inside the model_initialize function.
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 |
Nothing
See LibMdlRegCustomCode in matlabroot/rtw/c/tlc/mw/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 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 |
Nothing
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 Name | Code 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.
Places declaration statements and executable code inside the terminate function.
LibMdlTerminateCustomCode(buffer, location)
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 |
Nothing
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 Name | Code 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.
Returns the code required to set the model error status.
LibSetRTModelErrorStatus("Overrun")str (string) — char * to a C string
See LibSetRTModelErrorStatus in matlabroot/rtw/c/tlc/mw/codetemplatelib.tlc.
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.
Note Custom templates is a feature of the Real-Time Workshop Embedded Coder product. |
%assign tag = LibSetSourceFileCodeTemplate(opFile,name)
opFile (scope) — Reference to file
name (string) — Name of the desired template
Nothing
See LibSetSourceFileCodeTemplate in matlabroot/rtw/c/tlc/mw/codetemplatelib.tlc.
Sets a custom section previously created with LibAddSourceFileCustomSection. Available only with the Real-Time Workshop 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 matlabroot/rtw/c/tlc/mw/codetemplatelib.tlc.
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.
%assign tag = LibSetSourceFileOutputDirectory(opFile,dirName)
opFile (scope) — Reference to file
dirName (string) — Name of the desired output directory
Nothing
See LibSetSourceFileOutputDirectory in matlabroot/rtw/c/tlc/mw/codetemplatelib.tlc.
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.
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")>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.
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 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 |
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 code format:
| Function Name | Code 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.
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 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 |
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 matlabroot/rtw/c/tlc/mw/hookslib.tlc.
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 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 |
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 matlabroot/rtw/c/tlc/mw/hookslib.tlc.
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 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 |
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 code format:
| Function Name | Code 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.
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 matlabroot/rtw/c/tlc/mw/hookslib.tlc.
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 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 |
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 code format:
| Function Name | Code 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.
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) 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 |
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 code format:
| Function Name | Code 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.
Returns necessary data for the model (valid for ERT only).
See LibWriteModelData in matlabroot/rtw/c/tlc/mw/codetemplatelib.tlc.
Returns the code necessary to write to a particular root input (i.e., a model inport block). Valid for ERT only.
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.
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.
Returns the code necessary to write to a particular root output (i.e., a model outport block). Valid for ERT only.
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.
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.
![]() | Block Path and Error Reporting Functions | Sample Time Functions | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |