]> rtime.felk.cvut.cz Git - jenkicar/rpp-simulink.git/blob - rpp/blocks/rpp_generate_lib.m
Change file name of the ADC block
[jenkicar/rpp-simulink.git] / rpp / blocks / rpp_generate_lib.m
1 % Copyright (C) 2013-2014 Czech Technical University in Prague
2 %
3 % Authors:
4 %     - Michal Horn <hornmich@fel.cvut.cz>
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_generate_lib.m
12 % Abstract:
13 %     Generates library rpp_lib.slx for targets
14 %
15 % References:
16 %     http://www.mathworks.com/help/matlab/ref/mex.html
17 %     http://www.mathworks.com/help/matlab/matlab_external/custom-building-mex-files.html
18
19 %% This array contains a set of blocks, which are distributed
20 %% with the [platform TMS570 RPP. The blocks names are derived
21 %% from the names of their slx files without the .slx suffix.
22 tms570_rpp_blocks = {
23         'rpp_rpp_ain',
24         'rpp_aout',
25         'rpp_can_rx',
26         'rpp_can_setup',
27         'rpp_can_tx',
28         'rpp_din',
29         'rpp_din_cfg',
30         'rpp_dout',
31         'rpp_fr_cfg',
32         'rpp_fr_rx',
33         'rpp_fr_tx',
34         'rpp_hbr',
35         'rpp_ircin',
36         'rpp_log',
37         'rpp_overrun',
38         'rpp_power',
39         'rpp_sci_cfg',
40         'rpp_sci_printf',
41         'rpp_sci_rx',
42         'rpp_sci_tx'
43 };
44
45 %% This array contains a list of all targets, for which the
46 %% library will be generated.
47 %% Each record contains two items:
48 %%     1. the name of the directory containing the generated
49 %%        library for the target,
50 %%     2. the reference to the list of blocks assigned to the
51 %%        target.
52 targets = {
53         {'_tms570_rpp', tms570_rpp_blocks}
54 };
55
56 resultLibName = 'rpp_lib';
57
58 for i=1:length(targets),
59         disp(['Generating library for target: ', targets{i}{1}]);
60         libFilePath=[targets{i}{1}, '/', resultLibName, '.slx'];
61         load_system(libFilePath);
62         set_param(resultLibName, 'Lock', 'off');
63         blocks = find_system(resultLibName, 'Type', 'block');
64         disp('Removing old blocks:');
65         for j=1:length(blocks),
66                 disp(['    ', blocks{j}]);
67                 delete_block(blocks{j});
68         end
69         disp('Adding new blocks:');
70         for j=1:length(targets{i}{2}),
71                 blockFilePath=[targets{i}{2}{j}, '.slx'];
72                 disp(['    from: ', blockFilePath, ':']);
73                 load_system(blockFilePath)
74                 blocks = find_system(targets{i}{2}{j}, 'Type', 'block');
75                 for k=1:length(blocks),
76                         [tok, blockName] = strtok(blocks{k}, '/');
77                         blockName = [resultLibName, blockName];
78                         disp(['        ', blocks{k}, ' as ', blockName]);
79                         add_block(blocks{k}, blockName);
80                 end
81                 close_system(blockFilePath, 0);
82         end
83         disp(['Closing and saving file ', libFilePath]);
84         set_param(resultLibName, 'Lock', 'on');
85         close_system(libFilePath, 1);
86 end
87
88