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

Subversion Repositories galois_lfsr

[/] [galois_lfsr/] [trunk/] [rtl/] [quartus-synthesis/] [user.vhdl] - Blame information for rev 8

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 8 daniel.kho
/*
2
        This file is part of the Galois Linear Feedback Shift Register
3
        (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
 
10
        ToDo:
11
 
12
        Author(s):
13
        - Daniel C.K. Kho, daniel.kho@opencores.org | daniel.kho@tauhop.com
14
 
15
        Copyright (C) 2012-2013 Authors and OPENCORES.ORG
16
 
17
        This source file may be used and distributed without
18
        restriction provided that this copyright statement is not
19
        removed from the file and that any derivative work contains
20
        the original copyright notice and the associated disclaimer.
21
 
22
        This source file is free software; you can redistribute it
23
        and/or modify it under the terms of the GNU Lesser General
24
        Public License as published by the Free Software Foundation;
25
        either version 2.1 of the License, or (at your option) any
26
        later version.
27
 
28
        This source is distributed in the hope that it will be
29
        useful, but WITHOUT ANY WARRANTY; without even the implied
30
        warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
31
        PURPOSE. See the GNU Lesser General Public License for more
32
        details.
33
 
34
        You should have received a copy of the GNU Lesser General
35
        Public License along with this source; if not, download it
36
        from http://www.opencores.org/lgpl.shtml.
37
*/
38
library ieee; use ieee.std_logic_1164.all, ieee.numeric_std.all; use ieee.math_real.all;
39
/* Enable for synthesis; comment out for simulation.
40
        For this design, we just need boolean_vector. This is already included in Questa/ModelSim,
41
        but Quartus doesn't yet support this.
42
*/
43
use work.types.all;
44
 
45
entity user is
46
        generic(
47
                parallelLoad:boolean:=false;
48
                tapVector:boolean_vector:=(
49
                        /* Example polynomial from Wikipedia:
50
                                http://en.wikipedia.org/wiki/Computation_of_cyclic_redundancy_checks
51
                        */
52
                        0|1|2|8=>true, 7 downto 3=>false
53
                )
54
        );
55
        port(
56
                /* Comment-out for simulation. */
57
                clk,reset:in std_ulogic;
58
                msg:in unsigned(tapVector'high downto 0):=9x"57";
59
                crc32:out unsigned(31 downto 0):=(others=>'0')
60
        );
61
end entity user;
62
 
63
architecture rtl of user is
64
        signal n,c:natural;
65
 
66
        /* Tester signals. */
67
        signal d:std_ulogic;
68
        /* synthesis translate_off */
69
        signal clk,reset:std_ulogic:='0';
70
        /* synthesis translate_on */
71
 
72
        signal loadEn,computeClk:std_ulogic;            -- clock gating.
73
        signal loaded,i_loaded:boolean;
74
        signal computed,i_computed:boolean;
75
 
76
begin
77
        /* Simulation Tester. */
78
        /* synthesis translate_off */
79
        clk<=not clk after 10 ps;
80
 
81
        process is begin
82
                reset<='0'; wait for 1 ps;
83
                reset<='1'; wait for 500 ps;
84
                reset<='0';
85
                wait;
86
        end process;
87
        /* synthesis translate_on */
88
 
89
        loadEn<=clk when reset='0' and not i_computed else '0';
90
        computeClk<=clk when reset='0' and i_loaded and not i_computed else '0';
91
 
92
        /* Galois LFSR instance. */
93
        i_lfsr: entity work.lfsr(rtl)
94
                generic map(taps=>tapVector)
95
                /*generic map(taps => (
96
                        0|1|2|8=>true,
97
                        7 downto 3=>false
98
                ))*/
99
                port map(nReset=>not reset, clk=>loadEn,
100
                        load=>parallelLoad,
101
                        seed=>msg,
102
                        d=>d,
103
                        q=>crc32(msg'range)
104
        );
105
 
106
        /* Load message into LFSR. */
107
        process(reset,loadEn) is begin
108
                if reset then loaded<=false; n<=msg'length-1; d<='0';
109
                elsif rising_edge(loadEn) then
110
                        d<='0';
111
 
112
                        /* for parallel mode, LFSR automatically loads the seed in parallel. */
113
                        if parallelLoad then d<='0'; loaded<=true;
114
                        else
115
                                if not loaded then d<=msg(n); end if;
116
 
117
                                if n>0 then n<=n-1;
118
                                else loaded<=true;
119
                                end if;
120
                        end if;
121
                end if;
122
        end process;
123
 
124
        /* Shift zeroes into LFSR after message has been loaded completely. */
125
        process(reset,loaded,computeClk) is begin
126
                if reset='1' or not loaded then computed<=false; c<=msg'length-1;
127
                elsif rising_edge(computeClk) then
128
                        if c>0 then c<=c-1;
129
                        else computed<=true;
130
                        end if;
131
                end if;
132
        end process;
133
 
134
        /* Register pipelines. */
135
        process(clk) is begin
136
                if falling_edge(clk) then
137
                        i_loaded<=loaded;
138
                        i_computed<=computed;
139
                end if;
140
        end process;
141
end architecture rtl;

powered by: WebSVN 2.1.0

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