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 2

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 danv
-------------------------------------------------------------------------------
2
--
3
-- Copyright (C) 2009
4
-- ASTRON (Netherlands Institute for Radio Astronomy) <http://www.astron.nl/>
5
-- P.O.Box 2, 7990 AA Dwingeloo, The Netherlands
6
--
7
-- This program is free software: you can redistribute it and/or modify
8
-- it under the terms of the GNU General Public License as published by
9
-- the Free Software Foundation, either version 3 of the License, or
10
-- (at your option) any later version.
11
--
12
-- This program is distributed in the hope that it will be useful,
13
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
14
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
-- GNU General Public License for more details.
16
--
17
-- You should have received a copy of the GNU General Public License
18
-- along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
--
20
-------------------------------------------------------------------------------
21
 
22
LIBRARY IEEE, common_pkg_lib;
23
USE IEEE.std_logic_1164.ALL;
24
USE IEEE.numeric_std.ALL;
25
USE common_pkg_lib.common_pkg.ALL;
26
 
27
-- Purpose: Requantize the input data to the output data width by removing
28
--          LSbits and/or MSbits
29
-- Description:
30
--
31
-- . in_dat --> remove LSbits --> rem_dat --> remove MSbits --> shift left by c_gain_w --> out_dat
32
--
33
-- . Remove LSBits by means of ROUND or TRUNCATE
34
-- . Remove LSBits when c_lsb_w>0
35
--
36
-- . Remove MSBits by means of CLIP or WRAP
37
-- . Remove MSbits when g_in_dat_w-c_lsb_w > g_out_dat_w:
38
--     in_dat   <---------------------g_in_dat_w--------------------->
39
--     rem_dat  <---------------------c_rem_dat_w-------><--c_lsb_w-->
40
--     res_dat          <-------------g_out_dat_w-------><--c_lsb_w-->
41
--
42
-- . Extend MSbits when g_in_dat_w-c_lsb_w <= g_out_dat_w::
43
--     in_dat           <-------------g_in_dat_w--------------------->
44
--     rem_dat          <-------------c_rem_dat_w-------><--c_lsb_w-->
45
--     res_dat  <---------------------g_out_dat_w-------><--c_lsb_w-->
46
--
47
-- . 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
48
--     gain_dat <-------g_out_dat_w-------><--c_gain_w-->
49
--  
50
-- Remarks:
51
-- . It is not necessary to define g_msb_w, because the number of MSbits that
52
--   need to be removed (or extended) follows from the other widths.
53
 
54
ENTITY common_requantize IS
55
  GENERIC (
56
    g_representation      : STRING  := "SIGNED";  -- SIGNED (round +-0.5 away from zero to +- infinity) or UNSIGNED rounding (round 0.5 up to + inifinity)
57
    g_lsb_w               : INTEGER := 4;         -- when > 0, number of LSbits to remove from in_dat
58
                                                  -- when < 0, number of LSBits to insert as a gain before resize to out_dat'LENGTH
59
                                                  -- when 0 then no effect
60
    g_lsb_round           : BOOLEAN := TRUE;      -- when true ROUND else TRUNCATE the input LSbits
61
    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
62
    g_msb_clip            : BOOLEAN := TRUE;      -- when true CLIP else WRAP the input MSbits
63
    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
64
                                                  -- for wrapping when g_msb_clip=FALSE the g_msb_clip_symmetric is ignored, so signed wrapping is done asymmetric
65
    g_gain_w              : NATURAL := 0;         -- do not use, must be 0, use negative g_lsb_w instead
66
    g_pipeline_remove_lsb : NATURAL := 0;         -- >= 0
67
    g_pipeline_remove_msb : NATURAL := 0;         -- >= 0, use g_pipeline_remove_lsb=0 and g_pipeline_remove_msb=0 for combinatorial output
68
    g_in_dat_w            : NATURAL := 36;        -- input data width
69
    g_out_dat_w           : NATURAL := 18         -- output data width
70
  );
71
  PORT (
72
    clk        : IN  STD_LOGIC;
73
    clken      : IN  STD_LOGIC := '1';
74
    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
75
    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
76
    out_ovr    : OUT STD_LOGIC          -- out_ovr is '1' when the removal of MSbits causes clipping or wrapping
77
  );
78
END;
79
 
80
 
81
ARCHITECTURE str OF common_requantize IS
82
 
83
  -- Use c_lsb_w > 0 to remove LSBits and support c_lsb < 0 to shift in zero value LSbits as a gain
84
  CONSTANT c_lsb_w        : NATURAL := sel_a_b(g_lsb_w > 0,  g_lsb_w, 0);
85
  CONSTANT c_gain_w       : NATURAL := sel_a_b(g_lsb_w < 0, -g_lsb_w, 0);
86
 
87
  CONSTANT c_rem_dat_w    : NATURAL := g_in_dat_w-c_lsb_w;
88
 
89
  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
90
  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
91
 
92
  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
93
 
94
BEGIN
95
 
96
  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;
97
 
98
  -- Remove LSBits using ROUND or TRUNCATE
99
  u_remove_lsb : ENTITY work.common_round
100
  GENERIC MAP (
101
    g_representation  => g_representation,
102
    g_round           => g_lsb_round,
103
    g_round_clip      => g_lsb_round_clip,
104
    g_pipeline_input  => 0,
105
    g_pipeline_output => g_pipeline_remove_lsb,
106
    g_in_dat_w        => g_in_dat_w,
107
    g_out_dat_w       => c_rem_dat_w
108
  )
109
  PORT MAP (
110
    clk        => clk,
111
    clken      => clken,
112
    in_dat     => in_dat(g_in_dat_w-1 DOWNTO 0),
113
    out_dat    => rem_dat
114
  );
115
 
116
  -- Remove MSBits using CLIP or WRAP
117
  u_remove_msb : ENTITY work.common_resize
118
  GENERIC MAP (
119
    g_representation  => g_representation,
120
    g_pipeline_input  => 0,
121
    g_pipeline_output => g_pipeline_remove_msb,
122
    g_clip            => g_msb_clip,
123
    g_clip_symmetric  => g_msb_clip_symmetric,
124
    g_in_dat_w        => c_rem_dat_w,
125
    g_out_dat_w       => g_out_dat_w
126
  )
127
  PORT MAP (
128
    clk        => clk,
129
    clken      => clken,
130
    in_dat     => rem_dat,
131
    out_dat    => res_dat,
132
    out_ovr    => out_ovr
133
  );
134
 
135
  -- Output gain
136
  gain_dat(g_out_dat_w+c_gain_w-1 DOWNTO c_gain_w) <= res_dat;
137
 
138
  out_dat <= RESIZE_SVEC(gain_dat, out_dat'LENGTH) WHEN g_representation="SIGNED" ELSE RESIZE_UVEC(gain_dat, out_dat'LENGTH);
139
 
140
END str;

powered by: WebSVN 2.1.0

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