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

Subversion Repositories sata_controller_core

[/] [sata_controller_core/] [trunk/] [sata2_bus_v1_00_a/] [base_system/] [pcores/] [sata_core_v1_00_a/] [hdl/] [vhdl/] [crc.vhd] - Blame information for rev 11

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 11 ashwin_men
-- Copyright (C) 2012
2
-- Ashwin A. Mendon
3
--
4
-- This file is part of SATA2 core.
5
--
6
-- This program is free software; you can redistribute it and/or modify
7
-- it under the terms of the GNU General Public License as published by
8
-- the Free Software Foundation; either version 3 of the License, or
9
-- (at your option) any later version.
10
--
11
-- This program is distributed in the hope that it will be useful,
12
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
13
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
-- GNU General Public License for more details.
15
--
16
-- You should have received a copy of the GNU General Public License
17
-- along with this program.  If not, see <http://www.gnu.org/licenses/>.  
18
 
19
----------------------------------------------------------------------------------------
20
-- ENTITY: crc 
21
-- Version: 1.0
22
-- Author:  Ashwin Mendon 
23
-- Description: This sub-module implements the CRC Circuit for the SATA Protocol
24
--              The code takes 32-bit data word inputs and calculates the CRC for the stream
25
--              The generator polynomial used is     
26
--                      32  26  23  22  16  12  11  10  8   7   5   4   2       
27
--              G(x) = x + x + x + x + x + x + x + x + x + x + x + x + x + x + 1 
28
--              The CRC value is initialized to 0x52325032 as defined in the Serial ATA 
29
--              specification                                                           
30
-- PORTS: 
31
-----------------------------------------------------------------------------------------
32
 
33
library IEEE;
34
use IEEE.STD_LOGIC_1164.all;
35
use IEEE.STD_LOGIC_ARITH.all;
36
use IEEE.STD_LOGIC_UNSIGNED.all;
37
 
38
entity crc is
39
  generic(
40
    CHIPSCOPE             : boolean := false
41
       );
42
  port(
43
    -- Clock and Reset Signals
44
    clk                   : in  std_logic;
45
    reset                 : in  std_logic;
46
    -- ChipScope ILA / Trigger Signals
47
    --crc_ila_control       : in  std_logic_vector(35 downto 0);
48
    ---------------------------------------
49
    -- Signals from/to Sata Link Layer
50
    crc_en                : in  std_logic;
51
    data_in               : in  std_logic_vector(0 to 31);
52
    data_out              : out std_logic_vector(0 to 31)
53
      );
54
end crc;
55
 
56
-------------------------------------------------------------------------------
57
-- ARCHITECTURE
58
-------------------------------------------------------------------------------
59
architecture BEHAV of crc is
60
 
61
  -------------------------------------------------------------------------------
62
  -- Constants
63
  -------------------------------------------------------------------------------
64
  constant CRC_INIT       : std_logic_vector(0 to 31) := x"52325032";
65
 
66
  signal crc              : std_logic_vector (31 downto 0);
67
  signal crc_next         : std_logic_vector (31 downto 0);
68
  signal crc_new          : std_logic_vector (31 downto 0);
69
  signal data_out_ila     : std_logic_vector (31 downto 0);
70
 
71
 
72
-------------------------------------------------------------------------------
73
-- BEGIN
74
-------------------------------------------------------------------------------
75
begin
76
 
77
  -----------------------------------------------------------------------------
78
  -- PROCESS: CRC_PROC
79
  -- PURPOSE: Registering Signals and Next State
80
  -----------------------------------------------------------------------------
81
  CRC_PROC : process (clk)
82
  begin
