]> rtime.felk.cvut.cz Git - pes-rpp/rpp-simulink.git/blob - rpp/rpp/rpp_download.m
Undefined variable fixed
[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                         command = [...
37                                 RppLibRoot '/../loadopenocd/loadopenocd.sh -d flash -b -s ' ...
38                                 , outfile, ' 2> ' , downloadLog ];
39                         disp('### Running downloader script:');
40                         disp(command);
41                         status = system(command);
42                         if status ~= 0,
43                                 throw(MException('rpp:targetDlErr', ['Failed to download ' modelName ' to the target']))
44                         end
45                         disp(['Done. <a href="matlab:open(''', downloadLog, ''')">Open download log.</a>']);                    
46                 else
47                         if isunix
48                                 command = [...
49                                         RppLibRoot '/../loadopenocd/loadopenocd.sh -d flash -b -s ' ...
50                                         , outfile, ' 2> ' , downloadLog ];
51                                 disp('### Running downloader script:');
52                                 disp(command);
53                                 status = system(command);
54                                 if status ~= 0,
55                                         throw(MException('rpp:targetDlErr', ['Failed to download ' modelName ' to the target']))
56                                 end
57                                 disp(['Done. <a href="matlab:open(''', downloadLog, ''')">Open download log.</a>']);                    
58                         else
59                                 disp(['### Sorry code download is available for UNIX systems only.']);
60                                 disp(['###     -> Add support for non UNIX systems in <targetroot>/rpp/rpp_download.m file.']);
61                         end
62                 end
63         else
64                 if use_sdram
65                         disp(['### Sorry, Downloading to the SDRAM is not yet implemented.'])
66                 else
67                         if isunix
68
69                                 disp(['### Downloading ', modelName, ' to RPP board...']);
70
71                                 % -a,   --async-run             Run the specified executable and return without halting
72                                 % -r,   --reset                 Reset target before run
73                                 % -c,   --cfg-file=CONFIG_FILE  Target setup config file
74                                 command = [...
75                                         'CCS_SCRIPTING="' CCSRoot '/ccs_base/scripting/" ' ...
76                                         '"' RppLibRoot '/../loadti/loadti.sh" -a -r ' ...
77                                         '-c "', RppLibRoot, '/rpp/TMS570LS3137.ccxml" ', ...
78                                         '"', outfile, ...
79                                         '" 2> "', downloadLog, '"'];
80                                 disp('### Running downloader script:');
81                                 disp(command);
82                                 status = system(command);
83                                 if status ~= 0,
84                                         throw(MException('rpp:targetDlErr', ['Failed to download ' modelName ' to the target']))
85                                 end
86
87                                 disp(['Done. <a href="matlab:open(''', downloadLog, ''')">Open download log.</a>']);
88
89                         else
90                                 disp(['### Sorry code download is available for UNIX systems only.']);
91                                 disp(['###     -> Add support for non UNIX systems in <targetroot>/rpp/rpp_download.m file.']);
92                         end     
93                 end
94         end
95
96 end