1 % Copyright (C) 2013-2015 Czech Technical University in Prague
4 % - Carlos Jenkins <carlos@jenkins.co.cr>
6 % Permission is hereby granted, free of charge, to any person
7 % obtaining a copy of this software and associated documentation
8 % files (the "Software"), to deal in the Software without
9 % restriction, including without limitation the rights to use,
10 % copy, modify, merge, publish, distribute, sublicense, and/or sell
11 % copies of the Software, and to permit persons to whom the
12 % Software is furnished to do so, subject to the following
15 % The above copyright notice and this permission notice shall be
16 % included in all copies or substantial portions of the Software.
18 % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 % EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
20 % OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 % NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22 % HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23 % WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 % FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25 % OTHER DEALINGS IN THE SOFTWARE.
27 % File : rpp_make_rtw_hook.m
29 % Build process hooks file.
31 % This file is hook file that invoke target-specific functions or
32 % executables at specified points in the build process. In particular, this
33 % file handle the copying of required files before the compilation stage.
36 % rtw_ug.pdf p. 1066-1072 and 1131
38 function rpp_make_rtw_hook(hookMethod, modelName, rtwRoot, templateMakefile, ...
43 % Called if an error occurs anywhere during the build. If no error
44 % occurs during the build, then this hook will not be called. Valid
45 % arguments at this stage are hookMethod and modelName. This enables
46 % cleaning up any static or global data used by this hook file.
47 disp(['### Build procedure for model: ''', modelName, ...
48 ''' aborted due to an error.']);
52 % Called at start of code generation process (before anything
54 % Valid arguments at this stage are hookMethod, modelName, and
57 % FIXME: Implement step integrity verification?
61 % Called just prior to invoking TLC Compiler (actual code
63 % Valid arguments at this stage are hookMethod, modelName, and
68 % Called just after to invoking TLC Compiler (actual code
70 % Valid arguments at this stage are hookMethod, modelName, and
73 % FIXME: Implement model tasking mode check?
77 % Called after code generation is complete, and just prior to
78 % kicking off make process (assuming code generation only is not
79 % selected). All arguments are valid at this stage.
81 % Copy extra runtime header to code generation directory
82 copyfile(fullfile(getpref('rpp', 'TargetRoot'), 'rpp_simulink_runtime.h'));
84 % Copy extra makefiles and library files to code generation
86 rpp_write_makefiles(modelName);
90 % Called after make process is complete. All arguments are valid at
93 % Download generated binary to the board
94 rpp_do_download(modelName);
98 % Called at the end of the build process. All arguments are valid
100 disp(['### Successful completion of build ', ...
101 'procedure for model: ', modelName]);
107 function rpp_write_makefiles(modelName)
109 modelRoot = Simulink.fileGenControl('getConfig').CodeGenFolder;
110 buildFolder = fullfile(modelRoot, 'slprj');
112 % Get configuration variables and create paths configuration makefile
113 CompilerRoot = getpref('rpp', 'CompilerRoot');
114 CCSRoot = getpref('rpp', 'CCSRoot');
115 TargetRoot = getpref('rpp', 'TargetRoot');
116 RppLibRoot = getpref('rpp', 'RppLibRoot');
118 TargetPaths = fullfile(buildFolder, 'target_paths.mk');
120 fid = fopen(TargetPaths, 'w');
121 fwrite(fid, sprintf('%s\n\n', '# RPP paths'));
122 fwrite(fid, sprintf('COMPILER_ROOT = %s\n', CompilerRoot));
123 fwrite(fid, sprintf('CCS_ROOT = %s\n', CCSRoot));
124 fwrite(fid, sprintf('TARGET_ROOT = %s\n', TargetRoot));
125 fwrite(fid, sprintf('RPP_LIB_ROOT = %s\n', RppLibRoot));
128 % Copy the RPP version of target_tools.mk into the build area
129 tgtToolsFile = 'target_tools.mk';
130 copyfile(fullfile(TargetRoot, tgtToolsFile), ...
131 fullfile(buildFolder, tgtToolsFile));
136 function rpp_do_download(modelName)
137 if verLessThan('matlab', '8.1')
138 makertwObj = get_param(gcs, 'MakeRTWSettingsObject');
139 makertwBuildDirectory = makertwObj.BuildDirectory;
140 makertwArgs = makertwObj.BuildInfo.BuildArgs;
142 makertwObj = rtwprivate('get_makertwsettings', gcs, 'BuildInfo');
143 makertwBuildDirectory = rtwprivate('get_makertwsettings', gcs, 'BuildDirectory');
144 makertwArgs = makertwObj.BuildArgs;
147 % Check if user choose to Download to RPP board in Settings
151 for i=1:length(makertwArgs)
152 if strcmp(makertwArgs(i).DisplayLabel, 'RPP_DOWNLOAD')
153 download = str2double(makertwArgs(i).Value);
154 elseif strcmp(makertwArgs(i).DisplayLabel, 'RPP_USE_OPENOCD')
155 use_openocd = str2double(makertwArgs(i).Value);
156 elseif strcmp(makertwArgs(i).DisplayLabel, 'RPP_DOWNLOAD_TO_SDRAM')
157 use_sdram = str2double(makertwArgs(i).Value);
162 if getenv('RPP_NO_DOWNLOAD')
163 disp(['RPP_NO_DOWNLOAD defined - skipping downloading to target.'])
165 rpp_download(modelName, makertwBuildDirectory, use_openocd, use_sdram);