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

Subversion Repositories hight

[/] [hight/] [trunk/] [testbench/] [tb_CONTROL.v] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 truemind
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  Testbench of CONTROL module for HIGHT Crypto Core           ////
4
////                                                              ////
5
////  This file is part of the HIGHT Crypto Core project          ////
6
////  http://github.com/OpenSoCPlus/hight_crypto_core             ////
7
////  http://www.opencores.org/project,hight                      ////
8
////                                                              ////
9
////  Description                                                 ////
10
////  __description__                                             ////
11
////                                                              ////
12
////  Author(s):                                                  ////
13
////      - JoonSoo Ha, json.ha@gmail.com                         ////
14
////      - Younjoo Kim, younjookim.kr@gmail.com                  ////
15
////                                                              ////
16
//////////////////////////////////////////////////////////////////////
17
////                                                              ////
18
//// Copyright (C) 2015 Authors, OpenSoCPlus and OPENCORES.ORG    ////
19
////                                                              ////
20
//// This source file may be used and distributed without         ////
21
//// restriction provided that this copyright statement is not    ////
22
//// removed from the file and that any derivative work contains  ////
23
//// the original copyright notice and the associated disclaimer. ////
24
////                                                              ////
25
//// This source file is free software; you can redistribute it   ////
26
//// and/or modify it under the terms of the GNU Lesser General   ////
27
//// Public License as published by the Free Software Foundation; ////
28
//// either version 2.1 of the License, or (at your option) any   ////
29
//// later version.                                               ////
30
////                                                              ////
31
//// This source is distributed in the hope that it will be       ////
32
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
33
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
34
//// PURPOSE.  See the GNU Lesser General Public License for more ////
35
//// details.                                                     ////
36
////                                                              ////
37
//// You should have received a copy of the GNU Lesser General    ////
38
//// Public License along with this source; if not, download it   ////
39
//// from http://www.opencores.org/lgpl.shtml                     ////
40
////                                                              ////
41
//////////////////////////////////////////////////////////////////////
42
 
