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

Subversion Repositories astron_requantizer

[/] [astron_requantizer/] [trunk/] [common_requantize.vhd] - Blame information for rev 3

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
LIBRARY IEEE, common_pkg_lib;
22
USE IEEE.std_logic_1164.ALL;
23
USE IEEE.numeric_std.ALL;
24
USE common_pkg_lib.common_pkg.ALL;
25
 
26
-- Purpose: Requantize the input data to the output data width by removing
27
--          LSbits and/or MSbits
28
-- Description:
29
--
30
-- . in_dat --> remove LSbits --> rem_dat --> remove MSbits --> shift left by c_gain_w --> out_dat
31
--
32
-- . Remove LSBits by means of ROUND or TRUNCATE
33
-- . Remove LSBits when c_lsb_w>0
34
--
35
-- . Remove MSBits by means of CLIP or WRAP
36
-- . Remove MSbits when g_in_dat_w-c_lsb_w > g_out_dat_w:
37
--     in_dat   <---------------------g_in_dat_w--------------------->
38
--     rem_dat  <---------------------c_rem_dat_w-------><--c_lsb_w-->
39
--     res_dat          <-------------g_out_dat_w-------><--c_lsb_w-->
40
--
41
-- . Extend MSbits when g_in_dat_w-c_lsb_w <= g_out_dat_w::
42
--     in_dat           <-------------g_in_dat_w--------------------->
43
--     rem_dat          <-------------c_rem_dat_w-------><--c_lsb_w-->
44
--     res_dat  <---------------------g_out_dat_w-------><--c_lsb_w-->
45
--
46
-- . Shift left res_dat before resizing to out_dat'LENGTH, which is useful to keep the res_dat in the MSbits when out_dat'LENGTH > g_out_dat_w
47
--     gain_dat <-------g_out_dat_w-------><--c_gain_w-->
48
--  
49
-- Remarks:
50
-- . It is not necessary to define g_msb_w, because the number of MSbits that
51
--   need to be removed (or extended) follows from the other widths.
52
 
53
ENTITY common_requantize IS
54
  GENERIC (
55
    g_representation      : STRING  := "SIGNED";  -- SIGNED (round +-0.5 away from zero to +- infinity) or UNSIGNED rounding (round 0.5 up to + inifinity)
56
    g_lsb_w               : INTEGER := 4;         -- when > 0, number of LSbits to remove from in_dat
57
                                                  -- when < 0, number of LSBits to insert as a gain before resize to out_dat'LENGTH
58
                                                  -- when 0 then no effect
59
    g_lsb_round           : BOOLEAN := TRUE;      -- when true ROUND else TRUNCATE the input LSbits
60
    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
61
    g_msb_clip            : BOOLEAN := TRUE;      -- when true CLIP else WRAP the input MSbits
62
    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
63
                                                  -- for wrapping when g_msb_clip=FALSE the g_msb_clip_symmetric is ignored, so signed wrapping is done asymmetric
64
    g_gain_w              : NATURAL := 0;         -- do not use, must be 0, use negative g_lsb_w instead
65
    g_pipeline_remove_lsb : NATURAL := 0;         -- >= 0
66
    g_pipeline_remove_msb : NATURAL := 0;         -- >= 0, use g_pipeline_remove_lsb=0 and g_pipeline_remove_msb=0 for combinatorial output
67
    g_in_dat_w            : NATURAL := 36;        -- input data width
68
    g_out_dat_w           : NATURAL := 18         -- output data width
69
  );
70
  PORT (
71
    clk        : IN  STD_LOGIC;
72
    clken      : IN  STD_LOGIC := '1';
73
    in_dat     : IN  STD_LOGIC_VECTOR;  -- unconstrained slv to also support widths other than g_in_dat_w by only using [g_in_dat_w-1:0] from the in_dat slv
74
    out_dat    : OUT STD_LOGIC_VECTOR;  -- unconstrained slv to also support widths other then g_out_dat_w by resizing the result [g_out_dat_w-1:0] to the out_dat slv
75
    out_ovr    : OUT STD_LOGIC          -- out_ovr is '1' when the removal of MSbits causes clipping or wrapping
76
  );
77
END;
78
 
79
 
80
ARCHITECTURE str OF common_requantize IS
81
 
82
  -- Use c_lsb_w > 0 to remove LSBits and support c_lsb < 0 to shift in zero value LSbits as a gain
83
  CONSTANT c_lsb_w        : NATURAL := sel_a_b(g_lsb_w > 0,  g_lsb_w, 0);
84
  CONSTANT c_gain_w       : NATURAL := sel_a_b(g_lsb_w < 0, -g_lsb_w, 0);
85
 
86
  CONSTANT c_rem_dat_w    : NATURAL := g_in_dat_w-c_lsb_w;
87
 
88
  SIGNAL rem_dat       : STD_LOGIC_VECTOR(c_rem_dat_w-1 DOWNTO 0);  -- remaining in_dat after removing the c_lsb_w number of LSBits
89
  SIGNAL res_dat       : STD_LOGIC_VECTOR(g_out_dat_w-1 DOWNTO 0);  -- resulting out_dat after removing the g_msb_w number of MSBits
90
 
91
  SIGNAL gain_dat      : STD_LOGIC_VECTOR(g_out_dat_w+c_gain_w-1 DOWNTO 0) := (OTHERS=>'0');  -- fill extra LSBits with '0' instead of extending MSbits
92
 
93
BEGIN
94
 
95
  ASSERT g_gain_w=0 REPORT "common_requantize: must use g_gain_w = 0, because gain is now supported via negative g_lsb_w." SEVERITY FAILURE;
96
 
97
  -- Remove LSBits using ROUND or TRUNCATE
98
  u_remove_lsb : ENTITY work.common_round
99
  GENERIC MAP (
100
    g_representation  => g_representation,
101
    g_round           => g_lsb_round,
102
    g_round_clip      => g_lsb_round_clip,
103
    g_pipeline_input  => 0,
104
    g_pipeline_output => g_pipeline_remove_lsb,
105
    g_in_dat_w        => g_in_dat_w,
106
    g_out_dat_w       => c_rem_dat_w
107
  )
108
  PORT MAP (
109
    clk        => clk,
110
    clken      => clken,
111
    in_dat     => in_dat(g_in_dat_w-1 DOWNTO 0),
112
    out_dat    => rem_dat
113
  );
114
 
115
  -- Remove MSBits using CLIP or WRAP
116
  u_remove_msb : ENTITY work.common_resize
117
  GENERIC MAP (
118
    g_representation  => g_representation,
119
    g_pipeline_input  => 0,
120
    g_pipeline_output => g_pipeline_remove_msb,
121
    g_clip            => g_msb_clip,
122
    g_clip_symmetric  => g_msb_clip_symmetric,
123
    g_in_dat_w        => c_rem_dat_w,
124
    g_out_dat_w       => g_out_dat_w
125
  )
126
  PORT MAP (
127
    clk        => clk,
128
    clken      => clken,
129
    in_dat     => rem_dat,
130
    out_dat    => res_dat,
131
    out_ovr    => out_ovr
132
  );
133
 
134
  -- Output gain
135
  gain_dat(g_out_dat_w+c_gain_w-1 DOWNTO c_gain_w) <= res_dat;
136
 
137
  out_dat <= RESIZE_SVEC(gain_dat, out_dat'LENGTH) WHEN g_representation="SIGNED" ELSE RESIZE_UVEC(gain_dat, out_dat'LENGTH);
138
 
139
END str;

powered by: WebSVN 2.1.0

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