83
    if ((clk'event) and (clk = '1')) then
84
      if (reset = '1') then
85
        --Initializing internal signals
86
        crc            <=  CRC_INIT;
87
      elsif (crc_en = '1') then
88
        -- Register all Current Signals to their _next Signals
89
        crc            <= crc_next;
90
      else
91
        crc            <= crc;
92
      end if;
93
    end if;
94
  end process CRC_PROC ;
95
 
96
 crc_new      <= crc xor data_in;
97
 
98
 crc_next(31) <= crc_new(31) xor crc_new(30) xor crc_new(29) xor crc_new(28) xor crc_new(27) xor crc_new(25) xor crc_new(24) xor
99
                     crc_new(23) xor crc_new(15) xor crc_new(11) xor crc_new(9) xor  crc_new(8)  xor crc_new(5);
100
 crc_next(30) <= crc_new(30) xor crc_new(29) xor crc_new(28) xor crc_new(27) xor crc_new(26) xor crc_new(24) xor crc_new(23) xor
101
                     crc_new(22) xor crc_new(14) xor crc_new(10) xor crc_new(8) xor  crc_new(7)  xor crc_new(4);
102
 crc_next(29) <= crc_new(31) xor crc_new(29) xor crc_new(28) xor crc_new(27) xor crc_new(26) xor crc_new(25) xor crc_new(23) xor
103
                     crc_new(22) xor crc_new(21) xor crc_new(13) xor crc_new(9) xor  crc_new(7)  xor crc_new(6)  xor crc_new(3);
104
 crc_next(28) <= crc_new(30) xor crc_new(28) xor crc_new(27) xor crc_new(26) xor crc_new(25) xor crc_new(24) xor crc_new(22) xor
105
                     crc_new(21) xor crc_new(20) xor crc_new(12) xor crc_new(8) xor  crc_new(6)  xor crc_new(5)  xor crc_new(2);
106
 crc_next(27) <= crc_new(29) xor crc_new(27) xor crc_new(26) xor crc_new(25) xor crc_new(24) xor crc_new(23) xor crc_new(21) xor
107
                     crc_new(20) xor crc_new(19) xor crc_new(11) xor crc_new(7) xor  crc_new(5)  xor crc_new(4)  xor crc_new(1);
108
 crc_next(26) <= crc_new(31) xor crc_new(28) xor crc_new(26) xor crc_new(25) xor crc_new(24) xor crc_new(23) xor crc_new(22) xor
109
                     crc_new(20) xor crc_new(19) xor crc_new(18) xor crc_new(10) xor crc_new(6)  xor crc_new(4)  xor crc_new(3)  xor
110
                     crc_new(0);
111
 crc_next(25) <= crc_new(31) xor crc_new(29) xor crc_new(28) xor crc_new(22) xor crc_new(21) xor crc_new(19) xor crc_new(18) xor
112
                     crc_new(17) xor crc_new(15) xor crc_new(11) xor crc_new(8) xor  crc_new(3)  xor crc_new(2);
113
 crc_next(24) <= crc_new(30) xor crc_new(28) xor crc_new(27) xor crc_new(21) xor crc_new(20) xor crc_new(18) xor crc_new(17) xor
114
                     crc_new(16) xor crc_new(14) xor crc_new(10) xor crc_new(7) xor  crc_new(2)  xor crc_new(1);
115
 crc_next(23) <= crc_new(31) xor crc_new(29) xor crc_new(27) xor crc_new(26) xor crc_new(20) xor crc_new(19) xor crc_new(17) xor
116
                     crc_new(16) xor crc_new(15) xor crc_new(13) xor crc_new(9) xor  crc_new(6)  xor crc_new(1)  xor crc_new(0);
117
 crc_next(22) <= crc_new(31) xor crc_new(29) xor crc_new(27) xor crc_new(26) xor crc_new(24) xor crc_new(23) xor crc_new(19) xor
118
                     crc_new(18) xor crc_new(16) xor crc_new(14) xor crc_new(12) xor crc_new(11) xor crc_new(9)  xor crc_new(0);
119
 crc_next(21) <= crc_new(31) xor crc_new(29) xor crc_new(27) xor crc_new(26) xor crc_new(24) xor crc_new(22) xor crc_new(18) xor
120
                     crc_new(17) xor crc_new(13) xor crc_new(10) xor crc_new(9) xor  crc_new(5);
121
 crc_next(20) <= crc_new(30) xor crc_new(28) xor crc_new(26) xor crc_new(25) xor crc_new(23) xor crc_new(21) xor crc_new(17) xor
122
                     crc_new(16) xor crc_new(12) xor crc_new(9) xor crc_new(8) xor   crc_new(4);
123
 crc_next(19) <= crc_new(29) xor crc_new(27) xor crc_new(25) xor crc_new(24) xor crc_new(22) xor crc_new(20) xor crc_new(16) xor
124
                     crc_new(15) xor crc_new(11) xor crc_new(8) xor crc_new(7) xor   crc_new(3);
125
 crc_next(18) <= crc_new(31) xor crc_new(28) xor crc_new(26) xor crc_new(24) xor crc_new(23) xor crc_new(21) xor crc_new(19) xor
126
                     crc_new(15) xor crc_new(14) xor crc_new(10) xor crc_new(7) xor  crc_new(6)  xor crc_new(2);
127
 crc_next(17) <= crc_new(31) xor crc_new(30) xor crc_new(27) xor crc_new(25) xor crc_new(23) xor crc_new(22) xor crc_new(20) xor
128
                     crc_new(18) xor crc_new(14) xor crc_new(13) xor crc_new(9) xor  crc_new(6)  xor crc_new(5)  xor crc_new(1);
129
 crc_next(16) <= crc_new(30) xor crc_new(29) xor crc_new(26) xor crc_new(24) xor crc_new(22) xor crc_new(21) xor crc_new(19) xor
130
                     crc_new(17) xor crc_new(13) xor crc_new(12) xor crc_new(8) xor  crc_new(5)  xor crc_new(4)  xor crc_new(0);
131
 crc_next(15) <= crc_new(30) xor crc_new(27) xor crc_new(24) xor crc_new(21) xor crc_new(20) xor crc_new(18) xor crc_new(16) xor
132
                     crc_new(15) xor crc_new(12) xor crc_new(9) xor crc_new(8) xor   crc_new(7)  xor crc_new(5)  xor crc_new(4)  xor
133
                     crc_new(3);
134
 crc_next(14) <= crc_new(29) xor crc_new(26) xor crc_new(23) xor crc_new(20) xor crc_new(19) xor crc_new(17) xor crc_new(15) xor
135
                     crc_new(14) xor crc_new(11) xor crc_new(8) xor crc_new(7) xor   crc_new(6) xor crc_new(4) xor crc_new(3) xor
136
                     crc_new(2);
137
 crc_next(13) <= crc_new(31) xor crc_new(28) xor crc_new(25) xor crc_new(22) xor crc_new(19) xor crc_new(18) xor crc_new(16) xor
138
                     crc_new(14) xor crc_new(13) xor crc_new(10) xor crc_new(7) xor  crc_new(6) xor crc_new(5) xor crc_new(3) xor
139
                     crc_new(2) xor crc_new(1);
140
 crc_next(12) <= crc_new(31) xor crc_new(30) xor crc_new(27) xor crc_new(24) xor crc_new(21) xor crc_new(18) xor crc_new(17) xor
141
                     crc_new(15) xor crc_new(13) xor crc_new(12) xor crc_new(9) xor  crc_new(6) xor crc_new(5) xor crc_new(4) xor
142
                     crc_new(2) xor crc_new(1) xor crc_new(0);
143
 crc_next(11) <= crc_new(31) xor crc_new(28) xor crc_new(27) xor crc_new(26) xor crc_new(25) xor crc_new(24) xor crc_new(20) xor
144
                     crc_new(17) xor crc_new(16) xor crc_new(15) xor crc_new(14) xor crc_new(12) xor crc_new(9) xor crc_new(4) xor
145
                     crc_new(3) xor crc_new(1) xor crc_new(0);
146
 crc_next(10) <= crc_new(31) xor crc_new(29) xor crc_new(28) xor crc_new(26) xor crc_new(19) xor crc_new(16) xor crc_new(14) xor
147
                     crc_new(13) xor crc_new(9) xor crc_new(5) xor crc_new(3) xor    crc_new(2) xor crc_new(0);
148
 crc_next(9) <= crc_new(29) xor crc_new(24) xor crc_new(23) xor crc_new(18) xor  crc_new(13) xor crc_new(12) xor crc_new(11) xor
149
                   crc_new(9)  xor crc_new(5)  xor crc_new(4)  xor crc_new(2)  xor crc_new(1);
150
 crc_next(8)  <= crc_new(31) xor crc_new(28) xor crc_new(23) xor crc_new(22) xor crc_new(17) xor crc_new(12) xor crc_new(11) xor
151
                   crc_new(10) xor crc_new(8)  xor crc_new(4)  xor crc_new(3)  xor crc_new(1)  xor crc_new(0);
152
 crc_next(7)  <= crc_new(29) xor crc_new(28) xor crc_new(25) xor crc_new(24) xor crc_new(23) xor crc_new(22) xor crc_new(21) xor
153
                   crc_new(16) xor crc_new(15) xor crc_new(10) xor crc_new(8)  xor crc_new(7)  xor crc_new(5) xor crc_new(3) xor
154
                   crc_new(2)  xor crc_new(0);
155
 crc_next(6)  <= crc_new(30) xor crc_new(29) xor crc_new(25) xor crc_new(22) xor crc_new(21) xor crc_new(20) xor crc_new(14) xor
156
                   crc_new(11) xor crc_new(8)  xor crc_new(7) xor crc_new(6) xor crc_new(5) xor crc_new(4) xor crc_new(2) xor
157
                   crc_new(1);
158
 crc_next(5)  <= crc_new(29) xor crc_new(28) xor crc_new(24) xor crc_new(21) xor crc_new(20) xor crc_new(19) xor crc_new(13) xor
159
                   crc_new(10) xor crc_new(7) xor crc_new(6) xor crc_new(5) xor crc_new(4) xor crc_new(3) xor crc_new(1) xor
160
                   crc_new(0);
161
 crc_next(4)  <= crc_new(31) xor crc_new(30) xor crc_new(29) xor crc_new(25) xor crc_new(24) xor crc_new(20) xor crc_new(19) xor
162
                   crc_new(18) xor crc_new(15) xor crc_new(12) xor crc_new(11) xor crc_new(8) xor crc_new(6) xor crc_new(4) xor
163
                   crc_new(3)  xor crc_new(2)  xor crc_new(0);
164
 crc_next(3)  <= crc_new(31) xor crc_new(27) xor crc_new(25) xor crc_new(19) xor crc_new(18) xor crc_new(17) xor crc_new(15) xor
165
                   crc_new(14) xor crc_new(10) xor crc_new(9)  xor crc_new(8) xor crc_new(7) xor crc_new(3) xor crc_new(2) xor
166
                   crc_new(1);
167
 crc_next(2)  <= crc_new(31) xor crc_new(30) xor crc_new(26) xor crc_new(24) xor crc_new(18) xor crc_new(17) xor crc_new(16) xor
168
                   crc_new(14) xor crc_new(13) xor crc_new(9) xor crc_new(8) xor crc_new(7) xor crc_new(6) xor crc_new(2) xor
169
                   crc_new(1)  xor crc_new(0);
170
 crc_next(1)  <= crc_new(28) xor crc_new(27) xor crc_new(24) xor crc_new(17) xor crc_new(16) xor crc_new(13) xor crc_new(12) xor
171
                   crc_new(11) xor crc_new(9)  xor crc_new(7)  xor crc_new(6)  xor crc_new(1)  xor crc_new(0);
172
 crc_next(0)  <= crc_new(31) xor crc_new(30) xor crc_new(29) xor crc_new(28) xor crc_new(26) xor crc_new(25) xor crc_new(24) xor
173
                   crc_new(16) xor crc_new(12) xor crc_new(10) xor crc_new(9)  xor crc_new(6)  xor crc_new(0);
174
 
175
 
176
 data_out_ila <= crc_next;
177
 --data_out_ila <= crc;
178
 
179
 -----------------------------------------------------------------------------
180
 -- ILA Instantiation
181
 -----------------------------------------------------------------------------
182
 data_out <= data_out_ila;
183
 
184
 
185
end BEHAV;
186
 
187
 

powered by: WebSVN 2.1.0

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