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

Subversion Repositories galois_lfsr

[/] [galois_lfsr/] [trunk/] [rtl/] [user.vhdl] - Blame information for rev 6

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 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
--use work.types.all;
40
 
41
entity user is
42
        generic(
43
                parallelLoad:boolean:=false;
44
                tapVector:boolean_vector:=(
45 6 daniel.kho
                        /* Example polynomial from Wikipedia:
46
                                http://en.wikipedia.org/wiki/Computation_of_cyclic_redundancy_checks
47
                        */
48 2 daniel.kho
                        0|1|2|8=>true, 7 downto 3=>false
49
                )
50
        );
51
        port(
52
                /* Comment-out for simulation. */
53
                --clk,reset:in std_ulogic;
54 5 daniel.kho
                msg:in unsigned(tapVector'high downto 0):=9x"57";
55 2 daniel.kho
                crc32:out unsigned(31 downto 0):=(others=>'0')
56
        );
57
end entity user;
58
 
59
architecture rtl of user is
60
        signal n,c:natural;
61
 
62
        /* Tester signals. */
63
        signal d:std_ulogic;
64
        /* synthesis translate_off */
65
        signal clk,reset:std_ulogic:='0';
66
        /* synthesis translate_on */
67
 
68
        signal loadEn,computeClk:std_ulogic;            -- clock gating.
69
        signal loaded,i_loaded:boolean;
70
        signal computed,i_computed:boolean;
71
 
72
begin
73
        /* Simulation Tester. */
74
        /* synthesis translate_off */
75
        clk<=not clk after 10 ps;
76
 
77
        process is begin
78
                reset<='0'; wait for 1 ps;
79
                reset<='1'; wait for 500 ps;
80
                reset<='0';
81
                wait;
82
        end process;
83
        /* synthesis translate_on */
84
 
85
        loadEn<=clk when reset='0' and not i_computed else '0';
86
        computeClk<=clk when reset='0' and i_loaded and not i_computed else '0';
87
 
88 3 daniel.kho
        /* Galois LFSR instance. */
89 2 daniel.kho
        i_lfsr: entity work.lfsr(rtl)
90
                generic map(taps=>tapVector)
91
                /*generic map(taps => (
92
                        0|1|2|8=>true,
93
                        7 downto 3=>false
94
                ))*/
95
                port map(nReset=>not reset, clk=>loadEn,
96
                        load=>parallelLoad,
97
                        seed=>msg,
98
                        d=>d,
99
                        q=>crc32(msg'range)
100
        );
101
 
102
        /* Load message into LFSR. */
103
        process(reset,loadEn) is begin
104
                if reset then loaded<=false; n<=msg'length-1; d<='0';
105
                elsif rising_edge(loadEn) then
106
                        d<='0';
107
 
108
                        /* for parallel mode, LFSR automatically loads the seed in parallel. */
109
                        if parallelLoad then d<='0'; loaded<=true;
110
                        else
111
                                if not loaded then d<=msg(n); end if;
112
 
113
                                if n>0 then n<=n-1;
114
                                else loaded<=true;
115
                                end if;
116
                        end if;
117
                end if;
118
        end process;
119
 
120
        /* Shift zeroes into LFSR after message has been loaded completely. */
121
        process(reset,loaded,computeClk) is begin
122
                if reset='1' or not loaded then computed<=false; c<=msg'length-1;
123
                elsif rising_edge(computeClk) then
124
                        if c>0 then c<=c-1;
125
                        else computed<=true;
126
                        end if;
127
                end if;
128
        end process;
129
 
130
        /* Register pipelines. */
131
        process(clk) is begin
132
                if falling_edge(clk) then
133
                        i_loaded<=loaded;
134
                        i_computed<=computed;
135
                end if;
136
        end process;
137
end architecture rtl;

powered by: WebSVN 2.1.0

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