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

Subversion Repositories xgate

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

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

powered by: WebSVN 2.1.0

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