43
`timescale 1ns/1ps
44
 
45
module tb_CONTROL;
46
 
47
event do_finish;
48
 
49
//=====================================
50
//
51
//          PARAMETERS 
52
//
53
//=====================================
54
parameter   HP_CLK = 5; // Half period of clock
55
 
56
 
57
//=====================================
58
//
59
//          I/O PORTS 
60
//
61
//=====================================
62
reg         rstn           ;
63
reg         clk            ;
64
 
65
reg         i_mk_rdy       ;
66
reg         i_post_rdy     ;
67
reg         i_text_val     ;
68
 
69
wire        o_rdy          ;
70
wire        o_text_done    ;
71
 
72
wire[2:0]   o_xf_sel       ;
73
wire        o_rf_final     ;
74
 
75
wire        o_key_sel      ;
76
wire[4:0]   o_rnd_idx      ;
77
wire        o_wf_post_pre  ;
78
 
79
 
80
//=====================================
81
//
82
//          PORT MAPPING
83
//
84
//=====================================
85
CONTROL uut_CONTROL(
86
        .rstn          (rstn         ) ,
87
        .clk           (clk          ) ,
88
 
89
        .i_mk_rdy      (i_mk_rdy     ) ,
90
        .i_post_rdy    (i_post_rdy   ) ,
91
        .i_text_val    (i_text_val   ) ,
92
 
93
        .o_rdy         (o_rdy        ) ,
94
        .o_text_done   (o_text_done  ) ,
95
 
96
        .o_xf_sel      (o_xf_sel     ) ,
97
        .o_rf_final    (o_rf_final   ) ,
98
 
99
        .o_key_sel     (o_key_sel    ) ,
100
        .o_rnd_idx     (o_rnd_idx    ) ,
101
        .o_wf_post_pre (o_wf_post_pre)
102
);
103
 
104
 
105
//=====================================
106
//
107
//          STIMULUS
108
//
109
//=====================================
110
// clock generation
111
initial begin
112
        clk = 1'b0;
113
        forever clk = #(HP_CLK) ~clk;
114
end
115
 
116
// reset generation
117
initial begin
118
        rstn = 1'b1;
119
        @(posedge clk);
120
        @(negedge clk);
121
        rstn = 1'b0;
122
        repeat(2) @(negedge clk);
123
        rstn = 1'b1;
124
end
125
 
126
// input generation
127
initial begin
128
        $display("===== SIM START =====");
129
        // insert your code
130
 
131
        // initial input value
132
        i_mk_rdy   = 1'b1;
133
        i_post_rdy = 1'b1;
134
        i_text_val = 1'b0;
135
 
136
        // reset time
137
        @(negedge rstn);
138
        @(posedge rstn);
139
        @(negedge clk);
140
 
141
        // Key Config Phase
142
        @(negedge clk);
143
        i_mk_rdy  = 1'b0;
144
        repeat(4) @(posedge clk);
145
        @(negedge clk);
146
        i_mk_rdy = 1'b1;
147
 
148
        //// first ciphering //// 
149
        // insert 2 clock delay
150
        @(posedge clk);
151
        repeat(2) @(posedge clk);
152
 
153
        // insert text
154
        @(negedge clk);
155
        i_text_val = 1'b1;
156
        @(negedge clk);
157
        i_text_val = 1'b0;
158
 
159
        // wait text done 
160
        wait(o_text_done)
161
        @(posedge clk);
162
 
163
        // post rdy inactive
164
        @(negedge clk);
165
        i_post_rdy = 1'b0;
166
 
167
 
168
        //// second ciphering ////
169
        // insert text
170
        @(negedge clk);
171
        i_text_val = 1'b1;
172
        @(negedge clk);
173
        i_text_val = 1'b0;
174
 
175
        // wait done state
176
        wait(uut_CONTROL.r_pstate == uut_CONTROL.S_DONE)
177
        @(posedge clk);
178
 
179
        // insert 3clk delay
180
        repeat(3) @(posedge clk);
181
 
182
        // post rdy active
183
        i_post_rdy = 1'b1;
184
 
185
        repeat(10) @(posedge clk);
186
        -> do_finish;
187
end
188
 
189
// state monitoring
190
reg[20*8:1] state;
191
always @(uut_CONTROL.r_pstate) begin
192
        case(uut_CONTROL.r_pstate)
193
        uut_CONTROL.S_IDLE        : state <= "IDLE      ";
194
    uut_CONTROL.S_KEY_CONFIG  : state <= "KEY_CONFIG";
195
    uut_CONTROL.S_RDY         : state <= "RDY       ";
196
    uut_CONTROL.S_WF1         : state <= "WF1       ";
197
    uut_CONTROL.S_RF1         : state <= "RF1       ";
198
    uut_CONTROL.S_RF2         : state <= "RF2       ";
199
    uut_CONTROL.S_RF3         : state <= "RF3       ";
200
    uut_CONTROL.S_RF4         : state <= "RF4       ";
201
    uut_CONTROL.S_RF5         : state <= "RF5       ";
202
    uut_CONTROL.S_RF6         : state <= "RF6       ";
203
    uut_CONTROL.S_RF7         : state <= "RF7       ";
204
    uut_CONTROL.S_RF8         : state <= "RF8       ";
205
    uut_CONTROL.S_RF9         : state <= "RF9       ";
206
    uut_CONTROL.S_RF10        : state <= "RF10      ";
207
    uut_CONTROL.S_RF11        : state <= "RF11      ";
208
    uut_CONTROL.S_RF12        : state <= "RF12      ";
209
    uut_CONTROL.S_RF13        : state <= "RF13      ";
210
    uut_CONTROL.S_RF14        : state <= "RF14      ";
211
    uut_CONTROL.S_RF15        : state <= "RF15      ";
212
    uut_CONTROL.S_RF16        : state <= "RF16      ";
213
    uut_CONTROL.S_RF17        : state <= "RF17      ";
214
    uut_CONTROL.S_RF18        : state <= "RF18      ";
215
    uut_CONTROL.S_RF19        : state <= "RF19      ";
216
    uut_CONTROL.S_RF20        : state <= "RF20      ";
217
    uut_CONTROL.S_RF21        : state <= "RF21      ";
218
    uut_CONTROL.S_RF22        : state <= "RF22      ";
219
    uut_CONTROL.S_RF23        : state <= "RF23      ";
220
    uut_CONTROL.S_RF24        : state <= "RF24      ";
221
    uut_CONTROL.S_RF25        : state <= "RF25      ";
222
    uut_CONTROL.S_RF26        : state <= "RF26      ";
223
    uut_CONTROL.S_RF27        : state <= "RF27      ";
224
    uut_CONTROL.S_RF28        : state <= "RF28      ";
225
    uut_CONTROL.S_RF29        : state <= "RF29      ";
226
    uut_CONTROL.S_RF30        : state <= "RF30      ";
227
    uut_CONTROL.S_RF31        : state <= "RF31      ";
228
    uut_CONTROL.S_RF32        : state <= "RF32      ";
229
    uut_CONTROL.S_DONE        : state <= "DONE      ";
230
    uut_CONTROL.S_ERROR       : state <= "ERROR     ";
231
        endcase
232
end
233
 
234
// finish 
235
initial begin
236
        @do_finish
237
        $finish;
238
end
239
 
240
// vcd dump
241
initial begin
242
        $dumpfile("dump/sim_tb_CONTROL.vcd");
243
        $dumpvars(0, tb_CONTROL);
244
end
245
 
246
endmodule
247
 
248
 

powered by: WebSVN 2.1.0

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