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 260

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

Line No. Rev Author Line
1 191 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 220 jshamlet
--
28
-- Revision History
29
-- Author          Date     Change
30
------------------ -------- ---------------------------------------------------
31
-- Seth Henry      04/14/20 Code cleanup and revision section added
32 191 jshamlet
 
33
library ieee;
34
use ieee.std_logic_1164.all;
35
 
36
library work;
37
  use work.sdlc_serial_pkg.all;
38
 
39
entity sdlc_crc16_ccitt is
40
generic(
41
  Poly_Init                  : std_logic_vector(15 downto 0) := x"0000";
42
  Reset_Level                : std_logic := '1'
43
);
44
port(
45
  Clock                      : in  std_logic;
46
  Reset                      : in  std_logic;
47
  --
48
  Clear                      : in  std_logic;
49 202 jshamlet
  Wr_En                      : in  std_logic;
50 191 jshamlet
  Wr_Data                    : in  DATA_IN_TYPE;
51
  --
52 202 jshamlet
  CRC16_Valid                : out std_logic;
53
  CRC16_Out                  : out CRC_OUT_TYPE
54 191 jshamlet
);
55
end entity;
56
 
57
architecture behave of sdlc_crc16_ccitt is
58
 
59 205 jshamlet
  signal Calc_En             : std_logic    := '0';
60
  signal Buffer_En           : std_logic    := '0';
61
  signal Data                : DATA_IN_TYPE := x"00";
62
  signal Exr                 : DATA_IN_TYPE := x"00";
63
  signal Reg                 : CRC_OUT_TYPE := x"0000";
64 191 jshamlet
 
65
begin
66
 
67
  Exr(0)                     <= Reg(0) xor Data(0);
68
  Exr(1)                     <= Reg(1) xor Data(1);
69
  Exr(2)                     <= Reg(2) xor Data(2);
70
  Exr(3)                     <= Reg(3) xor Data(3);
71
  Exr(4)                     <= Reg(4) xor Data(4);
72
  Exr(5)                     <= Reg(5) xor Data(5);
73
  Exr(6)                     <= Reg(6) xor Data(6);
74
  Exr(7)                     <= Reg(7) xor Data(7);
75
 
76
  CRC16_Calc: process( Clock, Reset )
77
  begin
78
    if( Reset = Reset_Level )then
79
      Calc_En                <= '0';
80
      Buffer_En              <= '0';
81
      Data                   <= x"00";
82
      Reg                    <= x"0000";
83
      CRC16_Out              <= x"0000";
84
      CRC16_Valid            <= '0';
85
    elsif( rising_edge(Clock) )then
86
      Calc_En                <= Wr_En;
87
      if( Wr_En  = '1' )then
88
        Data                 <= Wr_Data;
89
      end if;
90
 
91
      if( Calc_En = '1' )then
92
        Reg(0)               <= Reg(8)  xor            Exr(4) xor Exr(0);
93
        Reg(1)               <= Reg(9)  xor            Exr(5) xor Exr(1);
94
        Reg(2)               <= Reg(10) xor            Exr(6) xor Exr(2);
95
        Reg(3)               <= Reg(11) xor Exr(0) xor Exr(7) xor Exr(3);
96
        Reg(4)               <= Reg(12) xor Exr(1)                      ;
97
        Reg(5)               <= Reg(13) xor Exr(2)                      ;
98
        Reg(6)               <= Reg(14) xor Exr(3)                      ;
99
        Reg(7)               <= Reg(15) xor Exr(4)            xor Exr(0);
100
        Reg(8)               <= Exr(0)  xor Exr(5)            xor Exr(1);
101
        Reg(9)               <= Exr(1)  xor Exr(6)            xor Exr(2);
102
        Reg(10)              <= Exr(2)  xor Exr(7)            xor Exr(3);
103
        Reg(11)              <= Exr(3)                                  ;
104
        Reg(12)              <= Exr(4)                        xor Exr(0);
105
        Reg(13)              <= Exr(5)                        xor Exr(1);
106
        Reg(14)              <= Exr(6)                        xor Exr(2);
107
        Reg(15)              <= Exr(7)                        xor Exr(3);
108 202 jshamlet
      end if;
109
 
110
      if( Clear = '1' )then
111 191 jshamlet
        Reg                  <= Poly_Init;
112
      end if;
113
 
114
      Buffer_En              <= Calc_En;
115
      if( Buffer_En = '1' )then
116
        CRC16_Out            <= Reg xor x"FFFF";
117
      end if;
118
      CRC16_Valid            <= Buffer_En;
119
    end if;
120
  end process;
121
 
122
end architecture;

powered by: WebSVN 2.1.0

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