]> rtime.felk.cvut.cz Git - pes-rpp/rpp-simulink.git/blob - rpp/rpp/rpp_download.m
Add parameters names to error messages
[pes-rpp/rpp-simulink.git] / rpp / rpp / rpp_download.m
1 % Copyright (C) 2013-2014 Czech Technical University in Prague
2 %
3 % Authors:
4 %     - Carlos Jenkins <carlos@jenkins.co.cr>
5 %
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.
10 %
11 % File : rpp_download.m
12 % Abstract:
13 %     Code download utility for Simulink RPP Target.
14 %
15 %     This function is optionally executed at the end of the build process
16 %     if it is successful and the user selected "Download compiled binary to
17 %     RPP" option on the build configuration panel. This function calls
18 %     loadti.sh script with the generated binary and using configuration for
19 %     the XDS100v2 JTAG Emulators.
20 %
21 % References:
22 %     loadti utility wiki at http://processors.wiki.ti.com/index.php/Loadti
23 %     Readme file in <cssroot>/ccs_base/scripting/examples/loadti/readme.txt
24
25
26 function rpp_download(modelName, buildDirectory, use_openocd, use_sdram)
27         RppLibRoot = getpref('rpp', 'RppLibRoot');
28         CCSRoot    = getpref('rpp', 'CCSRoot');
29         
30         %TODO: parse the EXE_FILE_EXT from target_tools.mk
31         outfile     = fullfile(buildDirectory, [modelName, '.out']);
32         downloadLog = fullfile(buildDirectory, 'download.log');
33
34         if use_openocd
35                 if use_sdram
36                         disp(['### Sorry, Downloading to the SDRAM is not yet implemented.'])
37                         disp(['###     -> Uncheck the option "Download compiled binary to SDRAM" (set use_openocd to false) to download the code to the Flash memory.'])
38                 else
39                         if isunix
40                                 command = [...
41                                         RppLibRoot '/../loadopenocd/loadopenocd.sh -d flash -b -s ' ...
42                                         , outfile, ' 2> ' , downloadLog ];
43                                 disp('### Running downloader script:');
44                                 disp(command);
45                                 status = system(command);
46                                 if status ~= 0,
47                                         throw(MException('rpp:targetDlErr', ['Failed to download ' modelName ' to the target']))
48                                 end
49                                 disp(['Done. <a href="matlab:open(''', downloadLog, ''')">Open download log.</a>']);                    
50                         else
51                                 disp(['### Sorry code download via OpenOCD is available for UNIX systems only. Uncheck the option']);
52                                 disp(['###     -> Uncheck the option "Use OpenOCD to download the compiled binary" to use Ti downloader, which is functional under Windows.']);
53                         end
54                 end
55         else
56                 if use_sdram
57                         disp(['### Sorry, Downloading to the SDRAM is not yet implemented.'])
58                         disp(['###     -> Uncheck the option "Download compiled binary to SDRAM" (set use_sdram to false) to download the code to the Flash memory.'])
59                 else
60                         if isunix
61
62                                 disp(['### Downloading ', modelName, ' to RPP board...']);
63
64                                 % -r,   --reset                 Reset target before run
65                                 % -c,   --cfg-file=CONFIG_FILE  Target setup config file
66                                 command = [...
67                                         'CCS_SCRIPTING="' CCSRoot '/ccs_base/scripting/" ' ...
68                                         '"' RppLibRoot '/../loadti/loadti.sh" -r ' ...
69                                         '-c "', RppLibRoot, '/rpp/TMS570LS3137.ccxml" ', ...
70                                         '"', outfile, ...
71                                         '" 2> "', downloadLog, '"'];
72                                 disp('### Running downloader script:');
73                                 disp(command);
74                                 status = system(command);
75                                 if status ~= 0,
76                                         throw(MException('rpp:targetDlErr', ['Failed to download ' modelName ' to the target']))
77                                 end
78
79                                 disp(['Done. <a href="matlab:open(''', downloadLog, ''')">Open download log.</a>']);
80
81                         else
82                                 disp(['### Sorry code download for Windows is not yet implemented.']);
83                                 disp(['###     -> Add support for non UNIX systems in <targetroot>/rpp/rpp_download.m file.']);
84                         end     
85                 end
86         end
87
88 end