OpenCores
URL https://opencores.org/ocsvn/sdhc-sc-core/sdhc-sc-core/trunk

Subversion Repositories sdhc-sc-core

[/] [sdhc-sc-core/] [trunk/] [grpCrc/] [unitCrc/] [src/] [Crc-Rtl-ea.vhdl] - Blame information for rev 185

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 164 rkastl
-- SDHC-SC-Core
2
-- Secure Digital High Capacity Self Configuring Core
3
-- 
4 170 rkastl
-- (C) Copyright 2010, Rainer Kastl
5
-- All rights reserved.
6 164 rkastl
-- 
7 170 rkastl
-- Redistribution and use in source and binary forms, with or without
8
-- modification, are permitted provided that the following conditions are met:
9
--     * Redistributions of source code must retain the above copyright
10
--       notice, this list of conditions and the following disclaimer.
11
--     * Redistributions in binary form must reproduce the above copyright
12
--       notice, this list of conditions and the following disclaimer in the
13
--       documentation and/or other materials provided with the distribution.
14
--     * Neither the name of the <organization> nor the
15
--       names of its contributors may be used to endorse or promote products
16
--       derived from this software without specific prior written permission.
17 164 rkastl
-- 
18 170 rkastl
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS  "AS IS" AND
19
-- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20
-- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
-- DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
22
-- DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23
-- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24
-- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25
-- ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 164 rkastl
-- 
29
-- File        : Crc-Rtl-ea.vhdl
30
-- Owner       : Rainer Kastl
31
-- Description : CRC implementation with generic polynoms
32
-- Links       : 
33
-- 
34
 
35
-- User information:
36 4 rkastl
-- While the data is shifted in bit by bit iDataIn
37
-- has to be '1'. The CRC can be shifted out by
38
-- setting iDataIn to '0'.
39
-- If the CRC should be checked it has to be shifted
40
-- in directly after the data. If the remainder is 0,
41
-- the CRC is correct.
42 3 rkastl
 
43
library ieee;
44
use ieee.std_logic_1164.all;
45 55 rkastl
use ieee.numeric_std.all;
46 6 rkastl
use work.CRCs.all;
47 3 rkastl
 
48
entity crc is
49 16 rkastl
        generic (
50
                gPolynom : std_ulogic_vector := crc7
51
        );
52
        port (
53
                iClk         : in std_ulogic;
54 165 rkastl
                iRstSync     : in std_ulogic; -- Synchronous high active reset
55 105 rkastl
                iStrobe      : in std_ulogic; -- Strobe, only shift when it is activated
56 165 rkastl
                iClear           : in std_ulogic; -- Clear register
57 16 rkastl
                iDataIn      : in std_ulogic; -- Signal that currently data is shifted in.
58
                                              -- Otherwise the current remainder is shifted out.
59
                iData     : in std_ulogic; -- Data input
60 55 rkastl
                oIsCorrect : out std_ulogic; -- Active, if crc is currently 0
61 16 rkastl
                oSerial   : out std_ulogic; -- Serial data output
62
                oParallel : out std_ulogic_vector(gPolynom'high - 1 downto gPolynom'low)
63
                -- parallel data output
64
        );
65
        begin
66
                -- check the used polynom
67
                assert gPolynom(gPolynom'high) = '1' report
68
                "Invalid polynom: no '1' at the highest position." severity failure;
69
                assert gPolynom(gPolynom'low) = '1' report
70
                "Invalid polynom: no '1' at the lowest position." severity failure;
71
        end crc;
72 3 rkastl
 
73
architecture rtl of crc is
74
 
75 16 rkastl
        signal regs : std_ulogic_vector(oParallel'range);
76 3 rkastl
 
77
begin
78
 
79 16 rkastl
        -- shift registers
80 165 rkastl
        crc : process (iClk) is
81 16 rkastl
                variable input : std_ulogic;
82
        begin
83 165 rkastl
                if (rising_edge(iClk)) then
84
                        if (iRstSync = '1') then
85 16 rkastl
                                regs <= (others => '0');
86 165 rkastl
                        else
87 105 rkastl
                                if (iStrobe = '1') then
88
                                        if (iDataIn = '1') then
89 16 rkastl
                                        -- calculate CRC
90 105 rkastl
                                                input := iData xor regs(regs'high);
91 3 rkastl
 
92 105 rkastl
                                                regs(0) <= input;
93 3 rkastl
 
94 105 rkastl
                                                for idx in 1 to regs'high loop
95
                                                        if (gPolynom(idx) = '1') then
96
                                                                regs(idx) <= regs(idx-1) xor input;
97
                                                        else
98
                                                                regs(idx) <= regs(idx-1);
99
                                                        end if;
100
                                                end loop;
101
                                        else
102
                                        -- shift data out
103
                                                regs(0) <= '0';
104
                                                for idx in 1 to regs'high loop
105 16 rkastl
                                                        regs(idx) <= regs(idx-1);
106 105 rkastl
                                                end loop;
107
                                        end if;
108 165 rkastl
 
109
                                        if (iClear = '1') then
110
                                                regs <= (others => '0');
111
                                        end if;
112 16 rkastl
                                end if;
113
                        end if;
114
                end if;
115
        end process crc;
116 3 rkastl
 
117 16 rkastl
        oParallel <= regs;
118
        oSerial   <= regs(regs'high);
119 55 rkastl
        oIsCorrect <= '1' when regs = std_ulogic_vector(to_unsigned(0,
120
                                  regs'length)) else '0';
121 3 rkastl
 
122 6 rkastl
end architecture rtl;

powered by: WebSVN 2.1.0

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