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

Subversion Repositories w11

[/] [w11/] [tags/] [w11a_V0.6/] [rtl/] [vlib/] [comlib/] [comlib.vhd] - Blame information for rev 24

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 13 wfjm
-- $Id: comlib.vhd 427 2011-11-19 21:04:11Z mueller $
2 2 wfjm
--
3 12 wfjm
-- Copyright 2007-2011 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
4 2 wfjm
--
5
-- This program is free software; you may redistribute and/or modify it under
6
-- the terms of the GNU General Public License as published by the Free
7
-- Software Foundation, either version 2, or at your option any later version.
8
--
9
-- This program is distributed in the hope that it will be useful, but
10
-- WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY
11
-- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12
-- for complete details.
13
--
14
------------------------------------------------------------------------------
15
-- Package Name:   comlib
16
-- Description:    communication components
17
--
18
-- Dependencies:   -
19 13 wfjm
-- Tool versions:  xst 8.2, 9.1, 9.2, 11.4, 12.1; ghdl 0.18-0.29
20 2 wfjm
-- Revision History: 
21
-- Date         Rev Version  Comment
22 13 wfjm
-- 2011-09-17   410   1.4    now numeric_std clean; use for crc8 'A6' polynomial
23
--                           of Koopman et al.; crc8_update(_tbl) now function
24 12 wfjm
-- 2011-07-30   400   1.3    added byte2word, word2byte
25 2 wfjm
-- 2007-10-12    88   1.2.1  avoid ieee.std_logic_unsigned, use cast to unsigned
26
-- 2007-07-08    65   1.2    added procedure crc8_update_tbl
27
-- 2007-06-29    61   1.1.1  rename for crc8 SALT->INIT 
28
-- 2007-06-17    58   1.1    add crc8 
29
-- 2007-06-03    45   1.0    Initial version 
30
------------------------------------------------------------------------------
31
 
32
library ieee;
33
use ieee.std_logic_1164.all;
34 13 wfjm
use ieee.numeric_std.all;
35 2 wfjm
 
36
use work.slvtypes.all;
37
 
38
package comlib is
39
 
40 12 wfjm
component byte2word is                  -- 2 byte -> 1 word stream converter
41
  port (
42
    CLK : in slbit;                     -- clock
43
    RESET : in slbit;                   -- reset
44
    DI : in slv8;                       -- input data (byte)
45
    ENA : in slbit;                     -- write enable
46
    BUSY : out slbit;                   -- write port hold    
47
    DO : out slv16;                     -- output data (word)
48
    VAL : out slbit;                    -- read valid
49
    HOLD : in slbit;                    -- read hold
50
    ODD : out slbit                     -- odd byte pending
51
  );
52
end component;
53
 
54
component word2byte is                  -- 1 word -> 2 byte stream converter
55
  port (
56
    CLK : in slbit;                     -- clock
57
    RESET : in slbit;                   -- reset
58
    DI : in slv16;                      -- input data (word)
59
    ENA : in slbit;                     -- write enable
60
    BUSY : out slbit;                   -- write port hold    
61
    DO : out slv8;                      -- output data (byte)
62
    VAL : out slbit;                    -- read valid
63
    HOLD : in slbit;                    -- read hold
64
    ODD : out slbit                     -- odd byte pending
65
  );
66
end component;
67
 
68 2 wfjm
component cdata2byte is                 -- 9bit comma,data -> byte stream
69
  generic (
70
    CPREF : slv4 :=  "1000";            -- comma prefix
71
    NCOMM : positive :=  4);            -- number of comma chars
72
  port (
73
    CLK : in slbit;                     -- clock
74
    RESET : in slbit;                   -- reset
75
    DI : in slv9;                       -- input data; bit 8 = komma flag
76
    ENA : in slbit;                     -- write enable
77
    BUSY : out slbit;                   -- write port hold    
78
    DO : out slv8;                      -- output data
79
    VAL : out slbit;                    -- read valid
80
    HOLD : in slbit                     -- read hold
81
  );
82
end component;
83
 
84
component byte2cdata is                 -- byte stream -> 9bit comma,data
85
  generic (
86
    CPREF : slv4 :=  "1000";            -- comma prefix
87
    NCOMM : positive :=  4);            -- number of comma chars
88
  port (
89
    CLK : in slbit;                     -- clock
90
    RESET : in slbit;                   -- reset
91
    DI : in slv8;                       -- input data
92
    ENA : in slbit;                     -- write enable
93
    BUSY : out slbit;                   -- write port hold    
94
    DO : out slv9;                      -- output data; bit 8 = komma flag
95
    VAL : out slbit;                    -- read valid
96
    HOLD : in slbit                     -- read hold
97
  );
98
end component;
99
 
100
component crc8 is                       -- crc-8 generator, checker
101
  generic (
102
    INIT: slv8 :=  "00000000");         -- initial state of crc register
103
  port (
104
    CLK : in slbit;                     -- clock
105
    RESET : in slbit;                   -- reset
106
    ENA : in slbit;                     -- update enable
107
    DI : in slv8;                       -- input data
108
    CRC : out slv8                      -- crc code
109
  );
