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

Subversion Repositories sport

[/] [sport/] [trunk/] [bench/] [testbench_top.v] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 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 "SPORT_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
  sport_top sport_top(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, DTxPRI,DTxSEC,TSCLKx,TFSx,DRxPRI,DRxSEC,RSCLKx,TRSx,);
74
 
75
  //tasks for simulation
76
 
77
  initial begin
78
    wb_addr_i = 6'h0;
79
    wb_dat_i = 32'h0;
80
    wb_cyc_i = 1'b0;
81
    wb_stb_i = 1'b0;
82
    wb_we_i = 1'b0;
83
    wb_rst_i = 1'b0;
84
    wb_clk_i = 1'b0;
85
    one_i = 1'b1;
86
    zero_i = 1'b1;
87
  end
88
 
89
  always
90
    #5 wb_clk_i = !wb_clk_i;
91
 
92
  /**********************   tasks run by testcases for this testbench ******************/
93
  //SPORT bus write tasks
94
  task SPORT_write;
95
    input [63:0] SPORT_data;
96
    input [5:0]  word_length;
97
    input [5:0]  p2p;
98
    input [5:0]  pw;
99
    integer i;
100
    integer j;
101
    begin
102
      j = 0;
103
      repeat (word_length) begin
104
        @ (posedge wb_clk_i) begin
105
          if (SPORT_data[j] == 1'b0) begin
106
            SPORT0(pw);
107
          end
108
          else begin
109
            SPORT1(pw);
110
          end
111
          j=j+1;
112
          i = 0;
113
          while(i <= p2p) begin
114
            @ (posedge wb_clk_i) begin i=i+1; end
115
          end
116
        end
117
      end
118
    end
119
  endtask
120
 
121
  task SPORT0;
122
    input [5:0] pw;
123
    integer i;
124
    begin
125
      for (i = 0; i <= pw; i=i+1) begin
126
        @(posedge wb_clk_i)  zero_i = 1'b0;
127
      end
128
      zero_i = 1'b1;
129
    end
130
  endtask
131
 
132
  task SPORT1;
133
    input [5:0] pw;
134
    integer i;
135
    begin
136
      for (i = 0; i <= pw; i=i+1) begin
137
        @(posedge wb_clk_i)  one_i = 1'b0;
138
      end
139
      one_i = 1'b1;
140
    end
141
  endtask
142
 
143
  //Wishbone readn adn write tasks
144
  task wb_rst;
145
    begin
146
          wb_rst_i = 1'b1;
147
      #20 wb_rst_i = 1'b0;
148
    end
149
  endtask
150
 
151
  task wb_write_async;
152
    input [31:0] wb_data;
153
    begin
154
      @ (posedge wb_clk_i) begin
155
        wb_addr_i = `SPORT_ADDR;
156
        wb_dat_i = wb_data;
157
        wb_stb_i = 1'b1;
158
        wb_cyc_i = 1'b1;
159
        wb_we_i = 1'b1;
160
      end
161
      @ (posedge wb_clk_i) begin
162
        wb_addr_i = 6'h0;
163
        wb_dat_i = 32'h0;
164
        wb_stb_i = 1'b0;
165
        wb_cyc_i = 1'b0;
166
        wb_we_i = 1'b0;
167
      end
168
    end
169
  endtask
170
 
171
  task wb_write_sync;
172
    input [31:0] wb_data;
173
    begin
174
      @ (posedge wb_clk_i) begin
175
        wb_addr_i = `SPORT_ADDR;
176
        wb_dat_i = wb_data;
177
        wb_stb_i = 1'b1;
178
        wb_cyc_i = 1'b1;
179
        wb_we_i = 1'b1;
180
      end
181
      @ (posedge wb_clk_i) begin
182
        wb_addr_i = `SPORT_ADDR;
183
        wb_dat_i = wb_data;
184
        wb_stb_i = 1'b1;
185
        wb_cyc_i = 1'b1;
186
        wb_we_i = 1'b1;
187
      end
188
      @ (posedge wb_clk_i) begin
189
        wb_addr_i = 6'h0;
190
        wb_dat_i = 32'h0;
191
        wb_stb_i = 1'b0;
192
        wb_cyc_i = 1'b0;
193
        wb_we_i = 1'b0;
194
      end
195
    end
196
  endtask
197
 
198
  task wb_writep2p_async;
199
    input [31:0] p2p;
200
    begin
201
      @ (posedge wb_clk_i) begin
202
        wb_addr_i = `WB_CNFG_RX;
203
        wb_dat_i = p2p;
204
        wb_stb_i = 1'b1;
205
        wb_cyc_i = 1'b1;
206
        wb_we_i = 1'b1;
207
      end
208
      @ (posedge wb_clk_i) begin
209
        wb_addr_i = 6'h0;
210
        wb_dat_i = 32'h0;
211
        wb_stb_i = 1'b0;
212
        wb_cyc_i = 1'b0;
213
        wb_we_i = 1'b0;
214
      end
215
    end
216
  endtask
217
 
218
  task wb_writepw_async;
219
    input [31:0] pw;
220
    begin
221
      @ (posedge wb_clk_i) begin
222
        wb_addr_i = `WB_CNFG_TX;
223
        wb_dat_i = pw;
224
        wb_stb_i = 1'b1;
225
        wb_cyc_i = 1'b1;
226
        wb_we_i = 1'b1;
227
      end
228
      @ (posedge wb_clk_i) begin
229
        wb_addr_i = 6'h0;
230
        wb_dat_i = 32'h0;
231
        wb_stb_i = 1'b0;
232
        wb_cyc_i = 1'b0;
233
        wb_we_i = 1'b0;
234
      end
235
    end
236
  endtask
237
 
238
  task wb_read_async;
239
    begin
240
      @ (posedge wb_clk_i) begin
241
        wb_stb_i = 1'b1;
242
        wb_cyc_i = 1'b1;
243
        wb_we_i = 1'b0;
244
      end
245
      @ (posedge wb_clk_i) begin
246
        wb_stb_i = 1'b0;
247
        wb_cyc_i = 1'b0;
248
      end
249
    end
250
  endtask
251
 
252
  task wb_read_sync;
253
    begin
254
      @ (posedge wb_clk_i) begin
255
        wb_stb_i = 1'b1;
256
        wb_cyc_i = 1'b1;
257
        wb_we_i = 1'b0;
258
      end
259
      @ (posedge wb_clk_i) begin
260
        wb_stb_i = 1'b1;
261
        wb_cyc_i = 1'b1;
262
      end
263
      @ (posedge wb_clk_i) begin
264
        wb_stb_i = 1'b0;
265
        wb_cyc_i = 1'b0;
266
      end
267
    end
268
  endtask
269
 
270
endmodule

powered by: WebSVN 2.1.0

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