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

Subversion Repositories xgate

[/] [xgate/] [trunk/] [bench/] [verilog/] [tst_bench_top.v] - Blame information for rev 86

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

Line No. Rev Author Line
1 2 rehayes
////////////////////////////////////////////////////////////////////////////////
2
//
3
//  WISHBONE revB.2 compliant Xgate Coprocessor - Test Bench
4
//
5
//  Author: Bob Hayes
6 62 rehayes
//          rehayes@opencores.org
7 2 rehayes
//
8
//  Downloaded from: http://www.opencores.org/projects/xgate.....
9
//
10
////////////////////////////////////////////////////////////////////////////////
11
// Copyright (c) 2009, Robert Hayes
12
//
13
// This source file is free software: you can redistribute it and/or modify
14
// it under the terms of the GNU Lesser General Public License as published
15
// by the Free Software Foundation, either version 3 of the License, or
16
// (at your option) any later version.
17
//
18
// Supplemental terms.
19
//     * Redistributions of source code must retain the above copyright
20 62 rehayes
//       notice, this list of conditions and the following disclaimer.
21 2 rehayes
//     * Neither the name of the <organization> nor the
22 62 rehayes
//       names of its contributors may be used to endorse or promote products
23
//       derived from this software without specific prior written permission.
24 2 rehayes
//
25
// THIS SOFTWARE IS PROVIDED BY Robert Hayes ''AS IS'' AND ANY
26
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
27
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28
// DISCLAIMED. IN NO EVENT SHALL Robert Hayes BE LIABLE FOR ANY
29
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
30
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
32
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35
//
36
// You should have received a copy of the GNU General Public License
37
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
38
////////////////////////////////////////////////////////////////////////////////
39
// 45678901234567890123456789012345678901234567890123456789012345678901234567890
40
 
41
 
42
`include "timescale.v"
43
 
44
module tst_bench_top();
45
 
46 62 rehayes
  parameter MAX_CHANNEL = 127;    // Max XGATE Interrupt Channel Number
47 5 rehayes
  parameter STOP_ON_ERROR = 1'b0;
48 65 rehayes
  parameter MAX_VECTOR = 9000;
49 86 rehayes
 
50
  parameter IR_BITS = 4;     // Number of bits in JTAG instruction
51
  parameter JTAG_PERIOD = 4; // JTAG Test clock half period
52 21 rehayes
 
53 41 rehayes
  parameter L_BYTE = 2'b01;
54
  parameter H_BYTE = 2'b10;
55 36 rehayes
  parameter WORD   = 2'b11;
56 21 rehayes
 
57 2 rehayes
 
58
  // Name Address Locations
59 62 rehayes
  parameter XGATE_BASE     = 24'h1000;
60 41 rehayes
  parameter XGATE_XGMCTL   = XGATE_BASE + 6'h00;
61
  parameter XGATE_XGCHID   = XGATE_BASE + 6'h02;
62
  parameter XGATE_XGISPHI  = XGATE_BASE + 6'h04;
63
  parameter XGATE_XGISPLO  = XGATE_BASE + 6'h06;
64 62 rehayes
  parameter XGATE_XGVBR    = XGATE_BASE + 6'h08;
65 41 rehayes
  parameter XGATE_XGIF_7   = XGATE_BASE + 6'h0a;
66
  parameter XGATE_XGIF_6   = XGATE_BASE + 6'h0c;
67
  parameter XGATE_XGIF_5   = XGATE_BASE + 6'h0e;
68
  parameter XGATE_XGIF_4   = XGATE_BASE + 6'h10;
69
  parameter XGATE_XGIF_3   = XGATE_BASE + 6'h12;
70
  parameter XGATE_XGIF_2   = XGATE_BASE + 6'h14;
71
  parameter XGATE_XGIF_1   = XGATE_BASE + 6'h16;
72
  parameter XGATE_XGIF_0   = XGATE_BASE + 6'h18;
73 62 rehayes
  parameter XGATE_XGSWT    = XGATE_BASE + 6'h1a;
74
  parameter XGATE_XGSEM    = XGATE_BASE + 6'h1c;
75
  parameter XGATE_RES1     = XGATE_BASE + 6'h1e;
76
  parameter XGATE_XGCCR    = XGATE_BASE + 6'h20;
77
  parameter XGATE_XGPC     = XGATE_BASE + 6'h22;
78
  parameter XGATE_RES2     = XGATE_BASE + 6'h24;
79
  parameter XGATE_XGR1     = XGATE_BASE + 6'h26;
80
  parameter XGATE_XGR2     = XGATE_BASE + 6'h28;
81
  parameter XGATE_XGR3     = XGATE_BASE + 6'h2a;
82
  parameter XGATE_XGR4     = XGATE_BASE + 6'h2c;
83
  parameter XGATE_XGR5     = XGATE_BASE + 6'h2e;
84
  parameter XGATE_XGR6     = XGATE_BASE + 6'h30;
85
  parameter XGATE_XGR7     = XGATE_BASE + 6'h32;
86 21 rehayes
 
87 11 rehayes
  // Define bits in XGATE Control Register
88 62 rehayes
  parameter XGMCTL_XGEM     = 16'h8000;
89 11 rehayes
  parameter XGMCTL_XGFRZM   = 16'h4000;
90
  parameter XGMCTL_XGDBGM   = 15'h2000;
91
  parameter XGMCTL_XGSSM    = 15'h1000;
92
  parameter XGMCTL_XGFACTM  = 15'h0800;
93
  parameter XGMCTL_XGBRKIEM = 15'h0400;
94
  parameter XGMCTL_XGSWEIFM = 15'h0200;
95
  parameter XGMCTL_XGIEM    = 15'h0100;
96 62 rehayes
  parameter XGMCTL_XGE      = 16'h0080;
97 11 rehayes
  parameter XGMCTL_XGFRZ    = 16'h0040;
98
  parameter XGMCTL_XGDBG    = 15'h0020;
99 62 rehayes
  parameter XGMCTL_XGSS     = 15'h0010;
100 11 rehayes
  parameter XGMCTL_XGFACT   = 15'h0008;
101
  parameter XGMCTL_XGBRKIE  = 15'h0004;
102
  parameter XGMCTL_XGSWEIF  = 15'h0002;
103 62 rehayes
  parameter XGMCTL_XGIE     = 15'h0001;
104 2 rehayes
 
105 68 rehayes
  parameter CHECK_POINT     = 16'h8000;
106
  parameter CHANNEL_ACK     = CHECK_POINT + 2;
107
  parameter CHANNEL_ERR     = CHECK_POINT + 4;
108 82 rehayes
  parameter DEBUG_CNTRL     = CHECK_POINT + 6;
109 68 rehayes
  parameter TB_SEMPHORE     = CHECK_POINT + 10;
110
  parameter CHANNEL_XGIRQ_0 = CHECK_POINT + 16;
111
  parameter CHANNEL_XGIRQ_1 = CHECK_POINT + 18;
112
  parameter CHANNEL_XGIRQ_2 = CHECK_POINT + 20;
113
  parameter CHANNEL_XGIRQ_3 = CHECK_POINT + 22;
114
  parameter CHANNEL_XGIRQ_4 = CHECK_POINT + 24;
115
  parameter CHANNEL_XGIRQ_5 = CHECK_POINT + 26;
116
  parameter CHANNEL_XGIRQ_6 = CHECK_POINT + 28;
117
  parameter CHANNEL_XGIRQ_7 = CHECK_POINT + 30;
118 36 rehayes
 
119 82 rehayes
  parameter BREAK_CAPT_0    = CHECK_POINT + 64;
120
  parameter BREAK_CAPT_1    = CHECK_POINT + 66;
121
  parameter BREAK_CAPT_2    = CHECK_POINT + 68;
122
  parameter BREAK_CAPT_3    = CHECK_POINT + 70;
123
  parameter BREAK_CAPT_4    = CHECK_POINT + 72;
124
  parameter BREAK_CAPT_5    = CHECK_POINT + 74;
125
  parameter BREAK_CAPT_6    = CHECK_POINT + 76;
126
  parameter BREAK_CAPT_7    = CHECK_POINT + 78;
127
 
128 62 rehayes
  parameter SYS_RAM_BASE = 24'h00_0000;
129 65 rehayes
 
130 68 rehayes
  parameter RAM_WAIT_STATES = 1; // Number between 0 and 15
131
  parameter SYS_READ_DELAY  = 10;
132 65 rehayes
  parameter XGATE_ACCESS_DELAY = SYS_READ_DELAY + RAM_WAIT_STATES;
133
  parameter XGATE_SS_DELAY = XGATE_ACCESS_DELAY + RAM_WAIT_STATES;
134 62 rehayes
 
135 68 rehayes
  parameter IRQ_BASE       = XGATE_BASE + 64;
136
  parameter IRQ_BYPS_0     = IRQ_BASE + 0;
137
  parameter IRQ_BYPS_1     = IRQ_BASE + 2;
138
  parameter IRQ_BYPS_2     = IRQ_BASE + 4;
139
  parameter IRQ_BYPS_3     = IRQ_BASE + 6;
140
  parameter IRQ_BYPS_4     = IRQ_BASE + 8;
141
  parameter IRQ_BYPS_5     = IRQ_BASE + 10;
142
  parameter IRQ_BYPS_6     = IRQ_BASE + 12;
143
  parameter IRQ_BYPS_7     = IRQ_BASE + 14;
144 65 rehayes
 
145 36 rehayes
  //
146
  // wires && regs
147
  //
148 62 rehayes
  reg         mstr_test_clk;
149 36 rehayes
  reg  [19:0] vector;
150
  reg  [15:0] error_count;
151
  reg  [ 7:0] test_num;
152 62 rehayes
 
153 36 rehayes
  reg  [15:0] q, qq;
154 21 rehayes
 
155 62 rehayes
  reg         rstn;
156
  reg         sync_reset;
157
  reg         por_reset_b;
158
  reg         scantestmode;
159 86 rehayes
 
160
  reg         jtag_tck;
161
  reg         jtag_tdi;
162
  reg         jtag_tms;
163
 
164
  wire        jtag_tdo;
165
  wire        jtag_tdo_en;
166 21 rehayes
 
167 73 rehayes
  reg  [MAX_CHANNEL:1] channel_req;  // XGATE Interrupt inputs
168
  wire [MAX_CHANNEL:1] xgif;         // XGATE Interrupt outputs
169 62 rehayes
  wire         [  7:0] xgswt;         // XGATE Software Trigger outputs
170
  wire                 xg_sw_irq;    // Xgate Software Error interrupt
171 82 rehayes
  wire          [15:0] brkpt_cntl;   // 
172 36 rehayes
 
173
 
174 62 rehayes
  wire [15:0] wbm_dat_o;  // WISHBONE Master Mode data output from XGATE
175
  wire [15:0] wbm_dat_i;  // WISHBONE Master Mode data input to XGATE
176
  wire [15:0] wbm_adr_o;  // WISHBONE Master Mode address output from XGATE
177 36 rehayes
  wire [ 1:0] wbm_sel_o;
178
 
179 62 rehayes
  reg         mem_wait_state_enable;
180 36 rehayes
 
181
  wire [15:0] tb_ram_out;
182
 
183 62 rehayes
  wire [15:0] tb_slave_dout; // WISHBONE data bus output from testbench slave module
184
  wire        error_pulse;   // Error detected output pulse from the testbench slave module
185 68 rehayes
  wire        tb_slave_ack;  // WISHBONE ack from testbench slave module
186 62 rehayes
  wire        ack_pulse;     // Thread ack output pulse from testbench slave module
187
 
188
  wire        wbm_cyc_o;
189
  wire        wbm_stb_o;
190
  wire        wbm_we_o;
191
  wire        wbs_err_o;
192
 
193
 
194 11 rehayes
  // Registers used to mirror internal registers
195 36 rehayes
  reg  [15:0] data_xgmctl;
196
  reg  [15:0] data_xgchid;
197
  reg  [15:0] data_xgvbr;
198
  reg  [15:0] data_xgswt;
199
  reg  [15:0] data_xgsem;
200 2 rehayes
 
201 62 rehayes
  wire        sys_cyc;
202
  wire        sys_stb;
203
  wire        sys_we;
204 36 rehayes
  wire [ 1:0] sys_sel;
205 54 rehayes
  wire [23:0] sys_adr;
206 36 rehayes
  wire [15:0] sys_dout;
207 54 rehayes
  wire [15:0] sys_din;
208 62 rehayes
 
209
  wire        host_ack;
210 36 rehayes
  wire [15:0] host_dout;
211 62 rehayes
  wire        host_cyc;
212
  wire        host_stb;
213
  wire        host_we;
214 36 rehayes
  wire [ 1:0] host_sel;
215 54 rehayes
  wire [23:0] host_adr;
216 36 rehayes
  wire [15:0] host_din;
217 62 rehayes
 
218
  wire        xgate_ack;
219 36 rehayes
  wire [15:0] xgate_dout;
220 62 rehayes
  wire        xgate_cyc;
221
  wire        xgate_stb;
222
  wire        xgate_we;
223 36 rehayes
  wire [ 1:0] xgate_sel;
224
  wire [15:0] xgate_adr;
225
  wire [15:0] xgate_din;
226 62 rehayes
 
227
  wire        xgate_s_stb;
228
  wire        xgate_s_ack;
229 36 rehayes
  wire [15:0] xgate_s_dout;
230 62 rehayes
 
231
  wire        slv2_stb;
232
  wire        ram_sel;
233 36 rehayes
  wire [15:0] ram_dout;
234
 
235 2 rehayes
  // initial values and testbench setup
236
  initial
237
    begin
238
      mstr_test_clk = 0;
239
      vector = 0;
240
      test_num = 0;
241
      por_reset_b = 0;
242
      scantestmode = 0;
243 5 rehayes
      error_count = 0;
244 11 rehayes
      mem_wait_state_enable = 0;
245 86 rehayes
      jtag_tck = 0;
246
      jtag_tdi = 0;
247
      jtag_tms = 1;
248
 
249 2 rehayes
      // channel_req = 0;
250
 
251
      `ifdef WAVES
252 62 rehayes
           $shm_open("waves");
253
           $shm_probe("AS",tst_bench_top,"AS");
