Real-Time Workshop User's Guide | ![]() ![]() |
Model Code Sublibrary
The Model Code sublibrary contains 10 blocks that insert custom code into the generated model files and functions. You can view the blocks either by:
The latter method opens this window.
The four blocks on the top row contain texts fields to insert custom code at the top and bottom of the following files:
model.h
-- Header File blockmodel_prm.h
-- Parameter File blockmodel.c
-- Source File blockmodel_reg.h
-- Registration File blockThe six function blocks in the second and third rows contain text fields to insert critical code sections at the top and bottom of these designated model functions:
Registration function
-- Registration Function blockMdlStart
-- MdlStart Function blockMdlTerminate
-- MdlTerminate Function blockMdlOutputs
-- MdlOutputs Function blockMdlUpdate
-- MdlUpdate Function blockMdlDerivatives
-- MdlDerivatives Function blockEach block provides a dialog box that contains three fields.
Example: Using a Custom Code Block
The following example uses an MdlStart Function block to introduce code into the MdlStart
function. The diagram below shows a simple model with the Model Start Function block inserted.
Double-clicking the Model Start Function block opens the Model Start Function Custom Code dialog box.
You can insert custom code into any or all of the available text fields.
The code below is the MdlStart
function for this example (mymodel
).
void MdlStart(void) { /* user code (Start function Header) */ /* System: <Root> */ unsigned int *ptr = 0xFFEE; /* user code (Start function Body) */ /* System: <Root> */ /* Initialize hardware */ *ptr = 0; /* state initialization */ /* DiscreteFilter Block: <Root>/Discrete Filter */ rtX.d.Discrete_Filter = 0.0; }
The custom code entered in the Model Start Function Custom Code dialog box is embedded directly in the generated code. Note that each block of custom code is tagged with a comment such as
/* user code (Start function Header) */
![]() | Custom Code Library | Subsystem Code Sublibrary | ![]() |