--- /dev/null
+% Copyright (C) 2013-2014 Czech Technical University in Prague
+%
+% Authors:
+% - Michal Horn <hornmich@fel.cvut.cz>
+%
+% This document contains proprietary information belonging to Czech
+% Technical University in Prague. Passing on and copying of this
+% document, and communication of its contents is not permitted
+% without prior written authorization.
+%
+% File : rpp_generate_lib.m
+% Abstract:
+% Generates library rpp_lib.slx for targets
+%
+% References:
+% http://www.mathworks.com/help/matlab/ref/mex.html
+% http://www.mathworks.com/help/matlab/matlab_external/custom-building-mex-files.html
+
+%% This array contains a set of blocks, which are distributed
+%% with the [platform TMS570 RPP. The blocks names are derived
+%% from the names of their slx files without the .slx suffix.
+tms570_rpp_blocks = {
+ 'rpp_ain',
+ 'rpp_aout',
+ 'rpp_can_rx',
+ 'rpp_can_setup',
+ 'rpp_can_tx',
+ 'rpp_din',
+ 'rpp_din_cfg',
+ 'rpp_dout',
+ 'rpp_fr_cfg',
+ 'rpp_fr_rx',
+ 'rpp_fr_tx',
+ 'rpp_hbr',
+ 'rpp_ircin',
+ 'rpp_log',
+ 'rpp_overrun',
+ 'rpp_power',
+ 'rpp_sci_cfg',
+ 'rpp_sci_printf',
+ 'rpp_sci_rx',
+ 'rpp_sci_tx'
+};
+
+%% This array contains a list of all targets, for which the
+%% library will be generated.
+%% Each record contains two items:
+%% 1. the name of the directory containing the generated
+%% library for the target,
+%% 2. the reference to the list of blocks assigned to the
+%% target.
+targets = {
+ {'_tms570_rpp', tms570_rpp_blocks}
+};
+
+resultLibName = 'rpp_lib';
+
+for i=1:length(targets),
+ disp(['Generating library for target: ', targets{i}{1}]);
+ libFilePath=[targets{i}{1}, '/', resultLibName, '.slx'];
+ load_system(libFilePath);
+ set_param(resultLibName, 'Lock', 'off');
+ blocks = find_system(resultLibName, 'Type', 'block');
+ disp('Removing old blocks:');
+ for j=1:length(blocks),
+ disp([' ', blocks{j}]);
+ delete_block(blocks{j});
+ end
+ disp('Adding new blocks:');
+ for j=1:length(targets{i}{2}),
+ blockFilePath=[targets{i}{2}{j}, '.slx'];
+ disp([' from: ', blockFilePath, ':']);
+ load_system(blockFilePath)
+ blocks = find_system(targets{i}{2}{j}, 'Type', 'block');
+ for k=1:length(blocks),
+ [tok, blockName] = strtok(blocks{k}, '/');
+ blockName = [resultLibName, blockName];
+ disp([' ', blocks{k}, ' as ', blockName]);
+ add_block(blocks{k}, blockName);
+ end
+ close_system(blockFilePath, 0);
+ end
+ disp(['Closing and saving file ', libFilePath]);
+ set_param(resultLibName, 'Lock', 'on');
+ close_system(libFilePath, 1);
+end
+
+