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

Subversion Repositories pit

[/] [pit/] [trunk/] [bench/] [verilog/] [tst_bench_top.v] - Blame information for rev 15

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 rehayes
////////////////////////////////////////////////////////////////////////////////
2
//
3
//  WISHBONE revB.2 compliant Programable Interval Timer - Test Bench
4
//
5
//  Author: Bob Hayes
6
//          rehayes@opencores.org
7
//
8
//  Downloaded from: http://www.opencores.org/projects/pit.....
9
//
10
////////////////////////////////////////////////////////////////////////////////
11
// Copyright (c) 2009, Robert Hayes
12
//
13
// All rights reserved.
14
//
15
// Redistribution and use in source and binary forms, with or without
16
// modification, are permitted provided that the following conditions are met:
17
//     * Redistributions of source code must retain the above copyright
18
//       notice, this list of conditions and the following disclaimer.
19
//     * Redistributions in binary form must reproduce the above copyright
20
//       notice, this list of conditions and the following disclaimer in the
21
//       documentation and/or other materials provided with the distribution.
22
//     * Neither the name of the <organization> nor the
23
//       names of its contributors may be used to endorse or promote products
24
//       derived from this software without specific prior written permission.
25
//
26
// THIS SOFTWARE IS PROVIDED BY Robert Hayes ''AS IS'' AND ANY
27
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
28
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
29
// DISCLAIMED. IN NO EVENT SHALL Robert Hayes BE LIABLE FOR ANY
30
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
31
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
32
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
33
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36
////////////////////////////////////////////////////////////////////////////////
37
// 45678901234567890123456789012345678901234567890123456789012345678901234567890
38
 
39
 
40
`include "timescale.v"
41
 
42
module tst_bench_top();
43
 
44
        //
45
        // wires && regs
46
        //
47
        reg        mstr_test_clk;
48
        reg [19:0] vector;
49
        reg [ 7:0] test_num;
50
        reg        rstn;
51
        reg        sync_reset;
52
 
53
        wire [31:0] adr;
54
        wire [15:0] dat_i, dat_o, dat0_i, dat1_i, dat2_i, dat3_i;
55
        wire we;
56
        wire stb;
57
        wire cyc;
58 8 rehayes
        wire ack, ack_1, ack_2, ack_3, ack_4;
59 3 rehayes
        wire inta_1, inta_2, inta_3, inta_4;
60
        wire count_en_1;
61
        wire count_flag_1;
62
 
63
        reg [15:0] q, qq;
64
 
65
        wire scl, scl0_o, scl0_oen, scl1_o, scl1_oen;
66
        wire sda, sda0_o, sda0_oen, sda1_o, sda1_oen;
67
 
68
        // Name Address Locations
69
        parameter PIT_CNTRL = 5'b0_0000;
70
        parameter PIT_MOD   = 5'b0_0001;
71
        parameter PIT_COUNT = 5'b0_0010;
72
 
73
        parameter RD      = 1'b1;
74
        parameter WR      = 1'b0;
75
        parameter SADR    = 7'b0010_000;
76
 
77
        parameter CTR_EN  = 8'b1000_0000;  // core enable bit
78
        parameter CTR_IEN = 8'b0100_0000;  // core interrupt enable bit
79
 
80
        parameter PIT_CNTRL_SLAVE  = 16'h8000;  // PIT Slave mode
81
        parameter PIT_CNTRL_FLAG   = 16'h0004;  // PIT Rollover Flag
82
        parameter PIT_CNTRL_IRQEN  = 16'h0002;  // PIT Interupt Enable
83
        parameter PIT_CNTRL_ENA    = 16'h0001;  // PIT Enable
84
 
85
        parameter SLAVE_0_CNTRL = 5'b0_1000;
86
        parameter SLAVE_0_MOD   = 5'b0_1001;
87
        parameter SLAVE_0_COUNT = 5'b0_1010;
88
 
89
        parameter SLAVE_1_CNTRL = 5'b1_0000;
90
        parameter SLAVE_1_MOD   = 5'b1_0001;
91
        parameter SLAVE_1_COUNT = 5'b1_0010;
92
 
93
        parameter SLAVE_2_CNTRL_0 = 5'b1_1000;
94
        parameter SLAVE_2_CNTRL_1 = 5'b1_1001;
95
        parameter SLAVE_2_MOD_0   = 5'b1_1010;
96
        parameter SLAVE_2_MOD_1   = 5'b1_1011;
97
        parameter SLAVE_2_COUNT_0 = 5'b1_1100;
98
        parameter SLAVE_2_COUNT_1 = 5'b1_1101;
99
 
100
        // initial values and testbench setup
101
        initial
102
          begin
103
            mstr_test_clk = 0;
104
            vector = 0;
105
            test_num = 0;
106
 
107
            `ifdef WAVES
