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

Subversion Repositories common_pkg

[/] [common_pkg/] [trunk/] [common_lfsr_sequences_pkg.vhd] - Blame information for rev 6

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

Line No. Rev Author Line
1 6 danv
--------------------------------------------------------------------------------
2
--
3
-- Copyright (C) 2009
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;
24
USE IEEE.std_logic_1164.ALL;
25
USE IEEE.numeric_std.ALL;
26
USE work.common_pkg.ALL;
27
 
28
PACKAGE common_lfsr_sequences_pkg IS
29
 
30
  CONSTANT c_common_lfsr_max_nof_feedbacks : NATURAL := 6;
31
  CONSTANT c_common_lfsr_first             : NATURAL := 1;  -- also support n = 1 and 2 in addition to n >= 3
32
 
33
  TYPE t_FEEDBACKS IS ARRAY (c_common_lfsr_max_nof_feedbacks-1 DOWNTO 0) OF NATURAL;
34
  TYPE t_SEQUENCES IS ARRAY (NATURAL RANGE <>) OF t_FEEDBACKS;
35
 
36
  -- XNOR feedbacks for n = 1:
37
  --   (0,0,0,0,0, 0) yields repeat <1>
38
  --   (0,0,0,0,0, 1) yields repeat <0, 1>
39
 
40
  -- XNOR feedbacks for n = 2:
41
  --   (0,0,0,0, 0, 1) yields repeat <1, 2>
42
  --   (0,0,0,0, 0, 2) yields repeat <0, 1, 3, 2>
43
  --   (0,0,0,0, 2, 1) yields repeat <0, 1, 2>
44
 
45
  -- XNOR feedbacks from outputs for n = 3 .. 72 from Xilinx xapp052.pdf (that lists feedbacks for in total 168 sequences)
46
  CONSTANT c_common_lfsr_sequences : t_SEQUENCES := ((0,0,0,0,0,               1),   -- 1 : <0, 1>
47
                                                     (0,0,0,0,              0, 2),   -- 2 : <0, 1, 3, 2>
48
                                                     (0,0,0,0,              3, 2),   -- 3
49
                                                     (0,0,0,0,              4, 3),   -- 4
50
                                                     (0,0,0,0,              5, 3),   -- 5
51
                                                     (0,0,0,0,              6, 5),   -- 6
52
                                                     (0,0,0,0,              7, 6),   -- 7
53
                                                     (0,0,            8, 6, 5, 4),   -- 8
54
                                                     (0,0,0,0,              9, 5),   -- 9
55
                                                     (0,0,0,0,             10, 7),   -- 10
56
                                                     (0,0,0,0,             11, 9),   -- 11
57
                                                     (0,0,           12, 6, 4, 1),   -- 12
58
                                                     (0,0,           13, 4, 3, 1),   -- 13
59
                                                     (0,0,           14, 5, 3, 1),   -- 14
60
                                                     (0,0,0,0,       15,14      ),   -- 15
61
                                                     (0,0,           16,15,13, 4),   -- 16
62
                                                     (0,0,0,0,       17,14      ),   -- 17
63
                                                     (0,0,0,0,       18,11      ),   -- 18
64
                                                     (0,0,           19, 6, 2, 1),   -- 19
65
                                                     (0,0,0,0,       20,17      ),   -- 20
66
                                                     (0,0,0,0,       21,19      ),   -- 21
67
                                                     (0,0,0,0,       22,21      ),   -- 22
68
                                                     (0,0,0,0,       23,18      ),   -- 23
69
                                                     (0,0,           24,23,22,17),   -- 24
70
                                                     (0,0,0,0,       25,22      ),   -- 25
71
                                                     (0,0,           26, 6, 2, 1),   -- 26
72
                                                     (0,0,           27, 5, 2, 1),   -- 27
73
                                                     (0,0,0,0,       28,25      ),   -- 28
74
                                                     (0,0,0,0,       29,27      ),   -- 29
75
                                                     (0,0,           30, 6, 4, 1),   -- 30
76
                                                     (0,0,0,0,       31,28      ),   -- 31
77
                                                     (0,0,           32,22, 2, 1),   -- 32
78
                                                     (0,0,0,0,       33,20      ),   -- 33
79
                                                     (0,0,           34,27, 2, 1),   -- 34
80
                                                     (0,0,0,0,       35,33      ),   -- 35
81
                                                     (0,0,0,0,       36,25      ),   -- 36
82
                                                     (         37, 5, 4, 3, 2, 1),   -- 37
83
                                                     (0,0,           38, 6, 5, 1),   -- 38
84
                                                     (0,0,0,0,       39,35      ),   -- 39
85
                                                     (0,0,           40,38,21,19),   -- 40
86
                                                     (0,0,0,0,       41,38      ),   -- 41
87
                                                     (0,0,           42,41,20,19),   -- 42
88
                                                     (0,0,           43,42,38,37),   -- 43
89
                                                     (0,0,           44,43,18,17),   -- 44
90
                                                     (0,0,           45,44,42,41),   -- 45
91
                                                     (0,0,           46,45,26,25),   -- 46
92
                                                     (0,0,0,0,       47,42      ),   -- 47
93
                                                     (0,0,           48,47,21,20),   -- 48
94
                                                     (0,0,0,0,       49,40      ),   -- 49
95
                                                     (0,0,           50,49,24,23),   -- 50
96
                                                     (0,0,           51,50,36,35),   -- 51
97
                                                     (0,0,0,0,       52,49      ),   -- 52
98
                                                     (0,0,           53,52,38,37),   -- 53
99
                                                     (0,0,           54,53,18,17),   -- 54
100
                                                     (0,0,0,0,       55,31      ),   -- 55
101
                                                     (0,0,           56,55,35,34),   -- 56
102
                                                     (0,0,0,0,       57,50      ),   -- 57
103
                                                     (0,0,0,0,       58,39      ),   -- 58
104
                                                     (0,0,           59,58,38,37),   -- 59
105
                                                     (0,0,0,0,       60,59      ),   -- 60
106
                                                     (0,0,           61,60,46,45),   -- 61
107
                                                     (0,0,           62,61, 6, 5),   -- 62
108
                                                     (0,0,0,0,       63,62      ),   -- 63
109
                                                     (0,0,           64,63,61,60),   -- 64
110
                                                     (0,0,0,0,       65,47      ),   -- 65
111
                                                     (0,0,           66,65,57,56),   -- 66
112
                                                     (0,0,           67,66,58,57),   -- 67
113
                                                     (0,0,0,0,       68,59      ),   -- 68
114
                                                     (0,0,           69,67,42,40),   -- 69
115
                                                     (0,0,           70,69,55,54),   -- 70
116
                                                     (0,0,0,0,       71,65      ),   -- 71
117
                                                     (0,0,           72,66,25,19));  -- 72
