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

Subversion Repositories wiegand_ctl

[/] [wiegand_ctl/] [trunk/] [bench/] [testbench_top.v] - Blame information for rev 14

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 14 jeaander
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  weigand_tx_top.v                                            ////
4
////                                                              ////
5
////                                                              ////
6
////  This file is part of the Time Triggered Protocol Controller ////
7
////  http://www.opencores.org/projects/weigand/                  ////
8
////                                                              ////
9
////                                                              ////
10
////  Author(s):                                                  ////
11
////       Jeff Anderson                                          ////
12
////       jeaander@opencores.org                                 ////
13
////                                                              ////
14
////                                                              ////
15
////  All additional information is available in the README.txt   ////
16
////  file.                                                       ////
17
////                                                              ////
18
//////////////////////////////////////////////////////////////////////
19
////                                                              ////
20
//// Copyright (C) 2013 Authors                                   ////
21
////                                                              ////
22
//// This source file may be used and distributed without         ////
23
//// restriction provided that this copyright statement is not    ////
24
//// removed from the file and that any derivative work contains  ////
25
//// the original copyright notice and the associated disclaimer. ////
26
////                                                              ////
27
//// This source file is free software; you can redistribute it   ////
28
//// and/or modify it under the terms of the GNU Lesser General   ////
29
//// Public License as published by the Free Software Foundation; ////
30
//// either version 2.1 of the License, or (at your option) any   ////
31
//// later version.                                               ////
32
////                                                              ////
33
//// This source is distributed in the hope that it will be       ////
34
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
35
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
36
//// PURPOSE.  See the GNU Lesser General Public License for more ////
37
//// details.                                                     ////
38
////                                                              ////
39
//// You should have received a copy of the GNU Lesser General    ////
40
//// Public License along with this source; if not, download it   ////
41
//// from http://www.opencores.org/lgpl.shtml                     ////
42
////                                                              ////
43
//// The Weigand protocol is maintained by                        ////
44
//// This product has been tested to interoperate with certified  ////
45
//// devices, but has not been certified itself.  This product    ////
46
//// should be certified through prior to claiming strict         ////
47
//// adherence to the standard.                                   ////
48
////                                                              ////
49
//////////////////////////////////////////////////////////////////////
50
//
51
//  Revisions at end of file
52
//
53
 
54
`include "timescale.v"
55
`include "wiegand_defines.v"
56
 
57
module testbench_top;
58
  reg [5:0]   wb_addr_i;
59
  reg [31:0]  wb_dat_i;
60
  wire [31:0] wb_dat_o;
61
  wire [31:0] wb_dat_o_rx;
62
  reg         wb_cyc_i;
63
  reg         wb_stb_i;
64
  reg [2:0]   wb_cti_i;
65
  reg [3:0]   wb_sel_i;
66
  reg         wb_we_i;
67
  reg         wb_rst_i;
68
  reg         wb_clk_i;
69
  reg         one_i, zero_i;
70
 
71
  //DUTs
72
  wiegand_tx_top wiegand_tx_top(one_o,zero_o,wb_clk_i,wb_rst_i,wb_dat_i,wb_dat_o,wb_cyc_i,wb_stb_i,wb_cti_i,wb_sel_i,wb_we_i,wb_addr_i,
73
                                wb_ack_o,wb_err_o,wb_rty_o);
74
 
75
  wiegand_rx_top wiegand_rx_top(one_i,zero_i,wb_clk_i,wb_rst_i,wb_dat_i,wb_dat_o_rx,wb_cyc_i,wb_stb_i,wb_cti_i,wb_sel_i,wb_we_i,wb_addr_i,
76
                                wb_ack_o_rx,wb_err_o_rx,wb_rty_o_rx);
77
 
78
  //tasks for simulation
79
 
80
  initial begin
81
    wb_addr_i = 6'h0;
82
    wb_dat_i = 32'h0;
83
    wb_cyc_i = 1'b0;
