OpenCores
URL https://opencores.org/ocsvn/astron_requantizer/astron_requantizer/trunk

Subversion Repositories astron_requantizer

[/] [astron_requantizer/] [trunk/] [dp_requantize.vhd] - Blame information for rev 4

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 danv
-------------------------------------------------------------------------------
2
--
3 3 danv
-- Copyright 2020
4 2 danv
-- ASTRON (Netherlands Institute for Radio Astronomy) <http://www.astron.nl/>
5
-- P.O.Box 2, 7990 AA Dwingeloo, The Netherlands
6 3 danv
-- 
7
-- Licensed under the Apache License, Version 2.0 (the "License");
8
-- you may not use this file except in compliance with the License.
9
-- You may obtain a copy of the License at
10
-- 
11
--     http://www.apache.org/licenses/LICENSE-2.0
12
-- 
13
-- Unless required by applicable law or agreed to in writing, software
14
-- distributed under the License is distributed on an "AS IS" BASIS,
15
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
-- See the License for the specific language governing permissions and
17
-- limitations under the License.
18 2 danv
--
19
-------------------------------------------------------------------------------
20
 
21 4 danv
LIBRARY IEEE, common_pkg_lib, dp_pkg_lib, astron_pipeline_lib;
22 2 danv
USE IEEE.std_logic_1164.all;
23
USE dp_pkg_lib.dp_stream_pkg.ALL;
24
--USE common_lib.all;     
25
USE common_pkg_lib.common_pkg.ALL;
26
 
27
-- Purpose: Requantize the data in the re, im or data field of the sosi record.
28
-- Description:
29
--   See common_requantize.vhd 
30
-- Remarks:
31
-- . It does not take into account the ready signal from the siso record. 
32
 
33
ENTITY dp_requantize IS
34
  GENERIC (
35
    g_complex             : BOOLEAN := TRUE;      -- when true, the re and im field are processed, when false, the data field is processed
36
    g_representation      : STRING  := "SIGNED";  -- SIGNED (round +-0.5 away from zero to +- infinity) or UNSIGNED rounding (round 0.5 up to + inifinity)         
37
    g_lsb_w               : INTEGER := 4;         -- when > 0, number of LSbits to remove from in_dat
38
                                                  -- when < 0, number of LSBits to insert as a gain before resize to out_dat'LENGTH
39
                                                  -- when 0 then no effect
40
    g_lsb_round           : BOOLEAN := TRUE;      -- when true ROUND else TRUNCATE the input LSbits                                                                
41
    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        
42
    g_msb_clip            : BOOLEAN := TRUE;      -- when true CLIP else WRAP the input MSbits                                                                     
43
    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                       
44
                                                  -- for wrapping when g_msb_clip=FALSE the g_msb_clip_symmetric is ignored, so signed wrapping is done asymmetric 
45
    g_gain_w              : NATURAL := 0;         -- do not use, must be 0, use negative g_lsb_w instead
46
    g_pipeline_remove_lsb : NATURAL := 0;         -- >= 0                                                                                                          
47
    g_pipeline_remove_msb : NATURAL := 0;         -- >= 0, use g_pipeline_remove_lsb=0 and g_pipeline_remove_msb=0 for combinatorial output                        
48
    g_in_dat_w            : NATURAL := 36;        -- input data width                                                                                              
49
    g_out_dat_w           : NATURAL := 18         -- output data width                                                                                             
50
  );
51
  PORT (
52
    rst          : IN  STD_LOGIC;
53
    clk          : IN  STD_LOGIC;
54
    -- ST sink
55
    snk_in       : IN  t_dp_sosi;
56
    -- ST source
57
    src_out      : OUT t_dp_sosi;
58
    -- 
59
    out_ovr      : OUT std_logic  -- out_ovr is '1' when the removal of MSbits causes clipping or wrapping
60
  );
61
END dp_requantize;
62
 
63
 
64
ARCHITECTURE str OF dp_requantize IS
65
 
66
  CONSTANT c_pipeline : NATURAL := g_pipeline_remove_lsb + g_pipeline_remove_msb;
67
 
68
  SIGNAL snk_in_piped   : t_dp_sosi;
69
 
70
  SIGNAL quantized_data : STD_LOGIC_VECTOR(g_out_dat_w-1 DOWNTO 0);
71
  SIGNAL quantized_re   : STD_LOGIC_VECTOR(g_out_dat_w-1 DOWNTO 0);
72
  SIGNAL quantized_im   : STD_LOGIC_VECTOR(g_out_dat_w-1 DOWNTO 0);
73
  SIGNAL out_ovr_re     : STD_LOGIC;
74
  SIGNAL out_ovr_im     : STD_LOGIC;
75
 
76
BEGIN
77
 
