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 207

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

powered by: WebSVN 2.1.0

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