| Real-Time Workshop | ![]() |
Tutorial: Creating a Custom Target Configuration
This tutorial walks through the task of creating a skeletal rapid prototyping target. This exercise illustrates several tasks that are usually required when creating a custom target:
You can use this process as a starting point for your own projects.
This example uses the LCC compiler under Windows. LCC is distributed with Real-Time Workshop. If you use a different compiler, you can set up LCC temporarily as your default compiler by typing the MATLAB command
A command prompt window will open; follow the prompts and select LCC.
| Note On UNIX systems, make sure that you have a C compiler installed. You can then do this exercise substituting appropriate UNIX directory syntax. |
In this example, the code is generated from targetModel.mdl, a very simple fixed-step model (see Figure 14-1). The resultant program behaves exactly as if it had been built for the generic real-time target.
The S-Function block will use the source code from the timestwo example. See the Writing S-Functions manual for a complete discussion of this S-function. The Target Language Compiler documentation discusses timestwo.tlc, the inlined version of timestwo.
To create the skeletal target system:
.tlc and .tmf files. We refer to this directory as d:/work/mytarget.
d:/work/mytarget to your MATLAB path.
d:/work/mytarget your working directory. Real-Time Workshop writes the output files of the code generation process into a build directory within the working directory.
timestwo S-function C source code from matlabroot/toolbox/rtw/rtwdemos/tlctutorial/timestwo/timestwo.c tod:/work/mytarget.
timestwo MEX-file in d:/work/mytarget.
fixed-step and ode4.
timestwo. The block is now bound to the timestwo MEX-file. Click OK.
timestwo S-function multiplies its input by 2.0.
timestwo S-Function block, you must have a corresponding TLC file in the working directory. If the Target Language Compiler detects a C-code S-function and a TLC file with the same name in the working directory, it generates inline code from the TLC file. Otherwise, it generates a function call to the external S-function.
timestwo block, copy the timestwo TLC source code from matlabroot/toolbox/rtw/rtwdemos/tlctutorial/timestwo/timestwo.tlc tod:/work/mytarget.
matlabroot/rtw/c/grt contains the main program (grt_main.c) and the system target file (grt.tlc) for the generic real-time target. Copy grt_main.c and grt.tlc to d:/work/mytarget. Rename them to mytarget_main.c and mytarget.tlc.
mytarget.tlc. The lines to remove are shown below.
my_target to the System Target File Browser. For now you should remove them.
rtwgensettings structure in the system target file.
Your build directory will be named targetModel__mytarget_rtw.
matlabroot/rtw/c/grt contains several compiler-specific template makefiles for the generic real-time target. The appropriate template makefile for the LCC compiler is grt_lcc.tmf. Copy grt_lcc.tmf to d:/work/mytarget, and rename it to mytarget.tmf.
mytarget.tmf. The SYS_TARGET FILE parameter must be changed so that the correct file reference is generated in the make file. Change the line
Also, change the source file list to include mytarget_main.c instead of grt_main.c.
REQ_SRCS = $(MODEL).c $(MODULES) mytarget_main.c...
mytarget_main.c. In an actual application, you would modify mytarget_main.c to execute your model code under the control of a timer interrupt, and make other changes.
mytarget.tmf) in the Make command field, as shown.
targetModel.exe file and the build directory, targetModel_mytarget_rtw.
d:/work/mytarget/targetModel_mytarget_rtw/targetModel.c and locate the MdlOutputs function. Observe the inlined code.
timestwo.tlc) with the same name as the timestwo S-Function block, the Target Language Compiler generated inline code instead of a function call to the external C- code S-function.
| Control Files | Customizing the Build Process | ![]() |