78
  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;
79
 
80
  ---------------------------------------------------------------
81
  -- Requantize the sosi data field
82
  ---------------------------------------------------------------
83
  gen_requantize_data : IF g_complex=FALSE GENERATE
84 4 danv
    u_requantize_data : ENTITY work.common_requantize
85 2 danv
    GENERIC MAP (
86
      g_representation      => g_representation,
87
      g_lsb_w               => g_lsb_w,
88
      g_lsb_round           => g_lsb_round,
89
      g_lsb_round_clip      => g_lsb_round_clip,
90
      g_msb_clip            => g_msb_clip,
91
      g_msb_clip_symmetric  => g_msb_clip_symmetric,
92
      g_pipeline_remove_lsb => g_pipeline_remove_lsb,
93
      g_pipeline_remove_msb => g_pipeline_remove_msb,
94
      g_in_dat_w            => g_in_dat_w,
95
      g_out_dat_w           => g_out_dat_w
96
    )
97
    PORT MAP (
98
      clk        => clk,
99
      in_dat     => snk_in.data,
100
      out_dat    => quantized_data,
101
      out_ovr    => out_ovr
102
    );
103
  END GENERATE;
104
 
105
  ---------------------------------------------------------------
106
  -- Requantize the sosi complex fields
107
  ---------------------------------------------------------------
108
  gen_requantize_complex : IF g_complex=TRUE GENERATE
109 4 danv
    u_requantize_re: ENTITY work.common_requantize
110 2 danv
    GENERIC MAP (
111
      g_representation      => g_representation,
112
      g_lsb_w               => g_lsb_w,
113
      g_lsb_round           => g_lsb_round,
114
      g_lsb_round_clip      => g_lsb_round_clip,
115
      g_msb_clip            => g_msb_clip,
116
      g_msb_clip_symmetric  => g_msb_clip_symmetric,
117
      g_pipeline_remove_lsb => g_pipeline_remove_lsb,
118
      g_pipeline_remove_msb => g_pipeline_remove_msb,
119
      g_in_dat_w            => g_in_dat_w,
120
      g_out_dat_w           => g_out_dat_w
121
    )
122
    PORT MAP (
123
      clk        => clk,
124
      in_dat     => snk_in.re,
125
      out_dat    => quantized_re,
126
      out_ovr    => out_ovr_re
127
    );
128
 
129 4 danv
    u_requantize_im: ENTITY work.common_requantize
130 2 danv
    GENERIC MAP (
131
      g_representation      => g_representation,
132
      g_lsb_w               => g_lsb_w,
133
      g_lsb_round           => g_lsb_round,
134
      g_lsb_round_clip      => g_lsb_round_clip,
135
      g_msb_clip            => g_msb_clip,
136
      g_msb_clip_symmetric  => g_msb_clip_symmetric,
137
      g_pipeline_remove_lsb => g_pipeline_remove_lsb,
138
      g_pipeline_remove_msb => g_pipeline_remove_msb,
139
      g_in_dat_w            => g_in_dat_w,
140
      g_out_dat_w           => g_out_dat_w
141
    )
142
    PORT MAP (
143
      clk        => clk,
144
      in_dat     => snk_in.im,
145
      out_dat    => quantized_im,
146
      out_ovr    => out_ovr_im
147
    );
148
 
149
    out_ovr <= out_ovr_re OR out_ovr_im;
150
  END GENERATE;
151
 
152
 
153
  --------------------------------------------------------------
154
  -- Pipeline to align the other sosi fields
155
  --------------------------------------------------------------
156 4 danv
  u_dp_pipeline : ENTITY astron_pipeline_lib.dp_pipeline
157 2 danv
  GENERIC MAP (
158
    g_pipeline   => c_pipeline  -- 0 for wires, > 0 for registers, 
159
  )
160
  PORT MAP (
161
    rst          => rst,
162
    clk          => clk,
163
    -- ST sink
164
    snk_in       => snk_in,
165
    -- ST source
166
    src_out      => snk_in_piped
167
  );
168
 
169
  PROCESS(snk_in_piped, quantized_data, quantized_re, quantized_im)
170
  BEGIN
171
    src_out <= snk_in_piped;
172
    IF g_complex=FALSE THEN
173
      IF g_representation="UNSIGNED" THEN
174
        src_out.data <= RESIZE_DP_DATA( quantized_data);
175
      ELSE
176
        src_out.data <= RESIZE_DP_SDATA(quantized_data);
177
      END IF;
178
    ELSE
179
      src_out.re <= RESIZE_DP_DSP_DATA(quantized_re);
180
      src_out.im <= RESIZE_DP_DSP_DATA(quantized_im);
181
    END IF;
182
  END PROCESS;
183
 
184
END str;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.