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

Subversion Repositories open8_urisc

[/] [open8_urisc/] [trunk/] [VHDL/] [sdlc_crc16_ccitt.vhd] - Blame information for rev 286

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

Line No. Rev Author Line
1 278 jshamlet
-- Copyright (c)2020 Jeremy Seth Henry
2
-- All rights reserved.
3
--
4
-- Redistribution and use in source and binary forms, with or without
5
-- modification, are permitted provided that the following conditions are met:
6
--     * Redistributions of source code must retain the above copyright
7
--       notice, this list of conditions and the following disclaimer.
8
--     * Redistributions in binary form must reproduce the above copyright
9
--       notice, this list of conditions and the following disclaimer in the
10
--       documentation and/or other materials provided with the distribution,
11
--       where applicable (as part of a user interface, debugging port, etc.)
12
--
13
-- THIS SOFTWARE IS PROVIDED BY JEREMY SETH HENRY ``AS IS'' AND ANY
14
-- EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15
-- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16
-- DISCLAIMED. IN NO EVENT SHALL JEREMY SETH HENRY BE LIABLE FOR ANY
17
-- DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18
-- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19
-- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
20
-- ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22
-- THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23
--
24
-- VHDL Units :  crc16_ccitt
25
-- Description:  Implements the 16-bit CCITT CRC on byte-wide data. Logic
26
--  equations were taken from Intel/Altera app note AN049.
27
--
28
-- Revision History
29
-- Author          Date     Change
30
------------------ -------- ---------------------------------------------------
31
-- Seth Henry      12/09/20 Created from original version
32
 
33
library ieee;
34
use ieee.std_logic_1164.all;
35
 
36
entity sdlc_crc16_ccitt is
37
generic(
38
  Poly_Init                  : std_logic_vector(15 downto 0) := x"0000";
39
  Reset_Level                : std_logic := '1'
40
);
41
port(
42
  Clock                      : in  std_logic;
43
  Reset                      : in  std_logic;
44
  --
45
  Clear                      : in  std_logic;
46
  Wr_En                      : in  std_logic;
47
  Wr_Data                    : in  std_logic_vector(7 downto 0);
48
  --
49
  CRC16_Valid                : out std_logic;
50
  CRC16_Out                  : out std_logic_vector(15 downto 0)
51
);
52
end entity;
53
 
54
architecture behave of sdlc_crc16_ccitt is
55
 
56
  signal Calc_En             : std_logic    := '0';
57
  signal Buffer_En           : std_logic    := '0';
58
  signal Data                : std_logic_vector(7 downto 0)  := x"00";
59
  signal Exr                 : std_logic_vector(7 downto 0)  := x"00";
60
  signal Reg                 : std_logic_vector(15 downto 0) := x"0000";
61
 
62
begin
63
 
64
  Exr(0)                     <= Reg(0) xor Data(0);
65
  Exr(1)                     <= Reg(1) xor Data(1);
66
  Exr(2)                     <= Reg(2) xor Data(2);
67
  Exr(3)                     <= Reg(3) xor Data(3);
68
  Exr(4)                     <= Reg(4) xor Data(4);
69
  Exr(5)                     <= Reg(5) xor Data(5);
70
  Exr(6)                     <= Reg(6) xor Data(6);
71
  Exr(7)                     <= Reg(7) xor Data(7);
72
 
73
  CRC16_Calc: process( Clock, Reset )
74
  begin
75
    if( Reset = Reset_Level )then
76
      Calc_En                <= '0';
77
      Buffer_En              <= '0';
78
      Data                   <= x"00";
79
      Reg                    <= Poly_Init;
80
      CRC16_Out              <= x"0000";
81
      CRC16_Valid            <= '0';
82
    elsif( rising_edge(Clock) )then
83
      Calc_En                <= Wr_En;
84
      if( Wr_En  = '1' )then
85
        Data                 <= Wr_Data;
86
      end if;
87
 
88
      if( Calc_En = '1' )then
89
        Reg(0)               <= Reg(8)  xor            Exr(4) xor Exr(0);
90
        Reg(1)               <= Reg(9)  xor            Exr(5) xor Exr(1);
91
        Reg(2)               <= Reg(10) xor            Exr(6) xor Exr(2);
92
        Reg(3)               <= Reg(11) xor Exr(0) xor Exr(7) xor Exr(3);
93
        Reg(4)               <= Reg(12) xor Exr(1)                      ;
94
        Reg(5)               <= Reg(13) xor Exr(2)                      ;
95
        Reg(6)               <= Reg(14) xor Exr(3)                      ;
96
        Reg(7)               <= Reg(15) xor Exr(4)            xor Exr(0);
97
        Reg(8)               <= Exr(0)  xor Exr(5)            xor Exr(1);
98
        Reg(9)               <= Exr(1)  xor Exr(6)            xor Exr(2);
99
        Reg(10)              <= Exr(2)  xor Exr(7)            xor Exr(3);
100
        Reg(11)              <= Exr(3)                                  ;
101
        Reg(12)              <= Exr(4)                        xor Exr(0);
102
        Reg(13)              <= Exr(5)                        xor Exr(1);
103
        Reg(14)              <= Exr(6)                        xor Exr(2);
104
        Reg(15)              <= Exr(7)                        xor Exr(3);
105
      end if;
106
 
107
      if( Clear = '1' )then
108
        Reg                  <= Poly_Init;
109
      end if;
110
 
111
      Buffer_En              <= Calc_En;
112
      if( Buffer_En = '1' )then
113
        CRC16_Out            <= Reg xor x"FFFF";
114
      end if;
115
      CRC16_Valid            <= Buffer_En;
116
    end if;
117
  end process;
118
 
119
end architecture;

powered by: WebSVN 2.1.0

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