Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library ieee;
- use ieee.std_logic_1164.all;
- package lfsr is
- function maxlen_lfsr_advance(reg : std_logic_vector) return std_logic_vector;
- end lfsr;
- package body lfsr is
- function l_xnor(r : std_logic_vector; i : integer; val : std_logic) return std_logic is
- begin
- if i /= -1 then
- return val xnor r(i - 1);
- end if;
- return val;
- end function;
- function lfs(r : std_logic_vector; a, b, c, d, e, f, g, h, i, j : integer := -1) return std_logic is
- begin
- return l_xnor(r, b, l_xnor(r, c, l_xnor(r, d, l_xnor(r, e, l_xnor(r, f, l_xnor(r, g, l_xnor(r, h, l_xnor(r, i, l_xnor(r, j, r(a - 1))))))))));
- end function;
- function maxlen_lfsr_advance(r : std_logic_vector) return std_logic_vector is
- variable ret : std_logic_vector(r'range);
- variable f : std_logic;
- variable l : integer := r'length;
- begin
- if ret'left > ret'right then
- ret(r'left downto 1) := r(r'left - 1 downto 0);
- else
- ret(1 to r'right) := r(0 to r'right - 1);
- end if;
- if l = 3 then
- f := r(2) xnor r(1);
- elsif l = 4 then
- f := r(3) xnor r(2);
- elsif l = 5 then
- f := lfs(r, 3, 5);
- elsif l = 6 then
- f := lfs(r, 5, 6);
- elsif l = 7 then
- f := lfs(r, 6, 7);
- elsif l = 8 then
- f := lfs(r, 4, 5, 6, 8);
- elsif l = 9 then
- f := lfs(r, 5, 9);
- elsif l = 10 then
- f := lfs(r, 7, 10);
- elsif l = 11 then
- f := lfs(r, 9, 11);
- elsif l = 12 then
- f := lfs(r, 1, 4, 6, 12);
- elsif l = 13 then
- f := lfs(r, 1, 3, 4, 13);
- elsif l = 14 then
- f := lfs(r, 1, 3, 5, 14);
- elsif l = 15 then
- f := lfs(r, 14, 15);
- elsif l = 16 then
- f := lfs(r, 4, 13, 15, 16);
- elsif l = 17 then
- f := lfs(r, 17, 14);
- elsif l = 18 then
- f := lfs(r, 18, 11);
- elsif l = 19 then
- f := lfs(r, 1, 2, 6, 19);
- elsif l = 57 then
- f := r(56) xnor r(49);
- else
- assert false report "no matching shift register configured for length " & integer'image(r'length) severity failure;
- end if;
- ret(0) := f;
- return ret;
- end function;
- end lfsr;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement