| 1 |
2 |
sonicwave |
----------------------------------------------------------------------------------
|
| 2 |
|
|
-- Company: University of Southern Denmark
|
| 3 |
|
|
-- Engineer: Simon Falsig
|
| 4 |
|
|
--
|
| 5 |
|
|
-- Create Date: 9/6/2008
|
| 6 |
|
|
-- Design Name: Linear Feedback Shift Register
|
| 7 |
|
|
-- Module Name: lfsr - Behavioral
|
| 8 |
|
|
-- File Name: lfsr.vhd
|
| 9 |
|
|
-- Project Name: TosNet
|
| 10 |
|
|
-- Target Devices: Spartan3/6
|
| 11 |
|
|
-- Tool versions: Xilinx ISE 12.2
|
| 12 |
|
|
-- Description: The LFSR is used to create pseudo-random sequences that are
|
| 13 |
|
|
-- used for scrambling outgoing data. With a similarly seeded
|
| 14 |
|
|
-- LFSR on the receiving side, the data can be de-scrambled.
|
| 15 |
|
|
--
|
| 16 |
|
|
-- Revision:
|
| 17 |
|
|
-- Revision 3.2 - Initial release
|
| 18 |
|
|
--
|
| 19 |
|
|
-- Copyright 2010
|
| 20 |
|
|
--
|
| 21 |
|
|
-- This module is free software: you can redistribute it and/or modify
|
| 22 |
|
|
-- it under the terms of the GNU Lesser General Public License as published by
|
| 23 |
|
|
-- the Free Software Foundation, either version 3 of the License, or
|
| 24 |
|
|
-- (at your option) any later version.
|
| 25 |
|
|
--
|
| 26 |
|
|
-- This module is distributed in the hope that it will be useful,
|
| 27 |
|
|
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 28 |
|
|
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 29 |
|
|
-- GNU Lesser General Public License for more details.
|
| 30 |
|
|
--
|
| 31 |
|
|
-- You should have received a copy of the GNU Lesser General Public License
|
| 32 |
|
|
-- along with this module. If not, see <http://www.gnu.org/licenses/>.
|
| 33 |
|
|
----------------------------------------------------------------------------------
|
| 34 |
|
|
library IEEE;
|
| 35 |
|
|
use IEEE.STD_LOGIC_1164.ALL;
|
| 36 |
|
|
use IEEE.STD_LOGIC_ARITH.ALL;
|
| 37 |
|
|
use IEEE.STD_LOGIC_UNSIGNED.ALL;
|
| 38 |
|
|
use IEEE.NUMERIC_STD.ALL;
|
| 39 |
|
|
|
| 40 |
|
|
|
| 41 |
|
|
entity lfsr is
|
| 42 |
|
|
generic (
|
| 43 |
|
|
lfsr_length : STD_LOGIC_VECTOR(7 downto 0);
|
| 44 |
|
|
lfsr_out_length : STD_LOGIC_VECTOR(7 downto 0);
|
| 45 |
|
|
lfsr_allow_zero : STD_LOGIC);
|
| 46 |
|
|
port (
|
| 47 |
|
|
lfsr_out : out STD_LOGIC_VECTOR((conv_integer(lfsr_out_length) - 1) downto 0);
|
| 48 |
|
|
lfsr_seed : in STD_LOGIC_VECTOR((conv_integer(lfsr_length) - 1) downto 0);
|
| 49 |
|
|
lfsr_reset : in STD_LOGIC;
|
| 50 |
|
|
lfsr_clk : in STD_LOGIC;
|
| 51 |
|
|
lfsr_clk_en : in STD_LOGIC);
|
| 52 |
|
|
end lfsr;
|
| 53 |
|
|
|
| 54 |
|
|
architecture Behavioral of lfsr is
|
| 55 |
|
|
|
| 56 |
|
|
signal value : STD_LOGIC_VECTOR((conv_integer(lfsr_length) - 1) downto 0);
|
| 57 |
|
|
|
| 58 |
|
|
begin
|
| 59 |
|
|
|
| 60 |
|
|
process(lfsr_clk)
|
| 61 |
|
|
begin
|
| 62 |
|
|
if(lfsr_clk = '1' and lfsr_clk'EVENT) then
|
| 63 |
|
|
if(lfsr_reset = '1') then
|
| 64 |
|
|
value <= lfsr_seed;
|
| 65 |
|
|
lfsr_out <= (others => '0');
|
| 66 |
|
|
elsif(lfsr_clk_en = '1') then
|
| 67 |
|
|
value((conv_integer(lfsr_length) - 2) downto 0) <= value((conv_integer(lfsr_length) - 1) downto 1);
|
| 68 |
|
|
value((conv_integer(lfsr_length) - 1)) <= value(1) xor value(0);
|
| 69 |
|
|
if(lfsr_allow_zero = '0' and value((conv_integer(lfsr_length) - 1) downto (conv_integer(lfsr_length) - conv_integer(lfsr_out_length))) = 0) then
|
| 70 |
|
|
lfsr_out <= (others => '1');
|
| 71 |
|
|
else
|
| 72 |
|
|
lfsr_out <= value((conv_integer(lfsr_length) - 1) downto (conv_integer(lfsr_length) - conv_integer(lfsr_out_length)));
|
| 73 |
|
|
end if;
|
| 74 |
|
|
end if;
|
| 75 |
|
|
end if;
|
| 76 |
|
|
end process;
|
| 77 |
|
|
|
| 78 |
|
|
end Behavioral;
|
| 79 |
|
|
|