108
                 $shm_open("waves");
109
                 $shm_probe("AS",tst_bench_top,"AS");
110
                 $display("\nINFO: Signal dump enabled ...\n\n");
111
              `endif
112
 
113
              `ifdef WAVES_V
114
                 $dumpfile ("pit_wave_dump.lxt");
115
                 $dumpvars (0, tst_bench_top);
116
                 $dumpon;
117
                 $display("\nINFO: VCD Signal dump enabled ...\n\n");
118
              `endif
119
 
120
          end
121
 
122
        // generate clock
123
        always #20 mstr_test_clk = ~mstr_test_clk;
124
 
125
        always @(posedge mstr_test_clk)
126 15 rehayes
          vector <= vector + 1;
127 3 rehayes
 
128
        // hookup wishbone master model
129
        wb_master_model #(.dwidth(16), .awidth(32))
130
                u0 (
131
                .clk(mstr_test_clk),
132
                .rst(rstn),
133
                .adr(adr),
134
                .din(dat_i),
135
                .dout(dat_o),
136
                .cyc(cyc),
137
                .stb(stb),
138
                .we(we),
139
                .sel(),
140
                .ack(ack),
141
                .err(1'b0),
142
                .rty(1'b0)
143
        );
144
 
145
 
146
        // Address decoding for different PIT module instances
147
        wire stb0 = stb && ~adr[4] && ~adr[3];
148
        wire stb1 = stb && ~adr[4] &&  adr[3];
149
        wire stb2 = stb &&  adr[4] && ~adr[3];
150
        wire stb3 = stb &&  adr[4] &&  adr[3];
151
 
152
        // Create the Read Data Bus
153
        assign dat_i = ({16{stb0}} & dat0_i) |
154
                       ({16{stb1}} & dat1_i) |
155
                       ({16{stb2}} & dat2_i) |
156
                       ({16{stb3}} & {8'b0, dat3_i[7:0]});
157
 
158 8 rehayes
        assign ack = ack_1 || ack_2 || ack_3 || ack_4;
159
 
160 3 rehayes
        // hookup wishbone_PIT_master core - Parameters take all default values
161
        //  Async Reset, 16 bit Bus, 16 bit Granularity
162
        pit_top pit_1(
163
                // wishbone interface
164
                .wb_clk_i(mstr_test_clk),
165
                .wb_rst_i(1'b0),
166
                .arst_i(rstn),
167
                .wb_adr_i(adr[2:0]),
168
                .wb_dat_i(dat_o),
169
                .wb_dat_o(dat0_i),
170
                .wb_we_i(we),
171
                .wb_stb_i(stb0),
172
                .wb_cyc_i(cyc),
173
                .wb_sel_i( 2'b11 ),
174 8 rehayes
                .wb_ack_o(ack_1),
175 3 rehayes
                .pit_irq_o(inta_1),
176
 
177
                .pit_o(pit_1_out),
178
                .ext_sync_i(1'b0),
179
                .cnt_sync_o(count_en_1),
180
                .cnt_flag_o(count_flag_1)
181
        );
182
 
183
        // hookup wishbone_PIT_slave core - Parameters take all default values
184
        //  Sync Reset, 16 bit Bus, 16 bit Granularity
185
        pit_top #(.ARST_LVL(1'b1))
186
                pit_2(
187
                // wishbone interface
188
                .wb_clk_i(mstr_test_clk),
189
                .wb_rst_i(sync_reset),
190
                .arst_i(1'b0),
191
                .wb_adr_i(adr[2:0]),
192
                .wb_dat_i(dat_o),
193
                .wb_dat_o(dat1_i),
194
                .wb_we_i(we),
195
                .wb_stb_i(stb1),
196
                .wb_cyc_i(cyc),
197
                .wb_sel_i( 2'b11 ),
198 8 rehayes
                .wb_ack_o(ack_2),
199 3 rehayes
                .pit_irq_o(inta_2),
200
 
201
                .pit_o(pit_2_out),
202
                .ext_sync_i(count_en_1),
203
                .cnt_sync_o(count_en_2),
204
                .cnt_flag_o(count_flag_2)
205
        );
206
 
207
        // hookup wishbone_PIT_slave core
208
        //  16 bit Bus, 16 bit Granularity
209
        pit_top #(.NO_PRESCALE(1'b1))
210
                pit_3(
211
                // wishbone interface
212
                .wb_clk_i(mstr_test_clk),
213
                .wb_rst_i(sync_reset),
214
                .arst_i(1'b1),
215
                .wb_adr_i(adr[2:0]),
216
                .wb_dat_i(dat_o),
217
                .wb_dat_o(dat2_i),
218
                .wb_we_i(we),
219
                .wb_stb_i(stb2),
220
                .wb_cyc_i(cyc),
221
                .wb_sel_i( 2'b11 ),
222 8 rehayes
                .wb_ack_o(ack_3),
223 3 rehayes
                .pit_irq_o(inta_3),
224
 
225
                .pit_o(pit_3_out),
226
                .ext_sync_i(count_en_1),
227
                .cnt_sync_o(count_en_3),
228
                .cnt_flag_o(count_flag_3)
229
        );
230
 
231
        // hookup wishbone_PIT_slave core
232
        //  8 bit Bus, 8 bit Granularity
233
        pit_top #(.DWIDTH(8))
234
                pit_4(
235
                // wishbone interface
236
                .wb_clk_i(mstr_test_clk),
237
                .wb_rst_i(sync_reset),
238
                .arst_i(1'b1),
239
                .wb_adr_i(adr[2:0]),
240
                .wb_dat_i(dat_o[7:0]),
241
                .wb_dat_o(dat3_i[7:0]),
242
                .wb_we_i(we),
243
                .wb_stb_i(stb3),
244
                .wb_cyc_i(cyc),
245
                .wb_sel_i( 2'b11 ),
246 8 rehayes
                .wb_ack_o(ack_4),
247 3 rehayes
                .pit_irq_o(inta_4),
248
 
249
                .pit_o(pit_4_out),
250
                .ext_sync_i(count_en_1),
251
                .cnt_sync_o(count_en_4),
252
                .cnt_flag_o(count_flag_4)
253
        );
254
 
255
// Test Program
256
initial
257
  begin
258
      $display("\nstatus: %t Testbench started", $time);
259
 
260
      // reset system
261
      rstn = 1'b1; // negate reset
262
      repeat(1) @(posedge mstr_test_clk);
263
      sync_reset = 1'b1;  // Make the sync reset 1 clock cycle long
264
      #2;          // move the async reset away from the clock edge
265
      rstn = 1'b0; // assert async reset
266
      #5;          // Keep the async reset pulse with less than a clock cycle
267
      rstn = 1'b1; // negate async reset
268
      repeat(1) @(posedge mstr_test_clk);
269
      sync_reset = 1'b0;
270
 
271
      $display("\nstatus: %t done reset", $time);
272
      test_num = test_num + 1;
273
 
274
      repeat(2) @(posedge mstr_test_clk);
275
 
276
      //
277
      // program core
278
      //
279
 
280
      reg_test_16;
281
 
282
      reg_test_8;
283
 
284
      u0.wb_write(1, SLAVE_0_CNTRL,   PIT_CNTRL_SLAVE); // Enable Slave Mode
285
      u0.wb_write(1, SLAVE_1_CNTRL,   PIT_CNTRL_SLAVE); // Enable Slave Mode
286
      u0.wb_write(1, SLAVE_2_CNTRL_1, 16'h0080); // Enable Slave Mode
287
      u0.wb_write(1, SLAVE_0_MOD,     16'h000a); // load Modulo
288
      u0.wb_write(1, SLAVE_1_MOD,     16'h0010); // load Modulo
289
      u0.wb_write(1, SLAVE_2_MOD_0,   16'h0010); // load Modulo
290
 
291
      // Set Master Mode PS=0, Modulo=16
292
      test_num = test_num + 1;
293
      $display("TEST #%d Starts at vector=%d, ms_test", test_num, vector);
294
 
295
      u0.wb_write(1, PIT_MOD,   16'h0010); // load prescaler hi-byte
296
      u0.wb_write(1, PIT_CNTRL, PIT_CNTRL_ENA); // Enable to start counting
297
      $display("status: %t programmed registers", $time);
298
 
299
      wait_flag_set;  // Wait for Counter to tomeout
300
      u0.wb_write(1, PIT_CNTRL, PIT_CNTRL_FLAG | PIT_CNTRL_ENA); //
301
 
302
      wait_flag_set;  // Wait for Counter to tomeout
303
      u0.wb_write(1, PIT_CNTRL, PIT_CNTRL_FLAG | PIT_CNTRL_ENA); //
304
 
305
      repeat(10) @(posedge mstr_test_clk);
306
      u0.wb_write(1, PIT_CNTRL, 16'b0); //
307
 
308
      repeat(10) @(posedge mstr_test_clk);
309
 
310
      mstr_psx_modx(2,4);
311
 
312
      mstr_psx_modx(4,0);
313
 
314
      repeat(100) @(posedge mstr_test_clk);
315
      $display("\nTestbench done at vector=%d\n", vector);
316
      $finish;
317
  end
318
 
319
// Poll for flag set
320
task wait_flag_set;
321
  begin
322
    u0.wb_read(1, PIT_CNTRL, q);
323
    while(~|(q & PIT_CNTRL_FLAG))
324
      u0.wb_read(1, PIT_CNTRL, q); // poll it until it is set
325
    $display("PIT Flag set detected at vector =%d", vector);
326
  end
327
endtask
328
 
329
// check register bits - reset, read/write
330
task reg_test_16;
331
  begin
332
      test_num = test_num + 1;
333
      $display("TEST #%d Starts at vector=%d, reg_test_16", test_num, vector);
334
      u0.wb_cmp(0, PIT_CNTRL, 16'h4000);   // verify reset
335
      u0.wb_cmp(0, PIT_MOD,   16'h0000);   // verify reset
336
      u0.wb_cmp(0, PIT_COUNT, 16'h0001);   // verify reset
337
 
338
      u0.wb_write(1, PIT_CNTRL, 16'hfffe); // load prescaler lo-byte
339
      u0.wb_cmp(  0, PIT_CNTRL, 16'hCf02); // verify write data
340
      u0.wb_write(1, PIT_CNTRL, 16'h0000); // load prescaler lo-byte
341
      u0.wb_cmp(  0, PIT_CNTRL, 16'h4000); // verify write data
342
 
343
      u0.wb_write(1, PIT_MOD, 16'h5555); // load prescaler lo-byte
344
      u0.wb_cmp(  0, PIT_MOD, 16'h5555); // verify write data
345
      u0.wb_write(1, PIT_MOD, 16'haaaa); // load prescaler lo-byte
346
      u0.wb_cmp(  0, PIT_MOD, 16'haaaa); // verify write data
347
 
348
      u0.wb_write(0, PIT_COUNT, 16'hfffe);
349
      u0.wb_cmp(  0, PIT_COUNT, 16'h0001); // verify register not writable
350
  end
351
endtask
352
 
353
task reg_test_8;
354
  begin
355
      test_num = test_num + 1;
356
      $display("TEST #%d Starts at vector=%d, reg_test_8", test_num, vector);
357
      u0.wb_cmp(0, SLAVE_2_CNTRL_0, 16'h0000);   // verify reset
358
      u0.wb_cmp(0, SLAVE_2_CNTRL_1, 16'h0040);   // verify reset
359
      u0.wb_cmp(0, SLAVE_2_MOD_0,   16'h0000);   // verify reset
360
      u0.wb_cmp(0, SLAVE_2_MOD_1,   16'h0000);   // verify reset
361
      u0.wb_cmp(0, SLAVE_2_COUNT_0, 16'h0001);   // verify reset
362
      u0.wb_cmp(0, SLAVE_2_COUNT_1, 16'h0000);   // verify reset
363
 
364
      u0.wb_write(1, SLAVE_2_CNTRL_0, 16'hfffe); // load prescaler lo-byte
365
      u0.wb_cmp(  0, SLAVE_2_CNTRL_0, 16'h0002); // verify write data
366
      u0.wb_write(1, SLAVE_2_CNTRL_0, 16'h0000); // load prescaler lo-byte
367
      u0.wb_cmp(  0, SLAVE_2_CNTRL_0, 16'h0000); // verify write data
368
      u0.wb_cmp(  0, SLAVE_2_CNTRL_1, 16'h0040); // verify write data
369
 
370
      u0.wb_write(1, SLAVE_2_MOD_0, 16'hff55); // load prescaler lo-byte
371
      u0.wb_cmp(  0, SLAVE_2_MOD_0, 16'h0055); // verify write data
372
      u0.wb_write(1, SLAVE_2_MOD_0, 16'hffaa); // load prescaler lo-byte
373
      u0.wb_cmp(  0, SLAVE_2_MOD_0, 16'h00aa); // verify write data
374
      u0.wb_write(1, SLAVE_2_MOD_1, 16'hff66); // load prescaler lo-byte
375
      u0.wb_cmp(  0, SLAVE_2_MOD_1, 16'h0066); // verify write data
376
      u0.wb_write(1, SLAVE_2_MOD_1, 16'hff99); // load prescaler lo-byte
377
      u0.wb_cmp(  0, SLAVE_2_MOD_1, 16'h0099); // verify write data
378
      u0.wb_write(1, SLAVE_2_MOD_1, 16'hff00); // load prescaler lo-byte
379
 
380
      u0.wb_write(0, SLAVE_2_COUNT_0, 16'hfffe);
381
      u0.wb_cmp(  0, SLAVE_2_COUNT_0, 16'h0001); // verify register not writable
382
      u0.wb_write(0, SLAVE_2_COUNT_1, 16'hfffe);
383
      u0.wb_cmp(  0, SLAVE_2_COUNT_1, 16'h0000); // verify register not writable
384
  end
385
endtask
386
 
387
task mstr_psx_modx;
388
  input [ 3:0] ps_val;
389
  input [15:0] mod_val;
390
  reg   [15:0] cntrl_val;
391
  begin
392
      test_num = test_num + 1;
393
      $display("TEST #%d Starts at vector=%d, mstr_psx_modx Pre=%h, Mod=%h",
394
                test_num, vector, ps_val, mod_val);
395
      // program internal registers
396
 
397
      cntrl_val = {1'b0, 3'b0, ps_val, 8'b0} | PIT_CNTRL_IRQEN;
398
      u0.wb_write(1, PIT_MOD,   mod_val); // load modulo
399
      u0.wb_write(1, PIT_CNTRL, ( cntrl_val | PIT_CNTRL_ENA)); // Enable to start counting
400
 
401
      wait_flag_set;  // Wait for Counter to timeout
402
      u0.wb_write(1, PIT_CNTRL, cntrl_val | PIT_CNTRL_FLAG | PIT_CNTRL_ENA); //
403
 
404
      wait_flag_set;  // Wait for Counter to timeout
405
      u0.wb_write(1, PIT_CNTRL, cntrl_val | PIT_CNTRL_FLAG | PIT_CNTRL_ENA); //
406
 
407
      repeat(10) @(posedge mstr_test_clk);
408
 
409
      u0.wb_write(1, PIT_CNTRL, 16'b0); //
410
 
411
   end
412
endtask
413
 
414
 
415
endmodule  // tst_bench_top
416
 

powered by: WebSVN 2.1.0

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