1 % Copyright (C) 2013-2015 Czech Technical University in Prague
4 % - Carlos Jenkins <carlos@jenkins.co.cr>
6 % This document contains proprietary information belonging to Czech
7 % Technical University in Prague. Passing on and copying of this
8 % document, and communication of its contents is not permitted
9 % without prior written authorization.
11 % File : rpp_make_rtw_hook.m
13 % Build process hooks file.
15 % This file is hook file that invoke target-specific functions or
16 % executables at specified points in the build process. In particular, this
17 % file handle the copying of required files before the compilation stage.
20 % rtw_ug.pdf p. 1066-1072 and 1131
22 function rpp_make_rtw_hook(hookMethod, modelName, rtwRoot, templateMakefile, ...
27 % Called if an error occurs anywhere during the build. If no error
28 % occurs during the build, then this hook will not be called. Valid
29 % arguments at this stage are hookMethod and modelName. This enables
30 % cleaning up any static or global data used by this hook file.
31 disp(['### Build procedure for model: ''', modelName, ...
32 ''' aborted due to an error.']);
36 % Called at start of code generation process (before anything
38 % Valid arguments at this stage are hookMethod, modelName, and
41 % FIXME: Implement step integrity verification?
45 % Called just prior to invoking TLC Compiler (actual code
47 % Valid arguments at this stage are hookMethod, modelName, and
52 % Called just after to invoking TLC Compiler (actual code
54 % Valid arguments at this stage are hookMethod, modelName, and
57 % FIXME: Implement model tasking mode check?
61 % Called after code generation is complete, and just prior to
62 % kicking off make process (assuming code generation only is not
63 % selected). All arguments are valid at this stage.
65 % Copy extra runtime header to code generation directory
66 copyfile(fullfile(getpref('rpp', 'TargetRoot'), 'rpp_simulink_runtime.h'));
68 % Copy extra makefiles and library files to code generation
70 rpp_write_makefiles(modelName);
74 % Called after make process is complete. All arguments are valid at
77 % Download generated binary to the board
78 rpp_do_download(modelName);
82 % Called at the end of the build process. All arguments are valid
84 disp(['### Successful completion of build ', ...
85 'procedure for model: ', modelName]);
91 function rpp_write_makefiles(modelName)
93 modelRoot = Simulink.fileGenControl('getConfig').CodeGenFolder;
94 buildFolder = fullfile(modelRoot, 'slprj');
96 % Get configuration variables and create paths configuration makefile
97 CompilerRoot = getpref('rpp', 'CompilerRoot');
98 CCSRoot = getpref('rpp', 'CCSRoot');
99 TargetRoot = getpref('rpp', 'TargetRoot');
100 RppLibRoot = getpref('rpp', 'RppLibRoot');
102 TargetPaths = fullfile(buildFolder, 'target_paths.mk');
104 fid = fopen(TargetPaths, 'w');
105 fwrite(fid, sprintf('%s\n\n', '# RPP paths'));
106 fwrite(fid, sprintf('COMPILER_ROOT = %s\n', CompilerRoot));
107 fwrite(fid, sprintf('CCS_ROOT = %s\n', CCSRoot));
108 fwrite(fid, sprintf('TARGET_ROOT = %s\n', TargetRoot));
109 fwrite(fid, sprintf('RPP_LIB_ROOT = %s\n', RppLibRoot));
112 % Copy the RPP version of target_tools.mk into the build area
113 tgtToolsFile = 'target_tools.mk';
114 copyfile(fullfile(TargetRoot, tgtToolsFile), ...
115 fullfile(buildFolder, tgtToolsFile));
120 function rpp_do_download(modelName)
121 if verLessThan('matlab', '8.1')
122 makertwObj = get_param(gcs, 'MakeRTWSettingsObject');
123 makertwBuildDirectory = makertwObj.BuildDirectory;
124 makertwArgs = makertwObj.BuildInfo.BuildArgs;
126 makertwObj = rtwprivate('get_makertwsettings', gcs, 'BuildInfo');
127 makertwBuildDirectory = rtwprivate('get_makertwsettings', gcs, 'BuildDirectory');
128 makertwArgs = makertwObj.BuildArgs;
131 % Check if user choose to Download to RPP board in Settings
135 for i=1:length(makertwArgs)
136 if strcmp(makertwArgs(i).DisplayLabel, 'RPP_DOWNLOAD')
137 download = str2double(makertwArgs(i).Value);
138 elseif strcmp(makertwArgs(i).DisplayLabel, 'RPP_USE_OPENOCD')
139 use_openocd = str2double(makertwArgs(i).Value);
140 elseif strcmp(makertwArgs(i).DisplayLabel, 'RPP_DOWNLOAD_TO_SDRAM')
141 use_sdram = str2double(makertwArgs(i).Value);
146 if getenv('RPP_NO_DOWNLOAD')
147 disp(['RPP_NO_DOWNLOAD defined - skipping downloading to target.'])
149 rpp_download(modelName, makertwBuildDirectory, use_openocd, use_sdram);