Release 11 New Features |
Real-Time Workshop 2.2
Asynchronous Processes
The Real-Time Workshop added support for asynchronous interrupt handling in VxWorks and provides templates so that you can create your own interrupt handlers for your target hardware. These blocks include:RTWlib
in the Real-Time Workshop User's Guide (online version).
RTWlib
The Real-Time Workshop now has a graphical user interface (GUI), called RTWlib, for quick access to:Merge Block Added
The new Merge block merges multiple signals into one for reduced memory utilization and increased model flexibility.Level 2 S-Functions
Real-Time Workshop 2.2 supports Level 2 S-functions. In particular, these Level 2 S-functions support:mdlCheckParameters
mdlRTW
, a method for code generation in which your S-function influences the code generation process.
In mdlRTW
, you can write additional subrecords into the model.rtw
file for the S-function block record. The Target Language Compiler (TLC) file that inlines your S-function can use this information. For more details about Level 2 S-functions, see Writing S-Functions.
Target Language Compiler (TLC) Enhancements
This section describes enhancements to the Target Language Compiler that is included as part of the Real-Time Workshop.Passing Parameters: mdlRTW and RTWData
The Real-Time Workshop generates amodel.rtw
file that is a description of the model. There are two additional methods of passing user-specified information into the model.rtw
file:
mdlRTW
-- Used with Level 2 S-functions
RTWData
-- Used with any nonvirtual Simulink block and with empty subsystems
mdlRTW
function to pass information from a C-MEX S-function into the model.rtw
file for use during code generation.
The information that the mdlRTW
function writes to model.rtw
is used by the block target file for that block type. The writer of the block target file can use the additional identifier/value pairs as desired. For all the possible functions that you can use inside mdlRTW
to generate information in the model.rtw
file, see the file matlabroot
/simulink/src/sfuntmpl.doc
. See Chapter 8 of Using Simulink for a discussion of how to write an mdlRTW
function.
Below is an example of how to use mdlRTW
in a Level 2 S-function.
static void mdlRTW(SimStruct *S) { int_T numElements = mxGetNumberOfElements(TASK_NAME); char *buf = NULL; if ((buf = malloc(numElements +1)) == NULL) { ssSetErrorStatus(S,"memory allocation error in mdlRTW"); return; } if (mxGetString(TASK_NAME,buf,numElements+1) != 0) { ssSetErrorStatus(S,"mxGetString error in mdlRTW"); free(buf); return; } /* Write out the parameters for this block.*/ if (!ssWriteRTWParamSettings(S, 3, SSWRITE_VALUE_QSTR,"TaskName", buf, SSWRITE_VALUE_NUM,"Priority", (real_T) (*(mxGetPr(PRIORITY))), SSWRITE_VALUE_NUM,"StackSize", (real_T) (*(mxGetPr(STACK_SIZE))))) { return; /* An error occurred which will be reported by SL */ } /* Write out names for the IWork vectors.*/ if (!ssWriteRTWWorkVect(S, "IWork", 1, "TaskID", 1)) { return; /* An error occurred which will be reported by SL */ } /* Write out names for the PWork vectors.*/ if (!ssWriteRTWWorkVect(S, "PWork", 1, "SemID", 1)) { return; /* An error occurred which will be reported by SL */ } free(buf); }This code contains the resulting
model.rtw
information:
Block { . . . SFcnParamSettings { TaskName"" Priority20 StackSize1024 } NumIWorkDefines 1 IWorkDefine { Name "TaskID" Width 1 } NumPWorkDefines 1 PWorkDefine { Name "SemID" Width 1 } }RTWData.
RTWData
is a parameter that you can set on Simulink blocks using the set_param()
command and view with the get_param()
command. The parameter/value pair is saved along with the model.
The command syntax is
set_param(gcb,'rtwdata',userdata)where
gcb
is the current block pathname. The variable userdata
must be a MATLAB data structure where each element is a string. For example:
userdata.a = 'rpm' userdata.b = '1.25'When attached to a nonvirtual block, the associated
model.rtw
information for the block is:
Block { . . . RTWdata { a "rpm" b "1.25" } }The block target file for that block type can process the information as desired. For example, if
RTWData
is attached to a S-function, the TLC inlining file for the S-function could process the information in the BlockInstanceSetup
function.
Besides nonvirtual blocks, RTWData
can be attached to one special case of a virtual block, an empty subsystem. This allows information the be passed into the model.rtw
without it being associated with a specific nonvirtual block. This is useful when some block-independent information needs to be passed into model.rtw
for use during code generation. For empty subsystems, the RTWData
parameter is placed in the System
record for the nonvirtual system in which the empty subsystem is contained.
System { . . . EmptySubsysInfo { NumRTWdatas 1 RTWdata { a "rpm" b "1.25" } } }Because the empty subsystem technique is used by the Custom Code block of the
RTWLib
, there is support built into the system target files to handle RTWData
attached to empty subsystems. Specifically, if an EmptySubsysInfo
record exists, all RTWdata
subrecords are checked for the existence of an identifier named TLCFile
. If the identifier exists, the value of TLCFile
is used as a block target filename and the TLC function ProcessRTWdata
in that file is called using the TLC GENERATE
directive. This functionality can also be used by other (user-written) blocks if desired.