OpenCores
URL https://opencores.org/ocsvn/galois_lfsr/galois_lfsr/trunk

Subversion Repositories galois_lfsr

[/] [galois_lfsr/] [trunk/] [rtl/] [galois-lfsr.vhdl] - Diff between revs 2 and 7

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 2 Rev 7
/*
/*
        This file is part of the Galois Linear Feedback Shift Register
        This file is part of the Galois Linear Feedback Shift Register
        (galois_lfsr) project:
        (galois_lfsr) project:
                http://www.opencores.org/project,galois_lfsr
                http://www.opencores.org/project,galois_lfsr
 
 
        Description
        Description
        Synthesisable use case for Galois LFSR.
        Synthesisable use case for Galois LFSR.
        This example is a CRC generator that uses a Galois LFSR.
        This example is a CRC generator that uses a Galois LFSR.
        Example applications include:
        Example applications include:
        * serial or parallel PRBS generation.
        * serial or parallel PRBS generation.
        * CRC computation.
        * CRC computation.
        * digital scramblers/descramblers.
        * digital scramblers/descramblers.
 
 
        ToDo:
        ToDo:
 
 
        Author(s):
        Author(s):
        - Daniel C.K. Kho, daniel.kho@opencores.org | daniel.kho@tauhop.com
        - Daniel C.K. Kho, daniel.kho@opencores.org | daniel.kho@tauhop.com
 
 
        Copyright (C) 2012-2013 Authors and OPENCORES.ORG
        Copyright (C) 2012-2013 Authors and OPENCORES.ORG
 
 
        This source file may be used and distributed without
        This source file may be used and distributed without
        restriction provided that this copyright statement is not
        restriction provided that this copyright statement is not
        removed from the file and that any derivative work contains
        removed from the file and that any derivative work contains
        the original copyright notice and the associated disclaimer.
        the original copyright notice and the associated disclaimer.
 
 
        This source file is free software; you can redistribute it
        This source file is free software; you can redistribute it
        and/or modify it under the terms of the GNU Lesser General
        and/or modify it under the terms of the GNU Lesser General
        Public License as published by the Free Software Foundation;
        Public License as published by the Free Software Foundation;
        either version 2.1 of the License, or (at your option) any
        either version 2.1 of the License, or (at your option) any
        later version.
        later version.
 
 
        This source is distributed in the hope that it will be
        This source is distributed in the hope that it will be
        useful, but WITHOUT ANY WARRANTY; without even the implied
        useful, but WITHOUT ANY WARRANTY; without even the implied
        warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
        warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
        PURPOSE. See the GNU Lesser General Public License for more
        PURPOSE. See the GNU Lesser General Public License for more
        details.
        details.
 
 
        You should have received a copy of the GNU Lesser General
        You should have received a copy of the GNU Lesser General
        Public License along with this source; if not, download it
        Public License along with this source; if not, download it
        from http://www.opencores.org/lgpl.shtml.
        from http://www.opencores.org/lgpl.shtml.
*/
*/
library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all;
library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all;
--use work.types.all;
/* Enable for synthesis; comment out for simulation.
 
        For this design, we just need boolean_vector. This is already included in Questa/ModelSim,
 
        but Quartus doesn't yet support this.
 
*/
 
use work.types.all;
 
 
entity lfsr is generic(
entity lfsr is generic(
                /*
                /*
                 * Tap vector: a TRUE means that position is tapped, otherwise that position is untapped.
                 * Tap vector: a TRUE means that position is tapped, otherwise that position is untapped.
                 */
                 */
                taps:boolean_vector
                taps:boolean_vector
        );
        );
 
 
        port(nReset,clk:in std_ulogic:='0';
        port(nReset,clk:in std_ulogic:='0';
                load:in boolean;
                load:in boolean;
                seed:in unsigned(taps'high downto 0);
                seed:in unsigned(taps'high downto 0);
 
 
                d:in std_ulogic;
                d:in std_ulogic;
                q:out unsigned(taps'high downto 0)
                q:out unsigned(taps'high downto 0)
        );
        );
end entity lfsr;
end entity lfsr;
 
 
architecture rtl of lfsr is
architecture rtl of lfsr is
        signal i_d,i_q:unsigned(taps'high downto 0);
        signal i_d,i_q:unsigned(taps'high downto 0);
        signal x:unsigned(taps'high-1 downto 0);
        signal x:unsigned(taps'high-1 downto 0);
 
 
begin
begin
--      /* [begin]: Simulation testbench stimuli. Do not remove.
--      /* [begin]: Simulation testbench stimuli. Do not remove.
--              TODO migrate to separate testbench when more testcases are developed.
--              TODO migrate to separate testbench when more testcases are developed.
--      */
--      */
--      /* synthesis translate_off */
--      /* synthesis translate_off */
--      clk<=not clk after 1 ns;
--      clk<=not clk after 1 ns;
--      /* synthesis translate_on */
--      /* synthesis translate_on */
--      /* [end]: simulation stimuli. */
--      /* [end]: simulation stimuli. */
 
 
 
 
        /* Receives a vector of taps; generates LFSR structure with correct XOR positionings. */
        /* Receives a vector of taps; generates LFSR structure with correct XOR positionings. */
        tapGenr: for i in 0 to taps'high-1 generate
        tapGenr: for i in 0 to taps'high-1 generate
                i_d(i+1)<=x(i) when taps(i) else i_q(i);
                i_d(i+1)<=x(i) when taps(i) else i_q(i);
                x(i)<=i_q(i) xor i_q(taps'high);        -- when nReset else '0';
                x(i)<=i_q(i) xor i_q(taps'high);
        end generate;
        end generate;
 
 
        process(nReset,load,seed,clk) is begin
        process(nReset,load,seed,clk) is begin
                --if nReset='0' or load then i_q<=seed;
 
                if nReset='0' then i_q<=(others=>'0');
                if nReset='0' then i_q<=(others=>'0');
                elsif load then i_q<=seed;
                elsif load then i_q<=seed;
                elsif rising_edge(clk) then
                elsif rising_edge(clk) then
                        i_q<=i_d;
                        i_q<=i_d;
                end if;
                end if;
        end process;
        end process;
 
 
        i_d(0)<=d;
        i_d(0)<=d;
        q<=i_d;
        q<=i_d;
 
 
end architecture rtl;
end architecture rtl;
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.