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 16

Details | Compare with Previous | View Log

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