28use ieee.std_logic_1164.
all;
29use ieee.numeric_std.
all;
107 INIT: slv8 := "
00000000");
154 variable t :
slv8 :=
(others=>'
0'
);
155 variable n :
slv8 :=
(others=>'
0'
);
160 n
(0) := t
(5) xor t
(4) xor t
(2) xor t
(0);
161 n
(1) := t
(6) xor t
(5) xor t
(3) xor t
(1);
162 n
(2) := t
(7) xor t
(6) xor t
(5) xor t
(0);
163 n
(3) := t
(7) xor t
(6) xor t
(5) xor t
(4) xor t
(2) xor t
(1) xor t
(0);
164 n
(4) := t
(7) xor t
(6) xor t
(5) xor t
(3) xor t
(2) xor t
(1);
165 n
(5) := t
(7) xor t
(6) xor t
(4) xor t
(3) xor t
(2);
166 n
(6) := t
(7) xor t
(3) xor t
(2) xor t
(0);
167 n
(7) := t
(4) xor t
(3) xor t
(1);
171 end function crc8_update;
175 type crc8_tbl_type
is array (0 to 255) of integer;
176 variable crc8_tbl : crc8_tbl_type :=
-- generated with gen_crc8_tbl
177 ( 0,
77,
154,
215,
121,
52,
227,
174,
-- 00-07
178 242,
191,
104,
37,
139,
198,
17,
92,
-- 00-0f
179 169,
228,
51,
126,
208,
157,
74,
7,
-- 10-17
180 91,
22,
193,
140,
34,
111,
184,
245,
-- 10-1f
181 31,
82,
133,
200,
102,
43,
252,
177,
-- 20-27
182 237,
160,
119,
58,
148,
217,
14,
67,
-- 20-2f
183 182,
251,
44,
97,
207,
130,
85,
24,
-- 30-37
184 68,
9,
222,
147,
61,
112,
167,
234,
-- 30-3f
185 62,
115,
164,
233,
71,
10,
221,
144,
-- 40-47
186 204,
129,
86,
27,
181,
248,
47,
98,
-- 40-4f
187 151,
218,
13,
64,
238,
163,
116,
57,
-- 50-57
188 101,
40,
255,
178,
28,
81,
134,
203,
-- 50-5f
189 33,
108,
187,
246,
88,
21,
194,
143,
-- 60-67
190 211,
158,
73,
4,
170,
231,
48,
125,
-- 60-6f
191 136,
197,
18,
95,
241,
188,
107,
38,
-- 70-70
192 122,
55,
224,
173,
3,
78,
153,
212,
-- 70-7f
193 124,
49,
230,
171,
5,
72,
159,
210,
-- 80-87
194 142,
195,
20,
89,
247,
186,
109,
32,
-- 80-8f
195 213,
152,
79,
2,
172,
225,
54,
123,
-- 90-97
196 39,
106,
189,
240,
94,
19,
196,
137,
-- 90-9f
197 99,
46,
249,
180,
26,
87,
128,
205,
-- a0-a7
198 145,
220,
11,
70,
232,
165,
114,
63,
-- a0-af
199 202,
135,
80,
29,
179,
254,
41,
100,
-- b0-b7
200 56,
117,
162,
239,
65,
12,
219,
150,
-- b0-bf
201 66,
15,
216,
149,
59,
118,
161,
236,
-- c0-c7
202 176,
253,
42,
103,
201,
132,
83,
30,
-- c0-cf
203 235,
166,
113,
60,
146,
223,
8,
69,
-- d0-d7
204 25,
84,
131,
206,
96,
45,
250,
183,
-- d0-df
205 93,
16,
199,
138,
36,
105,
190,
243,
-- e0-e7
206 175,
226,
53,
120,
214,
155,
76,
1,
-- e0-ef
207 244,
185,
110,
35,
141,
192,
23,
90,
-- f0-f7
208 6,
75,
156,
209,
127,
50,
229,
168 -- f0-ff
213 return slv(to_unsigned
(crc8_tbl
(to_integer
(unsigned(data
xor crc
))),
8));
215 end function crc8_update_tbl;
221 variable n :
slv16 :=
(others=>'
0'
);
222 variable t :
slv8 :=
(others=>'
0'
);
225 t := data
xor crc
(15 downto 8);
227 n
(0) := t
(4) xor t
(0);
228 n
(1) := t
(5) xor t
(1);
229 n
(2) := t
(6) xor t
(2);
230 n
(3) := t
(7) xor t
(3);
232 n
(5) := t
(5) xor t
(4) xor t
(0);
233 n
(6) := t
(6) xor t
(5) xor t
(1);
234 n
(7) := t
(7) xor t
(6) xor t
(2);
236 n
(8) := t
(7) xor t
(3) xor crc
(0);
237 n
(9) := t
(4) xor crc
(1);
238 n
(10) := t
(5) xor crc
(2);
239 n
(11) := t
(6) xor crc
(3);
240 n
(12) := t
(7) xor t
(4) xor t
(0) xor crc
(4);
241 n
(13) := t
(5) xor t
(1) xor crc
(5);
242 n
(14) := t
(6) xor t
(2) xor crc
(6);
243 n
(15) := t
(7) xor t
(3) xor crc
(7);
247 end function crc16_update;
251 type crc16_tbl_type
is array (0 to 255) of integer;
252 variable crc16_tbl : crc16_tbl_type :=
253 ( 0,
4129,
8258,
12387,
16516,
20645,
24774,
28903,
254 33032,
37161,
41290,
45419,
49548,
53677,
57806,
61935,
255 4657,
528,
12915,
8786,
21173,
17044,
29431,
25302,
256 37689,
33560,
45947,
41818,
54205,
50076,
62463,
58334,
257 9314,
13379,
1056,
5121,
25830,
29895,
17572,
21637,
258 42346,
46411,
34088,
38153,
58862,
62927,
50604,
54669,
259 13907,
9842,
5649,
1584,
30423,
26358,
22165,
18100,
260 46939,
42874,
38681,
34616,
63455,
59390,
55197,
51132,
261 18628,
22757,
26758,
30887,
2112,
6241,
10242,
14371,
262 51660,
55789,
59790,
63919,
35144,
39273,
43274,
47403,
263 23285,
19156,
31415,
27286,
6769,
2640,
14899,
10770,
264 56317,
52188,
64447,
60318,
39801,
35672,
47931,
43802,
265 27814,
31879,
19684,
23749,
11298,
15363,
3168,
7233,
266 60846,
64911,
52716,
56781,
44330,
48395,
36200,
40265,
267 32407,
28342,
24277,
20212,
15891,
11826,
7761,
3696,
268 65439,
61374,
57309,
53244,
48923,
44858,
40793,
36728,
269 37256,
33193,
45514,
41451,
53516,
49453,
61774,
57711,
270 4224,
161,
12482,
8419,
20484,
16421,
28742,
24679,
271 33721,
37784,
41979,
46042,
49981,
54044,
58239,
62302,
272 689,
4752,
8947,
13010,
16949,
21012,
25207,
29270,
273 46570,
42443,
38312,
34185,
62830,
58703,
54572,
50445,
274 13538,
9411,
5280,
1153,
29798,
25671,
21540,
17413,
275 42971,
47098,
34713,
38840,
59231,
63358,
50973,
55100,
276 9939,
14066,
1681,
5808,
26199,
30326,
17941,
22068,
277 55628,
51565,
63758,
59695,
39368,
35305,
47498,
43435,
278 22596,
18533,
30726,
26663,
6336,
2273,
14466,
10403,
279 52093,
56156,
60223,
64286,
35833,
39896,
43963,
48026,
280 19061,
23124,
27191,
31254,
2801,
6864,
10931,
14994,
281 64814,
60687,
56684,
52557,
48554,
44427,
40424,
36297,
282 31782,
27655,
23652,
19525,
15522,
11395,
7392,
3265,
283 61215,
65342,
53085,
57212,
44955,
49082,
36825,
40952,
284 28183,
32310,
20053,
24180,
11923,
16050,
3793,
7920
287 variable ch :
slv16 :=
(others=>'
0'
);
288 variable cu :
slv16 :=
(others=>'
0'
);
289 variable t :
slv8 :=
(others=>'
0'
);
290 variable td :
integer :=
0;
295 ch := crc
(7 downto 0) &
"00000000";
296 t := data
xor crc
(15 downto 8);
297 td := crc16_tbl
(to_integer
(unsigned(t
)));
298 return ch
xor slv(to_unsigned
(td,
16));
300 end function crc16_update_tbl;
slv3 := "100" c_cdata_ec_xon
slv8 := "00010011" c_cdata_xoff
slv3 := "111" c_cdata_ec_esc
slv3 := "110" c_cdata_ec_fill
slv8 := "11010101" c_cdata_fill
integer range 7 downto 6 c_cdata_edf_pref
integer range 2 downto 0 c_cdata_edf_ec
integer range 5 downto 3 c_cdata_edf_eci
slv3 := "101" c_cdata_ec_xoff
slv crc8_update_tblcrc,data,
slv crc16_update_tblcrc,data,
slv crc16_updatecrc,data,
slv2 := "01" c_cdata_ed_pref
slv8 := "11001010" c_cdata_escape
slv8 := "00010001" c_cdata_xon
INIT slv16 :=( others => '0')
std_logic_vector( 2 downto 0) slv3
std_logic_vector( 8 downto 0) slv9
std_logic_vector( 15 downto 0) slv16
std_logic_vector( 7 downto 0) slv8
std_logic_vector( 1 downto 0) slv2