110
end component;
111
 
112 13 wfjm
  function crc8_update     (crc : in slv8; data : in slv8) return slv8;
113
  function crc8_update_tbl (crc : in slv8; data : in slv8) return slv8;
114 2 wfjm
 
115 12 wfjm
end package comlib;
116 2 wfjm
 
117
-- ----------------------------------------------------------------------------
118
 
119
package body comlib is
120
 
121 13 wfjm
  function crc8_update (crc: in slv8; data: in slv8) return slv8 is
122 2 wfjm
    variable t : slv8 := (others=>'0');
123 13 wfjm
    variable n : slv8 := (others=>'0');
124 2 wfjm
  begin
125
 
126
    t := data xor crc;
127 13 wfjm
 
128
    n(0) := t(5) xor t(4) xor t(2) xor t(0);
129
    n(1) := t(6) xor t(5) xor t(3) xor t(1);
130
    n(2) := t(7) xor t(6) xor t(5) xor t(0);
131
    n(3) := t(7) xor t(6) xor t(5) xor t(4) xor t(2) xor t(1) xor t(0);
132
    n(4) := t(7) xor t(6) xor t(5) xor t(3) xor t(2) xor t(1);
133
    n(5) := t(7) xor t(6) xor t(4) xor t(3) xor t(2);
134
    n(6) := t(7) xor t(3) xor t(2) xor t(0);
135
    n(7) := t(4) xor t(3) xor t(1);
136
 
137
    return n;
138 2 wfjm
 
139 13 wfjm
  end function crc8_update;
140 2 wfjm
 
141 13 wfjm
  function crc8_update_tbl (crc: in slv8; data: in slv8) return slv8 is
142 2 wfjm
 
143
    type crc8_tbl_type is array (0 to 255) of integer;
144
    variable crc8_tbl : crc8_tbl_type :=        -- generated with gen_crc8_tbl
145 13 wfjm
      (  0,  77, 154, 215, 121,  52, 227, 174,    -- 00-07
146
       242, 191, 104,  37, 139, 198,  17,  92,    -- 00-0f
147
       169, 228,  51, 126, 208, 157,  74,   7,    -- 10-17
148
        91,  22, 193, 140,  34, 111, 184, 245,    -- 10-1f
149
        31,  82, 133, 200, 102,  43, 252, 177,    -- 20-27
150
       237, 160, 119,  58, 148, 217,  14,  67,    -- 20-2f
151
       182, 251,  44,  97, 207, 130,  85,  24,    -- 30-37
152
        68,   9, 222, 147,  61, 112, 167, 234,    -- 30-3f
153
        62, 115, 164, 233,  71,  10, 221, 144,    -- 40-47
154
       204, 129,  86,  27, 181, 248,  47,  98,    -- 40-4f
155
       151, 218,  13,  64, 238, 163, 116,  57,    -- 50-57
156
       101,  40, 255, 178,  28,  81, 134, 203,    -- 50-5f
157
        33, 108, 187, 246,  88,  21, 194, 143,    -- 60-67
158
       211, 158,  73,   4, 170, 231,  48, 125,    -- 60-6f
159
       136, 197,  18,  95, 241, 188, 107,  38,    -- 70-70
160
       122,  55, 224, 173,   3,  78, 153, 212,    -- 70-7f
161
       124,  49, 230, 171,   5,  72, 159, 210,    -- 80-87
162
       142, 195,  20,  89, 247, 186, 109,  32,    -- 80-8f
163
       213, 152,  79,   2, 172, 225,  54, 123,    -- 90-97
164
        39, 106, 189, 240,  94,  19, 196, 137,    -- 90-9f
165
        99,  46, 249, 180,  26,  87, 128, 205,    -- a0-a7
166
       145, 220,  11,  70, 232, 165, 114,  63,    -- a0-af
167
       202, 135,  80,  29, 179, 254,  41, 100,    -- b0-b7
168
        56, 117, 162, 239,  65,  12, 219, 150,    -- b0-bf
169
        66,  15, 216, 149,  59, 118, 161, 236,    -- c0-c7
170
       176, 253,  42, 103, 201, 132,  83,  30,    -- c0-cf
171
       235, 166, 113,  60, 146, 223,   8,  69,    -- d0-d7
172
        25,  84, 131, 206,  96,  45, 250, 183,    -- d0-df
173
        93,  16, 199, 138,  36, 105, 190, 243,    -- e0-e7
174
       175, 226,  53, 120, 214, 155,  76,   1,    -- e0-ef
175
       244, 185, 110,  35, 141, 192,  23,  90,    -- f0-f7
176
         6,  75, 156, 209, 127,  50, 229, 168     -- f0-ff
177
      );
178 2 wfjm
 
179
  begin
180
 
181 13 wfjm
    return slv(to_unsigned(crc8_tbl(to_integer(unsigned(data xor crc))), 8));
182 2 wfjm
 
183 13 wfjm
  end function crc8_update_tbl;
184 2 wfjm
 
185
end package body comlib;

powered by: WebSVN 2.1.0

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