1 |
2 |
danv |
-------------------------------------------------------------------------------
|
2 |
|
|
--
|
3 |
|
|
-- Copyright (C) 2010
|
4 |
|
|
-- ASTRON (Netherlands Institute for Radio Astronomy) <http://www.astron.nl/>
|
5 |
|
|
-- JIVE (Joint Institute for VLBI in Europe) <http://www.jive.nl/>
|
6 |
|
|
-- P.O.Box 2, 7990 AA Dwingeloo, The Netherlands
|
7 |
|
|
--
|
8 |
|
|
-- This program is free software: you can redistribute it and/or modify
|
9 |
|
|
-- it under the terms of the GNU General Public License as published by
|
10 |
|
|
-- the Free Software Foundation, either version 3 of the License, or
|
11 |
|
|
-- (at your option) any later version.
|
12 |
|
|
--
|
13 |
|
|
-- This program is distributed in the hope that it will be useful,
|
14 |
|
|
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15 |
|
|
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16 |
|
|
-- GNU General Public License for more details.
|
17 |
|
|
--
|
18 |
|
|
-- You should have received a copy of the GNU General Public License
|
19 |
|
|
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
|
20 |
|
|
--
|
21 |
|
|
-------------------------------------------------------------------------------
|
22 |
|
|
|
23 |
|
|
LIBRARY IEEE, common_pkg_lib, dp_pkg_lib, common_requantize_lib, dp_pipeline_lib;
|
24 |
|
|
USE IEEE.std_logic_1164.all;
|
25 |
|
|
USE dp_pkg_lib.dp_stream_pkg.ALL;
|
26 |
|
|
--USE common_lib.all;
|
27 |
|
|
USE common_pkg_lib.common_pkg.ALL;
|
28 |
|
|
|
29 |
|
|
-- Purpose: Requantize the data in the re, im or data field of the sosi record.
|
30 |
|
|
-- Description:
|
31 |
|
|
-- See common_requantize.vhd
|
32 |
|
|
-- Remarks:
|
33 |
|
|
-- . It does not take into account the ready signal from the siso record.
|
34 |
|
|
|
35 |
|
|
ENTITY dp_requantize IS
|
36 |
|
|
GENERIC (
|
37 |
|
|
g_complex : BOOLEAN := TRUE; -- when true, the re and im field are processed, when false, the data field is processed
|
38 |
|
|
g_representation : STRING := "SIGNED"; -- SIGNED (round +-0.5 away from zero to +- infinity) or UNSIGNED rounding (round 0.5 up to + inifinity)
|
39 |
|
|
g_lsb_w : INTEGER := 4; -- when > 0, number of LSbits to remove from in_dat
|
40 |
|
|
-- when < 0, number of LSBits to insert as a gain before resize to out_dat'LENGTH
|
41 |
|
|
-- when 0 then no effect
|
42 |
|
|
g_lsb_round : BOOLEAN := TRUE; -- when true ROUND else TRUNCATE the input LSbits
|
43 |
|
|
g_lsb_round_clip : BOOLEAN := FALSE; -- when true round clip to +max to avoid wrapping to output -min (signed) or 0 (unsigned) due to rounding
|
44 |
|
|
g_msb_clip : BOOLEAN := TRUE; -- when true CLIP else WRAP the input MSbits
|
45 |
|
|
g_msb_clip_symmetric : BOOLEAN := FALSE; -- when TRUE clip signed symmetric to +c_smax and -c_smax, else to +c_smax and c_smin_symm
|
46 |
|
|
-- for wrapping when g_msb_clip=FALSE the g_msb_clip_symmetric is ignored, so signed wrapping is done asymmetric
|
47 |
|
|
g_gain_w : NATURAL := 0; -- do not use, must be 0, use negative g_lsb_w instead
|
48 |
|
|
g_pipeline_remove_lsb : NATURAL := 0; -- >= 0
|
49 |
|
|
g_pipeline_remove_msb : NATURAL := 0; -- >= 0, use g_pipeline_remove_lsb=0 and g_pipeline_remove_msb=0 for combinatorial output
|
50 |
|
|
g_in_dat_w : NATURAL := 36; -- input data width
|
51 |
|
|
g_out_dat_w : NATURAL := 18 -- output data width
|
52 |
|
|
);
|
53 |
|
|
PORT (
|
54 |
|
|
rst : IN STD_LOGIC;
|
55 |
|
|
clk : IN STD_LOGIC;
|
56 |
|
|
-- ST sink
|
57 |
|
|
snk_in : IN t_dp_sosi;
|
58 |
|
|
-- ST source
|
59 |
|
|
src_out : OUT t_dp_sosi;
|
60 |
|
|
--
|
61 |
|
|
out_ovr : OUT std_logic -- out_ovr is '1' when the removal of MSbits causes clipping or wrapping
|
62 |
|
|
);
|
63 |
|
|
END dp_requantize;
|
64 |
|
|
|
65 |
|
|
|
66 |
|
|
ARCHITECTURE str OF dp_requantize IS
|
67 |
|
|
|
68 |
|
|
CONSTANT c_pipeline : NATURAL := g_pipeline_remove_lsb + g_pipeline_remove_msb;
|
69 |
|
|
|
70 |
|
|
SIGNAL snk_in_piped : t_dp_sosi;
|
71 |
|
|
|
72 |
|
|
SIGNAL quantized_data : STD_LOGIC_VECTOR(g_out_dat_w-1 DOWNTO 0);
|
73 |
|
|
SIGNAL quantized_re : STD_LOGIC_VECTOR(g_out_dat_w-1 DOWNTO 0);
|
74 |
|
|
SIGNAL quantized_im : STD_LOGIC_VECTOR(g_out_dat_w-1 DOWNTO 0);
|
75 |
|
|
SIGNAL out_ovr_re : STD_LOGIC;
|
76 |
|
|
SIGNAL out_ovr_im : STD_LOGIC;
|
77 |
|
|
|
78 |
|
|
BEGIN
|
79 |
|
|
|
80 |
|
|
ASSERT g_gain_w=0 REPORT "dp_requantize: must use g_gain_w = 0, because gain is now supported via negative g_lsb_w." SEVERITY FAILURE;
|
81 |
|
|
|
82 |
|
|
---------------------------------------------------------------
|
83 |
|
|
-- Requantize the sosi data field
|
84 |
|
|
---------------------------------------------------------------
|
85 |
|
|
gen_requantize_data : IF g_complex=FALSE GENERATE
|
86 |
|
|
u_requantize_data : ENTITY common_requantize_lib.common_requantize
|
87 |
|
|
GENERIC MAP (
|
88 |
|
|
g_representation => g_representation,
|
89 |
|
|
g_lsb_w => g_lsb_w,
|
90 |
|
|
g_lsb_round => g_lsb_round,
|
91 |
|
|
g_lsb_round_clip => g_lsb_round_clip,
|
92 |
|
|
g_msb_clip => g_msb_clip,
|
93 |
|
|
g_msb_clip_symmetric => g_msb_clip_symmetric,
|
94 |
|
|
g_pipeline_remove_lsb => g_pipeline_remove_lsb,
|
95 |
|
|
g_pipeline_remove_msb => g_pipeline_remove_msb,
|
96 |
|
|
g_in_dat_w => g_in_dat_w,
|
97 |
|
|
g_out_dat_w => g_out_dat_w
|
98 |
|
|
)
|
99 |
|
|
PORT MAP (
|
100 |
|
|
clk => clk,
|
101 |
|
|
in_dat => snk_in.data,
|
102 |
|
|
out_dat => quantized_data,
|
103 |
|
|
out_ovr => out_ovr
|
104 |
|
|
);
|
105 |
|
|
END GENERATE;
|
106 |
|
|
|
107 |
|
|
---------------------------------------------------------------
|
108 |
|
|
-- Requantize the sosi complex fields
|
109 |
|
|
---------------------------------------------------------------
|
110 |
|
|
gen_requantize_complex : IF g_complex=TRUE GENERATE
|
111 |
|
|
u_requantize_re: ENTITY common_requantize_lib.common_requantize
|
112 |
|
|
GENERIC MAP (
|
113 |
|
|
g_representation => g_representation,
|
114 |
|
|
g_lsb_w => g_lsb_w,
|
115 |
|
|
g_lsb_round => g_lsb_round,
|
116 |
|
|
g_lsb_round_clip => g_lsb_round_clip,
|
117 |
|
|
g_msb_clip => g_msb_clip,
|
118 |
|
|
g_msb_clip_symmetric => g_msb_clip_symmetric,
|
119 |
|
|
g_pipeline_remove_lsb => g_pipeline_remove_lsb,
|
120 |
|
|
g_pipeline_remove_msb => g_pipeline_remove_msb,
|
121 |
|
|
g_in_dat_w => g_in_dat_w,
|
122 |
|
|
g_out_dat_w => g_out_dat_w
|
123 |
|
|
)
|
124 |
|
|
PORT MAP (
|
125 |
|
|
clk => clk,
|
126 |
|
|
in_dat => snk_in.re,
|
127 |
|
|
out_dat => quantized_re,
|
128 |
|
|
out_ovr => out_ovr_re
|
129 |
|
|
);
|
130 |
|
|
|
131 |
|
|
u_requantize_im: ENTITY common_requantize_lib.common_requantize
|
132 |
|
|
GENERIC MAP (
|
133 |
|
|
g_representation => g_representation,
|
134 |
|
|
g_lsb_w => g_lsb_w,
|
135 |
|
|
g_lsb_round => g_lsb_round,
|
136 |
|
|
g_lsb_round_clip => g_lsb_round_clip,
|
137 |
|
|
g_msb_clip => g_msb_clip,
|
138 |
|
|
g_msb_clip_symmetric => g_msb_clip_symmetric,
|
139 |
|
|
g_pipeline_remove_lsb => g_pipeline_remove_lsb,
|
140 |
|
|
g_pipeline_remove_msb => g_pipeline_remove_msb,
|
141 |
|
|
g_in_dat_w => g_in_dat_w,
|
142 |
|
|
g_out_dat_w => g_out_dat_w
|
143 |
|
|
)
|
144 |
|
|
PORT MAP (
|
145 |
|
|
clk => clk,
|
146 |
|
|
in_dat => snk_in.im,
|
147 |
|
|
out_dat => quantized_im,
|
148 |
|
|
out_ovr => out_ovr_im
|
149 |
|
|
);
|
150 |
|
|
|
151 |
|
|
out_ovr <= out_ovr_re OR out_ovr_im;
|
152 |
|
|
END GENERATE;
|
153 |
|
|
|
154 |
|
|
|
155 |
|
|
--------------------------------------------------------------
|
156 |
|
|
-- Pipeline to align the other sosi fields
|
157 |
|
|
--------------------------------------------------------------
|
158 |
|
|
u_dp_pipeline : ENTITY dp_pipeline_lib.dp_pipeline
|
159 |
|
|
GENERIC MAP (
|
160 |
|
|
g_pipeline => c_pipeline -- 0 for wires, > 0 for registers,
|
161 |
|
|
)
|
162 |
|
|
PORT MAP (
|
163 |
|
|
rst => rst,
|
164 |
|
|
clk => clk,
|
165 |
|
|
-- ST sink
|
166 |
|
|
snk_in => snk_in,
|
167 |
|
|
-- ST source
|
168 |
|
|
src_out => snk_in_piped
|
169 |
|
|
);
|
170 |
|
|
|
171 |
|
|
PROCESS(snk_in_piped, quantized_data, quantized_re, quantized_im)
|
172 |
|
|
BEGIN
|
173 |
|
|
src_out <= snk_in_piped;
|
174 |
|
|
IF g_complex=FALSE THEN
|
175 |
|
|
IF g_representation="UNSIGNED" THEN
|
176 |
|
|
src_out.data <= RESIZE_DP_DATA( quantized_data);
|
177 |
|
|
ELSE
|
178 |
|
|
src_out.data <= RESIZE_DP_SDATA(quantized_data);
|
179 |
|
|
END IF;
|
180 |
|
|
ELSE
|
181 |
|
|
src_out.re <= RESIZE_DP_DSP_DATA(quantized_re);
|
182 |
|
|
src_out.im <= RESIZE_DP_DSP_DATA(quantized_im);
|
183 |
|
|
END IF;
|
184 |
|
|
END PROCESS;
|
185 |
|
|
|
186 |
|
|
END str;
|