]> rtime.felk.cvut.cz Git - jenkicar/rpp-simulink.git/blob - rpp/rpp/rpp_setup.m
e402b48300e24aa615d420e81179729f07f0d84f
[jenkicar/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 ~exist(fullfile(targetPath, 'rpp', 'rpp_setup.m'), 'file'),
42         error('rpp:wrong_setup_dir', ['rpp_setup called from directory ' ...
43                             'other than .../rpp/rpp']);
44     end
45
46     if nargin == 0,
47         % Ask user setup variables
48         if ispref('rpp', 'CompilerRoot')
49             possiblePath = getpref('rpp', 'CompilerRoot');
50         else
51             if isunix, prefix='/usr/local'; else prefix='C:'; end
52             possiblePath = [prefix, '/ti/ccsv5/tools/compiler/arm_5.1.1'];
53         end
54
55         CompilerRoot = fix_slash(uigetdir(possiblePath, ...
56                                           ['CCS Compiler root ' ...
57                             'directory: (<ccs_root>/tools/compiler/arm_5.X.X)']));
58     else
59         CompilerRoot = fix_slash(varargin{1});
60     end
61     CCSRoot      = fullfile(fileparts(fileparts(fileparts(CompilerRoot))));
62     TargetRoot   = fix_slash(currentPath);
63     RppLibRoot   = fullfile(fileparts(TargetRoot), 'lib');
64
65     if ispc, ext='.exe'; else ext=''; end
66     armcl = fullfile(CompilerRoot, 'bin', ['armcl' ext]);
67     if ~exist(armcl, 'file'),
68         fprintf('Error: "%s" does not exist!\n', armcl);
69         return;
70     end
71
72     % Remove old paths and preferences (if any)
73     if ispref('rpp')
74         oldTargetPath = getpref('rpp', 'TargetRoot');
75         rmpath(fullfile(oldTargetPath, '..', 'rpp'));
76         rmpath(fullfile(oldTargetPath, '..', 'demos'));
77         rmpath(fullfile(oldTargetPath, '..', 'blocks'));
78         rmpref('rpp');
79     end
80
81     % Add target system folders to Matlab path
82     addpath(fullfile(targetPath, 'rpp'));
83     addpath(fullfile(targetPath, 'demos'));
84     addpath(fullfile(targetPath, 'blocks'));
85     savepath();
86
87     % Save preferences
88     addpref('rpp', 'CompilerRoot', CompilerRoot);
89     addpref('rpp', 'CCSRoot'     , CCSRoot);
90     addpref('rpp', 'TargetRoot'  , TargetRoot);
91     addpref('rpp', 'RppLibRoot'  , RppLibRoot);
92
93
94     % Generate blocks and library
95     cd('../blocks');
96     compile_blocks();
97     rpp_update_blocks_for_target()
98     rpp_generate_lib();
99     cd(currentPath);
100
101     % Generate help
102     % FIXME: Write and generate help
103     %cd('../help/source');
104     %genenerate_help();
105     %cd(currentPath);
106
107     % Apply changes and finish
108     sl_refresh_customizations();
109     disp('<strong>RPP</strong> Target setup is complete!');
110     disp('    Current configuration:');
111     disp(['        CompilerRoot : ', CompilerRoot]);
112     disp(['        CCSRoot      : ', CCSRoot]);
113     disp(['        TargetRoot   : ', TargetRoot]);
114     disp(['        RppLibRoot   : ', RppLibRoot]);
115     disp(['        Hardware     : ', rpp_get_target]);
116     disp('Explore <a href="matlab:cd([getpref(''rpp'',''TargetRoot''),''/../demos''])">demos</a> directory.');
117     %disp('Explore <a href="matlab:cd([getpref(''rpp'',''TargetRoot''),''/../demos''])">demos</a> directory and access <a href="matlab:doc -classic">documentation</a>');
118 end
119
120
121 function path = fix_slash(path0)
122     path = path0;
123     if ispc
124         path(path=='\')='/';
125     end
126 end