254
           $display("\nINFO: Signal dump enabled ...\n\n");
255 2 rehayes
      `endif
256
 
257
      `ifdef WAVES_V
258 62 rehayes
           $dumpfile ("xgate_wave_dump.lxt");
259
           $dumpvars (0, tst_bench_top);
260
           $dumpon;
261
           $display("\nINFO: VCD Signal dump enabled ...\n\n");
262 2 rehayes
      `endif
263
 
264
    end
265
 
266
  // generate clock
267
  always #20 mstr_test_clk = ~mstr_test_clk;
268
 
269 5 rehayes
  // Keep a count of how many clocks we've simulated
270 2 rehayes
  always @(posedge mstr_test_clk)
271 11 rehayes
    begin
272
      vector <= vector + 1;
273
      if (vector > MAX_VECTOR)
274 62 rehayes
        begin
275
          error_count <= error_count + 1;
276
          $display("\n ------ !!!!! Simulation Timeout at vector=%d\n -------", vector);
277
          wrap_up;
278
        end
279 11 rehayes
    end
280 2 rehayes
 
281 50 rehayes
  // Add up errors that come from WISHBONE read compares
282 36 rehayes
  always @host.cmp_error_detect
283 21 rehayes
    begin
284
      error_count <= error_count + 1;
285
    end
286 11 rehayes
 
287 54 rehayes
  always @(posedge error_pulse) //channel_ack_wrt
288 2 rehayes
    begin
289 54 rehayes
      #1;
290 5 rehayes
      error_count = error_count + 1;
291
      if (STOP_ON_ERROR == 1'b1)
292 62 rehayes
        wrap_up;
293 5 rehayes
    end
294
 
295 2 rehayes
  wire [ 6:0] current_active_channel = xgate.risc.xgchid;
296 54 rehayes
  always @(posedge ack_pulse) //channel_ack_wrt
297 2 rehayes
    clear_channel(current_active_channel);
298 21 rehayes
 
299 2 rehayes
 
300 62 rehayes
 
301 36 rehayes
  // Testbench RAM for Xgate program storage and Load/Store instruction tests
302
  ram p_ram
303
  (
304
    // Outputs
305
    .ram_out( ram_dout ),
306
    // inputs
307 54 rehayes
    .address( sys_adr[15:0] ),
308 36 rehayes
    .ram_in( sys_dout ),
309
    .we( sys_we ),
310 54 rehayes
    .ce( ram_sel ),
311 36 rehayes
    .stb( mstr_test_clk ),
312 54 rehayes
    .sel( sys_sel )
313 36 rehayes
  );
314
 
315
  // hookup wishbone master model
316 54 rehayes
  wb_master_model #(.dwidth(16), .awidth(24))
317 36 rehayes
    host(
318
    // Outputs
319
    .cyc( host_cyc ),
320
    .stb( host_stb ),
321
    .we( host_we ),
322
    .sel( host_sel ),
323
    .adr( host_adr ),
324
    .dout( host_dout ),
325
    // inputs
326 68 rehayes
    .din( sys_din ),
327
    .clk( mstr_test_clk ),
328
    .ack( host_ack ),
329
    .rst( rstn ),
330
    .err( 1'b0 ),
331
    .rty( 1'b0 )
332 36 rehayes
  );
333
 
334
  bus_arbitration  #(.dwidth(16),
335 62 rehayes
                     .awidth(24),
336 54 rehayes
                     .ram_base(0),
337
                     .ram_size(17'h10000),
338
                     .slv1_base(XGATE_BASE),
339 68 rehayes
                     .slv1_size(128),
340 54 rehayes
                     .slv2_base(CHECK_POINT),
341 68 rehayes
                     .slv2_size(32),
342 65 rehayes
                     .ram_wait_states(RAM_WAIT_STATES)
343
)
344 36 rehayes
    arb(
345
    // System bus I/O
346
    .sys_cyc( sys_cyc ),
347
    .sys_stb( sys_stb ),
348
    .sys_we( sys_we ),
349
    .sys_sel( sys_sel ),
350
    .sys_adr( sys_adr ),
351
    .sys_dout( sys_dout ),
352 54 rehayes
    .sys_din( sys_din ),
353 36 rehayes
    // Host bus I/O
354
    .host_ack( host_ack ),
355
    .host_dout( host_din ),
356
    .host_cyc( host_cyc ),
357
    .host_stb( host_stb ),
358
    .host_we( host_we ),
359
    .host_sel( host_sel ),
360
    .host_adr( host_adr ),
361
    .host_din( host_dout ),
362
    // Alternate Bus Master #1 Bus I/O
363
    .alt1_ack( xgate_ack ),
364
    .alt1_cyc( wbm_cyc_o ),
365
    .alt1_stb( wbm_stb_o ),
366
    .alt1_we( wbm_we_o ),
367
    .alt1_sel( wbm_sel_o ),
368 54 rehayes
    .alt1_adr( {8'h00, wbm_adr_o} ),
369 36 rehayes
    .alt1_din( wbm_dat_o ),
370 54 rehayes
    // RAM
371
    .ram_sel( ram_sel ),
372
    .ram_dout( ram_dout ),
373 36 rehayes
    // Slave #1 Bus I/O
374
    .slv1_stb( xgate_s_stb ),
375
    .slv1_ack( xgate_s_ack ),
376
    .slv1_din( xgate_s_dout ),
377
    // Slave #2 Bus I/O
378
    .slv2_stb( slv2_stb ),
379 68 rehayes
    .slv2_ack( tb_slave_ack ),
380 62 rehayes
    .slv2_din( tb_slave_dout ),
381 36 rehayes
    // Miscellaneous
382
    .host_clk( mstr_test_clk ),
383
    .risc_clk( mstr_test_clk ),
384
    .rst( rstn ),  // No Connect
385
    .err( 1'b0 ),  // No Connect
386
    .rty( 1'b0 )   // No Connect
387
  );
388 62 rehayes
 
389 5 rehayes
  // hookup XGATE core - Parameters take all default values
390 54 rehayes
  xgate_top  #(.SINGLE_CYCLE(1'b0),
391 68 rehayes
               .WB_RD_DEFAULT(1'b0),
392 62 rehayes
               .MAX_CHANNEL(MAX_CHANNEL))    // Max XGATE Interrupt Channel Number
393
          xgate(
394
          // Wishbone slave interface
395
          .wbs_clk_i( mstr_test_clk ),
396
          .wbs_rst_i( 1'b0 ),         // sync_reset
397
          .arst_i( rstn ),            // async resetn
398 68 rehayes
          .wbs_adr_i( sys_adr[6:1] ),
399 62 rehayes
          .wbs_dat_i( sys_dout ),
400
          .wbs_dat_o( xgate_s_dout ),
401
          .wbs_we_i( sys_we ),
402
          .wbs_stb_i( xgate_s_stb ),
403
          .wbs_cyc_i( sys_cyc ),
404
          .wbs_sel_i( sys_sel ),
405
          .wbs_ack_o( xgate_s_ack ),
406
          .wbs_err_o( wbs_err_o ),
407 2 rehayes
 
408 62 rehayes
          // Wishbone master Signals
409
          .wbm_dat_o( wbm_dat_o ),
410
          .wbm_we_o( wbm_we_o ),
411
          .wbm_stb_o( wbm_stb_o ),
412
          .wbm_cyc_o( wbm_cyc_o ),
413
          .wbm_sel_o( wbm_sel_o ),
414
          .wbm_adr_o( wbm_adr_o ),
415
          .wbm_dat_i( sys_din ),
416
          .wbm_ack_i( xgate_ack ),
417 5 rehayes
 
418 62 rehayes
          .xgif( xgif ),             // XGATE Interrupt Flag output
419
          .xg_sw_irq( xg_sw_irq ),   // XGATE Software Error Interrupt Flag output
420
          .xgswt( xgswt ),
421
          .risc_clk( mstr_test_clk ),
422 73 rehayes
          .chan_req_i( {channel_req[MAX_CHANNEL:40], xgswt, channel_req[31:1]} ),
423 62 rehayes
          .debug_mode_i( 1'b0 ),
424
          .secure_mode_i( 1'b0 ),
425
          .scantestmode( scantestmode )
426 2 rehayes
  );
427 86 rehayes
 
428
  xgate_jtag #(.IR_BITS(IR_BITS))
429
  jtag(
430
  .jtag_tdo( jtag_tdo ),
431
  .jtag_tdo_en( jtag_tdo_en ),
432 2 rehayes
 
433 86 rehayes
  .jtag_tdi( jtag_tdi ),
434
  .jtag_clk( jtag_tck ),
435
  .jtag_reset_n( rstn ),
436
  .jtag_tms( jtag_tms )
437
  );
438
 
439
 
440 54 rehayes
  tb_slave #(.DWIDTH(16),
441 68 rehayes
             .SINGLE_CYCLE(1'b1),
442
             .MAX_CHANNEL(MAX_CHANNEL))
443 54 rehayes
          tb_slave_regs(
444
          // wishbone interface
445
          .wb_clk_i( mstr_test_clk ),
446
          .wb_rst_i( 1'b0 ),
447
          .arst_i( rstn ),
448 68 rehayes
          .wb_adr_i( sys_adr[4:1] ),
449 54 rehayes
          .wb_dat_i( sys_dout ),
450 62 rehayes
          .wb_dat_o( tb_slave_dout),
451 54 rehayes
          .wb_we_i( sys_we ),
452
          .wb_stb_i( slv2_stb ),
453
          .wb_cyc_i( sys_cyc ),
454
          .wb_sel_i( sys_sel ),
455 68 rehayes
          .wb_ack_o( tb_slave_ack ),
456 2 rehayes
 
457 62 rehayes
          .ack_pulse( ack_pulse ),
458 82 rehayes
          .brkpt_cntl( brkpt_cntl ),
459 54 rehayes
          .error_pulse( error_pulse ),
460 65 rehayes
          .brk_pt(  ),
461
          .x_address( wbm_adr_o ),
462 68 rehayes
          .xgif( xgif ),
463 54 rehayes
          .vector( vector )
464
  );
465 2 rehayes
 
466 82 rehayes
tb_debug #(.DWIDTH(16),                  // Data bus width
467
           .BREAK_CAPT_0(BREAK_CAPT_0),
468
           .BREAK_CAPT_1(BREAK_CAPT_1),
469
           .BREAK_CAPT_2(BREAK_CAPT_2),
470
           .BREAK_CAPT_3(BREAK_CAPT_3),
471
           .BREAK_CAPT_4(BREAK_CAPT_4),
472
           .BREAK_CAPT_5(BREAK_CAPT_5),
473
           .BREAK_CAPT_6(BREAK_CAPT_6),
474
           .BREAK_CAPT_7(BREAK_CAPT_7))
475
  debugger(
476
          .arst_i( rstn ),
477
          .risc_clk( mstr_test_clk ),
478
          .brkpt_cntl( brkpt_cntl )
479
  );
480 54 rehayes
 
481
 
482 2 rehayes
////////////////////////////////////////////////////////////////////////////////
483
////////////////////////////////////////////////////////////////////////////////
484
////////////////////////////////////////////////////////////////////////////////
485
 
486 54 rehayes
// Main Test Program
487 2 rehayes
initial
488
  begin
489 36 rehayes
    $display("\nstatus at time: %t Testbench started", $time);
490 2 rehayes
 
491 36 rehayes
    // reset system
492
    rstn = 1'b1; // negate reset
493
    channel_req = 1; //
494
    repeat(1) @(posedge mstr_test_clk);
495 62 rehayes
    sync_reset = 1'b1;  // Make the sync reset 1 clock cycle long
496
    #2;          // move the async reset away from the clock edge
497 36 rehayes
    rstn = 1'b0; // assert async reset
498 62 rehayes
    #5;          // Keep the async reset pulse with less than a clock cycle
499 36 rehayes
    rstn = 1'b1; // negate async reset
500
    por_reset_b = 1'b1;
501
    channel_req = 0; //
502
    repeat(1) @(posedge mstr_test_clk);
503
    sync_reset = 1'b0;
504
    channel_req = 0; //
505 2 rehayes
 
506 36 rehayes
    $display("\nstatus at time: %t done reset", $time);
507 21 rehayes
 
508 36 rehayes
    test_inst_set;
509 21 rehayes
 
510 36 rehayes
    test_debug_mode;
511 2 rehayes
 
512 36 rehayes
    test_debug_bit;
513 21 rehayes
 
514 36 rehayes
    test_chid_debug;
515 21 rehayes
 
516 41 rehayes
    reg_test_16;
517 68 rehayes
 
518
    reg_irq;
519 41 rehayes
 
520 68 rehayes
    // host_ram;
521 54 rehayes
 
522 82 rehayes
    // test_skipjack;
523
 
524 36 rehayes
    // End testing
525
    wrap_up;
526 2 rehayes
  end
527
 
528 86 rehayes
// Main JTAG Test Program
529
initial
530
  begin
531
    $display("\nstatus at time: %t Testbench started", $time);
532
  //              tms, tdi
533
    send_jtag_bit(1,0);  // RUN/TEST/IDLE
534
    send_jtag_bit(0,1);  // SEL DR
535
    send_jtag_bit(1,1);  // SEL IR
536
    send_jtag_bit(1,1);  // Capture IR
537
    send_jtag_bit(0,1);  // Dead Bit?
538
    send_jtag_bit(0,1);  // LSB
539
    send_jtag_bit(0,0);  // Bit 1
540
    send_jtag_bit(0,1);  // Bit 2
541
    send_jtag_bit(0,0);  // Bit 3
542
    send_jtag_bit(1,1);  // EXIT1 IR
543
    send_jtag_bit(1,1);  // UPDATE IR
544
    send_jtag_bit(0,1);  // RUN/TEST/IDLE    
545
    send_jtag_bit(0,1);  // RUN/TEST/IDLE    
546
 
547
  end
548
 
549 36 rehayes
////////////////////////////////////////////////////////////////////////////////
550 21 rehayes
// Test CHID Debug mode operation
551
task test_chid_debug;
552
  begin
553
    test_num = test_num + 1;
554
    $display("\nTEST #%d Starts at vector=%d, test_chid_debug", test_num, vector);
555 36 rehayes
    $readmemh("../../../bench/verilog/debug_test.v", p_ram.ram_8);
556 21 rehayes
 
557 68 rehayes
    // Enable interrupts to RISC
558
    host.wb_write(0, IRQ_BYPS_0,  16'h0000, WORD);
559
 
560 21 rehayes
    data_xgmctl = XGMCTL_XGBRKIEM | XGMCTL_XGBRKIE;
561 62 rehayes
    host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD);    // Enable interrupt on BRK instruction
562 65 rehayes
    $display("BRK Software Error Interrupt enabled at vector=%d", vector);
563 21 rehayes
 
564
    activate_thread_sw(3);
565
 
566
    wait_debug_set;   // Debug Status bit is set by BRK instruction
567
 
568 62 rehayes
    host.wb_cmp(0, XGATE_XGPC,      16'h20c6, WORD);      // See Program code (BRK).
569
    host.wb_cmp(0, XGATE_XGR3,      16'h0001, WORD);      // See Program code.R3 = 1
570
    host.wb_cmp(0, XGATE_XGCHID,   16'h0003, WORD);       // Check for Correct CHID
571 65 rehayes
    $display("Debug entry detected at vector=%d", vector);
572 21 rehayes
 
573
    channel_req[5] = 1'b1; //
574
    repeat(7) @(posedge mstr_test_clk);
575 62 rehayes
    host.wb_cmp(0, XGATE_XGCHID,   16'h0003, WORD);       // Check for Correct CHID
576 21 rehayes
 
577 62 rehayes
    host.wb_write(0, XGATE_XGCHID, 16'h000f, H_BYTE);     // Check byte select lines
578 41 rehayes
    repeat(4) @(posedge mstr_test_clk);
579 62 rehayes
    host.wb_cmp(0, XGATE_XGCHID,   16'h0003, WORD);       // Verify CHID is unchanged
580 21 rehayes
 
581 62 rehayes
    host.wb_write(0, XGATE_XGCHID, 16'h000f, L_BYTE);     // Change CHID
582
    host.wb_cmp(0, XGATE_XGCHID,   16'h000f, WORD);       // Check for Correct CHID
583 21 rehayes
 
584 62 rehayes
    host.wb_write(0, XGATE_XGCHID, 16'h0000, WORD);       // Change CHID to 00, RISC should go to IDLE state
585
 
586 21 rehayes
    repeat(1) @(posedge mstr_test_clk);
587
 
588 62 rehayes
    host.wb_write(0, XGATE_XGCHID, 16'h0004, WORD);       // Change CHID
589 21 rehayes
 
590
    repeat(8) @(posedge mstr_test_clk);
591 65 rehayes
    $display("Channel ID changed at vector=%d", vector);
592 21 rehayes
 
593 65 rehayes
 
594 21 rehayes
    data_xgmctl = XGMCTL_XGDBGM;
595 62 rehayes
    host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD);    // Clear Debug Mode Control Bit
596 21 rehayes
 
597
    wait_debug_set;   // Debug Status bit is set by BRK instruction
598 62 rehayes
    host.wb_cmp(0, XGATE_XGCHID,   16'h0004, WORD);       // Check for Correct CHID
599
    host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD);    // Clear Debug Mode Control Bit (Excape from Break State and run)
600 21 rehayes
 
601
    wait_debug_set;   // Debug Status bit is set by BRK instruction
602 62 rehayes
    host.wb_cmp(0, XGATE_XGCHID,   16'h0005, WORD);       // Check for Correct CHID
603 21 rehayes
    activate_channel(6);
604 62 rehayes
    host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD);    // Clear Debug Mode Control Bit (Excape from Break State and run)
605 21 rehayes
 
606
    wait_debug_set;   // Debug Status bit is set by BRK instruction
607 62 rehayes
    host.wb_cmp(0, XGATE_XGCHID,   16'h0006, WORD);       // Check for Correct CHID
608
    host.wb_cmp(0, XGATE_XGPC,      16'h211c, WORD);      // See Program code (BRK)
609 21 rehayes
    data_xgmctl = XGMCTL_XGSSM | XGMCTL_XGSS;
610 62 rehayes
    host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD);    // Do a Single Step
611 65 rehayes
    repeat(XGATE_SS_DELAY) @(posedge mstr_test_clk);
612 62 rehayes
    host.wb_cmp(0, XGATE_XGPC,      16'h211e, WORD);      // See Program code (BRA)
613
    host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD);    // Do a Single Step
614 65 rehayes
    repeat(XGATE_SS_DELAY) @(posedge mstr_test_clk);
615 62 rehayes
    host.wb_cmp(0, XGATE_XGPC,      16'h2122, WORD);      // See Program code ()
616 21 rehayes
 
617
    repeat(20) @(posedge mstr_test_clk);
618
 
619
    data_xgmctl = XGMCTL_XGDBGM;
620 62 rehayes
    host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD);    // Clear Debug Mode Control Bit
621 21 rehayes
 
622
    repeat(50) @(posedge mstr_test_clk);
623
 
624 36 rehayes
    p_ram.dump_ram(0);
625
 
626 68 rehayes
    read_ram_cmp(16'h0000, 16'h7b55);
627
    read_ram_cmp(16'h0004, 16'h7faa);
628
    read_ram_cmp(16'h0006, 16'h6f55);
629
    read_ram_cmp(16'h0008, 16'h00c3);
630
    read_ram_cmp(16'h000a, 16'h5f66);
631
    read_ram_cmp(16'h000c, 16'h0003);
632
    read_ram_cmp(16'h0022, 16'hccxx);
633
    read_ram_cmp(16'h0026, 16'hxx99);
634
    read_ram_cmp(16'h0032, 16'h1fcc);
635
    read_ram_cmp(16'h0038, 16'h2f99);
636
    read_ram_cmp(16'h0042, 16'h33xx);
637
    read_ram_cmp(16'h0046, 16'hxx55);
638
    read_ram_cmp(16'h0052, 16'hxx66);
639
    read_ram_cmp(16'h0058, 16'h99xx);
640
    read_ram_cmp(16'h0062, 16'h1faa);
641
    read_ram_cmp(16'h0068, 16'h2fcc);
642 41 rehayes
 
643 21 rehayes
  end
644
endtask
645
 
646 36 rehayes
////////////////////////////////////////////////////////////////////////////////
647 11 rehayes
// Test Debug bit operation
648
task test_debug_bit;
649 2 rehayes
  begin
650 11 rehayes
    test_num = test_num + 1;
651 21 rehayes
    $display("\nTEST #%d Starts at vector=%d, test_debug_bit", test_num, vector);
652 36 rehayes
    $readmemh("../../../bench/verilog/debug_test.v", p_ram.ram_8);
653 21 rehayes
 
654 68 rehayes
    // Enable interrupts to RISC
655
    host.wb_write(0, IRQ_BYPS_0,  16'h0000, WORD);
656
 
657 11 rehayes
    data_xgmctl = XGMCTL_XGBRKIEM | XGMCTL_XGBRKIE;
658 62 rehayes
    host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD);    // Enable interrupt on BRK instruction
659 11 rehayes
 
660
    activate_thread_sw(2);
661 21 rehayes
 
662 65 rehayes
    // Approxmatly 12 instructions need to be done before activating Debug Mode
663
    repeat(12 + RAM_WAIT_STATES*12) @(posedge mstr_test_clk);
664 11 rehayes
 
665
    data_xgmctl = XGMCTL_XGDBGM | XGMCTL_XGDBG;
666 62 rehayes
    host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD);    // Set Debug Mode Control Bit
667 21 rehayes
    repeat(5) @(posedge mstr_test_clk);
668 65 rehayes
    $display("DEBUG bit set at vector=%d", vector);
669 21 rehayes
 
670 36 rehayes
    host.wb_read(1, XGATE_XGR3, q, WORD);
671 21 rehayes
    data_xgmctl = XGMCTL_XGSSM | XGMCTL_XGSS;
672
    qq = q;
673
 
674
    // The Xgate test program is in an infinate loop incrementing R3
675
    while (qq == q)  // Look for change in R3 register
676
      begin
677 62 rehayes
        host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD);   // Do a Single Step
678 65 rehayes
        repeat(XGATE_SS_DELAY) @(posedge mstr_test_clk);
679 62 rehayes
        host.wb_read(1, XGATE_XGR3, q, WORD);
680 21 rehayes
      end
681
    if (q != (qq+1))
682
      begin
683 62 rehayes
        $display("Error! - Unexpected value of R3 at vector=%d", vector);
684
        error_count = error_count + 1;
685 21 rehayes
      end
686
 
687
 
688 62 rehayes
    host.wb_write(1, XGATE_XGPC, 16'h2094, WORD);        // Write to PC to force exit from infinite loop
689 54 rehayes
    repeat(10) @(posedge mstr_test_clk);
690 65 rehayes
    host.wb_cmp(0, XGATE_XGPC,      16'h2094, WORD);      // Verify Proram Counter was changed
691
    $display("Program Counter changed at vector=%d", vector);
692 21 rehayes
 
693
    data_xgmctl = XGMCTL_XGSSM | XGMCTL_XGSS;
694 62 rehayes
    host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD);    // Do a Single Step (Load ADDL instruction)
695 65 rehayes
    repeat(XGATE_SS_DELAY) @(posedge mstr_test_clk);
696 62 rehayes
    host.wb_cmp(0, XGATE_XGR4,      16'h0002, WORD);      // See Program code.(R4 <= R4 + 1)
697 21 rehayes
 
698 62 rehayes
    host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD);    // Do a Single Step (Load ADDL instruction)
699 65 rehayes
    repeat(XGATE_SS_DELAY) @(posedge mstr_test_clk);
700 62 rehayes
    host.wb_cmp(0, XGATE_XGR4,      16'h0003, WORD);      // See Program code.(R4 <= R4 + 1)
701 21 rehayes
 
702
    data_xgmctl = XGMCTL_XGDBGM;
703 62 rehayes
    host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD);    // Clear Debug Mode Control Bit
704
                                                 // Should be back in Run Mode
705 21 rehayes
 
706
//    data_xgmctl = XGMCTL_XGSWEIFM | XGMCTL_XGSWEIF | XGMCTL_XGBRKIEM;
707 36 rehayes
//    host.wb_write(0, XGATE_XGMCTL, data_xgmctl);   // Clear Software Interrupt and BRK Interrupt Enable Bit
708 11 rehayes
    repeat(15) @(posedge mstr_test_clk);
709 21 rehayes
 
710 2 rehayes
  end
711
endtask
712
 
713 36 rehayes
////////////////////////////////////////////////////////////////////////////////
714 11 rehayes
// Test Debug mode operation
715
task test_debug_mode;
716 2 rehayes
  begin
717 11 rehayes
    test_num = test_num + 1;
718
    $display("\nTEST #%d Starts at vector=%d, test_debug_mode", test_num, vector);
719 36 rehayes
    $readmemh("../../../bench/verilog/debug_test.v", p_ram.ram_8);
720 21 rehayes
 
721 68 rehayes
    // Enable interrupts to RISC
722
    host.wb_write(0, IRQ_BYPS_0,  16'h0000, WORD);
723
 
724 11 rehayes
    data_xgmctl = XGMCTL_XGBRKIEM | XGMCTL_XGBRKIE;
725 62 rehayes
    host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD);    // Enable interrupt on BRK instruction
726 11 rehayes
 
727
    activate_thread_sw(1);
728 21 rehayes
 
729 11 rehayes
    wait_debug_set;   // Debug Status bit is set by BRK instruction
730
 
731 62 rehayes
    host.wb_cmp(0, XGATE_XGPC,      16'h203a, WORD);      // See Program code (BRK).
732
    host.wb_cmp(0, XGATE_XGR3,      16'h0001, WORD);      // See Program code.R3 = 1
733 11 rehayes
 
734
    data_xgmctl = XGMCTL_XGSSM | XGMCTL_XGSS;
735
 
736 62 rehayes
    host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD);    // Do a Single Step (Load ADDL instruction)
737 65 rehayes
    repeat(XGATE_SS_DELAY) @(posedge mstr_test_clk);
738 62 rehayes
    host.wb_cmp(0, XGATE_XGPC,      16'h203c, WORD);      // PC + 2.
739 11 rehayes
 
740 62 rehayes
    host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD);    // Do a Single Step (Load NOP instruction)
741 65 rehayes
    repeat(XGATE_SS_DELAY) @(posedge mstr_test_clk);                     // Execute ADDL instruction
742 62 rehayes
    host.wb_cmp(0, XGATE_XGR3,      16'h0002, WORD);      // See Program code.(R3 <= R3 + 1)
743
    host.wb_cmp(0, XGATE_XGCCR,     16'h0000, WORD);      // See Program code.
744
    host.wb_cmp(0, XGATE_XGPC,      16'h203e, WORD);      // PC + 2.
745 65 rehayes
    repeat(XGATE_SS_DELAY) @(posedge mstr_test_clk);
746 62 rehayes
    host.wb_cmp(0, XGATE_XGPC,      16'h203e, WORD);      // Still no change.
747 11 rehayes
 
748 62 rehayes
    host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD);    // Do a Single Step (Load BRA instruction)
749 65 rehayes
    repeat(XGATE_SS_DELAY) @(posedge mstr_test_clk);                     // Execute NOP instruction
750 62 rehayes
    host.wb_cmp(0, XGATE_XGPC,      16'h2040, WORD);      // See Program code.
751 11 rehayes
 
752
 
753 62 rehayes
    host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD);    // Do a Single Step
754 65 rehayes
    repeat(XGATE_SS_DELAY) @(posedge mstr_test_clk);                     // Execute BRA instruction
755 62 rehayes
    host.wb_cmp(0, XGATE_XGPC,      16'h2064, WORD);      // PC = Branch destination.
756
                                                         // Load ADDL instruction
757 21 rehayes
 
758 62 rehayes
    host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD);    // Do a Single Step (Load LDW R7 instruction)
759 65 rehayes
    repeat(XGATE_SS_DELAY) @(posedge mstr_test_clk);                     // Execute ADDL instruction
760 62 rehayes
    host.wb_cmp(0, XGATE_XGPC,      16'h2066, WORD);      // PC + 2.
761
    host.wb_cmp(0, XGATE_XGR3,      16'h0003, WORD);      // See Program code.(R3 <= R3 + 1)
762 11 rehayes
 
763 62 rehayes
    host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD);    // Do a Single Step (LDW R7)
764 65 rehayes
    repeat(XGATE_SS_DELAY) @(posedge mstr_test_clk);
765 62 rehayes
    host.wb_cmp(0, XGATE_XGPC,      16'h2068, WORD);      // PC + 2.
766
    host.wb_cmp(0, XGATE_XGR7,      16'h00c3, WORD);      // See Program code
767 11 rehayes
 
768
    repeat(1) @(posedge mstr_test_clk);
769 62 rehayes
    host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD);    // Do a Single Step (BRA)
770 65 rehayes
    repeat(XGATE_SS_DELAY) @(posedge mstr_test_clk);
771 62 rehayes
    host.wb_cmp(0, XGATE_XGPC,      16'h2048, WORD);      // See Program code.
772 11 rehayes
 
773 62 rehayes
    host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD);    // Do a Single Step (STW R3)
774 65 rehayes
    repeat(XGATE_SS_DELAY) @(posedge mstr_test_clk);
775 62 rehayes
    host.wb_cmp(0, XGATE_XGPC,      16'h204a, WORD);      // PC + 2.
776
    host.wb_cmp(0, XGATE_XGR3,      16'h0003, WORD);      // See Program code.(R3 <= R3 + 1)
777 11 rehayes
 
778 62 rehayes
    host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD);    // Do a Single Step (R3 <= R3 + 1)
779 65 rehayes
    repeat(XGATE_SS_DELAY) @(posedge mstr_test_clk);
780 62 rehayes
    host.wb_cmp(0, XGATE_XGPC,      16'h204c, WORD);      // PC + 2.
781 11 rehayes
 
782 65 rehayes
    repeat(XGATE_SS_DELAY) @(posedge mstr_test_clk);
783 11 rehayes
 
784
    data_xgmctl = XGMCTL_XGDBGM;
785 62 rehayes
    host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD);    // Clear Debug Mode Control Bit
786
                                                         // Should be back in Run Mode
787 11 rehayes
    wait_irq_set(1);
788 36 rehayes
    host.wb_write(1, XGATE_XGIF_0, 16'h0002, WORD);
789 21 rehayes
 
790 11 rehayes
    data_xgmctl = XGMCTL_XGSWEIFM | XGMCTL_XGSWEIF | XGMCTL_XGBRKIEM;
791 62 rehayes
    host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD);    // Clear Software Interrupt and BRK Interrupt Enable Bit
792 11 rehayes
    repeat(15) @(posedge mstr_test_clk);
793 21 rehayes
 
794 2 rehayes
  end
795
endtask
796
 
797 36 rehayes
////////////////////////////////////////////////////////////////////////////////
798 11 rehayes
// Test instruction set
799
task test_inst_set;
800
  begin
801 36 rehayes
    $readmemh("../../../bench/verilog/inst_test.v", p_ram.ram_8);
802 11 rehayes
    test_num = test_num + 1;
803 65 rehayes
    $display("\nTEST #%d Starts at vector=%d, test_inst_set", test_num, vector);
804 21 rehayes
    repeat(1) @(posedge mstr_test_clk);
805 68 rehayes
 
806
    // Enable interrupts to RISC
807
    host.wb_write(0, IRQ_BYPS_0,  16'h0000, WORD);
808 11 rehayes
 
809
    activate_thread_sw(1);
810
    wait_irq_set(1);
811 36 rehayes
    host.wb_write(1, XGATE_XGIF_0, 16'h0002, WORD);
812 21 rehayes
 
813 11 rehayes
    activate_thread_sw(2);
814
    wait_irq_set(2);
815 36 rehayes
    host.wb_write(1, XGATE_XGIF_0, 16'h0004, WORD);
816 11 rehayes
 
817
    activate_thread_sw(3);
818
    wait_irq_set(3);
819 36 rehayes
    host.wb_write(1, XGATE_XGIF_0, 16'h0008, WORD);
820 21 rehayes
 
821 11 rehayes
    activate_thread_sw(4);
822
    wait_irq_set(4);
823 36 rehayes
    host.wb_write(1, XGATE_XGIF_0, 16'h0010, WORD);
824 21 rehayes
 
825 11 rehayes
    activate_thread_sw(5);
826
    wait_irq_set(5);
827 36 rehayes
    host.wb_write(1, XGATE_XGIF_0, 16'h0020, WORD);
828 21 rehayes
 
829 11 rehayes
    activate_thread_sw(6);
830
    wait_irq_set(6);
831 36 rehayes
    host.wb_write(1, XGATE_XGIF_0, 16'h0040, WORD);
832 21 rehayes
 
833 11 rehayes
    activate_thread_sw(7);
834
    wait_irq_set(7);
835 36 rehayes
    host.wb_write(1, XGATE_XGIF_0, 16'h0080, WORD);
836 21 rehayes
 
837 11 rehayes
    activate_thread_sw(8);
838
    wait_irq_set(8);
839 36 rehayes
    host.wb_write(1, XGATE_XGIF_0, 16'h0100, WORD);
840 21 rehayes
 
841 11 rehayes
    activate_thread_sw(9);
842
    wait_irq_set(9);
843 36 rehayes
    host.wb_write(1, XGATE_XGIF_0, 16'h0200, WORD);
844 21 rehayes
 
845 36 rehayes
    host.wb_write(1, XGATE_XGSEM, 16'h5050, WORD);
846 62 rehayes
    host.wb_cmp(0, XGATE_XGSEM,     16'h0050, WORD);   //
847 11 rehayes
    activate_thread_sw(10);
848
    wait_irq_set(10);
849 36 rehayes
    host.wb_write(1, XGATE_XGIF_0, 16'h0400, WORD);
850 21 rehayes
 
851 36 rehayes
    host.wb_write(1, XGATE_XGSEM, 16'hff00, WORD);    // clear the old settings
852 62 rehayes
    host.wb_cmp(0, XGATE_XGSEM,     16'h0000, WORD);   //
853 36 rehayes
    host.wb_write(1, XGATE_XGSEM, 16'ha0a0, WORD);    // Verify that bits were unlocked by RISC
854 62 rehayes
    host.wb_cmp(0, XGATE_XGSEM,     16'h00a0, WORD);   // Verify bits were set
855 36 rehayes
    host.wb_write(1, XGATE_XGSEM, 16'hff08, WORD);    // Try to set the bit that was left locked by the RISC
856 62 rehayes
    host.wb_cmp(0, XGATE_XGSEM,     16'h0000, WORD);   // Verify no bits were set
857 21 rehayes
 
858 11 rehayes
    repeat(20) @(posedge mstr_test_clk);
859
 
860 36 rehayes
    p_ram.dump_ram(0);
861 62 rehayes
 
862 41 rehayes
    read_ram_cmp(16'h0000,16'haa55);
863
    read_ram_cmp(16'h0004,16'h7faa);
864
    read_ram_cmp(16'h0006,16'h6f55);
865
    read_ram_cmp(16'h000a,16'h5f66);
866
    read_ram_cmp(16'h0032,16'h1fcc);
867
    read_ram_cmp(16'h0038,16'h2f99);
868
    read_ram_cmp(16'h0062,16'h1faa);
869
    read_ram_cmp(16'h0068,16'h2fcc);
870
    read_ram_cmp(16'h0022,16'hccxx);
871
    read_ram_cmp(16'h0026,16'hxx99);
872
    read_ram_cmp(16'h0052,16'hxx66);
873
    read_ram_cmp(16'h0058,16'h99xx);
874 62 rehayes
 
875 50 rehayes
    data_xgmctl = 16'hff00;
876 62 rehayes
    host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD);    // Disable XGATE
877 50 rehayes
 
878 11 rehayes
  end
879
endtask
880
 
881 36 rehayes
////////////////////////////////////////////////////////////////////////////////
882 82 rehayes
// Test SKIPJACK Application Program
883
task test_skipjack;
884
  begin
885
    $readmemh("../../../bench/verilog/skipjack.v", p_ram.ram_8);
886
    test_num = test_num + 1;
887
    $display("\nTEST #%d Starts at vector=%d, test_skipjack", test_num, vector);
888
    repeat(1) @(posedge mstr_test_clk);
889
 
890
    host.wb_write(0, DEBUG_CNTRL,  16'hFFFF, WORD);
891
 
892
    // Enable interrupts to RISC
893
    host.wb_write(0, IRQ_BYPS_0,  16'h0000, WORD);
894
 
895
    activate_thread_sw(2);
896
    wait_irq_set(2);
897
    host.wb_write(1, XGATE_XGIF_0, 16'h0002, WORD);
898
 
899
 
900
    repeat(20) @(posedge mstr_test_clk);
901
 
902
    p_ram.dump_ram(16'h2000);
903
    // repeat(2) @(posedge mstr_test_clk);
904
    // p_ram.dump_ram(16'h9000);
905
 
906
    data_xgmctl = 16'hff00;
907
    host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD);    // Disable XGATE
908
 
909
  end
910
endtask
911
 
912
////////////////////////////////////////////////////////////////////////////////
913 2 rehayes
// check register bits - reset, read/write
914
task reg_test_16;
915
  begin
916 65 rehayes
    test_num = test_num + 1;
917
    $display("\nTEST #%d Starts at vector=%d, reg_test_16", test_num, vector);
918 41 rehayes
 
919 65 rehayes
    system_reset;
920 2 rehayes
 
921 65 rehayes
    host.wb_cmp(0, XGATE_XGMCTL,   16'h0000, WORD);      // verify reset
922
    host.wb_cmp(0, XGATE_XGCHID,   16'h0000, WORD);      // verify reset
923
    host.wb_cmp(0, XGATE_XGISPHI,  16'h0000, WORD);      // verify reset
924
    host.wb_cmp(0, XGATE_XGISPLO,  16'h0000, WORD);      // verify reset
925
    host.wb_cmp(0, XGATE_XGVBR,    16'hfe00, WORD);      // verify reset
926
    host.wb_cmp(0, XGATE_XGIF_7,   16'h0000, WORD);      // verify reset
927
    host.wb_cmp(0, XGATE_XGIF_6,   16'h0000, WORD);      // verify reset
928
    host.wb_cmp(0, XGATE_XGIF_5,   16'h0000, WORD);      // verify reset
929
    host.wb_cmp(0, XGATE_XGIF_4,   16'h0000, WORD);      // verify reset
930
    host.wb_cmp(0, XGATE_XGIF_3,   16'h0000, WORD);      // verify reset
931
    host.wb_cmp(0, XGATE_XGIF_2,   16'h0000, WORD);      // verify reset
932
    host.wb_cmp(0, XGATE_XGIF_1,   16'h0000, WORD);      // verify reset
933 73 rehayes
    host.wb_cmp(0, XGATE_XGIF_0,   16'h0000, WORD);      // verify reset
934 65 rehayes
    host.wb_cmp(0, XGATE_XGSWT,    16'h0000, WORD);      // verify reset
935
    host.wb_cmp(0, XGATE_XGSEM,    16'h0000, WORD);      // verify reset
936
    host.wb_cmp(0, XGATE_XGCCR,    16'h0000, WORD);      // verify reset
937
    host.wb_cmp(0, XGATE_XGPC,     16'h0000, WORD);      // verify reset
938
    host.wb_cmp(0, XGATE_XGR1,     16'h0000, WORD);      // verify reset
939
    host.wb_cmp(0, XGATE_XGR2,     16'h0000, WORD);      // verify reset
940
    host.wb_cmp(0, XGATE_XGR3,     16'h0000, WORD);      // verify reset
941
    host.wb_cmp(0, XGATE_XGR4,     16'h0000, WORD);      // verify reset
942
    host.wb_cmp(0, XGATE_XGR5,     16'h0000, WORD);      // verify reset
943
    host.wb_cmp(0, XGATE_XGR6,     16'h0000, WORD);      // verify reset
944
    host.wb_cmp(0, XGATE_XGR7,     16'h0000, WORD);      // verify reset
945 62 rehayes
 
946 41 rehayes
/*
947
  parameter XGMCTL_XGDBGM   = 15'h2000;
948
  parameter XGMCTL_XGSSM    = 15'h1000;
949
  parameter XGMCTL_XGBRKIEM = 15'h0400;
950
  parameter XGMCTL_XGSWEIFM = 15'h0200;
951
  parameter XGMCTL_XGIEM    = 15'h0100;
952 2 rehayes
 
953 41 rehayes
  parameter XGMCTL_XGDBG    = 15'h0020;
954 62 rehayes
  parameter XGMCTL_XGSS     = 15'h0010;
955 41 rehayes
  parameter XGMCTL_XGBRKIE  = 15'h0004;
956
  parameter XGMCTL_XGSWEIF  = 15'h0002;
957 62 rehayes
  parameter XGMCTL_XGIE     = 15'h0001;
958 41 rehayes
*/
959 65 rehayes
    // Test bits in the Xgate Control Register (XGMCTL)
960
    data_xgmctl = XGMCTL_XGEM | XGMCTL_XGFRZM | XGMCTL_XGFACTM | XGMCTL_XGFRZ | XGMCTL_XGFACT | XGMCTL_XGE;
961
    host.wb_write(0, XGATE_XGMCTL,   data_xgmctl, WORD);   //
962
    data_xgmctl = XGMCTL_XGFRZ | XGMCTL_XGFACT | XGMCTL_XGE;
963
    host.wb_cmp(  0, XGATE_XGMCTL, data_xgmctl, WORD);
964 2 rehayes
 
965 65 rehayes
    data_xgmctl = XGMCTL_XGEM;
966
    host.wb_write(0, XGATE_XGMCTL,   data_xgmctl, WORD);   //
967
    data_xgmctl = XGMCTL_XGFRZ | XGMCTL_XGFACT;
968
    host.wb_cmp(  0, XGATE_XGMCTL, data_xgmctl, WORD);
969 2 rehayes
 
970 65 rehayes
    data_xgmctl = XGMCTL_XGFRZM | XGMCTL_XGFACTM;
971
    host.wb_write(0, XGATE_XGMCTL,   data_xgmctl, WORD);   //
972
    data_xgmctl = 16'h0000;
973
    host.wb_cmp(  0, XGATE_XGMCTL, data_xgmctl, WORD);
974 41 rehayes
 
975 65 rehayes
    data_xgmctl = 16'hffff;
976
    host.wb_write(0, XGATE_XGMCTL,   data_xgmctl, H_BYTE);   //
977
    data_xgmctl = 16'h0000;
978
    host.wb_cmp(  0, XGATE_XGMCTL, data_xgmctl, WORD);
979 41 rehayes
 
980 65 rehayes
    data_xgmctl = 16'hffff;
981
    host.wb_write(0, XGATE_XGMCTL,   data_xgmctl, L_BYTE);   //
982
    data_xgmctl = 16'h0000;
983
    host.wb_cmp(  0, XGATE_XGMCTL, data_xgmctl, WORD);
984 41 rehayes
 
985 65 rehayes
    // Test the Xgate Vector Base Address Register (XGVBR)
986
    host.wb_write(0, XGATE_XGVBR,  16'h5555, WORD);
987
    host.wb_cmp(0, XGATE_XGVBR,    16'h5554, WORD);
988 41 rehayes
 
989 65 rehayes
    host.wb_write(0, XGATE_XGVBR,  16'hAAAA, WORD);
990
    host.wb_cmp(0, XGATE_XGVBR,    16'hAAAA, WORD);
991 41 rehayes
 
992 65 rehayes
    host.wb_write(0, XGATE_XGVBR,  16'hFF55, L_BYTE);
993
    host.wb_cmp(0, XGATE_XGVBR,    16'hAA54, WORD);
994 62 rehayes
 
995 65 rehayes
    host.wb_write(0, XGATE_XGVBR,  16'h55AA, H_BYTE);
996
    host.wb_cmp(0, XGATE_XGVBR,    16'h5554, WORD);
997 62 rehayes
 
998 65 rehayes
    data_xgmctl = XGMCTL_XGEM | XGMCTL_XGE;
999
    host.wb_write(0, XGATE_XGMCTL,   data_xgmctl, WORD);   //
1000
    data_xgmctl = XGMCTL_XGE;
1001
    host.wb_cmp(  0, XGATE_XGMCTL, data_xgmctl, WORD);
1002
    host.wb_write(0, XGATE_XGVBR,  16'hFFFF, WORD);
1003
    host.wb_cmp(0, XGATE_XGVBR,    16'h5554, WORD);
1004 41 rehayes
 
1005 65 rehayes
    data_xgmctl = XGMCTL_XGEM;
1006
    host.wb_write(0, XGATE_XGMCTL,   data_xgmctl, WORD);   //
1007 41 rehayes
 
1008 65 rehayes
    // Test the Xgate Software Trigger Register (XGSWT)
1009
    host.wb_write(0, XGATE_XGSWT,  16'hFFFF, WORD);
1010
    host.wb_cmp(0, XGATE_XGSWT,    16'h00FF, WORD);
1011
    host.wb_write(0, XGATE_XGSWT,  16'hFF00, WORD);
1012
    host.wb_cmp(0, XGATE_XGSWT,    16'h0000, WORD);
1013 41 rehayes
 
1014 65 rehayes
    host.wb_write(0, XGATE_XGSWT,  16'hFF55, L_BYTE);
1015
    host.wb_cmp(0, XGATE_XGSWT,    16'h0000, WORD);
1016
    host.wb_write(0, XGATE_XGSWT,  16'hFF55, H_BYTE);
1017
    host.wb_cmp(0, XGATE_XGSWT,    16'h0000, WORD);
1018 41 rehayes
 
1019 65 rehayes
    // Test the Xgate Semaphore Register (XGSEM)
1020
    host.wb_write(0, XGATE_XGSEM,  16'hFFFF, WORD);
1021
    host.wb_cmp(0, XGATE_XGSEM,    16'h00FF, WORD);
1022
    host.wb_write(0, XGATE_XGSEM,  16'hFF00, WORD);
1023
    host.wb_cmp(0, XGATE_XGSEM,    16'h0000, WORD);
1024 41 rehayes
 
1025 65 rehayes
    host.wb_write(0, XGATE_XGSEM,  16'hFFFF, L_BYTE);
1026
    host.wb_cmp(0, XGATE_XGSEM,    16'h0000, WORD);
1027
    host.wb_write(0, XGATE_XGSEM,  16'hFFFF, H_BYTE);
1028
    host.wb_cmp(0, XGATE_XGSEM,    16'h0000, WORD);
1029 41 rehayes
 
1030 65 rehayes
    // Test the Xgate Condition Code Register (XGCCR)
1031
    host.wb_write(0, XGATE_XGCCR,  16'hFFFF, L_BYTE);
1032
    host.wb_cmp(0, XGATE_XGCCR,    16'h000F, WORD);
1033
    host.wb_write(0, XGATE_XGCCR,  16'hFFF0, WORD);
1034
    host.wb_cmp(0, XGATE_XGCCR,    16'h0000, WORD);
1035 41 rehayes
 
1036 65 rehayes
    // Test the Xgate Program Counter Register (XGPC)
1037
    host.wb_write(0, XGATE_XGPC,  16'hFF55, L_BYTE);
1038
    host.wb_cmp(0, XGATE_XGPC,    16'h0055, WORD);
1039
    host.wb_write(0, XGATE_XGPC,  16'hAAFF, H_BYTE);
1040
    host.wb_cmp(0, XGATE_XGPC,    16'hAA55, WORD);
1041
    host.wb_write(0, XGATE_XGPC,  16'h9966, WORD);
1042
    host.wb_cmp(0, XGATE_XGPC,    16'h9966, WORD);
1043 41 rehayes
 
1044 65 rehayes
    // Test the Xgate Register #1 (XGR1)
1045
    host.wb_write(0, XGATE_XGR1,  16'hFF33, L_BYTE);
1046
    host.wb_cmp(0, XGATE_XGR1,    16'h0033, WORD);
1047
    host.wb_write(0, XGATE_XGR1,  16'hccFF, H_BYTE);
1048
    host.wb_cmp(0, XGATE_XGR1,    16'hcc33, WORD);
1049
    host.wb_write(0, XGATE_XGR1,  16'hf11f, WORD);
1050
    host.wb_cmp(0, XGATE_XGR1,    16'hf11f, WORD);
1051 41 rehayes
 
1052 65 rehayes
    // Test the Xgate Register #2 (XGR2)
1053
    host.wb_write(0, XGATE_XGR2,  16'hFF11, L_BYTE);
1054
    host.wb_cmp(0, XGATE_XGR2,    16'h0011, WORD);
1055
    host.wb_write(0, XGATE_XGR2,  16'h22FF, H_BYTE);
1056
    host.wb_cmp(0, XGATE_XGR2,    16'h2211, WORD);
1057
    host.wb_write(0, XGATE_XGR2,  16'hddee, WORD);
1058
    host.wb_cmp(0, XGATE_XGR2,    16'hddee, WORD);
1059 41 rehayes
 
1060 65 rehayes
    // Test the Xgate Register #3 (XGR3)
1061
    host.wb_write(0, XGATE_XGR3,  16'hFF43, L_BYTE);
1062
    host.wb_cmp(0, XGATE_XGR3,    16'h0043, WORD);
1063
    host.wb_write(0, XGATE_XGR3,  16'h54FF, H_BYTE);
1064
    host.wb_cmp(0, XGATE_XGR3,    16'h5443, WORD);
1065
    host.wb_write(0, XGATE_XGR3,  16'habbc, WORD);
1066
    host.wb_cmp(0, XGATE_XGR3,    16'habbc, WORD);
1067 41 rehayes
 
1068 65 rehayes
    // Test the Xgate Register #4 (XGR4)
1069
    host.wb_write(0, XGATE_XGR4,  16'hFF54, L_BYTE);
1070
    host.wb_cmp(0, XGATE_XGR4,    16'h0054, WORD);
1071
    host.wb_write(0, XGATE_XGR4,  16'h65FF, H_BYTE);
1072
    host.wb_cmp(0, XGATE_XGR4,    16'h6554, WORD);
1073
    host.wb_write(0, XGATE_XGR4,  16'h9aab, WORD);
1074
    host.wb_cmp(0, XGATE_XGR4,    16'h9aab, WORD);
1075 41 rehayes
 
1076 65 rehayes
    // Test the Xgate Register #5 (XGR5)
1077
    host.wb_write(0, XGATE_XGR5,  16'hFF65, L_BYTE);
1078
    host.wb_cmp(0, XGATE_XGR5,    16'h0065, WORD);
1079
    host.wb_write(0, XGATE_XGR5,  16'h76FF, H_BYTE);
1080
    host.wb_cmp(0, XGATE_XGR5,    16'h7665, WORD);
1081
    host.wb_write(0, XGATE_XGR5,  16'h899a, WORD);
1082
    host.wb_cmp(0, XGATE_XGR5,    16'h899a, WORD);
1083 41 rehayes
 
1084 65 rehayes
    // Test the Xgate Register #6 (XGR6)
1085
    host.wb_write(0, XGATE_XGR6,  16'hFF76, L_BYTE);
1086
    host.wb_cmp(0, XGATE_XGR6,    16'h0076, WORD);
1087
    host.wb_write(0, XGATE_XGR6,  16'h87FF, H_BYTE);
1088
    host.wb_cmp(0, XGATE_XGR6,    16'h8776, WORD);
1089
    host.wb_write(0, XGATE_XGR6,  16'h7889, WORD);
1090
    host.wb_cmp(0, XGATE_XGR6,    16'h7889, WORD);
1091 41 rehayes
 
1092 65 rehayes
    // Test the Xgate Register #7 (XGR7)
1093
    host.wb_write(0, XGATE_XGR7,  16'hFF87, L_BYTE);
1094
    host.wb_cmp(0, XGATE_XGR7,    16'h0087, WORD);
1095
    host.wb_write(0, XGATE_XGR7,  16'h98FF, H_BYTE);
1096
    host.wb_cmp(0, XGATE_XGR7,    16'h9887, WORD);
1097
    host.wb_write(0, XGATE_XGR7,  16'h6778, WORD);
1098
    host.wb_cmp(0, XGATE_XGR7,    16'h6778, WORD);
1099 41 rehayes
 
1100 65 rehayes
    host.wb_cmp(0, XGATE_XGPC,    16'h9966, WORD);
1101
    host.wb_cmp(0, XGATE_XGR1,    16'hf11f, WORD);
1102
    host.wb_cmp(0, XGATE_XGR2,    16'hddee, WORD);
1103
    host.wb_cmp(0, XGATE_XGR3,    16'habbc, WORD);
1104
    host.wb_cmp(0, XGATE_XGR4,    16'h9aab, WORD);
1105
    host.wb_cmp(0, XGATE_XGR5,    16'h899a, WORD);
1106
    host.wb_cmp(0, XGATE_XGR6,    16'h7889, WORD);
1107
    host.wb_cmp(0, XGATE_XGR7,    16'h6778, WORD);
1108 41 rehayes
 
1109 2 rehayes
  end
1110
endtask
1111
 
1112 68 rehayes
////////////////////////////////////////////////////////////////////////////////
1113 73 rehayes
// check irq register bits - reset, read/write
1114 68 rehayes
task reg_irq;
1115
  begin
1116
    test_num = test_num + 1;
1117
    $display("\nTEST #%d Starts at vector=%d, reg_irq", test_num, vector);
1118
    $readmemh("../../../bench/verilog/irq_test.v", p_ram.ram_8);
1119 2 rehayes
 
1120 68 rehayes
    system_reset;
1121
 
1122 73 rehayes
    host.wb_cmp(0, IRQ_BYPS_0,   16'hFFFE, WORD);        // verify reset
1123 68 rehayes
    host.wb_cmp(0, IRQ_BYPS_1,   16'hFFFF, WORD);        // verify reset
1124
    host.wb_cmp(0, IRQ_BYPS_2,   16'hFFFF, WORD);        // verify reset
1125
    host.wb_cmp(0, IRQ_BYPS_3,   16'hFFFF, WORD);        // verify reset
1126
    host.wb_cmp(0, IRQ_BYPS_4,   16'hFFFF, WORD);        // verify reset
1127
    host.wb_cmp(0, IRQ_BYPS_5,   16'hFFFF, WORD);        // verify reset
1128
    host.wb_cmp(0, IRQ_BYPS_6,   16'hFFFF, WORD);        // verify reset
1129
    host.wb_cmp(0, IRQ_BYPS_7,   16'hFFFF, WORD);        // verify reset
1130
 
1131
 
1132
    // Test the Xgate IRQ Bypass Registers (IRQ_BYPS)
1133
    host.wb_write(0, IRQ_BYPS_0,  16'hAAAA, WORD);
1134
    host.wb_cmp(0, IRQ_BYPS_0,    16'hAAAA, WORD);
1135
    host.wb_write(0, IRQ_BYPS_0,  16'h5555, WORD);
1136 73 rehayes
    host.wb_cmp(0, IRQ_BYPS_0,    16'h5554, WORD);
1137 68 rehayes
 
1138
    host.wb_write(0, IRQ_BYPS_0,  16'hFF66, L_BYTE);
1139
    host.wb_cmp(0, IRQ_BYPS_0,    16'h5566, WORD);
1140
    host.wb_write(0, IRQ_BYPS_0,  16'h33FF, H_BYTE);
1141
    host.wb_cmp(0, IRQ_BYPS_0,    16'h3366, WORD);
1142
    host.wb_write(0, IRQ_BYPS_0,  16'hFFFF, H_BYTE);
1143
 
1144
    channel_req[17] = 1'b1; //
1145
    repeat(4) @(posedge mstr_test_clk);
1146
    host.wb_cmp(0, CHANNEL_XGIRQ_1,    16'h0002, WORD);
1147
    channel_req[17] = 1'b0; //
1148
    repeat(4) @(posedge mstr_test_clk);
1149
    host.wb_cmp(0, CHANNEL_XGIRQ_1,    16'h0000, WORD);
1150
 
1151
    host.wb_write(0, TB_SEMPHORE,  16'h0000, WORD);
1152
    host.wb_write(0, IRQ_BYPS_0,  16'h0000, WORD);
1153
    host.wb_write(0, IRQ_BYPS_0,  16'h0000, WORD);
1154
    data_xgmctl = XGMCTL_XGEM | XGMCTL_XGE;
1155
    host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD);   // Enable XGATE
1156
    repeat(XGATE_ACCESS_DELAY+2) @(posedge mstr_test_clk);
1157
    channel_req[3:1] = 3'b111; //
1158
 
1159
    q = 0;
1160
    // The Xgate test program is in an infinate loop for the test bench semaphore register to be changed
1161
    while (q == 0)  // Look for change in test bench semapore register
1162
      begin
1163
        host.wb_read(1, TB_SEMPHORE, q, WORD);
1164
      end
1165
 
1166
    if (q != 1)
1167
      begin
1168
        $display("IRQ test failure, Wrong interrupt being processed! Interrupt=%d, vector=%d", q, vector);
1169
      end
1170
 
1171
    channel_req[1] = 1'b0; //
1172
    repeat(XGATE_ACCESS_DELAY+2) @(posedge mstr_test_clk);
1173
    host.wb_write(0, TB_SEMPHORE,  16'h0000, WORD);
1174
    repeat(XGATE_ACCESS_DELAY+2) @(posedge mstr_test_clk);
1175
 
1176
//    host.wb_cmp(0, CHANNEL_XGIRQ_0, 16'h0002, WORD);  // Verify Xgate output interrupt flag set
1177
//    host.wb_cmp(0, XGATE_XGIF_0,    16'h0002, WORD);  // Verify Xgate interrupt status bit set
1178
    host.wb_write(1, XGATE_XGIF_0, 16'h0002, WORD);  // Clear Interrupt Flag from Xgate
1179
//    host.wb_cmp(0, XGATE_XGIF_0,    16'h0000, WORD);  // Verify flag cleared
1180
 
1181
    q = 0;
1182
    // The Xgate test program is in an infinate loop for the test bench semaphore register to be changed
1183
    while (q == 0)  // Look for change in test bench semapore register
1184
      begin
1185
        host.wb_read(1, TB_SEMPHORE, q, WORD);
1186
      end
1187
 
1188
    if (q != 2)
1189
      begin
1190
        $display("IRQ test failure, Wrong interrupt being processed! Interrupt=%d, vector=%d", q, vector);
1191
      end
1192
 
1193
    channel_req[2] = 1'b0; //
1194
    repeat(XGATE_ACCESS_DELAY+2) @(posedge mstr_test_clk);
1195
    host.wb_write(0, TB_SEMPHORE,  16'h0000, WORD);
1196
    repeat(XGATE_ACCESS_DELAY+2) @(posedge mstr_test_clk);
1197
 
1198
//    host.wb_cmp(0, CHANNEL_XGIRQ_0, 16'h0002, WORD);  // Verify Xgate output interrupt flag set
1199
//    host.wb_cmp(0, XGATE_XGIF_0,    16'h0002, WORD);  // Verify Xgate interrupt status bit set
1200
    host.wb_write(1, XGATE_XGIF_0, 16'h0004, WORD);  // Clear Interrupt Flag from Xgate
1201
//    host.wb_cmp(0, XGATE_XGIF_0,    16'h0000, WORD);  // Verify flag cleared
1202
 
1203
    q = 0;
1204
    // The Xgate test program is in an infinate loop for the test bench semaphore register to be changed
1205
    while (q == 0)  // Look for change in test bench semapore register
1206
      begin
1207
        host.wb_read(1, TB_SEMPHORE, q, WORD);
1208
      end
1209
 
1210
    if (q != 3)
1211
      begin
1212
        $display("IRQ test failure, Wrong interrupt being processed! Interrupt=%d, vector=%d", q, vector);
1213
      end
1214
 
1215
    channel_req[3] = 1'b0; //
1216
    repeat(XGATE_ACCESS_DELAY+2) @(posedge mstr_test_clk);
1217
    host.wb_write(0, TB_SEMPHORE,  16'h0000, WORD);
1218
    repeat(XGATE_ACCESS_DELAY+2) @(posedge mstr_test_clk);
1219
 
1220
//    host.wb_cmp(0, CHANNEL_XGIRQ_0, 16'h0002, WORD);  // Verify Xgate output interrupt flag set
1221
//    host.wb_cmp(0, XGATE_XGIF_0,    16'h0002, WORD);  // Verify Xgate interrupt status bit set
1222
    host.wb_write(1, XGATE_XGIF_0, 16'h0008, WORD);  // Clear Interrupt Flag from Xgate
1223
//    host.wb_cmp(0, XGATE_XGIF_0,    16'h0000, WORD);  // Verify flag cleared
1224
 
1225
  end
1226
endtask
1227
 
1228
 
1229 36 rehayes
////////////////////////////////////////////////////////////////////////////////
1230
// check RAM Read/Write from host
1231
task host_ram;
1232
  begin
1233
    test_num = test_num + 1;
1234 65 rehayes
    $display("\nTEST #%d Starts at vector=%d, host_ram", test_num, vector);
1235 36 rehayes
 
1236
    host.wb_write(1, SYS_RAM_BASE, 16'h5555, WORD);
1237
    host.wb_cmp(  0, SYS_RAM_BASE, 16'h5555, WORD);
1238
 
1239
    repeat(5) @(posedge mstr_test_clk);
1240
    p_ram.dump_ram(0);
1241
 
1242
  end
1243
endtask
1244
 
1245
////////////////////////////////////////////////////////////////////////////////
1246 11 rehayes
// Poll for XGATE Interrupt set
1247
task wait_irq_set;
1248
  input [ 6:0] chan_val;
1249
  begin
1250
    while(!xgif[chan_val])
1251
      @(posedge mstr_test_clk); // poll it until it is set
1252
    $display("XGATE Interrupt Request #%d set detected at vector =%d", chan_val, vector);
1253
  end
1254
endtask
1255 2 rehayes
 
1256 36 rehayes
////////////////////////////////////////////////////////////////////////////////
1257 11 rehayes
// Poll for debug bit set
1258
task wait_debug_set;
1259
  begin
1260 36 rehayes
    host.wb_read(1, XGATE_XGMCTL, q, WORD);
1261 11 rehayes
    while(~|(q & XGMCTL_XGDBG))
1262 36 rehayes
      host.wb_read(1, XGATE_XGMCTL, q, WORD); // poll it until it is set
1263 11 rehayes
    $display("DEBUG Flag set detected at vector =%d", vector);
1264
  end
1265
endtask
1266 2 rehayes
 
1267 11 rehayes
 
1268 36 rehayes
////////////////////////////////////////////////////////////////////////////////
1269 2 rehayes
task system_reset;  // reset system
1270
  begin
1271
      repeat(1) @(posedge mstr_test_clk);
1272
      sync_reset = 1'b1;  // Make the sync reset 1 clock cycle long
1273 62 rehayes
      #2;                 // move the async reset away from the clock edge
1274
      rstn = 1'b0;        // assert async reset
1275
      #5;                 // Keep the async reset pulse with less than a clock cycle
1276
      rstn = 1'b1;        // negate async reset
1277 2 rehayes
      repeat(1) @(posedge mstr_test_clk);
1278
      sync_reset = 1'b0;
1279
 
1280
      $display("\nstatus: %t System Reset Task Done", $time);
1281
      test_num = test_num + 1;
1282
 
1283
      repeat(2) @(posedge mstr_test_clk);
1284
   end
1285
endtask
1286
 
1287
 
1288 36 rehayes
////////////////////////////////////////////////////////////////////////////////
1289 2 rehayes
task activate_channel;
1290
  input [ 6:0] chan_val;
1291
  begin
1292 21 rehayes
    $display("Activating Channel %d", chan_val);
1293 2 rehayes
 
1294 21 rehayes
    channel_req[chan_val] = 1'b1; //
1295
    repeat(1) @(posedge mstr_test_clk);
1296 2 rehayes
  end
1297
endtask
1298
 
1299
 
1300 36 rehayes
////////////////////////////////////////////////////////////////////////////////
1301 2 rehayes
task clear_channel;
1302
  input [ 6:0] chan_val;
1303
  begin
1304 21 rehayes
    $display("Clearing Channel interrupt input #%d", chan_val);
1305 2 rehayes
 
1306 21 rehayes
    channel_req[chan_val] = 1'b0; //
1307
    repeat(1) @(posedge mstr_test_clk);
1308
  end
1309 2 rehayes
endtask
1310
 
1311
 
1312 36 rehayes
////////////////////////////////////////////////////////////////////////////////
1313 2 rehayes
task clear_irq_flag;
1314
  input [ 6:0] chan_val;
1315
  begin
1316
      $display("Clearing Channel interrupt flag #%d", chan_val);
1317
      if (0 < chan_val < 16)
1318 62 rehayes
        host.wb_write(1, XGATE_XGIF_0, 16'hffff, WORD);
1319 2 rehayes
      if (15 < chan_val < 32)
1320 62 rehayes
        host.wb_write(1, XGATE_XGIF_1, 16'hffff, WORD);
1321 2 rehayes
      if (31 < chan_val < 48)
1322 62 rehayes
        host.wb_write(1, XGATE_XGIF_2, 16'hffff, WORD);
1323 2 rehayes
      if (47 < chan_val < 64)
1324 62 rehayes
        host.wb_write(1, XGATE_XGIF_3, 16'hffff, WORD);
1325 2 rehayes
      if (63 < chan_val < 80)
1326 62 rehayes
        host.wb_write(1, XGATE_XGIF_4, 16'hffff, WORD);
1327 2 rehayes
      if (79 < chan_val < 96)
1328 62 rehayes
        host.wb_write(1, XGATE_XGIF_5, 16'hffff, WORD);
1329 2 rehayes
      if (95 < chan_val < 112)
1330 62 rehayes
        host.wb_write(1, XGATE_XGIF_6, 16'hffff, WORD);
1331 2 rehayes
      if (111 < chan_val < 128)
1332 62 rehayes
        host.wb_write(1, XGATE_XGIF_7, 16'hffff, WORD);
1333 2 rehayes
 
1334 21 rehayes
      channel_req[chan_val] = 1'b0; //
1335 2 rehayes
      repeat(1) @(posedge mstr_test_clk);
1336
   end
1337
endtask
1338
 
1339
 
1340 36 rehayes
////////////////////////////////////////////////////////////////////////////////
1341 2 rehayes
task activate_thread_sw;
1342
  input [ 6:0] chan_val;
1343
  begin
1344 50 rehayes
      $display("Activating Software Thread - Channel #%d", chan_val);
1345 2 rehayes
 
1346 11 rehayes
      data_xgmctl = XGMCTL_XGEM | XGMCTL_XGE;
1347 36 rehayes
      host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD);   // Enable XGATE
1348 2 rehayes
 
1349 21 rehayes
      channel_req[chan_val] = 1'b1; //
1350 2 rehayes
      repeat(1) @(posedge mstr_test_clk);
1351
   end
1352
endtask
1353
 
1354 36 rehayes
////////////////////////////////////////////////////////////////////////////////
1355 41 rehayes
task read_ram_cmp;
1356
  input [15:0] address;
1357
  input [15:0] value;
1358 62 rehayes
  reg   [15:0] q;
1359 41 rehayes
  begin
1360
 
1361
      // BIGENDIAN
1362
      q = {p_ram.ram_8[address], p_ram.ram_8[address+1]};
1363
      // "X" compares don't work, "X" in value or q always match
1364
      if (value != q)
1365
        begin
1366 62 rehayes
          error_count = error_count + 1;
1367
          $display("RAM Data compare error at address %h. Received %h, expected %h at time %t", address, q, value, $time);
1368 41 rehayes
        end
1369
   end
1370
endtask
1371
 
1372
////////////////////////////////////////////////////////////////////////////////
1373 5 rehayes
task wrap_up;
1374
  begin
1375 21 rehayes
    test_num = test_num + 1;
1376
    repeat(10) @(posedge mstr_test_clk);
1377 5 rehayes
    $display("\nSimulation Finished!! - vector =%d", vector);
1378
    if (error_count == 0)
1379
      $display("Simulation Passed");
1380
    else
1381 21 rehayes
      $display("Simulation Failed  --- Errors =%d", error_count);
1382 5 rehayes
 
1383
    $finish;
1384
  end
1385
endtask
1386
 
1387 36 rehayes
////////////////////////////////////////////////////////////////////////////////
1388 86 rehayes
task send_jtag_bit;
1389
  input tms_val;
1390
  input tdi_val;
1391
  begin
1392
        jtag_tck = 0;
1393
        repeat(JTAG_PERIOD) @(posedge mstr_test_clk);
1394
        jtag_tck = 1;
1395
        #1;
1396
        jtag_tms = tms_val;
1397
        jtag_tdi = tdi_val;
1398
        repeat(JTAG_PERIOD) @(posedge mstr_test_clk);
1399
        jtag_tck = 0;
1400
  end
1401
endtask
1402
 
1403
////////////////////////////////////////////////////////////////////////////////
1404 2 rehayes
function [15:0] four_2_16;
1405
  input [3:0] vector;
1406
  begin
1407
    case (vector)
1408
      4'h0 : four_2_16 = 16'b0000_0000_0000_0001;
1409
      4'h1 : four_2_16 = 16'b0000_0000_0000_0010;
1410
      4'h2 : four_2_16 = 16'b0000_0000_0000_0100;
1411
      4'h3 : four_2_16 = 16'b0000_0000_0000_1000;
1412
      4'h4 : four_2_16 = 16'b0000_0000_0001_0000;
1413
      4'h5 : four_2_16 = 16'b0000_0000_0010_0000;
1414
      4'h6 : four_2_16 = 16'b0000_0000_0100_0000;
1415
      4'h7 : four_2_16 = 16'b0000_0000_1000_0000;
1416
      4'h8 : four_2_16 = 16'b0000_0001_0000_0000;
1417
      4'h9 : four_2_16 = 16'b0000_0010_0000_0000;
1418
      4'ha : four_2_16 = 16'b0000_0100_0000_0000;
1419
      4'hb : four_2_16 = 16'b0000_1000_0000_0000;
1420
      4'hc : four_2_16 = 16'b0001_0000_0000_0000;
1421
      4'hd : four_2_16 = 16'b0010_0000_0000_0000;
1422
      4'he : four_2_16 = 16'b0100_0000_0000_0000;
1423
      4'hf : four_2_16 = 16'b1000_0000_0000_0000;
1424
    endcase
1425
  end
1426
endfunction
1427
 
1428
endmodule  // tst_bench_top
1429
 
1430 36 rehayes
////////////////////////////////////////////////////////////////////////////////
1431
////////////////////////////////////////////////////////////////////////////////
1432
////////////////////////////////////////////////////////////////////////////////
1433 62 rehayes
module bus_arbitration  #(parameter dwidth = 16,
1434
                          parameter awidth = 24,
1435 54 rehayes
                          parameter ram_base = 0,
1436
                          parameter ram_size = 16'hffff,
1437
                          parameter slv1_base = 0,
1438
                          parameter slv1_size = 1,
1439
                          parameter slv2_base = 0,
1440 65 rehayes
                          parameter slv2_size = 1,
1441
                          parameter ram_wait_states = 0) // Number between 0 and 15
1442 36 rehayes
  (
1443
  // System bus I/O
1444 62 rehayes
  output reg                 sys_cyc,
1445
  output reg                 sys_stb,
1446
  output reg                 sys_we,
1447 54 rehayes
  output reg [dwidth/8 -1:0] sys_sel,
1448
  output reg [awidth   -1:0] sys_adr,
1449
  output reg [dwidth   -1:0] sys_dout,
1450
  output     [dwidth   -1:0] sys_din,
1451 62 rehayes
 
1452 36 rehayes
  // Host bus I/O
1453 62 rehayes
  output                     host_ack,
1454 36 rehayes
  output     [dwidth   -1:0] host_dout,
1455 62 rehayes
  input                      host_cyc,
1456
  input                      host_stb,
1457
  input                      host_we,
1458
  input      [dwidth/8 -1:0] host_sel,
1459
  input      [awidth   -1:0] host_adr,
1460
  input      [dwidth   -1:0] host_din,
1461
 
1462 36 rehayes
  // Alternate Bus Master #1 Bus I/O
1463 62 rehayes
  output                     alt1_ack,
1464 36 rehayes
  output     [dwidth   -1:0] alt1_dout,
1465 62 rehayes
  input                      alt1_cyc,
1466
  input                      alt1_stb,
1467
  input                      alt1_we,
1468
  input      [dwidth/8 -1:0] alt1_sel,
1469
  input      [awidth   -1:0] alt1_adr,
1470
  input      [dwidth   -1:0] alt1_din,
1471
 
1472 54 rehayes
  // System RAM memory signals
1473 62 rehayes
  output                     ram_sel,
1474
  input      [dwidth   -1:0] ram_dout,
1475 54 rehayes
 
1476 36 rehayes
  // Slave #1 Bus I/O
1477 62 rehayes
  output                     slv1_stb,
1478
  input                      slv1_ack,
1479
  input      [dwidth   -1:0] slv1_din,
1480
 
1481 36 rehayes
  // Slave #2 Bus I/O
1482 62 rehayes
  output                     slv2_stb,
1483
  input                      slv2_ack,
1484
  input      [dwidth   -1:0] slv2_din,
1485
 
1486 36 rehayes
  // Miscellaneous
1487 62 rehayes
  input                      host_clk,
1488
  input                      risc_clk,
1489
  input                      rst,  // No Connect
1490
  input                      err,  // No Connect
1491
  input                      rty   // No Connect
1492 36 rehayes
  );
1493 62 rehayes
 
1494 60 rehayes
  // States for bus arbitration
1495 54 rehayes
  parameter [1:0] BUS_IDLE = 2'b00,
1496 62 rehayes
                  HOST_OWNS = 2'b10,
1497
                  RISC_OWNS = 2'b11;
1498
 
1499
  parameter max_bus_hold = 5;    // Max number of cycles any bus master can hold the system bus
1500 36 rehayes
  //////////////////////////////////////////////////////////////////////////////
1501
  //
1502
  // Local Wires and Registers
1503
  //
1504 62 rehayes
  wire       ram_ack;        //
1505
  wire       any_ack;        //
1506
  reg        host_wait;      // Host bus in wait state, Hold the bus till the transaction complets
1507 36 rehayes
  reg  [3:0] host_cycle_cnt; // Used to count the cycle the host and break the lock if the risc needs access
1508 62 rehayes
 
1509
  wire       risc_lock;      // RISC has the slave bus
1510
  reg        risc_wait;      // RISC bus in wait state, Hold the bus till the transaction complets
1511 36 rehayes
  reg  [3:0] risc_cycle_cnt; // Used to count the cycle the risc and break the lock if the host needs access
1512 62 rehayes
 
1513 54 rehayes
  reg  [1:0] owner_state;
1514
  reg  [1:0] owner_ns;
1515 36 rehayes
 
1516 62 rehayes
  wire       host_timeout;
1517
  wire       risc_timeout;
1518
 
1519
  wire       ram_ack_dly;    // Delayed bus ack to simulate bus wait states
1520 60 rehayes
  reg  [3:0] ack_dly_cnt;    // Counter to delay bus ack to master modules
1521 54 rehayes
 
1522
 
1523
  //
1524 36 rehayes
  always @(posedge host_clk or negedge rst)
1525
    if (!rst)
1526 54 rehayes
      owner_state <= BUS_IDLE;
1527 36 rehayes
    else
1528 54 rehayes
      owner_state <= owner_ns;
1529 62 rehayes
 
1530 54 rehayes
  //
1531
  always @*
1532
    case (owner_state)
1533
      BUS_IDLE :
1534
        begin
1535
          if (host_cyc)
1536
            owner_ns = HOST_OWNS;
1537
          else if (alt1_cyc)
1538
            owner_ns = RISC_OWNS;
1539
        end
1540
      HOST_OWNS :
1541
        begin
1542
          if (!host_cyc && !alt1_cyc)
1543
            owner_ns = BUS_IDLE;
1544
          else if (alt1_cyc && (!host_cyc || host_timeout))
1545
            owner_ns = RISC_OWNS;
1546
        end
1547
      RISC_OWNS :
1548
        begin
1549
          if (!host_cyc && !alt1_cyc)
1550
            owner_ns = BUS_IDLE;
1551
          else if (host_cyc && (!alt1_cyc || risc_timeout))
1552
            owner_ns = HOST_OWNS;
1553
        end
1554
      default : owner_ns = BUS_IDLE;
1555
    endcase
1556 36 rehayes
 
1557 62 rehayes
 
1558 60 rehayes
  assign host_timeout = (owner_state == HOST_OWNS) && (host_cycle_cnt > max_bus_hold) && any_ack;
1559
  assign risc_timeout = (owner_state == RISC_OWNS) && (risc_cycle_cnt > max_bus_hold) && any_ack;
1560 54 rehayes
 
1561
  // Start counting cycles that the host has the bus, if the risc is also requesting the bus
1562 36 rehayes
  always @(posedge host_clk or negedge rst)
1563
    if (!rst)
1564
      host_cycle_cnt <= 0;
1565 54 rehayes
    else if ((owner_state != HOST_OWNS) || !alt1_cyc)
1566
      host_cycle_cnt <= 0;
1567 62 rehayes
    else if (&host_cycle_cnt && !host_timeout)  // Don't allow rollover
1568 54 rehayes
      host_cycle_cnt <= host_cycle_cnt;
1569
    else if ((owner_state == HOST_OWNS) && alt1_cyc)
1570
      host_cycle_cnt <= host_cycle_cnt + 1'b1;
1571 36 rehayes
 
1572 54 rehayes
  // Start counting cycles that the risc has the bus, if the host is also requesting the bus
1573 36 rehayes
  always @(posedge host_clk or negedge rst)
1574
    if (!rst)
1575
      risc_cycle_cnt <= 0;
1576 54 rehayes
    else if ((owner_state != RISC_OWNS) || !host_cyc)
1577
      risc_cycle_cnt <= 0;
1578 62 rehayes
    else if (&risc_cycle_cnt && !risc_timeout)  // Don't allow rollover
1579 54 rehayes
      risc_cycle_cnt <= risc_cycle_cnt;
1580
    else if ((owner_state == RISC_OWNS) && host_cyc)
1581
      risc_cycle_cnt <= risc_cycle_cnt + 1'b1;
1582 36 rehayes
 
1583 62 rehayes
  // Aribartration Logic for System Bus access
1584 54 rehayes
  assign any_ack  = slv1_ack || slv2_ack || ram_ack;
1585
  assign host_ack = (owner_state == HOST_OWNS) && any_ack && host_cyc;
1586
  assign alt1_ack = (owner_state == RISC_OWNS) && any_ack && alt1_cyc;
1587 36 rehayes
 
1588 54 rehayes
 
1589
  // Address decoding for different Slave module instances
1590
  assign slv1_stb = sys_stb && (sys_adr >= slv1_base) && (sys_adr < (slv1_base + slv1_size));
1591
  assign slv2_stb = sys_stb && (sys_adr >= slv2_base) && (sys_adr < (slv2_base + slv2_size));
1592 62 rehayes
 
1593 36 rehayes
  // Address decoding for Testbench access to RAM
1594 54 rehayes
  assign ram_sel = sys_cyc && sys_stb && !(slv1_stb || slv2_stb) &&
1595 62 rehayes
                   (sys_adr >= ram_base) &&
1596 54 rehayes
                   (sys_adr < (ram_base + ram_size));
1597 62 rehayes
 
1598 60 rehayes
  // Throw in some wait states from the memory
1599
  always @(posedge host_clk)
1600
    if ((ack_dly_cnt == ram_wait_states) || !ram_sel)
1601
      ack_dly_cnt <= 0;
1602
    else if (ram_sel)
1603
      ack_dly_cnt <= ack_dly_cnt + 1'b1;
1604 36 rehayes
 
1605 60 rehayes
  assign ram_ack_dly = (ack_dly_cnt == ram_wait_states);
1606
  assign ram_ack = ram_sel && ram_ack_dly;
1607 36 rehayes
 
1608 60 rehayes
 
1609 54 rehayes
  // Create the System Read Data Bus from the Slave output data buses
1610 68 rehayes
  assign sys_din = ({dwidth{1'b1}} & slv1_din) |
1611 62 rehayes
                   ({dwidth{slv2_stb}} & slv2_din) |
1612
                   ({dwidth{ram_sel}}  & ram_dout);
1613 36 rehayes
 
1614 54 rehayes
  // Mux for System Bus access
1615
  always @*
1616
    case (owner_state)
1617
      BUS_IDLE :
1618
        begin
1619 62 rehayes
          sys_cyc   = 0;
1620
          sys_stb   = 0;
1621
          sys_we    = 0;
1622
          sys_sel   = 0;
1623
          sys_adr   = 0;
1624
          sys_dout  = 0;
1625 54 rehayes
        end
1626
      HOST_OWNS :
1627
        begin
1628 62 rehayes
          sys_cyc   = host_cyc;
1629
          sys_stb   = host_stb;
1630
          sys_we    = host_we;
1631
          sys_sel   = host_sel;
1632
          sys_adr   = host_adr;
1633
          sys_dout  = host_din;
1634 54 rehayes
        end
1635
      RISC_OWNS :
1636
        begin
1637 62 rehayes
          sys_cyc   = alt1_cyc;
1638
          sys_stb   = alt1_stb;
1639
          sys_we    = alt1_we;
1640
          sys_sel   = alt1_sel;
1641
          sys_adr   = alt1_adr;
1642
          sys_dout  = alt1_din;
1643 54 rehayes
        end
1644
      default :
1645
        begin
1646 62 rehayes
          sys_cyc   = 0;
1647
          sys_stb   = 0;
1648
          sys_we    = 0;
1649
          sys_sel   = 0;
1650
          sys_adr   = 0;
1651
          sys_dout  = 0;
1652 54 rehayes
        end
1653
    endcase
1654 36 rehayes
 
1655 54 rehayes
endmodule   // bus_arbitration
1656 36 rehayes
 
1657 54 rehayes
////////////////////////////////////////////////////////////////////////////////
1658
////////////////////////////////////////////////////////////////////////////////
1659
////////////////////////////////////////////////////////////////////////////////
1660
module tb_slave #(parameter SINGLE_CYCLE = 1'b0,  // No bus wait state added
1661 68 rehayes
                  parameter MAX_CHANNEL = 127,    // Max XGATE Interrupt Channel Number
1662 62 rehayes
                  parameter DWIDTH = 16)          // Data bus width
1663 54 rehayes
  (
1664
  // Wishbone Signals
1665 62 rehayes
  output [DWIDTH-1:0] wb_dat_o,      // databus output
1666
  output              wb_ack_o,     // bus cycle acknowledge output
1667
  input               wb_clk_i,     // master clock input
1668
  input               wb_rst_i,     // synchronous active high reset
1669
  input               arst_i,       // asynchronous reset
1670 68 rehayes
  input         [3:0] wb_adr_i,      // lower address bits
1671 62 rehayes
  input  [DWIDTH-1:0] wb_dat_i,      // databus input
1672
  input               wb_we_i,      // write enable input
1673
  input               wb_stb_i,     // stobe/core select signal
1674
  input               wb_cyc_i,     // valid bus cycle input
1675
  input         [1:0] wb_sel_i,      // Select byte in word bus transaction
1676
  // Slave unique IO Signals
1677 82 rehayes
  output reg              error_pulse,  // Error detected output pulse
1678
  output reg              ack_pulse,    // Thread ack output pulse
1679
  output reg [DWIDTH-1:0] brkpt_cntl,   // Break Point Control reg
1680
 
1681 65 rehayes
  output              brk_pt,       // Break point
1682 68 rehayes
  input        [15:0] x_address,    // XGATE WISHBONE Master bus address
1683 73 rehayes
  input [MAX_CHANNEL:1] xgif,       // XGATE Interrupt Flag to Host
1684 62 rehayes
  input        [19:0] vector
1685 54 rehayes
  );
1686 62 rehayes
 
1687
  wire                  async_rst_b;   // Asyncronous reset
1688
  wire                  sync_reset;    // Syncronous reset
1689
 
1690 54 rehayes
  // Wishbone Bus interface
1691
  // registers
1692 68 rehayes
  reg               bus_wait_state;  // Holdoff wb_ack_o for one clock to add wait state
1693
  reg  [DWIDTH-1:0] rd_data_mux;     // Pseudo Register, WISHBONE Read Data Mux
1694
  reg  [DWIDTH-1:0] rd_data_reg;     // Latch for WISHBONE Read Data
1695 36 rehayes
 
1696 68 rehayes
  reg  [DWIDTH-1:0] check_point_reg;
1697
  reg  [DWIDTH-1:0] channel_ack_reg;
1698
  reg  [DWIDTH-1:0] channel_err_reg;
1699 36 rehayes
 
1700 68 rehayes
  reg  [DWIDTH-1:0] brkpt_addr_reg;  // Break Point Address reg
1701 65 rehayes
 
1702 68 rehayes
  reg  [DWIDTH-1:0] tb_semaphr_reg;  // Test bench semaphore reg
1703
 
1704 54 rehayes
  event check_point_wrt;
1705
  event channel_ack_wrt;
1706
  event channel_err_wrt;
1707 36 rehayes
 
1708 54 rehayes
  // Wires
1709 62 rehayes
  wire   module_sel;      // This module is selected for bus transaction
1710
  wire   wb_wacc;         // WISHBONE Write Strobe
1711
  wire   wb_racc;         // WISHBONE Read Access (Clock gating signal)
1712 36 rehayes
 
1713 54 rehayes
  //
1714
  // module body
1715
  //
1716 36 rehayes
 
1717 54 rehayes
  // generate internal resets
1718
 
1719
 
1720
  // generate wishbone signals
1721
  assign module_sel = wb_cyc_i && wb_stb_i;
1722
  assign wb_wacc    = module_sel && wb_we_i && (wb_ack_o || SINGLE_CYCLE);
1723
  assign wb_racc    = module_sel && !wb_we_i;
1724
  assign wb_ack_o   = SINGLE_CYCLE ? module_sel : bus_wait_state;
1725
  assign wb_dat_o   = SINGLE_CYCLE ? rd_data_mux : rd_data_reg;
1726
 
1727
  // generate acknowledge output signal, By using register all accesses takes two cycles.
1728
  //  Accesses in back to back clock cycles are not possable.
1729
  always @(posedge wb_clk_i or negedge arst_i)
1730
    if (!arst_i)
1731 62 rehayes
      bus_wait_state <=  1'b0;
1732 54 rehayes
    else if (wb_rst_i)
1733 62 rehayes
      bus_wait_state <=  1'b0;
1734 54 rehayes
    else
1735 62 rehayes
      bus_wait_state <=  module_sel && !bus_wait_state;
1736 54 rehayes
 
1737
  // assign data read bus -- DAT_O
1738
  always @(posedge wb_clk_i)
1739 62 rehayes
    if ( wb_racc )                     // Clock gate for power saving
1740 54 rehayes
      rd_data_reg <= rd_data_mux;
1741
 
1742
  // WISHBONE Read Data Mux
1743
  always @*
1744
    case (wb_adr_i) // synopsys parallel_case
1745 68 rehayes
      4'b0000: rd_data_mux = check_point_reg;
1746
      4'b0001: rd_data_mux = channel_ack_reg;
1747
      4'b0010: rd_data_mux = channel_err_reg;
1748 82 rehayes
      4'b0011: rd_data_mux = brkpt_cntl;
1749 68 rehayes
      4'b0100: rd_data_mux = brkpt_addr_reg;
1750
      4'b0101: rd_data_mux = tb_semaphr_reg;
1751 73 rehayes
      4'b1000: rd_data_mux = {xgif[15: 1], 1'b0};
1752 68 rehayes
      4'b1001: rd_data_mux = xgif[31:16];
1753
      4'b1010: rd_data_mux = xgif[47:32];
1754
      4'b1011: rd_data_mux = xgif[63:48];
1755
      4'b1100: rd_data_mux = xgif[79:64];
1756
      4'b1101: rd_data_mux = xgif[95:80];
1757
      4'b1110: rd_data_mux = xgif[111:96];
1758
      4'b1111: rd_data_mux = xgif[127:112];
1759
      default: rd_data_mux = {DWIDTH{1'b0}};
1760 54 rehayes
    endcase
1761
 
1762
  // generate wishbone write register strobes
1763
  always @(posedge wb_clk_i or negedge arst_i)
1764
    begin
1765
      if (!arst_i)
1766 62 rehayes
        begin
1767
          check_point_reg <= 0;
1768
          channel_ack_reg <= 0;
1769
          channel_err_reg <= 0;
1770
          ack_pulse       <= 0;
1771
          error_pulse     <= 0;
1772 82 rehayes
          brkpt_cntl      <= 0;
1773 68 rehayes
          brkpt_addr_reg  <= 0;
1774
          tb_semaphr_reg  <= 0;
1775 62 rehayes
        end
1776 54 rehayes
      else if (wb_wacc)
1777
        case (wb_adr_i) // synopsys parallel_case
1778
           3'b000 :
1779
             begin
1780 62 rehayes
               check_point_reg[ 7:0] <= wb_sel_i[0] ? wb_dat_i[ 7:0] : check_point_reg[ 7:0];
1781
               check_point_reg[15:8] <= wb_sel_i[1] ? wb_dat_i[15:8] : check_point_reg[15:8];
1782
               -> check_point_wrt;
1783 54 rehayes
             end
1784
           3'b001 :
1785
             begin
1786 62 rehayes
               channel_ack_reg[ 7:0] <= wb_sel_i[0] ? wb_dat_i[ 7:0] : channel_ack_reg[ 7:0];
1787
               channel_ack_reg[15:8] <= wb_sel_i[1] ? wb_dat_i[15:8] : channel_ack_reg[15:8];
1788 54 rehayes
               ack_pulse <= 1;
1789 62 rehayes
               -> channel_ack_wrt;
1790 54 rehayes
             end
1791
           3'b010 :
1792
             begin
1793 62 rehayes
               channel_err_reg[ 7:0] <= wb_sel_i[0] ? wb_dat_i[ 7:0] : channel_err_reg[ 7:0];
1794
               channel_err_reg[15:8] <= wb_sel_i[1] ? wb_dat_i[15:8] : channel_err_reg[15:8];
1795 54 rehayes
               error_pulse <= 1'b1;
1796 62 rehayes
               -> channel_err_wrt;
1797 54 rehayes
             end
1798
           3'b011 :
1799
             begin
1800 82 rehayes
               brkpt_cntl[ 7:0] <= wb_sel_i[0] ? wb_dat_i[ 7:0] : brkpt_cntl[ 7:0];
1801
               brkpt_cntl[15:8] <= wb_sel_i[1] ? wb_dat_i[15:8] : brkpt_cntl[15:8];
1802 54 rehayes
             end
1803 65 rehayes
           3'b100 :
1804
             begin
1805
               brkpt_addr_reg[ 7:0] <= wb_sel_i[0] ? wb_dat_i[ 7:0] : brkpt_addr_reg[ 7:0];
1806
               brkpt_addr_reg[15:8] <= wb_sel_i[1] ? wb_dat_i[15:8] : brkpt_addr_reg[15:8];
1807
             end
1808 68 rehayes
           3'b101 :
1809
             begin
1810
               tb_semaphr_reg[ 7:0] <= wb_sel_i[0] ? wb_dat_i[ 7:0] : tb_semaphr_reg[ 7:0];
1811
               tb_semaphr_reg[15:8] <= wb_sel_i[1] ? wb_dat_i[15:8] : tb_semaphr_reg[15:8];
1812
             end
1813 54 rehayes
           default: ;
1814
        endcase
1815
      else
1816
        begin
1817
          ack_pulse   <= 0;
1818
          error_pulse <= 1'b0;
1819 62 rehayes
        end
1820 54 rehayes
    end
1821
 
1822
  always @check_point_wrt
1823
    begin
1824
      #1;
1825
      $display("\nSoftware Checkpoint #%h -- at vector=%d\n", check_point_reg, vector);
1826
    end
1827
 
1828
  always @channel_err_wrt
1829
    begin
1830
      #1;
1831 62 rehayes
      $display("\n ------ !!!!! Software Checkpoint Error #%d -- at vector=%d\n  -------", channel_err_reg, vector);
1832 54 rehayes
    end
1833
 
1834
 
1835
endmodule // tb_slave
1836
 
1837 82 rehayes
////////////////////////////////////////////////////////////////////////////////
1838
////////////////////////////////////////////////////////////////////////////////
1839
////////////////////////////////////////////////////////////////////////////////
1840
module tb_debug #(parameter DWIDTH = 16,          // Data bus width
1841
                  parameter BREAK_CAPT_0 = 0,
1842
                  parameter BREAK_CAPT_1 = 0,
1843
                  parameter BREAK_CAPT_2 = 0,
1844
                  parameter BREAK_CAPT_3 = 0,
1845
                  parameter BREAK_CAPT_4 = 0,
1846
                  parameter BREAK_CAPT_5 = 0,
1847
                  parameter BREAK_CAPT_6 = 0,
1848
                  parameter BREAK_CAPT_7 = 0
1849
                  )
1850
  (
1851
  // Wishbone Signals
1852
  input               arst_i,       // asynchronous reset
1853
  input               risc_clk,
1854
  input  [DWIDTH-1:0] brkpt_cntl    // databus input
1855
  );
1856
 
1857
  wire [15:0] next_pc = xgate.risc.program_counter;
1858
  wire [15:0] x1 = xgate.risc.xgr1;
1859
  wire [15:0] x2 = xgate.risc.xgr2;
1860
  wire [15:0] x3 = xgate.risc.xgr3;
1861
  wire [15:0] x4 = xgate.risc.xgr4;
1862
  wire [15:0] x5 = xgate.risc.xgr5;
1863
  wire [15:0] x6 = xgate.risc.xgr6;
1864
  wire [15:0] x7 = xgate.risc.xgr7;
1865
 
1866
  reg [15:0] cap_x1;
1867
  reg [15:0] cap_x2;
1868
  reg [15:0] cap_x3;
1869
  reg [15:0] cap_x4;
1870
  reg [15:0] cap_x5;
1871
  reg [15:0] cap_x6;
1872
  reg [15:0] cap_x7;
1873
 
1874
  reg [15:0] break_addr_0;
1875
  reg [15:0] break_addr_1;
1876
  reg [15:0] break_addr_2;
1877
  reg [15:0] break_addr_3;
1878
  reg [15:0] break_addr_4;
1879
  reg [15:0] break_addr_5;
1880
  reg [15:0] break_addr_6;
1881
  reg [15:0] break_addr_7;
1882
 
1883
  reg detect_addr;
1884
 
1885
  wire trigger, trigger0, trigger1, trigger3, trigger4, trigger5, trigger6, trigger7;
1886
 
1887
  initial
1888
    begin
1889
      break_addr_0 = 0;
1890
      break_addr_1 = 0;
1891
      break_addr_2 = 0;
1892
      break_addr_3 = 0;
1893
      break_addr_4 = 0;
1894
      break_addr_5 = 0;
1895
      break_addr_6 = 0;
1896
      break_addr_7 = 0;
1897
      repeat(4) @(posedge risc_clk); // Note: !! This should come after code load
1898
      break_addr_0 = {p_ram.ram_8[BREAK_CAPT_0], p_ram.ram_8[BREAK_CAPT_0+1]};
1899
      break_addr_1 = {p_ram.ram_8[BREAK_CAPT_1], p_ram.ram_8[BREAK_CAPT_1+1]};
1900
      break_addr_2 = {p_ram.ram_8[BREAK_CAPT_2], p_ram.ram_8[BREAK_CAPT_2+1]};
1901
      break_addr_3 = {p_ram.ram_8[BREAK_CAPT_3], p_ram.ram_8[BREAK_CAPT_3+1]};
1902
      break_addr_4 = {p_ram.ram_8[BREAK_CAPT_4], p_ram.ram_8[BREAK_CAPT_4+1]};
1903
      break_addr_5 = {p_ram.ram_8[BREAK_CAPT_5], p_ram.ram_8[BREAK_CAPT_5+1]};
1904
      break_addr_6 = {p_ram.ram_8[BREAK_CAPT_6], p_ram.ram_8[BREAK_CAPT_6+1]};
1905
      break_addr_7 = {p_ram.ram_8[BREAK_CAPT_7], p_ram.ram_8[BREAK_CAPT_7+1]};
1906
    end
1907
 
1908
  assign trigger0 = (next_pc === break_addr_0) && brkpt_cntl[ 8];
1909
  assign trigger1 = (next_pc === break_addr_1) && brkpt_cntl[ 9];
1910
  assign trigger2 = (next_pc === break_addr_2) && brkpt_cntl[10];
1911
  assign trigger3 = (next_pc === break_addr_3) && brkpt_cntl[11];
1912
  assign trigger4 = (next_pc === break_addr_4) && brkpt_cntl[12];
1913
  assign trigger5 = (next_pc === break_addr_5) && brkpt_cntl[13];
1914
  assign trigger6 = (next_pc === break_addr_6) && brkpt_cntl[14];
1915
  assign trigger7 = (next_pc === break_addr_7) && brkpt_cntl[15];
1916
 
1917
  assign trigger = brkpt_cntl[0] &
1918
                   (trigger0 | trigger1 | trigger2 | trigger3 | trigger4 | trigger5 | trigger6 | trigger7);
1919
 
1920
  always @(posedge risc_clk or negedge arst_i)
1921
    begin
1922
      if (!arst_i)
1923
        begin
1924
          cap_x1 <= 0;
1925
          cap_x2 <= 0;
1926
          cap_x3 <= 0;
1927
          cap_x4 <= 0;
1928
          cap_x5 <= 0;
1929
          cap_x6 <= 0;
1930
          cap_x7 <= 0;
1931
        end
1932
      else if (trigger)
1933
        begin
1934
          cap_x1 <= x1;
1935
          cap_x2 <= x2;
1936
          cap_x3 <= x3;
1937
          cap_x4 <= x4;
1938
          cap_x5 <= x5;
1939
          cap_x6 <= x6;
1940
          cap_x7 <= x7;
1941
        end
1942
    end
1943
 
1944
 
1945
endmodule // tb_debug
1946
 

powered by: WebSVN 2.1.0

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