-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparallel_adder_init_xblock.m
More file actions
84 lines (77 loc) · 3.83 KB
/
parallel_adder_init_xblock.m
File metadata and controls
84 lines (77 loc) · 3.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% Center for Astronomy Signal Processing and Electronics Research %
% http://casper.berkeley.edu %
% Copyright (C) 2011 Hong Chen %
% %
% This program is free software; you can redistribute it and/or modify %
% it under the terms of the GNU General Public License as published by %
% the Free Software Foundation; either version 2 of the License, or %
% (at your option) any later version. %
% %
% This program is distributed in the hope that it will be useful, %
% but WITHOUT ANY WARRANTY; without even the implied warranty of %
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the %
% GNU General Public License for more details. %
% %
% You should have received a copy of the GNU General Public License along %
% with this program; if not, write to the Free Software Foundation, Inc., %
% 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function parallel_adder_init_xblock(n_inputs,R,add_latency)
sync_in = xInport('sync_in');
inports = cell(1,n_inputs);
sync_out = xOutport('sync_out');
outports = cell(1,n_inputs);
adder_tree_blks = cell(1,n_inputs);
adder_tree_inports = cell(n_inputs,R);
for i =1:n_inputs
inports{i} = xInport(['in',num2str(i)]);
outports{i} = xOutport(['out',num2str(i)]);
end
if n_inputs*2 > R
if R > n_inputs
delay_blks = cell(1,n_inputs);
delay_outs = cell(1,n_inputs);
for i = 1:n_inputs
delay_outs{i} = xSignal(['d',num2str(i)]);
delay_blks{i} = xBlock(struct('source','Delay','name', ['delay',num2str(i)]), ...
struct('latency', 1), ...
{inports{i}}, ...
{delay_outs{i}});
end
else
delay_blks = cell(1,R-1);
delay_outs = cell(1,n_inputs);
for i =1:R-1
delay_outs{n_inputs-i+1} = xSignal(['d',num2str(n_inputs-i+1)]);
delay_blks{i} = xBlock(struct('source','Delay','name', ['delay',num2str(n_inputs-i+1)]), ...
struct('latency', 1), ...
{inports{n_inputs-i+1}}, ...
{delay_outs{n_inputs-i+1}});
end
end
else
disp('not supported yet');
end
adder_tree_sync_in = cell(1,R+1);
adder_tree_sync_in{1} = sync_in;
for i =1:n_inputs
adder_tree_inports{i,1} = inports{i};
for j = 2:R
if i-j+1> 0
adder_tree_inports{i,j} = inports{i-j+1};
else
adder_tree_inports{i,j} = delay_outs{n_inputs+(i-j+1)};
end
end
adder_tree_sync_in{i+1} = xSignal(['adder_tree_sync_in',num2str(i+1)]);
adder_tree_sync_in{i+1} =xSignal(['adder_tree_sync_in',num2str(i)]);
adder_tree_blks{i} = xBlock(struct('source', str2func('adder_tree_init_xblock'),'name', ['adder_tree',num2str(i)]), ...
{R, add_latency, 'Round (unbiased: +/- Inf)', 'Saturate', 'Behavioral'}, ...
{adder_tree_sync_in{i},adder_tree_inports{i,:}}, ...
{adder_tree_sync_in{i+1},outports{i}});
end
sync_out.bind(adder_tree_sync_in{n_inputs+1});
end