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

Subversion Repositories crcahb

[/] [crcahb/] [trunk/] [testbench/] [tb_crc_ip.v] - Blame information for rev 2

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

Line No. Rev Author Line
1 2 julioameri
module tb_crc_ip();
2
 
3
//Memory Map
4
localparam CRC_DR   = 32'h0;
5
localparam CRC_IDR  = 32'h4;
6
localparam CRC_CR   = 32'h8;
7
localparam CRC_INIT = 32'h10;
8
localparam CRC_POL  = 32'h14;
9
 
10
//HTRANS Encoding
11
localparam IDLE    = 2'b00;
12
localparam BUSY    = 2'b01;
13
localparam NON_SEQ = 2'b10;
14
localparam SEQ     = 2'b11;
15
 
16
//HSIZE Encoding
17
localparam BYTE      = 2'b00;
18
localparam HALF_WORD = 2'b01;
19
localparam WORD      = 2'b10;
20
 
21
//CRC_CR Encoding
22
localparam RESET             = 32'h00000001;
23
localparam POLY_SIZE_32      = 32'h00000000;
24
localparam POLY_SIZE_16      = 32'h00000001 << 3;
25
localparam POLY_SIZE_8       = 32'h00000001 << 4;
26
localparam POLY_SIZE_7       = 32'h00000003 << 3;
27
localparam REV_IN_NORMAL     = 32'h00000000;
28
localparam REV_IN_BYTE       = 32'h00000001 << 5;
29
localparam REV_IN_HALF_WORD  = 32'h00000001 << 6;
30
localparam REV_IN_WORD       = 32'h00000003 << 5;
31
localparam REV_OUT_NORMAL    = 32'h00000000;
32
localparam REV_OUT_REV       = 32'h00000001 << 7;
33
 
34
wire [31:0] HRDATA;
35
wire HREADYOUT;
36
wire HRESP;
37
 
38
reg [31:0] HWDATA;
39
reg [31:0] HADDR;
40
reg [ 2:0] HSIZE;
41
reg [ 1:0] HTRANS;
42
reg HWRITE;
43
reg HSElx;
44
reg HREADY;
45
reg HRESETn;
46
reg HCLK;
47
 
48
reg [31:0] result, golden;
49
reg [31:0] data_init, data_crc;
50
reg [31:0] data_rev;
51
 
52
task reset;
53
        begin
54
                HWDATA = 0;
55
                HADDR = 0;
56
                HSIZE = 0;
57
                HTRANS = 0;
58
                HWRITE = 0;
59
                HSElx = 0;
60
                HREADY = 1;
61
                HRESETn = 0;
62
                HCLK = 0;
63
                @(posedge HCLK);
64
                @(posedge HCLK);
65
                HRESETn = 1;
66
                @(posedge HCLK);
67
        end
68
endtask
69
 
70
task write_ahb;
71
        input [31:0] addr;
72
        input [31:0] data;
73
        input [ 1:0] size;
74
        begin
75
                HADDR <= addr;
76
                HSElx <= 1;
77
                HTRANS <= NON_SEQ;
78
                HSIZE <= size;
79
                HWRITE <= 1;
80
                @(negedge HCLK);
81
                if(HREADYOUT == 0)
82
                        @(posedge HREADYOUT);
83
                @(posedge HCLK);
84
                HWDATA <= data;
85
                HSElx <= 0;
86
                HTRANS <= IDLE;
87
        end
88
endtask
89
 
90
task read_ahb;
91
        input  [31:0] addr;
92
        output [31:0] data_rd;
93
        begin
94
                HADDR <= addr;
95
                HSElx <= 1;
96
                HTRANS <= NON_SEQ;
97
                HWRITE <= 0;
98
                @(posedge HCLK);
99
                @(negedge HCLK);
100
                if(HREADYOUT == 0)
101
                        @(posedge HREADYOUT);
102
                @(negedge HCLK);
103
                //@(posedge HCLK);
104
                data_rd = HRDATA;
105
                HSElx = 0;
106
                HTRANS = IDLE;
107
        end
108
endtask
109
 
110
task compare;
111
        input [31:0] golden;
112
        input [31:0] result;
113
        begin
114
                if(golden != result)
115
                        begin
116
                                $display("Error Founded...Expected %x, obtained %x", golden, result);
117
                                $stop;
118
                        end
119
        end
120
endtask
121
 
