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