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

Subversion Repositories galois_lfsr

[/] [galois_lfsr/] [trunk/] [rtl/] [galois-lfsr.vhdl] - Blame information for rev 8

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 daniel.kho
/*
2 8 daniel.kho
        This file is part of the Galois-type linear-feedback shift register
3 2 daniel.kho
        (galois_lfsr) project:
4
                http://www.opencores.org/project,galois_lfsr
5
 
6
        Description
7
        Synthesisable use case for Galois LFSR.
8
        This example is a CRC generator that uses a Galois LFSR.
9
        Example applications include:
10
        * serial or parallel PRBS generation.
11
        * CRC computation.
12
        * digital scramblers/descramblers.
13
 
14
        ToDo:
15
 
16
        Author(s):
17
        - Daniel C.K. Kho, daniel.kho@opencores.org | daniel.kho@tauhop.com
18
 
19
        Copyright (C) 2012-2013 Authors and OPENCORES.ORG
20
 
21
        This source file may be used and distributed without
22
        restriction provided that this copyright statement is not
23
        removed from the file and that any derivative work contains
24
        the original copyright notice and the associated disclaimer.
25
 
26
        This source file is free software; you can redistribute it
27
        and/or modify it under the terms of the GNU Lesser General
28
        Public License as published by the Free Software Foundation;
29
        either version 2.1 of the License, or (at your option) any
30
        later version.
31
 
32
        This source is distributed in the hope that it will be
33
        useful, but WITHOUT ANY WARRANTY; without even the implied
34
        warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
35
        PURPOSE. See the GNU Lesser General Public License for more
36
        details.
37
 
38
        You should have received a copy of the GNU Lesser General
39
        Public License along with this source; if not, download it
40
        from http://www.opencores.org/lgpl.shtml.
41
*/
42
library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all;
43 7 daniel.kho
/* Enable for synthesis; comment out for simulation.
44
        For this design, we just need boolean_vector. This is already included in Questa/ModelSim,
45
        but Quartus doesn't yet support this.
46
*/
47 8 daniel.kho
--use work.types.all;
48 2 daniel.kho
 
49
entity lfsr is generic(
50
                /*
51
                 * Tap vector: a TRUE means that position is tapped, otherwise that position is untapped.
52
                 */
53
                taps:boolean_vector
54
        );
55
 
56
        port(nReset,clk:in std_ulogic:='0';
57
                load:in boolean;
58
                seed:in unsigned(taps'high downto 0);
59
 
60
                d:in std_ulogic;
61
                q:out unsigned(taps'high downto 0)
62
        );
63
end entity lfsr;
64
 
65
architecture rtl of lfsr is
66
        signal i_d,i_q:unsigned(taps'high downto 0);
67
        signal x:unsigned(taps'high-1 downto 0);
68
 
69
begin
70
--      /* [begin]: Simulation testbench stimuli. Do not remove.
71
--              TODO migrate to separate testbench when more testcases are developed.
72
--      */
73
--      /* synthesis translate_off */
74
--      clk<=not clk after 1 ns;
75
--      /* synthesis translate_on */
76
--      /* [end]: simulation stimuli. */
77
 
78
 
79
        /* Receives a vector of taps; generates LFSR structure with correct XOR positionings. */
80
        tapGenr: for i in 0 to taps'high-1 generate
81
                i_d(i+1)<=x(i) when taps(i) else i_q(i);
82 7 daniel.kho
                x(i)<=i_q(i) xor i_q(taps'high);
83 2 daniel.kho
        end generate;
84
 
85
        process(nReset,load,seed,clk) is begin
86
                if nReset='0' then i_q<=(others=>'0');
87
                elsif load then i_q<=seed;
88
                elsif rising_edge(clk) then
89
                        i_q<=i_d;
90
                end if;
91
        end process;
92
 
93
        i_d(0)<=d;
94
        q<=i_d;
95
 
96
end architecture rtl;

powered by: WebSVN 2.1.0

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