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

Subversion Repositories w11

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 wfjm
-- $Id: comlib.vhd 314 2010-07-09 17:38:41Z mueller $
2
--
3
-- Copyright 2007- by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
4
--
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
-- Tool versions:  xst 8.1, 8.2, 9.1, 9.2, 11.4; ghdl 0.18-0.26
20
-- Revision History: 
21
-- Date         Rev Version  Comment
22
-- 2007-10-12    88   1.2.1  avoid ieee.std_logic_unsigned, use cast to unsigned
23
-- 2007-07-08    65   1.2    added procedure crc8_update_tbl
24
-- 2007-06-29    61   1.1.1  rename for crc8 SALT->INIT 
25
-- 2007-06-17    58   1.1    add crc8 
26
-- 2007-06-03    45   1.0    Initial version 
27
------------------------------------------------------------------------------
28
 
29
library ieee;
30
use ieee.std_logic_1164.all;
31
use ieee.std_logic_arith.all;
32
 
33
use work.slvtypes.all;
34
 
35
package comlib is
36
 
37
component cdata2byte is                 -- 9bit comma,data -> byte stream
38
  generic (
39
    CPREF : slv4 :=  "1000";            -- comma prefix
40
    NCOMM : positive :=  4);            -- number of comma chars
41
  port (
42
    CLK : in slbit;                     -- clock
43
    RESET : in slbit;                   -- reset
44
    DI : in slv9;                       -- input data; bit 8 = komma flag
45
    ENA : in slbit;                     -- write enable
46
    BUSY : out slbit;                   -- write port hold    
47
    DO : out slv8;                      -- output data
48
    VAL : out slbit;                    -- read valid
49
    HOLD : in slbit                     -- read hold
50
  );
51
end component;
52
 
53
component byte2cdata is                 -- byte stream -> 9bit comma,data
54
  generic (
55
    CPREF : slv4 :=  "1000";            -- comma prefix
56
    NCOMM : positive :=  4);            -- number of comma chars
57
  port (
58
    CLK : in slbit;                     -- clock
59
    RESET : in slbit;                   -- reset
60
    DI : in slv8;                       -- input data
61
    ENA : in slbit;                     -- write enable
62
    BUSY : out slbit;                   -- write port hold    
63
    DO : out slv9;                      -- output data; bit 8 = komma flag
64
    VAL : out slbit;                    -- read valid
65
    HOLD : in slbit                     -- read hold
66
  );
67
end component;
68
 
69
component crc8 is                       -- crc-8 generator, checker
70
  generic (
71
    INIT: slv8 :=  "00000000");         -- initial state of crc register
72
  port (
73
    CLK : in slbit;                     -- clock
74
    RESET : in slbit;                   -- reset
75
    ENA : in slbit;                     -- update enable
76
    DI : in slv8;                       -- input data
77
    CRC : out slv8                      -- crc code
78
  );
79
end component;
80
 
81
  procedure crc8_update (crc : inout slv8;
82
                         data : in slv8);
83
  procedure crc8_update_tbl (crc : inout slv8;
84
                             data : in slv8);
85
 
86
end comlib;
87
 
88
-- ----------------------------------------------------------------------------
89
 
90
package body comlib is
91
 
92
  procedure crc8_update (crc : inout slv8;
93
                         data : in slv8) is
94
    variable t : slv8 := (others=>'0');
95
  begin
96
 
97
    t := data xor crc;
98
    crc(0) := t(0) xor t(4) xor t(5) xor t(6);
99
    crc(1) := t(1) xor t(5) xor t(6) xor t(7);
100
    crc(2) := t(0) xor t(2) xor t(4) xor t(5) xor t(7);
101
    crc(3) := t(0) xor t(1) xor t(3) xor t(4);
102
    crc(4) := t(0) xor t(1) xor t(2) xor t(6);
103
    crc(5) := t(1) xor t(2) xor t(3) xor t(7);
104
    crc(6) := t(2) xor t(3) xor t(4);
105
    crc(7) := t(3) xor t(4) xor t(5);
106
 
107
  end procedure crc8_update;
108
 
109
  procedure crc8_update_tbl (crc : inout slv8;
110
                             data : in slv8) is
111
 
112
    type crc8_tbl_type is array (0 to 255) of integer;
113
    variable crc8_tbl : crc8_tbl_type :=        -- generated with gen_crc8_tbl
114
      (   0,  29,  58,  39, 116, 105,  78,  83,
115
        232, 245, 210, 207, 156, 129, 166, 187,
116
        205, 208, 247, 234, 185, 164, 131, 158,
117
         37,  56,  31,   2,  81,  76, 107, 118,
118
        135, 154, 189, 160, 243, 238, 201, 212,
119
        111, 114,  85,  72,  27,   6,  33,  60,
120
         74,  87, 112, 109,  62,  35,   4,  25,
121
        162, 191, 152, 133, 214, 203, 236, 241,
122
         19,  14,  41,  52, 103, 122,  93,  64,
123
        251, 230, 193, 220, 143, 146, 181, 168,
124
        222, 195, 228, 249, 170, 183, 144, 141,
125
         54,  43,  12,  17,  66,  95, 120, 101,
126
        148, 137, 174, 179, 224, 253, 218, 199,
127
        124,  97,  70,  91,   8,  21,  50,  47,
128
         89,  68,  99, 126,  45,  48,  23,  10,
129
        177, 172, 139, 150, 197, 216, 255, 226,
130
         38,  59,  28,   1,  82,  79, 104, 117,
131
        206, 211, 244, 233, 186, 167, 128, 157,
132
        235, 246, 209, 204, 159, 130, 165, 184,
133
          3,  30,  57,  36, 119, 106,  77,  80,
134
        161, 188, 155, 134, 213, 200, 239, 242,
135
         73,  84, 115, 110,  61,  32,   7,  26,
136
        108, 113,  86,  75,  24,   5,  34,  63,
137
        132, 153, 190, 163, 240, 237, 202, 215,
138
         53,  40,  15,  18,  65,  92, 123, 102,
139
        221, 192, 231, 250, 169, 180, 147, 142,
140
        248, 229, 194, 223, 140, 145, 182, 171,
141
         16,  13,  42,  55, 100, 121,  94,  67,
142
        178, 175, 136, 149, 198, 219, 252, 225,
143
         90,  71,  96, 125,  46,  51,  20,   9,
144
        127,  98,  69,  88,  11,  22,  49,  44,
145
        151, 138, 173, 176, 227, 254, 217, 196
146
       );
147
 
148
  begin
149
 
150
    crc := conv_std_logic_vector(
151
             crc8_tbl(conv_integer(unsigned(data xor crc))), 8);
152
 
153
  end procedure crc8_update_tbl;
154
 
155
end package body comlib;

powered by: WebSVN 2.1.0

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