-% Copyright (C) 2013 Czech Technical University in Prague
+% Copyright (C) 2013-2015 Czech Technical University in Prague
%
% Authors:
% - Carlos Jenkins <carlos@jenkins.co.cr>
%
-% This program is free software; you can redistribute it and/or modify
-% it under the terms of the GNU General Public License as published by
-% the Free Software Foundation; either version 2 of the License, or
-% (at your option) any later version.
-%
-% This program is distributed in the hope that it will be useful,
-% but WITHOUT ANY WARRANTY; without even the implied warranty of
-% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-% GNU General Public License for more details.
-%
-% You should have received a copy of the GNU General Public License
-% along with this program. If not, see <http://www.gnu.org/licenses/>.
+% Permission is hereby granted, free of charge, to any person
+% obtaining a copy of this software and associated documentation
+% files (the "Software"), to deal in the Software without
+% restriction, including without limitation the rights to use,
+% copy, modify, merge, publish, distribute, sublicense, and/or sell
+% copies of the Software, and to permit persons to whom the
+% Software is furnished to do so, subject to the following
+% conditions:
+
+% The above copyright notice and this permission notice shall be
+% included in all copies or substantial portions of the Software.
+
+% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+% EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+% OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+% NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+% HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+% WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+% FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+% OTHER DEALINGS IN THE SOFTWARE.
%
% File : rpp_download.m
% Abstract:
% Code download utility for Simulink RPP Target.
%
+% This function is executed by rpp_make_rtw_hook.m only if the build process
+% finished successfully and RPP_DOWNLOAD is set to TRUE. The RPP_DOWNLOAD option
+% is controlled by "Download to RPP board" option in RPP code generation options.
+%
+% Avoid executing this function with Code Composer Studio running on background.
+%
+% Parameters:
+% use_openocd - When set to TRUE, an OpenOCD will be used for the code
+% download. This tool is available only for Unix based systems.
+% When set to FALSE, a Texas Instruments Loader will be used.
+% for the code download. The TI tool is available for Unix based
+% systems and Windows.
+% This parameter is controled by "Use OpenOCD to download the compiled binary"
+% option in RPP code generation options.
+% use_sdram - When set to TRUE, the code will be downloaded into SDRAM. This option
+% requires a base code for the MPU, EMIF, POM and SDRAM configuration to
+% be present in the device Flash memory. The presence of the code is not
+% verified.
+% When set to FALSE, the code will be downloaded into the Flash memory.
+% This option is usefull for debugging as the Flash memory has very limited
+% number of rewrites.
+% NOTE: The code execution may be slower from the SDRAM than from the Flash.
+% NOTE: This function is not yet implemented.
+% This parameter is controlled by "Download compiled binary to SDRAM"
+% option in RPP code generation options.
+%
% References:
% loadti utility wiki at http://processors.wiki.ti.com/index.php/Loadti
% Readme file in <cssroot>/ccs_base/scripting/examples/loadti/readme.txt
+% OpenOCD wiki at https://rtime.felk.cvut.cz/hw/index.php/TMS570LS3137#OpenOCD_setup_and_Flashing
+function rpp_download(modelName, buildDirectory, use_openocd, use_sdram)
+ RppLibRoot = getpref('rpp', 'RppLibRoot');
+ CCSRoot = getpref('rpp', 'CCSRoot');
+
+ %TODO: parse the EXE_FILE_EXT from target_tools.mk
+ outfile = fullfile(buildDirectory, [modelName, '.out']);
+ downloadLog = fullfile(buildDirectory, 'download.log');
-function rpp_download(modelName, buildDirectory)
+ if use_openocd
+ if use_sdram
+ disp(['### Sorry, Downloading to the SDRAM is not yet implemented.'])
+ disp(['### -> Uncheck the option "Download compiled binary to SDRAM" (set use_openocd to false) to download the code to the Flash memory.'])
+ else
+ if isunix
+ command = [...
+ RppLibRoot '/../loadopenocd/loadopenocd.sh -d flash -b -s ' ...
+ , outfile, ' 2> ' , downloadLog ];
+ disp('### Running downloader script:');
+ disp(command);
+ status = system(command);
+ if status ~= 0,
+ throw(MException('rpp:targetDlErr', ['Failed to download ' modelName ' to the target']))
+ end
+ disp(['Done. <a href="matlab:open(''', downloadLog, ''')">Open download log.</a>']);
+ else
+ disp(['### Sorry code download via OpenOCD is available for UNIX systems only. Uncheck the option']);
+ disp(['### -> Uncheck the option "Use OpenOCD to download the compiled binary" to use Ti downloader, which is functional under Windows.']);
+ end
+ end
+ else
+ if use_sdram
+ disp(['### Sorry, Downloading to the SDRAM is not yet implemented.'])
+ disp(['### -> Uncheck the option "Download compiled binary to SDRAM" (set use_sdram to false) to download the code to the Flash memory.'])
+ else
+ disp(['### Downloading ', modelName, ' to RPP board...']);
+ ccxml_filename = ccxml_read(RppLibRoot);
+ if isunix
+ % -r, --reset Reset target before run
+ % -c, --cfg-file=CONFIG_FILE Target setup config file
+ command = [...
+ 'CCS_SCRIPTING="' CCSRoot '/ccs_base/scripting/" ' ...
+ '"' RppLibRoot '/../loadti/loadti.sh" -r ' ...
+ '-c "', ccxml_filename, '" ', ...
+ '"', outfile, ...
+ '" 2> "', downloadLog, '"'];
+ else
+ % -r, --reset Reset target before run
+ % -c, --cfg-file=CONFIG_FILE Target setup config file
+ command = [...
+ 'set CCS_SCRIPTING="' CCSRoot '\ccs_base\DebugServer"&&' ...
+ '"' RppLibRoot '\..\loadti\loadti.bat" -r ' ...
+ '-c "', ccxml_filename, '" ', ...
+ '"', outfile];
+ end
+ disp('### Running downloader script:');
+ disp(command);
+ status = system(command, '-echo');
+ if status ~= 0,
+ throw(MException('rpp:targetDlErr', ['Failed to download ' modelName ' to the target']))
+ end
+ disp(['Done. <a href="matlab:open(''', downloadLog, ''')">Open download log.</a>']);
+ end
+ end
- CCSRoot = getpref('rpp', 'CCSRoot');
- RppLibRoot = getpref('rpp', 'RppLibRoot');
-
- %TODO: parse the EXE_FILE_EXT from target_tools.mk
- outfile = fullfile(buildDirectory, [modelName, '.out']);
- downloadLog = fullfile(buildDirectory, 'download.log');
-
- if isunix
-
- disp(['### Downloading ', modelName, ' to RPP board...']);
-
- % -a, --async-run Run the specified executable and return without halting
- % -r, --reset Reset target before run
- % -c, --cfg-file=CONFIG_FILE Target setup config file
- system(['LD_PRELOAD="', ...
- CCSRoot, '/ccs_base/DebugServer/bin/libti_xpcom.so" "', ...
- CCSRoot, '/ccs_base/scripting/examples/loadti/loadti.sh" -a -r ', ...
- '-c "', RppLibRoot, '/TMS570LS3137.ccxml" ', ...
- '"', outfile, ...
- '" 2> "', downloadLog, '"']);
-
- disp(['Done. <a href="matlab:open(''', downloadLog, ''')">Open download log.</a>']);
+end
- else
- disp(['### Sorry code download is available for UNIX systems only.']);
- disp(['### -> Add support for non UNIX systems in <targetroot>/rpp/rpp_download.m file.']);
+function ccxml_path = ccxml_read(RppLibRoot)
+ f = fopen(fullfile(RppLibRoot, 'Makefile.config'), 'r');
+ while ~feof(f),
+ l = fgetl(f);
+ [val, count] = sscanf(l, ' TARGET_CCXML = %s');
+ if count, ccxml=val; end
+ [val, count] = sscanf(l, ' TARGET = %s');
+ if count, target=val; end
end
-end
+ ccxml_path = fullfile(RppLibRoot, 'build', target, ccxml);
+ fclose(f);
+end
\ No newline at end of file