1 |
6 |
homer.hsin |
/*
|
2 |
|
|
* Copyright 2013, Homer Hsing <homer.hsing@gmail.com>
|
3 |
|
|
*
|
4 |
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
5 |
|
|
* you may not use this file except in compliance with the License.
|
6 |
|
|
* You may obtain a copy of the License at
|
7 |
|
|
*
|
8 |
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
9 |
|
|
*
|
10 |
|
|
* Unless required by applicable law or agreed to in writing, software
|
11 |
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
12 |
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13 |
|
|
* See the License for the specific language governing permissions and
|
14 |
|
|
* limitations under the License.
|
15 |
|
|
*/
|
16 |
|
|
|
17 |
|
|
/* test "f permutation".
|
18 |
|
|
* write a block, wait 3 cycles, write another block, do not wait, write the third block */
|
19 |
|
|
|
20 |
|
|
`timescale 1ns / 1ps
|
21 |
|
|
`define P 20
|
22 |
|
|
|
23 |
|
|
module test_f_permutation;
|
24 |
|
|
|
25 |
|
|
// Inputs
|
26 |
|
|
reg clk;
|
27 |
|
|
reg reset;
|
28 |
|
|
reg [575:0] in;
|
29 |
|
|
reg in_ready;
|
30 |
|
|
|
31 |
|
|
// Outputs
|
32 |
|
|
wire ack;
|
33 |
|
|
wire [1599:0] out;
|
34 |
|
|
wire out_ready;
|
35 |
|
|
|
36 |
|
|
integer i;
|
37 |
|
|
|
38 |
|
|
// Instantiate the Unit Under Test (UUT)
|
39 |
|
|
f_permutation uut (
|
40 |
|
|
.clk(clk),
|
41 |
|
|
.reset(reset),
|
42 |
|
|
.in(in),
|
43 |
|
|
.in_ready(in_ready),
|
44 |
|
|
.ack(ack),
|
45 |
|
|
.out(out),
|
46 |
|
|
.out_ready(out_ready)
|
47 |
|
|
);
|
48 |
|
|
|
49 |
|
|
initial begin
|
50 |
|
|
// Initialize Inputs
|
51 |
|
|
clk = 0;
|
52 |
|
|
reset = 1;
|
53 |
|
|
in = 0;
|
54 |
|
|
in_ready = 0;
|
55 |
|
|
|
56 |
|
|
// Wait 100 ns for global reset to finish
|
57 |
|
|
#100;
|
58 |
|
|
|
59 |
|
|
// Add stimulus here
|
60 |
|
|
@ (negedge clk);
|
61 |
|
|
if (out !== 0) error; /* should be 0 */
|
62 |
|
|
if (ack !== 0) error; /* should be 0 */
|
63 |
|
|
if (out_ready !== 0) error; /* should be 0 */
|
64 |
|
|
|
65 |
|
|
#(`P);
|
66 |
|
|
reset = 0;
|
67 |
|
|
in = 0;
|
68 |
|
|
in_ready = 1;
|
69 |
|
|
#(`P);
|
70 |
|
|
if (out_ready !== 0) error; /* should be 0 */
|
71 |
|
|
in_ready = 0;
|
72 |
|
|
|
73 |
|
|
/* check 1~10-th cycles */
|
74 |
|
|
for(i=0; i<10; i=i+1)
|
75 |
|
|
begin
|
76 |
|
|
if (out === 0) error; /* should not be 0 */
|
77 |
|
|
if (ack !== 0) error; /* should be 0 */
|
78 |
|
|
if (out_ready !== 0) error; /* should be 0 */
|
79 |
|
|
#(`P);
|
80 |
|
|
end
|
81 |
|
|
|
82 |
|
|
/* check the 11-th cycle */
|
83 |
|
|
if (out === 0) error; /* should not be 0 */
|
84 |
|
|
if (ack !== 0) error; /* should be 0 */
|
85 |
|
|
if (out_ready !== 0) error; /* should be 0 */
|
86 |
|
|
#(`P);
|
87 |
|
|
|
88 |
|
|
/* check the 12-th cycle */
|
89 |
|
|
#(`P); /* wait out */
|
90 |
|
|
if (out_ready !== 1) error; /* should be 1 */
|
91 |
|
|
if(out !== 1600'hf1258f7940e1dde784d5ccf933c0478ad598261ea65aa9eebd1547306f80494d8b284e056253d057ff97a42d7f8e6fd490fee5a0a44647c48c5bda0cd6192e76ad30a6f71b19059c30935ab7d08ffc64eb5aa93f2317d635a9a6e6260d71210381a57c16dbcf555f43b831cd0347c82601f22f1a11a5569f05e5635a21d9ae6164befef28cc970f2613670957bc46611b87c5a554fd00ecb8c3ee88a1ccf32c8940c7922ae3a26141841f924a2c509e416f53526e70465c275f644e97f30a13beaf1ff7b5ceca249) error;
|
92 |
|
|
|
93 |
|
|
#(3*`P); /* wait more cycles */
|
94 |
|
|
if (out_ready !== 1) error; /* should be 1 */
|
95 |
|
|
/* "out" should not change */
|
96 |
|
|
if(out !== 1600'hf1258f7940e1dde784d5ccf933c0478ad598261ea65aa9eebd1547306f80494d8b284e056253d057ff97a42d7f8e6fd490fee5a0a44647c48c5bda0cd6192e76ad30a6f71b19059c30935ab7d08ffc64eb5aa93f2317d635a9a6e6260d71210381a57c16dbcf555f43b831cd0347c82601f22f1a11a5569f05e5635a21d9ae6164befef28cc970f2613670957bc46611b87c5a554fd00ecb8c3ee88a1ccf32c8940c7922ae3a26141841f924a2c509e416f53526e70465c275f644e97f30a13beaf1ff7b5ceca249) error;
|
97 |
|
|
|
98 |
|
|
in_ready = 1; /* feed in one more block */
|
99 |
|
|
in = 0;
|
100 |
|
|
#(`P);
|
101 |
|
|
if (out_ready !== 0) error; /* should be 0 */
|
102 |
|
|
in_ready = 0;
|
103 |
|
|
|
104 |
|
|
while (out_ready !== 1)
|
105 |
|
|
#(`P);
|
106 |
|
|
if(out !== 1600'h2d5c954df96ecb3c6a332cd07057b56d093d8d1270d76b6c8a20d9b25569d0944f9c4f99e5e7f156f957b9a2da65fb3885773dae1275af0dfaf4f247c3d810f71f1b9ee6f79a8759e4fecc0fee98b42568ce61b6b9ce68a1deea66c4ba8f974f33c43d836eafb1f5e00654042719dbd97cf8a9f009831265fd5449a6bf17474397ddad33d8994b4048ead5fc5d0be774e3b8c8ee55b7b03c91a0226e649e42e9900e3129e7badd7b202a9ec5faa3cce85b3402464e1c3db6609f4e62a44c105920d06cd26a8fbf5c) error;
|
107 |
|
|
|
108 |
|
|
/* no wait, feed in one more block */
|
109 |
|
|
in_ready = 1;
|
110 |
|
|
#(`P);
|
111 |
|
|
if (out_ready !== 0) error; /* should be 0 */
|
112 |
|
|
in_ready = 0;
|
113 |
|
|
|
114 |
|
|
while (out_ready !== 1)
|
115 |
|
|
#(`P);
|
116 |
|
|
if(out !== 1600'h55eabb80767d364686c354c8d01cbace9452d254b0979b3dde59422be2c66f16c660e4f2d4d8212e78414f691b639bb3cbb20f9f1b22e381cf16da5fac2da63f83c0b76552d95f7c44efc84eaf017e1548d380ff3e532c9592436ec5c5e02f05bde57ca1ee8de7e9240970468a1fd1b012a978439cbb7686d26b59fcceff8b4dd2aa0f472110fff87bd44abf53f72551e15ad2b722d00bb7c56095932c792c459e02d1766ad3a79c312f2da72ada4ec368b9f274a8d7d6b92b7239f7e51eea1eb6947f6894d77aeb) error;
|
117 |
|
|
|
118 |
|
|
$display("Good!");
|
119 |
|
|
$finish;
|
120 |
|
|
end
|
121 |
|
|
|
122 |
|
|
always #(`P/2) clk = ~ clk;
|
123 |
|
|
|
124 |
|
|
task error;
|
125 |
|
|
begin
|
126 |
|
|
$display("Error!");
|
127 |
|
|
$finish;
|
128 |
|
|
end
|
129 |
|
|
endtask
|
130 |
|
|
endmodule
|
131 |
|
|
|
132 |
|
|
`undef P
|