]> rtime.felk.cvut.cz Git - pes-rpp/rpp-simulink.git/blob - rpp/rpp/rpp_setup.m
Merge branches 'master' and 'rm48/master'
[pes-rpp/rpp-simulink.git] / rpp / rpp / rpp_setup.m
1 % Copyright (C) 2013, 2014, 2015 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_setup.m
12 % Abstract:
13 %     RPP Target install script.
14 %
15 %         This script configures RPP target for use. It stores the location of
16 %         armcl compiler and other location of other directories needed for
17 %         proper function of the target. Finally, it compiles S-Function
18 %         for RPP target blocks.
19 %
20 %         RPP_SETUP  RPP Target install script
21 %         RPP_SETUP asks for the path to the Code Composer Studio's compiler.
22 %         RPP_SETUP(PATH) uses the PATH argument as the path to the
23 %         compiler.
24 %
25 %
26 %     IMPORTANT: This script _MUST_ be run by user after extracting the target
27 %                package and before using the target. To execute:
28 %
29 %         1. Start Matlab.
30 %         2. Change directory (cd) to this file folder.
31 %         3. Execute rpp_setup on command window.
32 %
33 % References:
34 %     rtw_ug.pdf p. 1137
35
36 function rpp_setup(varargin)
37     % Get current target path in user's filesystem
38     currentPath = pwd();
39     targetPath = currentPath(1:end-length('/rpp'));
40
41     if nargin == 0,
42         % Ask user setup variables
43         if ispref('rpp', 'CompilerRoot')
44             possiblePath = getpref('rpp', 'CompilerRoot');
45         else
46             if isunix, prefix='/usr/local'; else prefix='C:'; end
47             possiblePath = [prefix, '/ti/ccsv5/tools/compiler/arm_5.1.1'];
48         end
49
50         CompilerRoot = fix_slash(uigetdir(possiblePath, ...
51                                           ['CCS Compiler root ' ...
52                             'directory: (<ccs_root>/tools/compiler/arm_5.X.X)']));
53     else
54         CompilerRoot = fix_slash(varargin{1});
55     end
56     CCSRoot      = fullfile(fileparts(fileparts(fileparts(CompilerRoot))));
57     TargetRoot   = fix_slash(currentPath);
58     RppLibRoot   = fullfile(fileparts(TargetRoot), 'lib');
59
60     if ispc, ext='.exe'; else ext=''; end
61     armcl = fullfile(CompilerRoot, 'bin', ['armcl' ext]);
62     if ~exist(armcl, 'file'),
63         fprintf('Error: "%s" does not exist!\n', armcl);
64         return;
65     end
66
67     % Remove old paths and preferences (if any)
68     if ispref('rpp')
69         oldTargetPath = getpref('rpp', 'TargetRoot');
70         rmpath(fullfile(oldTargetPath, '..', 'rpp'));
71         rmpath(fullfile(oldTargetPath, '..', 'demos'));
72         rmpath(fullfile(oldTargetPath, '..', 'blocks'));
73         rmpref('rpp');
74     end
75
76     % Add target system folders to Matlab path
77     addpath(fullfile(targetPath, 'rpp'));
78     addpath(fullfile(targetPath, 'demos'));
79     addpath(fullfile(targetPath, 'blocks'));
80     savepath();
81
82     % Save preferences
83     addpref('rpp', 'CompilerRoot', CompilerRoot);
84     addpref('rpp', 'CCSRoot'     , CCSRoot);
85     addpref('rpp', 'TargetRoot'  , TargetRoot);
86     addpref('rpp', 'RppLibRoot'  , RppLibRoot);
87
88
89     % Generate blocks and library
90     cd('../blocks');
91     compile_blocks();
92     rpp_generate_lib();
93     cd(currentPath);
94
95     % Generate help
96     % FIXME: Write and generate help
97     %cd('../help/source');
98     %genenerate_help();
99     %cd(currentPath);
100
101     % Apply changes and finish
102     sl_refresh_customizations();
103     disp('<strong>RPP</strong> Target setup is complete!');
104     disp('    Current configuration:');
105     disp(['        CompilerRoot : ', CompilerRoot]);
106     disp(['        CCSRoot      : ', CCSRoot]);
107     disp(['        TargetRoot   : ', TargetRoot]);
108     disp(['        RppLibRoot   : ', RppLibRoot]);
109     disp('Explore <a href="matlab:cd([getpref(''rpp'',''TargetRoot''),''/../demos''])">demos</a> directory.');
110     %disp('Explore <a href="matlab:cd([getpref(''rpp'',''TargetRoot''),''/../demos''])">demos</a> directory and access <a href="matlab:doc -classic">documentation</a>');
111 end
112
113
114 function path = fix_slash(path0)
115     path = path0;
116     if ispc
117         path(path=='\')='/';
118     end
119 end