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

Subversion Repositories tosnet

[/] [tosnet/] [trunk/] [gateware/] [MicroBlaze_Peripheral_rev3_2/] [pcores/] [tosnet_v3_20_a/] [hdl/] [vhdl/] [crcgen.vhd] - Blame information for rev 5

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 5 sonicwave
----------------------------------------------------------------------------------
2
-- Company:             University of Southern Denmark
3
-- Engineer:            Simon Falsig
4
-- 
5
-- Create Date:         1/4/2010 
6
-- Design Name          8bit CRC generator
7
-- Module Name:         crcgen - Behavioral 
8
-- File Name:           crcgen.vhd
9
-- Project Name:        TosNet
10
-- Target Devices:      Spartan3/6
11
-- Tool versions:       Xilinx ISE 12.2
12
-- Description:         Adapted from "Parallel CRC Realization", by Guiseppe
13
--                                      Campobello, Guiseppe Patanč and Marco Russo, IEEE
14
--                                      Transactions on Computers, Vol.52, No.10, October 2003.
15
--                                      Adjustments have been made to the layout, the reset has been
16
--                                      converted to a synchronous reset instead of the asynchronous
17
--                                      reset from the original paper, and a clock enable has been
18
--                                      added.
19
--
20
-- Revision: 
21
-- Revision 3.2 -       Initial release
22
--
23
-- Copyright 2010
24
--
25
-- This module is free software: you can redistribute it and/or modify
26
-- it under the terms of the GNU Lesser General Public License as published by
27
-- the Free Software Foundation, either version 3 of the License, or
28
-- (at your option) any later version.
29
--
30
-- This module is distributed in the hope that it will be useful,
31
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
32
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
33
-- GNU Lesser General Public License for more details.
34
--
35
-- You should have received a copy of the GNU Lesser General Public License
36
-- along with this module.  If not, see <http://www.gnu.org/licenses/>.
37
----------------------------------------------------------------------------------
38
library ieee;
39
use ieee.std_logic_1164.all;
40
use work.crcpack.all;
41
 
42
 
43
entity crcgen is
44
        Port (  reset           : in    STD_LOGIC;
45
                        clk             : in    STD_LOGIC;
46
                        clk_en          : in    STD_LOGIC;
47
                        Din                     : in    STD_LOGIC_VECTOR(DATA_WIDTH - 1 downto 0);
48
                        Xout            : out   STD_LOGIC_VECTOR(CRCDIM - 1 downto 0));
49
end crcgen;
50
 
51
 
52
architecture rtl of crcgen is
53
        signal X                        : STD_LOGIC_VECTOR(CRCDIM - 1 downto 0);
54
        signal X1                       : STD_LOGIC_VECTOR(CRCDIM - 1 downto 0);
55
        signal X2                       : STD_LOGIC_VECTOR(CRCDIM - 1 downto 0);
56
        signal Dins                     : STD_LOGIC_VECTOR(CRCDIM - 1 downto 0);
57
begin
58
 
59
        process(Din)
60
                variable Dinv   : STD_LOGIC_VECTOR(CRCDIM - 1 downto 0);
61
        begin
62
                Dinv := (others => '0');
63
                Dinv(DATA_WIDTH - 1 downto 0) := Din;                                            --LFSR:
64
                Dins <= Dinv;
65
        end process;
66
 
67
        X2 <= X ;                       --LFSR
68
 
69
        process(clk)
70
        begin
71
                if(clk = '1' and clk'EVENT) then
72
                        if(reset = '1') then
73
                                X <= (others => '0');
74
                        elsif(clk_en = '1') then
75
                                X <= X1 xor Dins ;      --LFSR
76
                        end if;
77
                end if;
78
        end process;
79
 
80
        Xout <= X;
81
 
82
--This process builds matrix M=F^w
83
        process(X2)
84
                variable Xtemp  : STD_LOGIC_VECTOR(CRCDIM - 1 downto 0);
85
                variable vect   : STD_LOGIC_VECTOR(CRCDIM - 1 downto 0);
86
                variable vect2  : STD_LOGIC_VECTOR(CRCDIM - 1 downto 0);
87
                variable M              : matrix;
88
                variable F              : matrix;
89
        begin
90
        --Matrix F
91
                F(0) := CRC(CRCDIM - 1 downto 0);
92
                for i in 0 to CRCDIM - 2  loop
93
                        vect := (others => '0');
94
                        vect(CRCDIM - i - 1) := '1';
95
                        F(i+1) := vect;
96
                end loop;
97
        --Matrix M=F?w
98
                M(DATA_WIDTH - 1) := CRC(CRCDIM - 1 downto 0);
99
                for k in 2 to DATA_WIDTH loop
100
                        vect2 := M(DATA_WIDTH - k + 1 );
101
                        vect := (others => '0');
102
                        for i in 0 to CRCDIM - 1 loop
103
                                if(vect2(CRCDIM - 1 - i) = '1') then
104
                                        vect := vect xor F(i);
105
                                end if;
106
                        end loop;
107
                        M(DATA_WIDTH - k) := vect;
108
                end loop;
109
                for k in DATA_WIDTH - 1 to CRCDIM - 1 loop
110
                        M(k) := F(k - DATA_WIDTH + 1);
111
                end loop;
112
 
113
--Combinatorial logic equations : X1 = M ( x ) X
114
 
115
                Xtemp := (others => '0');
116
                for i in 0 to CRCDIM - 1 loop
117
                        vect := M(i);
118
                        for j in 0 to CRCDIM - 1 loop
119
                                if(vect(j) = '1') then
120
                                        Xtemp(j) := Xtemp(j) xor X2(CRCDIM - 1 - i);
121
                                end if;
122
                        end loop;
123
                end loop;
124
                X1 <= Xtemp;
125
 
126
        end process;
127
end rtl;

powered by: WebSVN 2.1.0

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