Advertisement
Guest User

lfsr in vhdl

a guest
Jun 23rd, 2019
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 1.98 KB | None | 0 0
  1. library ieee;
  2. use ieee.std_logic_1164.all;
  3.  
  4. package lfsr is
  5.     function maxlen_lfsr_advance(reg : std_logic_vector) return std_logic_vector;
  6. end lfsr;
  7.  
  8. package body lfsr is
  9.     function l_xnor(r : std_logic_vector; i : integer; val : std_logic) return std_logic is
  10.     begin
  11.         if i /= -1 then
  12.             return val xnor r(i - 1);
  13.         end if;
  14.         return val;
  15.     end function;
  16.     function lfs(r : std_logic_vector; a, b, c, d, e, f, g, h, i, j : integer := -1) return std_logic is
  17.     begin
  18.         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))))))))));
  19.     end function;
  20.  
  21.     function maxlen_lfsr_advance(r : std_logic_vector) return std_logic_vector is
  22.         variable ret : std_logic_vector(r'range);
  23.         variable f : std_logic;
  24.         variable l : integer := r'length;
  25.     begin
  26.         if ret'left > ret'right then
  27.             ret(r'left downto 1) := r(r'left - 1 downto 0);
  28.         else
  29.             ret(1 to r'right) := r(0 to r'right - 1);
  30.         end if;
  31.         if l = 3 then
  32.             f := r(2) xnor r(1);
  33.         elsif l = 4 then
  34.             f := r(3) xnor r(2);
  35.         elsif l = 5 then
  36.             f := lfs(r, 3, 5);
  37.         elsif l = 6 then
  38.             f := lfs(r, 5, 6);
  39.         elsif l = 7 then
  40.             f := lfs(r, 6, 7);
  41.         elsif l = 8 then
  42.             f := lfs(r, 4, 5, 6, 8);
  43.         elsif l = 9 then
  44.             f := lfs(r, 5, 9);
  45.         elsif l = 10 then
  46.             f := lfs(r, 7, 10);
  47.         elsif l = 11 then
  48.             f := lfs(r, 9, 11);
  49.         elsif l = 12 then
  50.             f := lfs(r, 1, 4, 6, 12);
  51.         elsif l = 13 then
  52.             f := lfs(r, 1, 3, 4, 13);
  53.         elsif l = 14 then
  54.             f := lfs(r, 1, 3, 5, 14);
  55.         elsif l = 15 then
  56.             f := lfs(r, 14, 15);
  57.         elsif l = 16 then
  58.             f := lfs(r, 4, 13, 15, 16);
  59.         elsif l = 17 then
  60.             f := lfs(r, 17, 14);
  61.         elsif l = 18 then
  62.             f := lfs(r, 18, 11);
  63.         elsif l = 19 then
  64.             f := lfs(r, 1, 2, 6, 19);
  65.         elsif l = 57 then
  66.             f := r(56) xnor r(49);
  67.         else
  68.             assert false report "no matching shift register configured for length " & integer'image(r'length) severity failure;
  69.         end if;
  70.         ret(0) := f;
  71.         return ret;
  72.     end function;
  73. end lfsr;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement