Debian Codegraph @

hdl/fpga/ip/nuand/synthesis/constellation_mapper.vhd

raw
1 -- Copyright (c) 2013 Nuand LLC
2 --
3 -- Permission is hereby granted, free of charge, to any person obtaining a copy
4 -- of this software and associated documentation files (the "Software"), to deal
5 -- in the Software without restriction, including without limitation the rights
6 -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 -- copies of the Software, and to permit persons to whom the Software is
8 -- furnished to do so, subject to the following conditions:
9 --
10 -- The above copyright notice and this permission notice shall be included in
11 -- all copies or substantial portions of the Software.
12 --
13 -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 -- THE SOFTWARE.
20
21 library ieee ;
22 use ieee.std_logic_1164.all ;
23 use ieee.numeric_std.all ;
24 use ieee.math_real.all ;
25 use ieee.math_complex.all ;
26
27 package constellation_mapper_p is
28
29 -- All possible modulations
30 type constellation_mapper_modulation_t is (
31 APSK_16,
32 APSK_32,
33 MSK,
34 PSK_2,
35 PSK_4,
36 PSK_8,
37 PSK_8_GRAY,
38 PSK_16,
39 QAM_16,
40 QAM_32,
41 QAM_64,
42 QAM_128,
43 QAM_256,
44 QAM_512,
45 QAM_1024,
46 QAM_2048,
47 QAM_4096,
48 VSB_8,
49 MAX_MODULATION
50 ) ;
51
52 type complex_fixed_t is record
53 re : signed(15 downto 0);
54 im : signed(15 downto 0);
55 end record;
56
57 type complex_fixed_array_t is array(natural range <>) of complex_fixed_t;
58
59 type real_array_t is array(natural range <>) of real ;
60 type complex_array_t is array(natural range <>) of complex ;
61
62 -- Array of modulations
63 type constellation_mapper_modulation_array_t is array(natural range <>) of constellation_mapper_modulation_t ;
64
65 -- Inputs to the mapper
66 type constellation_mapper_inputs_t is record
67 bits : std_logic_vector(15 downto 0) ;
68 modulation : constellation_mapper_modulation_t ;
69 valid : std_logic ;
70 end record ;
71
72 -- Outputs of the mapper
73 type constellation_mapper_outputs_t is record
74 symbol : complex_fixed_t ;
75 valid : std_logic ;
76 end record ;
77
78 end package ; -- constellation_mapper_p
79
80 library ieee ;
81 use ieee.std_logic_1164.all ;
82 use ieee.numeric_std.all ;
83 use ieee.math_real.all ;
84 use ieee.math_complex.all ;
85
86 library work ;
87 use work.constellation_mapper_p.all ;
88
89 entity constellation_mapper is
90 generic (
91 SCALE_FACTOR : real := 4096.0;
92 MODULATIONS : constellation_mapper_modulation_array_t := ( MSK, PSK_2, QAM_16, VSB_8 )
93 ) ;
94 port (
95 clock : in std_logic ;
96 inputs : in constellation_mapper_inputs_t ;
97 outputs : out constellation_mapper_outputs_t
98 ) ;
99 end entity ; -- constellation_mapper
100
101 architecture arch of constellation_mapper is
102
103 type modulation_info_t is record
104 index : natural ;
105 mask : std_logic_vector(15 downto 0) ;
106 end record ;
107
108 -- NOTE: If QAM_4096 is ever not the end, this needs to change
109 type modulation_index_t is array(0 to constellation_mapper_modulation_t'pos(MAX_MODULATION)-1) of modulation_info_t ;
110
111 -- Get the number of entries of each of the supported modulations
112 function size( x : constellation_mapper_modulation_t ) return natural is
113 variable rv : natural := 0;
114 begin
115 case x is
116 when APSK_16 => rv := 16;
117 when APSK_32 => rv := 32;
118 when MSK => rv := 2 ;
119 when PSK_2 => rv := 2 ;
120 when PSK_4 => rv := 4 ;
121 when PSK_8 => rv := 8 ;
122 when PSK_8_GRAY => rv := 8 ;
123 when PSK_16 => rv := 16 ;
124 when QAM_16 => rv := 16 ;
125 when QAM_32 => rv := 32 ;
126 when QAM_64 => rv := 64 ;
127 when QAM_128 => rv := 128 ;
128 when QAM_256 => rv := 256 ;
129 when QAM_512 => rv := 512 ;
130 when QAM_1024 => rv := 1024 ;
131 when QAM_2048 => rv := 2048 ;
132 when QAM_4096 => rv := 4096 ;
133 when VSB_8 => rv := 8;
134 when MAX_MODULATION => rv := 0;
135 end case ;
136 return rv ;
137 end function ;
138
139 -- 16-APSK Modulation points
140 function constellation_apsk_16 return complex_fixed_array_t is
141 variable rv : complex_fixed_array_t(0 to 15) := (others =>(to_signed(0,16),to_signed(0,16))) ;
142 begin
143 return rv ;
144 end function ;
145
146 -- 32-APSK Modulation Points
147 function constellation_apsk_32 return complex_fixed_array_t is
148 variable rv : complex_fixed_array_t(0 to 31) := (others =>(to_signed(0,16),to_signed(0,16))) ;
149 begin
150 return rv ;
151 end function ;
152
153 -- MSK Modulation Points
154 function constellation_msk return complex_fixed_array_t is
155 variable rv : complex_fixed_array_t(0 to 1) := (others =>(to_signed(0,16),to_signed(0,16))) ;
156 begin
157 return rv ;
158 end function ;
159
160 -- BPSK Modulation Points
161 function constellation_psk_2 return complex_fixed_array_t is
162 variable rv : complex_fixed_array_t(0 to 1) := (others =>(to_signed(0,16),to_signed(0,16))) ;
163 begin
164 return rv ;
165 end function ;
166
167 -- QPSK Modulation Points
168 function constellation_psk_4 return complex_fixed_array_t is
169 variable rv : complex_fixed_array_t(0 to 3) := (others =>(to_signed(0,16),to_signed(0,16))) ;
170 begin
171 return rv ;
172 end function ;
173
174 -- 8-PSK Modulation Points
175 function constellation_psk_8 return complex_fixed_array_t is
176 variable rv : complex_fixed_array_t(0 to 7) := (others =>(to_signed(0,16),to_signed(0,16))) ;
177 begin
178 return rv ;
179 end function ;
180
181 -- 8-PSK Offset Modulation Points
182 function constellation_psk_8_gray return complex_fixed_array_t is
183 variable rv : complex_fixed_array_t(0 to 7) := (others =>(to_signed(0,16),to_signed(0,16))) ;
184 begin
185 return rv ;
186 end function ;
187
188 -- 16-PSK Modulation Points
189 function constellation_psk_16 return complex_fixed_array_t is
190 variable rv : complex_fixed_array_t(0 to 15) := (others =>(to_signed(0,16),to_signed(0,16))) ;
191 begin
192 return rv ;
193 end function ;
194
195 -- 16-QAM Modulation Points
196 function constellation_qam_16 return complex_fixed_array_t is
197 variable rv : complex_fixed_array_t(0 to 15) := (others =>(to_signed(0,16),to_signed(0,16))) ;
198 begin
199 return rv ;
200 end function ;
201
202 -- 32-QAM Modulation Points
203 function constellation_qam_32 return complex_fixed_array_t is
204 variable rv : complex_fixed_array_t(0 to 31) := (others =>(to_signed(0,16),to_signed(0,16))) ;
205 begin
206 return rv ;
207 end function ;
208
209 -- 64-QAM Modulation Points
210 function constellation_qam_64 return complex_fixed_array_t is
211 variable rv : complex_fixed_array_t(0 to 63) := (others =>(to_signed(0,16),to_signed(0,16))) ;
212 begin
213 return rv ;
214 end function ;
215
216 -- 128-QAM Modulation Points
217 function constellation_qam_128 return complex_fixed_array_t is
218 variable rv : complex_fixed_array_t(0 to 127) := (others =>(to_signed(0,16),to_signed(0,16))) ;
219 begin
220 return rv ;
221 end function ;
222
223 -- 256-QAM Modulation Points
224 function constellation_qam_256 return complex_fixed_array_t is
225 variable rv : complex_fixed_array_t(0 to 255) := (others =>(to_signed(0,16),to_signed(0,16))) ;
226 begin
227 return rv ;
228 end function ;
229
230 -- 512-QAM Modulation Points
231 function constellation_qam_512 return complex_fixed_array_t is
232 variable rv : complex_fixed_array_t(0 to 511) := (others =>(to_signed(0,16),to_signed(0,16))) ;
233 begin
234 return rv ;
235 end function ;
236
237 -- 1024-QAM Modulation Points
238 function constellation_qam_1024 return complex_fixed_array_t is
239 variable rv : complex_fixed_array_t(0 to 1023) := (others =>(to_signed(0,16),to_signed(0,16))) ;
240 begin
241 return rv ;
242 end function ;
243
244 -- 2048-QAM Modulation Points
245 function constellation_qam_2048 return complex_fixed_array_t is
246 variable rv : complex_fixed_array_t(0 to 2047) := (others =>(to_signed(0,16),to_signed(0,16))) ;
247 begin
248 return rv ;
249 end function ;
250
251 -- 4096-QAM Modulation Points
252 function constellation_qam_4096 return complex_fixed_array_t is
253 variable rv : complex_fixed_array_t(0 to 4096) := (others =>(to_signed(0,16),to_signed(0,16))) ;
254 begin
255 return rv ;
256 end function ;
257
258
259 -- 8- VSB
260 function constellation_vsb_8 return complex_fixed_array_t is
261 -- (-7.0,0.0)(-5.0,0.0),(-3.0,0.0),(-1.0,0.0),(1.0,0.0),(3.0,0.0)(5.0,0.0),(7.0,0.0)
262 variable rv : complex_fixed_array_t(0 to 7) := (
263 (to_signed(natural(-7.0/7.0 * SCALE_FACTOR),16), to_signed(0,16)),
264 (to_signed(natural(-5.0/7.0 * SCALE_FACTOR),16),to_signed(0,16)),
265 (to_signed(natural(-3.0/7.0 * SCALE_FACTOR),16),to_signed(0,16)),
266 (to_signed(natural(-1.0/7.0 * SCALE_FACTOR),16),to_signed(0,16)),
267 (to_signed(natural(1.0/7.0 * SCALE_FACTOR),16),to_signed(0,16)),
268 (to_signed(natural(3.0/7.0 * SCALE_FACTOR),16),to_signed(0,16)),
269 (to_signed(natural(5.0/7.0 * SCALE_FACTOR),16),to_signed(0,16)),
270 (to_signed(natural(7.0/7.0 * SCALE_FACTOR),16),to_signed(0,16)));
271 begin
272 return rv;
273 end function;
274
275 -- Get each of the constellation arrays
276 function constellation( x : constellation_mapper_modulation_t ) return complex_fixed_array_t is
277 begin
278 case x is
279 when APSK_16 => return constellation_apsk_16 ;
280 when APSK_32 => return constellation_apsk_32 ;
281 when MSK => return constellation_msk ;
282 when PSK_2 => return constellation_psk_2 ;
283 when PSK_4 => return constellation_psk_4 ;
284 when PSK_8 => return constellation_psk_8 ;
285 when PSK_8_GRAY => return constellation_psk_8_gray ;
286 when PSK_16 => return constellation_psk_16 ;
287 when QAM_16 => return constellation_qam_16 ;
288 when QAM_32 => return constellation_qam_32 ;
289 when QAM_64 => return constellation_qam_64 ;
290 when QAM_128 => return constellation_qam_128 ;
291 when QAM_256 => return constellation_qam_256 ;
292 when QAM_512 => return constellation_qam_512 ;
293 when QAM_1024 => return constellation_qam_1024 ;
294 when QAM_2048 => return constellation_qam_2048 ;
295 when QAM_4096 => return constellation_qam_4096 ;
296 when VSB_8 => return constellation_vsb_8 ;
297 when MAX_MODULATION => return constellation_msk;
298 end case ;
299 end function ;
300
301 -- Calculate the base indicies for each modulation type
302 function calculate_indices( x : constellation_mapper_modulation_array_t ) return modulation_index_t is
303 variable index : natural := 0;
304 variable rv : modulation_index_t := (others =>(0, x"0000")) ;
305 begin
306 for i in x'range loop
307 rv(constellation_mapper_modulation_t'pos(x(i))).index := index ;
308 rv(constellation_mapper_modulation_t'pos(x(i))).mask := std_logic_vector(to_unsigned(size(x(i))-1,rv(constellation_mapper_modulation_t'pos(x(i))).mask'length)) ;
309 index := index + size(x(i)) ;
310 end loop ;
311 return rv ;
312 end function ;
313
314 -- Take in the array and create the modulations recursively
315 function generate_modulation_table( x : constellation_mapper_modulation_array_t ) return complex_fixed_array_t is
316 begin
317 report "x'low is " & integer'image(x'low) & " x'high is " &integer'image(x'high);
318 if (x'low + 1 <= x'high) then
319 return constellation(x(x'low)) & generate_modulation_table(x(x'low+1 to x'high)) ;
320 else
321 return constellation(x(x'low));
322 end if;
323 end function ;
324
325 -- Constant values generated
326 constant modulation_index : modulation_index_t := calculate_indices(MODULATIONS) ;
327 constant modulation_table : complex_fixed_array_t := generate_modulation_table(MODULATIONS) ;
328
329 -- Actual signals!
330 signal base : modulation_info_t ;
331 signal symbol : complex_fixed_t ;
332
333 begin
334
335 -- Get the inputs and base address
336 base <= modulation_index(constellation_mapper_modulation_t'pos(inputs.modulation)) ;
337
338 -- Map it to the modulation table
339 symbol <= modulation_table(base.index + to_integer(unsigned(inputs.bits and base.mask))) ;
340
341 -- Register the outputs
342 outputs.symbol <= symbol when rising_edge( clock ) and inputs.valid = '1' ;
343 outputs.valid <= inputs.valid when rising_edge( clock ) ;
344
345 end architecture ; -- arch