122
crc_ip CRC_IP
123
(
124
        .HRDATA    ( HRDATA    ),
125
        .HREADYOUT ( HREADYOUT ),
126
        .HRESP     ( HRESP     ),
127
        .HWDATA    ( HWDATA    ),
128
        .HADDR     ( HADDR     ),
129
        .HSIZE     ( HSIZE     ),
130
        .HTRANS    ( HTRANS    ),
131
        .HWRITE    ( HWRITE    ),
132
        .HSElx     ( HSElx     ),
133
        .HREADY    ( HREADY    ),
134
        .HRESETn   ( HRESETn   ),
135
        .HCLK      ( HCLK      )
136
);
137
 
138
initial
139
        begin
140
                reset;
141
 
142
                write_ahb(CRC_DR, 32'h01020304, WORD);
143
                write_ahb(3'h1, 32'h05060708, WORD);
144
                write_ahb(3'h2, 32'h090a0b0c, WORD);
145
                write_ahb(3'h3, 32'h0d0e0f00, WORD);
146
                write_ahb(3'h4, 32'h00112233, WORD);
147
 
148
                read_ahb(CRC_DR, result);
149
 
150
                write_ahb(CRC_IDR, 32'h89abcdef, WORD);
151
                read_ahb(CRC_IDR, result);
152
 
153
                //Test Case 1: Write and Read in IDR
154
                golden = 32'h89abcdee;
155
                write_ahb(CRC_IDR, golden, WORD);
156
                read_ahb(CRC_IDR, result);
157
                compare(32'hff & golden, result);
158
 
159
                golden = 32'hffeeddcc;
160
                write_ahb(CRC_IDR, golden, BYTE);
161
                read_ahb(CRC_IDR, result);
162
                compare(32'hff & golden, result);
163
 
164
   //Test Case 2: Write and Read in CR
165
                golden = 32'hffeeddcc;
166
 
167
   //Test Case 2: Write and Read in CR
168
                golden = 32'hffeeddcc;
169
                write_ahb(CRC_CR, golden, WORD);
170
                read_ahb(CRC_CR, result);
171
                compare(32'hf8 & golden, result);
172
 
173
                golden = 32'hffeeddff;
174
                write_ahb(CRC_CR, golden, WORD);
175
                read_ahb(CRC_CR, result);
176
                compare(32'hf8 & golden, result);
177
 
178
        //Test Case 3: Write and Read in INIT
179
                golden = 32'hffeeddcc;
180
                write_ahb(CRC_INIT, golden, WORD);
181
                read_ahb(CRC_INIT, result);
182
                compare(golden, result);
183
 
184
                golden = 32'hffeeddff;
185
                write_ahb(CRC_INIT, golden, WORD);
186
                read_ahb(CRC_INIT, result);
187
                compare(golden, result);
188
 
189
        //Test Case 4: Write and Read in POL
190
                golden = 32'h11235813;
191
                write_ahb(CRC_POL, golden, WORD);
192
                read_ahb(CRC_POL, result);
193
                compare(golden, result);
194
 
195
                golden = 32'h24161614;
196
                write_ahb(CRC_POL, golden, WORD);
197
                read_ahb(CRC_POL, result);
198
                compare(golden, result);
199
 
200
        //Test Case 5: Programmable Initial CRC Value
201
                //POLY_SIZE_32, Data_32
202
                data_init = 32'h14635287;
203
                data_crc = 32'haabbccdd;
204
                golden = //crc_32(32'hddccbbaa, data_init);
205
                crc_32(data_crc[31:24], crc_32(data_crc[23:16], crc_32(data_crc[15:8], crc_32(data_crc[7:0], data_init))));
206
                write_ahb(CRC_POL, 32'h04c11db7, WORD);
207
                write_ahb(CRC_CR, POLY_SIZE_32 | RESET, WORD);
208
                write_ahb(CRC_INIT, data_init, WORD);
209
                write_ahb(CRC_DR, data_crc, WORD);
210
                read_ahb(CRC_DR, result);
211
                compare(golden, result);
212
                $display("%x", golden);
213
 
214
                //POLY_SIZE_32, Data_16
215
                data_init = 32'h14635287;
216
                data_crc = 32'h11223344;
217
                golden = crc_32(data_crc[15:8], crc_32(data_crc[7:0], data_init));
218
                write_ahb(CRC_POL, 32'h04c11db7, WORD);
219
                write_ahb(CRC_CR, POLY_SIZE_32 | RESET, WORD);
220
                write_ahb(CRC_INIT, data_init, WORD);
221
                write_ahb(CRC_DR, data_crc, HALF_WORD);
222
                read_ahb(CRC_DR, result);
223
                compare(golden, result);
224
                $display("%x", golden);
225
 
226
                //POLY_SIZE_32, Data_8
227
                data_init = 32'h11223344;
228
                data_crc = 32'h01463528;
229
                golden = crc_32(data_crc[7:0], data_init);
230
                write_ahb(CRC_POL, 32'h04c11db7, WORD);
231
                write_ahb(CRC_CR, POLY_SIZE_32 | RESET, WORD);
232
                write_ahb(CRC_INIT, data_init, WORD);
233
                write_ahb(CRC_DR, data_crc, BYTE);
234
                read_ahb(CRC_DR, result);
235
                compare(golden, result);
236
                $display("%x", golden);
237
 
238
                //POLY_SIZE_16, Data_32
239
                data_init = 32'hadefbc89;
240
                data_crc = 32'h01463528;
241
                golden = crc_16(data_crc[31:24], crc_16(data_crc[23:16], crc_16(data_crc[15:8], crc_16(data_crc[7:0], data_init))));
242
                write_ahb(CRC_POL, 32'h00018005, WORD);
243
                write_ahb(CRC_CR, POLY_SIZE_16 | RESET, WORD);
244
                write_ahb(CRC_INIT, data_init, WORD);
245
                write_ahb(CRC_DR, data_crc, WORD);
246
                read_ahb(CRC_DR, result);
247
                compare(golden, result);
248
                $display("%x", golden);
249
 
250
                //POLY_SIZE_16, Data_16
251
                data_init = 32'h01463528;
252
                data_crc = 32'hadefbc89;
253
                golden = crc_16(data_crc[15:8], crc_16(data_crc[7:0], data_init));
254
                write_ahb(CRC_POL, 32'h00018005, WORD);
255
                write_ahb(CRC_CR, POLY_SIZE_16 | RESET, WORD);
256
                write_ahb(CRC_INIT, data_init, WORD);
257
                write_ahb(CRC_DR, data_crc, HALF_WORD);
258
                read_ahb(CRC_DR, result);
259
                compare(golden, result);
260
                $display("%x", golden);
261
 
262
                //POLY_SIZE_16, Data_8
263
                data_init = 32'h01463d28;
264
                data_crc = 32'haedfbc89;
265
                golden = crc_16(data_crc[7:0], data_init);
266
                write_ahb(CRC_POL, 32'h00018005, WORD);
267
                write_ahb(CRC_CR, POLY_SIZE_16 | RESET, WORD);
268
                write_ahb(CRC_INIT, data_init, WORD);
269
                write_ahb(CRC_DR, data_crc, BYTE);
270
                read_ahb(CRC_DR, result);
271
                compare(golden, result);
272
                $display("%x", golden);
273
 
274
                //POLY_SIZE_8, Data_32
275
                data_init = 32'h11453028;
276
                data_crc = 32'haed7bc39;
277
                golden = crc_8(data_crc[31:24], crc_8(data_crc[23:16], crc_8(data_crc[15:8], crc_8(data_crc[7:0], data_init))));
278
                write_ahb(CRC_POL, 32'h00000107, WORD);
279
                write_ahb(CRC_CR, POLY_SIZE_8 | RESET, WORD);
280
                write_ahb(CRC_INIT, data_init, WORD);
281
                write_ahb(CRC_DR, data_crc, WORD);
282
                read_ahb(CRC_DR, result);
283
                compare(golden, result);
284
                $display("%x", golden);
285
 
286
                //POLY_SIZE_8, Data_16
287
                data_init = 32'h11003028;
288
                data_crc = 32'haed70039;
289
                golden = crc_8(data_crc[15:8], crc_8(data_crc[7:0], data_init));
290
                write_ahb(CRC_POL, 32'h00000107, WORD);
291
                write_ahb(CRC_CR, POLY_SIZE_8 | RESET, WORD);
292
                write_ahb(CRC_INIT, data_init, WORD);
293
                write_ahb(CRC_DR, data_crc, HALF_WORD);
294
                read_ahb(CRC_DR, result);
295
                compare(golden, result);
296
                $display("%x", golden);
297
 
298
                //POLY_SIZE_8, Data_8
299
                data_init = 32'h11000028;
300
                data_crc = 32'hafdfff39;
301
                golden = crc_8(data_crc[7:0], data_init);
302
                write_ahb(CRC_POL, 32'h00000107, WORD);
303
                write_ahb(CRC_CR, POLY_SIZE_8 | RESET, WORD);
304
                write_ahb(CRC_INIT, data_init, WORD);
305
                write_ahb(CRC_DR, data_crc, BYTE);
306
                read_ahb(CRC_DR, result);
307
                compare(golden, result);
308
                $display("%x", golden);
309
 
310
                //POLY_SIZE_7, Data_32
311
                data_init = 32'h11453087;
312
                data_crc = 32'haed7bcfd;
313
                golden = crc_7(data_crc[31:24], crc_7(data_crc[23:16], crc_7(data_crc[15:8], crc_7(data_crc[7:0], data_init))));
314
                write_ahb(CRC_POL, 32'h00000087, WORD);
315
                write_ahb(CRC_CR, POLY_SIZE_7 | RESET, WORD);
316
                write_ahb(CRC_INIT, data_init, WORD);
317
                write_ahb(CRC_DR, data_crc, WORD);
318
                read_ahb(CRC_DR, result);
319
                compare(golden, result);
320
                $display("%x", golden);
321
 
322
                //POLY_SIZE_7, Data_16
323
                data_init = 32'h00453057;
324
                data_crc = 32'haed773fd;
325
                golden = crc_7(data_crc[15:8], crc_7(data_crc[7:0], data_init));
326
                write_ahb(CRC_POL, 32'h00000087, WORD);
327
                write_ahb(CRC_CR, POLY_SIZE_7 | RESET, WORD);
328
                write_ahb(CRC_INIT, data_init, WORD);
329
                write_ahb(CRC_DR, data_crc, HALF_WORD);
330
                read_ahb(CRC_DR, result);
331
                compare(golden, result);
332
                $display("%x", golden);
333
 
334
                //POLY_SIZE_7, Data_8
335
                data_init = 32'h0045301d;
336
                data_crc = 32'haed7732a;
337
                golden = crc_7(data_crc[7:0], data_init);
338
                write_ahb(CRC_POL, 32'h00000087, WORD);
339
                write_ahb(CRC_CR, POLY_SIZE_7 | RESET, WORD);
340
                write_ahb(CRC_INIT, data_init, WORD);
341
                write_ahb(CRC_DR, data_crc, BYTE);
342
                read_ahb(CRC_DR, result);
343
                compare(golden, result);
344
                $display("%x", golden);
345
 
346
        //Test Case 6: Test REV_IN configuratin
347
        //REV_IN_BYTE
348
                data_init = 32'h14635287;
349
                data_crc = 32'h1a2b3c4d;
350
                data_rev = 32'h58d43cb2;
351
                golden = crc_32(data_rev[31:24], crc_32(data_rev[23:16], crc_32(data_rev[15:8], crc_32(data_rev[7:0], data_init))));
352
                write_ahb(CRC_POL, 32'h04c11db7, WORD);
353
                write_ahb(CRC_CR, POLY_SIZE_32 | RESET | REV_IN_BYTE, WORD);
354
                write_ahb(CRC_INIT, data_init, WORD);
355
                write_ahb(CRC_DR, data_crc, WORD);
356
                read_ahb(CRC_DR, result);
357
                compare(golden, result);
358
                $display("%x", golden);
359
 
360
        //REV_IN_HALF_WORD
361
                data_init = 32'h14635287;
362
                data_crc = 32'h1a2b3c4d;
363
                data_rev = 32'hd458b23c;
364
                golden = crc_32(data_rev[31:24], crc_32(data_rev[23:16], crc_32(data_rev[15:8], crc_32(data_rev[7:0], data_init))));
365
                write_ahb(CRC_POL, 32'h04c11db7, WORD);
366
                write_ahb(CRC_CR, POLY_SIZE_32 | RESET | REV_IN_HALF_WORD, WORD);
367
                write_ahb(CRC_INIT, data_init, WORD);
368
                write_ahb(CRC_DR, data_crc, WORD);
369
                read_ahb(CRC_DR, result);
370
                compare(golden, result);
371
                $display("%x", golden);
372
 
373
        //REV_IN_WORD
374
                data_init = 32'h14635287;
375
                data_crc = 32'h1a2b3c4d;
376
                data_rev = 32'hb23cd458;
377
                golden = crc_32(data_rev[31:24], crc_32(data_rev[23:16], crc_32(data_rev[15:8], crc_32(data_rev[7:0], data_init))));
378
                write_ahb(CRC_POL, 32'h04c11db7, WORD);
379
                write_ahb(CRC_CR, POLY_SIZE_32 | RESET | REV_IN_WORD, WORD);
380
                write_ahb(CRC_INIT, data_init, WORD);
381
                write_ahb(CRC_DR, data_crc, WORD);
382
                read_ahb(CRC_DR, result);
383
                compare(golden, result);
384
                $display("%x", golden);
385
 
386
        //Test Case 7: Test REV_OUT configuratin
387
        //REV_IN_BYTE
388
                data_init = 32'h14635287;
389
                data_crc = 32'h1a2b3c4d;
390
                golden = rev_out(crc_32(data_crc[31:24], crc_32(data_crc[23:16], crc_32(data_crc[15:8], crc_32(data_crc[7:0], data_init)))));
391
                write_ahb(CRC_POL, 32'h04c11db7, WORD);
392
                write_ahb(CRC_CR, POLY_SIZE_32 | RESET | REV_OUT_REV, WORD);
393
                write_ahb(CRC_INIT, data_init, WORD);
394
                write_ahb(CRC_DR, data_crc, WORD);
395
                read_ahb(CRC_DR, result);
396
                compare(golden, result);
397
                $display("%x", golden);
398
 
399
        //Test Case 8: Test RESET, Data 32
400
                data_init = 32'h14635287;
401
                write_ahb(CRC_POL, 32'h04c11db7, WORD);
402
                write_ahb(CRC_CR, POLY_SIZE_32 | RESET, WORD);
403
                write_ahb(CRC_INIT, data_init, WORD);
404
 
405
                //Data 1
406
                data_crc = 32'h00112233;
407
                write_ahb(CRC_DR, data_crc, WORD);
408
                write_ahb(CRC_CR, RESET, WORD);
409
 
410
                //Data 2
411
                data_crc = 32'h44556677;
412
                write_ahb(CRC_DR, data_crc, WORD);
413
                write_ahb(CRC_CR, RESET, WORD);
414
 
415
                //Data 3
416
                data_crc = 32'h8899aabb;
417
                write_ahb(CRC_DR, data_crc, WORD);
418
                write_ahb(CRC_CR, RESET, WORD);
419
 
420
                //Data 4
421
                data_crc = 32'hccddeeff;
422
                write_ahb(CRC_INIT, data_init, WORD);
423
                write_ahb(CRC_DR, data_crc, WORD);
424
                write_ahb(CRC_CR, RESET, WORD);
425
 
426
 
427
                read_ahb(CRC_DR, result);
428
                golden = crc_32(data_crc[31:24], crc_32(data_crc[23:16], crc_32(data_crc[15:8], crc_32(data_crc[7:0], data_init))));
429
                compare(golden, result);
430
                $display("%x", golden);
431
 
432
                //Test Case 9: Test RESET, Data 16
433
                data_init = 32'h14635287;
434
                write_ahb(CRC_POL, 32'h04c11db7, WORD);
435
                write_ahb(CRC_CR, POLY_SIZE_32 | RESET, WORD);
436
                write_ahb(CRC_INIT, data_init, WORD);
437
 
438
                //Data 1
439
                data_crc = 32'h00112233;
440
                write_ahb(CRC_DR, data_crc, HALF_WORD);
441
                write_ahb(CRC_CR, RESET, WORD);
442
 
443
                //Data 2
444
                data_crc = 32'h44556677;
445
                write_ahb(CRC_DR, data_crc, HALF_WORD);
446
                write_ahb(CRC_CR, RESET, WORD);
447
 
448
                //Data 3
449
                data_crc = 32'h8899aabb;
450
                write_ahb(CRC_DR, data_crc, HALF_WORD);
451
                write_ahb(CRC_CR, RESET, WORD);
452
 
453
                //Data 4
454
                data_crc = 32'hccddeeff;
455
                write_ahb(CRC_INIT, data_init, WORD);
456
                write_ahb(CRC_DR, data_crc, HALF_WORD);
457
                write_ahb(CRC_CR, RESET, WORD);
458
 
459
 
460
                read_ahb(CRC_DR, result);
461
                golden = crc_32(data_crc[15:8], crc_32(data_crc[7:0], data_init));
462
                compare(golden, result);
463
                $display("%x", golden);
464
 
465
                //Test Case 10: Test RESET, Data 8
466
                data_init = 32'h14635287;
467
                write_ahb(CRC_POL, 32'h04c11db7, WORD);
468
                write_ahb(CRC_CR, POLY_SIZE_32 | RESET, WORD);
469
                write_ahb(CRC_INIT, data_init, WORD);
470
 
471
                //Data 1
472
                data_crc = 32'h00112233;
473
                write_ahb(CRC_DR, data_crc, BYTE);
474
                write_ahb(CRC_CR, RESET, WORD);
475
 
476
                //Data 2
477
                data_crc = 32'h44556677;
478
                write_ahb(CRC_DR, data_crc, BYTE);
479
                write_ahb(CRC_CR, RESET, WORD);
480
 
481
                //Data 3
482
                data_crc = 32'h8899aabb;
483
                write_ahb(CRC_DR, data_crc, BYTE);
484
                write_ahb(CRC_CR, RESET, WORD);
485
 
486
                //Data 4
487
                data_crc = 32'hccddeeff;
488
                write_ahb(CRC_INIT, data_init, WORD);
489
                write_ahb(CRC_DR, data_crc, BYTE);
490
                write_ahb(CRC_CR, RESET, WORD);
491
 
492
 
493
                read_ahb(CRC_DR, result);
494
                golden = crc_32(data_crc[7:0], data_init);
495
                compare(golden, result);
496
                $display("%x", golden);
497
 
498
                //Test Case 11: Write-Write-Reset
499
                data_init = 32'h146352dd;
500
                write_ahb(CRC_POL, 32'h04c11db7, WORD);
501
                write_ahb(CRC_CR, POLY_SIZE_32 | RESET, WORD);
502
                write_ahb(CRC_INIT, data_init, WORD);
503
 
504
                //Data 1
505
                data_crc = 32'h55112233;
506
                write_ahb(CRC_DR, data_crc, WORD);
507
                golden = crc_32(data_crc[31:24], crc_32(data_crc[23:16], crc_32(data_crc[15:8], crc_32(data_crc[7:0], data_init))));
508
 
509
                //Data 2
510
                data_crc = 32'h44006677;
511
                write_ahb(CRC_DR, data_crc, WORD);
512
                write_ahb(CRC_CR, RESET, WORD);
513
 
514
                read_ahb(CRC_DR, result);
515
                golden = crc_32(data_crc[31:24], crc_32(data_crc[23:16], crc_32(data_crc[15:8], crc_32(data_crc[7:0], golden))));
516
                compare(golden, result);
517
                $display("%x", golden);
518
 
519
                //Data 3
520
                data_crc = 32'h44005127;
521
                data_init = 32'h11112222;
522
                write_ahb(CRC_INIT, data_init, WORD);
523
                write_ahb(CRC_DR, data_crc, WORD);
524
                read_ahb(CRC_DR, result);
525
                golden = crc_32(data_crc[31:24], crc_32(data_crc[23:16], crc_32(data_crc[15:8], crc_32(data_crc[7:0], data_init))));
526
                compare(golden, result);
527
                $display("%x", golden);
528
                $stop;
529
        end
530
 
531
always #10
532
        HCLK = !HCLK;
533
 
534
function [31:0] rev_out;
535
        input [31:0] in;
536
        integer i;
537
        begin
538
                for(i = 0; i < 32; i = i + 1)
539
                        rev_out[i] = in[31 - i];
540
        end
541
endfunction
542
 
543
  function [31:0] crc_32;
544
 
545
    input [7:0] Data;
546
    input [31:0] crc;
547
    reg [7:0] d;
548
    reg [31:0] c;
549
    reg [31:0] newcrc;
550
  begin
551
    d = Data;
552
    c = crc;
553
 
554
    newcrc[0] = d[6] ^ d[0] ^ c[24] ^ c[30];
555
    newcrc[1] = d[7] ^ d[6] ^ d[1] ^ d[0] ^ c[24] ^ c[25] ^ c[30] ^ c[31];
556
    newcrc[2] = d[7] ^ d[6] ^ d[2] ^ d[1] ^ d[0] ^ c[24] ^ c[25] ^ c[26] ^ c[30] ^ c[31];
557
    newcrc[3] = d[7] ^ d[3] ^ d[2] ^ d[1] ^ c[25] ^ c[26] ^ c[27] ^ c[31];
558
    newcrc[4] = d[6] ^ d[4] ^ d[3] ^ d[2] ^ d[0] ^ c[24] ^ c[26] ^ c[27] ^ c[28] ^ c[30];
559
    newcrc[5] = d[7] ^ d[6] ^ d[5] ^ d[4] ^ d[3] ^ d[1] ^ d[0] ^ c[24] ^ c[25] ^ c[27] ^ c[28] ^ c[29] ^ c[30] ^ c[31];
560
    newcrc[6] = d[7] ^ d[6] ^ d[5] ^ d[4] ^ d[2] ^ d[1] ^ c[25] ^ c[26] ^ c[28] ^ c[29] ^ c[30] ^ c[31];
561
    newcrc[7] = d[7] ^ d[5] ^ d[3] ^ d[2] ^ d[0] ^ c[24] ^ c[26] ^ c[27] ^ c[29] ^ c[31];
562
    newcrc[8] = d[4] ^ d[3] ^ d[1] ^ d[0] ^ c[0] ^ c[24] ^ c[25] ^ c[27] ^ c[28];
563
    newcrc[9] = d[5] ^ d[4] ^ d[2] ^ d[1] ^ c[1] ^ c[25] ^ c[26] ^ c[28] ^ c[29];
564
    newcrc[10] = d[5] ^ d[3] ^ d[2] ^ d[0] ^ c[2] ^ c[24] ^ c[26] ^ c[27] ^ c[29];
565
    newcrc[11] = d[4] ^ d[3] ^ d[1] ^ d[0] ^ c[3] ^ c[24] ^ c[25] ^ c[27] ^ c[28];
566
    newcrc[12] = d[6] ^ d[5] ^ d[4] ^ d[2] ^ d[1] ^ d[0] ^ c[4] ^ c[24] ^ c[25] ^ c[26] ^ c[28] ^ c[29] ^ c[30];
567
    newcrc[13] = d[7] ^ d[6] ^ d[5] ^ d[3] ^ d[2] ^ d[1] ^ c[5] ^ c[25] ^ c[26] ^ c[27] ^ c[29] ^ c[30] ^ c[31];
568
    newcrc[14] = d[7] ^ d[6] ^ d[4] ^ d[3] ^ d[2] ^ c[6] ^ c[26] ^ c[27] ^ c[28] ^ c[30] ^ c[31];
569
    newcrc[15] = d[7] ^ d[5] ^ d[4] ^ d[3] ^ c[7] ^ c[27] ^ c[28] ^ c[29] ^ c[31];
570
    newcrc[16] = d[5] ^ d[4] ^ d[0] ^ c[8] ^ c[24] ^ c[28] ^ c[29];
571
    newcrc[17] = d[6] ^ d[5] ^ d[1] ^ c[9] ^ c[25] ^ c[29] ^ c[30];
572
    newcrc[18] = d[7] ^ d[6] ^ d[2] ^ c[10] ^ c[26] ^ c[30] ^ c[31];
573
    newcrc[19] = d[7] ^ d[3] ^ c[11] ^ c[27] ^ c[31];
574
    newcrc[20] = d[4] ^ c[12] ^ c[28];
575
    newcrc[21] = d[5] ^ c[13] ^ c[29];
576
    newcrc[22] = d[0] ^ c[14] ^ c[24];
577
    newcrc[23] = d[6] ^ d[1] ^ d[0] ^ c[15] ^ c[24] ^ c[25] ^ c[30];
578
    newcrc[24] = d[7] ^ d[2] ^ d[1] ^ c[16] ^ c[25] ^ c[26] ^ c[31];
579
    newcrc[25] = d[3] ^ d[2] ^ c[17] ^ c[26] ^ c[27];
580
    newcrc[26] = d[6] ^ d[4] ^ d[3] ^ d[0] ^ c[18] ^ c[24] ^ c[27] ^ c[28] ^ c[30];
581
    newcrc[27] = d[7] ^ d[5] ^ d[4] ^ d[1] ^ c[19] ^ c[25] ^ c[28] ^ c[29] ^ c[31];
582
    newcrc[28] = d[6] ^ d[5] ^ d[2] ^ c[20] ^ c[26] ^ c[29] ^ c[30];
583
    newcrc[29] = d[7] ^ d[6] ^ d[3] ^ c[21] ^ c[27] ^ c[30] ^ c[31];
584
    newcrc[30] = d[7] ^ d[4] ^ c[22] ^ c[28] ^ c[31];
585
    newcrc[31] = d[5] ^ c[23] ^ c[29];
586
    crc_32 = newcrc;
587
  end
588
  endfunction
589
 
590
function [15:0] crc_16;
591
 
592
    input [7:0] Data;
593
    input [15:0] crc;
594
    reg [7:0] d;
595
    reg [15:0] c;
596
    reg [15:0] newcrc;
597
  begin
598
    d = Data;
599
    c = crc;
600
 
601
    newcrc[0] = d[7] ^ d[6] ^ d[5] ^ d[4] ^ d[3] ^ d[2] ^ d[1] ^ d[0] ^ c[8] ^ c[9] ^ c[10] ^ c[11] ^ c[12] ^ c[13] ^ c[14] ^ c[15];
602
    newcrc[1] = d[7] ^ d[6] ^ d[5] ^ d[4] ^ d[3] ^ d[2] ^ d[1] ^ c[9] ^ c[10] ^ c[11] ^ c[12] ^ c[13] ^ c[14] ^ c[15];
603
    newcrc[2] = d[1] ^ d[0] ^ c[8] ^ c[9];
604
    newcrc[3] = d[2] ^ d[1] ^ c[9] ^ c[10];
605
    newcrc[4] = d[3] ^ d[2] ^ c[10] ^ c[11];
606
    newcrc[5] = d[4] ^ d[3] ^ c[11] ^ c[12];
607
    newcrc[6] = d[5] ^ d[4] ^ c[12] ^ c[13];
608
    newcrc[7] = d[6] ^ d[5] ^ c[13] ^ c[14];
609
    newcrc[8] = d[7] ^ d[6] ^ c[0] ^ c[14] ^ c[15];
610
    newcrc[9] = d[7] ^ c[1] ^ c[15];
611
    newcrc[10] = c[2];
612
    newcrc[11] = c[3];
613
    newcrc[12] = c[4];
614
    newcrc[13] = c[5];
615
    newcrc[14] = c[6];
616
    newcrc[15] = d[7] ^ d[6] ^ d[5] ^ d[4] ^ d[3] ^ d[2] ^ d[1] ^ d[0] ^ c[7] ^ c[8] ^ c[9] ^ c[10] ^ c[11] ^ c[12] ^ c[13] ^ c[14] ^ c[15];
617
    crc_16 = newcrc;
618
  end
619
  endfunction
620
 
621
function [7:0] crc_8;
622
 
623
    input [7:0] Data;
624
    input [7:0] crc;
625
    reg [7:0] d;
626
    reg [7:0] c;
627
    reg [7:0] newcrc;
628
  begin
629
    d = Data;
630
    c = crc;
631
 
632
    newcrc[0] = d[7] ^ d[6] ^ d[0] ^ c[0] ^ c[6] ^ c[7];
633
    newcrc[1] = d[6] ^ d[1] ^ d[0] ^ c[0] ^ c[1] ^ c[6];
634
    newcrc[2] = d[6] ^ d[2] ^ d[1] ^ d[0] ^ c[0] ^ c[1] ^ c[2] ^ c[6];
635
    newcrc[3] = d[7] ^ d[3] ^ d[2] ^ d[1] ^ c[1] ^ c[2] ^ c[3] ^ c[7];
636
    newcrc[4] = d[4] ^ d[3] ^ d[2] ^ c[2] ^ c[3] ^ c[4];
637
    newcrc[5] = d[5] ^ d[4] ^ d[3] ^ c[3] ^ c[4] ^ c[5];
638
    newcrc[6] = d[6] ^ d[5] ^ d[4] ^ c[4] ^ c[5] ^ c[6];
639
    newcrc[7] = d[7] ^ d[6] ^ d[5] ^ c[5] ^ c[6] ^ c[7];
640
    crc_8 = newcrc;
641
  end
642
  endfunction
643
 
644
function [6:0] crc_7;
645
 
646
    input [7:0] Data;
647
    input [6:0] crc;
648
    reg [7:0] d;
649
    reg [6:0] c;
650
    reg [6:0] newcrc;
651
  begin
652
    d = Data;
653
    c = crc;
654
 
655
    newcrc[0] = d[7] ^ d[6] ^ d[5] ^ d[0] ^ c[4] ^ c[5] ^ c[6];
656
    newcrc[1] = d[5] ^ d[1] ^ d[0] ^ c[0] ^ c[4];
657
    newcrc[2] = d[7] ^ d[5] ^ d[2] ^ d[1] ^ d[0] ^ c[0] ^ c[1] ^ c[4] ^ c[6];
658
    newcrc[3] = d[6] ^ d[3] ^ d[2] ^ d[1] ^ c[0] ^ c[1] ^ c[2] ^ c[5];
659
    newcrc[4] = d[7] ^ d[4] ^ d[3] ^ d[2] ^ c[1] ^ c[2] ^ c[3] ^ c[6];
660
    newcrc[5] = d[5] ^ d[4] ^ d[3] ^ c[2] ^ c[3] ^ c[4];
661
    newcrc[6] = d[6] ^ d[5] ^ d[4] ^ c[3] ^ c[4] ^ c[5];
662
    crc_7 = newcrc;
663
                end
664
                endfunction
665
endmodule

powered by: WebSVN 2.1.0

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