84
    wb_stb_i = 1'b0;
85
    wb_we_i = 1'b0;
86
    wb_rst_i = 1'b0;
87
    wb_clk_i = 1'b0;
88
    one_i = 1'b1;
89
    zero_i = 1'b1;
90
  end
91
 
92
  always
93
    #5 wb_clk_i = !wb_clk_i;
94
 
95
  /**********************   tasks run by testcases for this testbench ******************/
96
  //Wiegand bus write tasks
97
  task wiegand_write;
98
    input [63:0] wiegand_data;
99
    input [5:0]  word_length;
100
    input [5:0]  p2p;
101
    input [5:0]  pw;
102
    integer i;
103
    integer j;
104
    begin
105
      j = 0;
106
      repeat (word_length) begin
107
        @ (posedge wb_clk_i) begin
108
          if (wiegand_data[j] == 1'b0) begin
109
            wiegand0(pw);
110
          end
111
          else begin
112
            wiegand1(pw);
113
          end
114
          j=j+1;
115
          i = 0;
116
          while(i <= p2p) begin
117
            @ (posedge wb_clk_i) begin i=i+1; end
118
          end
119
        end
120
      end
121
    end
122
  endtask
123
 
124
  task wiegand0;
125
    input [5:0] pw;
126
    integer i;
127
    begin
128
      for (i = 0; i <= pw; i=i+1) begin
129
        @(posedge wb_clk_i)  zero_i = 1'b0;
130
      end
131
      zero_i = 1'b1;
132
    end
133
  endtask
134
 
135
  task wiegand1;
136
    input [5:0] pw;
137
    integer i;
138
    begin
139
      for (i = 0; i <= pw; i=i+1) begin
140
        @(posedge wb_clk_i)  one_i = 1'b0;
141
      end
142
      one_i = 1'b1;
143
    end
144
  endtask
145
 
146
  //Wishbone readn adn write tasks
147
  task wb_rst;
148
    begin
149
          wb_rst_i = 1'b1;
150
      #20 wb_rst_i = 1'b0;
151
    end
152
  endtask
153
 
154
  task wb_write_async;
155
    input [31:0] wb_data;
156
    begin
157
      @ (posedge wb_clk_i) begin
158
        wb_addr_i = `WIEGAND_ADDR;
159
        wb_dat_i = wb_data;
160
        wb_stb_i = 1'b1;
161
        wb_cyc_i = 1'b1;
162
        wb_we_i = 1'b1;
163
      end
164
      @ (posedge wb_clk_i) begin
165
        wb_addr_i = 6'h0;
166
        wb_dat_i = 32'h0;
167
        wb_stb_i = 1'b0;
168
        wb_cyc_i = 1'b0;
169
        wb_we_i = 1'b0;
170
      end
171
    end
172
  endtask
173
 
174
  task wb_write_sync;
175
    input [31:0] wb_data;
176
    begin
177
      @ (posedge wb_clk_i) begin
178
        wb_addr_i = `WIEGAND_ADDR;
179
        wb_dat_i = wb_data;
180
        wb_stb_i = 1'b1;
181
        wb_cyc_i = 1'b1;
182
        wb_we_i = 1'b1;
183
      end
184
      @ (posedge wb_clk_i) begin
185
        wb_addr_i = `WIEGAND_ADDR;
186
        wb_dat_i = wb_data;
187
        wb_stb_i = 1'b1;
188
        wb_cyc_i = 1'b1;
189
        wb_we_i = 1'b1;
190
      end
191
      @ (posedge wb_clk_i) begin
192
        wb_addr_i = 6'h0;
193
        wb_dat_i = 32'h0;
194
        wb_stb_i = 1'b0;
195
        wb_cyc_i = 1'b0;
196
        wb_we_i = 1'b0;
197
      end
198
    end
199
  endtask
200
 
201
  task wb_writep2p_async;
202
    input [31:0] p2p;
203
    begin
204
      @ (posedge wb_clk_i) begin
205
        wb_addr_i = `WB_CNFG_P2P;
206
        wb_dat_i = p2p;
207
        wb_stb_i = 1'b1;
208
        wb_cyc_i = 1'b1;
209
        wb_we_i = 1'b1;
210
      end
211
      @ (posedge wb_clk_i) begin
212
        wb_addr_i = 6'h0;
213
        wb_dat_i = 32'h0;
214
        wb_stb_i = 1'b0;
215
        wb_cyc_i = 1'b0;
216
        wb_we_i = 1'b0;
217
      end
218
    end
219
  endtask
220
 
221
  task wb_writepw_async;
222
    input [31:0] pw;
223
    begin
224
      @ (posedge wb_clk_i) begin
225
        wb_addr_i = `WB_CNFG_PW;
226
        wb_dat_i = pw;
227
        wb_stb_i = 1'b1;
228
        wb_cyc_i = 1'b1;
229
        wb_we_i = 1'b1;
230
      end
231
      @ (posedge wb_clk_i) begin
232
        wb_addr_i = 6'h0;
233
        wb_dat_i = 32'h0;
234
        wb_stb_i = 1'b0;
235
        wb_cyc_i = 1'b0;
236
        wb_we_i = 1'b0;
237
      end
238
    end
239
  endtask
240
 
241
  task wb_writesize_async;
242
    input [31:0] size;
243
    begin
244
      @ (posedge wb_clk_i) begin
245
        wb_addr_i = `WB_CNFG_MSGSIZE;
246
        wb_dat_i = (size & 32'h7F);
247
        wb_stb_i = 1'b1;
248
        wb_cyc_i = 1'b1;
249
        wb_we_i = 1'b1;
250
      end
251
      @ (posedge wb_clk_i) begin
252
        wb_addr_i = 6'h0;
253
        wb_dat_i = 32'h0;
254
        wb_stb_i = 1'b0;
255
        wb_cyc_i = 1'b0;
256
        wb_we_i = 1'b0;
257
      end
258
    end
259
  endtask
260
 
261
  task wb_writesend_async;
262
    input [31:0] size;
263
    begin
264
      @ (posedge wb_clk_i) begin
265
        wb_addr_i = `WB_CNFG_MSGSIZE;
266
        wb_dat_i = (size | 32'h80);
267
        wb_stb_i = 1'b1;
268
        wb_cyc_i = 1'b1;
269
        wb_we_i = 1'b1;
270
      end
271
      @ (posedge wb_clk_i) begin
272
        wb_addr_i = 6'h0;
273
        wb_dat_i = 32'h0;
274
        wb_stb_i = 1'b0;
275
        wb_cyc_i = 1'b0;
276
        wb_we_i = 1'b0;
277
      end
278
    end
279
  endtask
280
 
281
  task wb_read_async;
282
    begin
283
      @ (posedge wb_clk_i) begin
284
        wb_stb_i = 1'b1;
285
        wb_cyc_i = 1'b1;
286
        wb_we_i = 1'b0;
287
      end
288
      @ (posedge wb_clk_i) begin
289
        wb_stb_i = 1'b0;
290
        wb_cyc_i = 1'b0;
291
      end
292
    end
293
  endtask
294
 
295
  task wb_read_sync;
296
    begin
297
      @ (posedge wb_clk_i) begin
298
        wb_stb_i = 1'b1;
299
        wb_cyc_i = 1'b1;
300
        wb_we_i = 1'b0;
301
      end
302
      @ (posedge wb_clk_i) begin
303
        wb_stb_i = 1'b1;
304
        wb_cyc_i = 1'b1;
305
      end
306
      @ (posedge wb_clk_i) begin
307
        wb_stb_i = 1'b0;
308
        wb_cyc_i = 1'b0;
309
      end
310
    end
311
  endtask
312
 
313
endmodule

powered by: WebSVN 2.1.0

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