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