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

Subversion Repositories crcahb

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

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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