118
 
119
 
120
  -- Procedure for calculating the next PSRG and COUNTER sequence value
121
  PROCEDURE common_lfsr_nxt_seq(CONSTANT c_lfsr_nr : IN  NATURAL;
122
                                CONSTANT g_incr    : IN  INTEGER;
123
                                         in_en     : IN  STD_LOGIC;
124
                                         in_req    : IN  STD_LOGIC;
125
                                         in_dat    : IN  STD_LOGIC_VECTOR;
126
                                         prsg      : IN  STD_LOGIC_VECTOR;
127
                                         cntr      : IN  STD_LOGIC_VECTOR;
128
                                SIGNAL   nxt_prsg  : OUT STD_LOGIC_VECTOR;
129
                                SIGNAL   nxt_cntr  : OUT STD_LOGIC_VECTOR);
130
 
131
  -- Use lfsr part of common_lfsr_nxt_seq to make a random bit generator function
132
  -- . width of lfsr selects the LFSR sequence
133
  -- . initialized lfsr with (OTHERS=>'0')
134
  -- . use lfsr(lfsr'HIGH) as random bit
135
  FUNCTION func_common_random(lfsr : STD_LOGIC_VECTOR) RETURN STD_LOGIC_VECTOR;
136
 
137
END common_lfsr_sequences_pkg;
138
 
139
 
140
PACKAGE BODY common_lfsr_sequences_pkg IS
141
 
142
  PROCEDURE common_lfsr_nxt_seq(CONSTANT c_lfsr_nr : IN  NATURAL;
143
                                CONSTANT g_incr    : IN  INTEGER;
144
                                         in_en     : IN  STD_LOGIC;
145
                                         in_req    : IN  STD_LOGIC;
146
                                         in_dat    : IN  STD_LOGIC_VECTOR;
147
                                         prsg      : IN  STD_LOGIC_VECTOR;
148
                                         cntr      : IN  STD_LOGIC_VECTOR;
149
                                SIGNAL   nxt_prsg  : OUT STD_LOGIC_VECTOR;
150
                                SIGNAL   nxt_cntr  : OUT STD_LOGIC_VECTOR) IS
151
    VARIABLE v_feedback : STD_LOGIC;
152
  BEGIN
153
    nxt_prsg <= prsg;
154
    nxt_cntr <= cntr;
155
    IF in_en='0' THEN     -- init reference value
156
      nxt_prsg <= in_dat;
157
      nxt_cntr <= in_dat;
158
    ELSIF in_req='1' THEN   -- next reference value
159
      -- PRSG shift
160
      nxt_prsg    <= prsg(prsg'HIGH-1 DOWNTO 0) & '0';
161
      -- PRSG feedback
162
      v_feedback := '0';
163
      FOR I IN c_common_lfsr_max_nof_feedbacks-1 DOWNTO 0 LOOP
164
        IF c_common_lfsr_sequences(c_lfsr_nr)(I) /= 0 THEN
165
          v_feedback := v_feedback XOR prsg(c_common_lfsr_sequences(c_lfsr_nr)(I)-1);
166
        END IF;
167
      END LOOP;
168
      nxt_prsg(0) <= NOT v_feedback;
169
 
170
      -- COUNTER
171
      nxt_cntr <= INCR_UVEC(cntr, g_incr);
172
    END IF;
173
  END common_lfsr_nxt_seq;
174
 
175
  FUNCTION func_common_random(lfsr : STD_LOGIC_VECTOR) RETURN STD_LOGIC_VECTOR IS
176
    CONSTANT c_lfsr_nr  : NATURAL := lfsr'LENGTH - c_common_lfsr_first;
177
    VARIABLE v_nxt_lfsr : STD_LOGIC_VECTOR(lfsr'RANGE);
178
    VARIABLE v_feedback : STD_LOGIC;
179
  BEGIN
180
    -- shift
181
    v_nxt_lfsr := lfsr(lfsr'HIGH-1 DOWNTO 0) & '0';
182
    -- feedback
183
    v_feedback := '0';
184
    FOR I IN c_common_lfsr_max_nof_feedbacks-1 DOWNTO 0 LOOP
185
      IF c_common_lfsr_sequences(c_lfsr_nr)(I) /= 0 THEN
186
        v_feedback := v_feedback XOR lfsr(c_common_lfsr_sequences(c_lfsr_nr)(I)-1);
187
      END IF;
188
    END LOOP;
189
    v_nxt_lfsr(0) := NOT v_feedback;
190
    RETURN v_nxt_lfsr;
191
  END func_common_random;
192
 
193
END common_lfsr_sequences_pkg;

powered by: WebSVN 2.1.0

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