Target Language Compiler |
 |
Generate Code Without a Wrapper
Before creating a wrapper, generate code that uses the Simulink generic API.
- Build a stand-alone model (the file will be called
externalcode.exe
in Windows and externalcode
in UNIX environments). Click Tools -> Real-Time Workshop -> Build Model, or type Ctrl+B. Simulink will report the results, as follows:

|
|

|
### Creating project marker file: rtw_proj.tmw
### Creating externalcode.mk from D:\MATLAB6p1\rtw\c\grt\grt_lcc.tmf
### Building externalcode: .\externalcode.bat
D:\Work\wrapper\externalcode_grt_rtw>set MATLAB=D:\MATLAB6p1
D:\Work\wrapper\externalcode_grt_rtw>"D:\MATLAB6p1\rtw\bin\win32\gmake" -f
externalcode.mk
D:\MATLAB6p1\sys\lcc\bin\lcc -c -Foexternalcode.obj -DMODEL=externalcode
-DRT -DNUMST=2 -DTID01EQ=1 -DNCSTATES=0 -DMT=0 -DHAVESTDIO -I. -I..
-ID:\MATLAB6p1\simulink\include -ID:\MATLAB6p1\extern\include
-ID:\MATLAB6p1\rtw\c\src -ID:\MATLAB6p1\rtw\c\libsrc
-ID:\MATLAB6p1\sys\lcc\include -noregistrylookup externalcode.c
Warning: externalcode.c: 41 Statement has no effect
0 errors, 1 warnings
|

|
|

|
|
- Real-Time Workshop creates the stand-alone program,
externalcode.exe
, in your working directory and places the source and object files in your build directory.
- Run the stand-alone to see that it behaves the same as the Simulink version. There should be no differences:
- Inspect the
mdloutputs()
function of the code in wrapsfcn.c
to see how the external function is called:
static void mdlOutputs(SimStruct *S, int tid)
{
int_T i; /* not needed */
InputRealPtrsType uPtrs = ssGetInputPortRealSignalPtrs(S,0);
real_T *y = ssGetOutputPortRealSignal(S,0);
int_T width = ssGetOutputPortWidth(S,0);
*y = my_alg(*uPtrs[0]);
}
- Notice this line in
wrapsfcn.c
:
This pulls in the external function. That function consists entirely of
Generally, functions to be wrapped are either included in the wrapper, as above, or (when object modules are being wrapped) are resolved at link time.
| Getting Started | | Generate Code Using a Wrapper |  |