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

Subversion Repositories xgate

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

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
//          rehayes@opencores.org
7
//
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
//       notice, this list of conditions and the following disclaimer.
21
//     * Neither the name of the <organization> nor the
22
//       names of its contributors may be used to endorse or promote products
23
//       derived from this software without specific prior written permission.
24
//
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
  parameter MAX_CHANNEL = 127;    // Max XGATE Interrupt Channel Number
47 5 rehayes
  parameter STOP_ON_ERROR = 1'b0;
48 50 rehayes
  parameter MAX_VECTOR = 2300;
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 36 rehayes
  parameter XGATE_BASE     = 32'b0;
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
  parameter XGATE_XGVBR    = XGATE_BASE + 6'h08;
62
  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
  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
  parameter XGMCTL_XGEM     = 16'h8000;
86
  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
  parameter XGMCTL_XGE      = 16'h0080;
94
  parameter XGMCTL_XGFRZ    = 16'h0040;
95
  parameter XGMCTL_XGDBG    = 15'h0020;
96
  parameter XGMCTL_XGSS     = 15'h0010;
97
  parameter XGMCTL_XGFACT   = 15'h0008;
98
  parameter XGMCTL_XGBRKIE  = 15'h0004;
99
  parameter XGMCTL_XGSWEIF  = 15'h0002;
100
  parameter XGMCTL_XGIE     = 15'h0001;
101 2 rehayes
 
102 5 rehayes
  parameter CHECK_POINT = 16'h8000;
103
  parameter CHANNEL_ACK = CHECK_POINT + 2;
104
  parameter CHANNEL_ERR = CHECK_POINT + 4;
105 36 rehayes
 
106
  parameter SYS_RAM_BASE = 32'h0002_0000;
107
 
108
  //
109
  // wires && regs
110
  //
111
  reg         mstr_test_clk;
112
  reg  [19:0] vector;
113
  reg  [15:0] error_count;
114
  reg  [ 7:0] test_num;
115
 
116
  reg  [15:0] q, qq;
117
  reg  [ 7:0] check_point_reg;
118
  reg  [ 7:0] channel_ack_reg;
119
  reg  [ 7:0] channel_err_reg;
120 5 rehayes
  event check_point_wrt;
121
  event channel_ack_wrt;
122
  event channel_err_wrt;
123 21 rehayes
 
124 36 rehayes
  reg         rstn;
125
  reg         sync_reset;
126
  reg         por_reset_b;
127
  reg         stop_mode;
128
  reg         wait_mode;
129
  reg         debug_mode;
130
  reg         scantestmode;
131 21 rehayes
 
132 36 rehayes
  reg         wbm_ack_i;
133
 
134
  wire [15:0] dat_i, dat1_i, dat2_i, dat3_i;
135
  wire        ack, ack_2, ack_3, ack_4;
136
 
137
  reg  [MAX_CHANNEL:0] channel_req;  // XGATE Interrupt inputs
138
  wire [MAX_CHANNEL:0] xgif;         // XGATE Interrupt outputs
139
  wire         [  7:0] xgswt;        // XGATE Software Trigger outputs
140
  wire                 xg_sw_irq;    // Xgate Software Error interrupt
141
 
142
 
143
  wire [15:0] wbm_dat_o;         // WISHBONE Master Mode data output from XGATE
144
  wire [15:0] wbm_dat_i;         // WISHBONE Master Mode data input to XGATE
145
  wire [15:0] wbm_adr_o;         // WISHBONE Master Mode address output from XGATE
146
  wire [ 1:0] wbm_sel_o;
147
 
148
  reg         mem_wait_state_enable;
149
 
150
  wire [15:0] tb_ram_out;
151
  wire [31:0] sys_addr;
152
 
153 11 rehayes
  // Registers used to mirror internal registers
154 36 rehayes
  reg  [15:0] data_xgmctl;
155
  reg  [15:0] data_xgchid;
156
  reg  [15:0] data_xgvbr;
157
  reg  [15:0] data_xgswt;
158
  reg  [15:0] data_xgsem;
159 2 rehayes
 
160 36 rehayes
  wire        sys_cyc;
161
  wire        sys_stb;
162
  wire        sys_we;
163
  wire [ 1:0] sys_sel;
164
  wire [31:0] sys_adr;
165
  wire [15:0] sys_dout;
166
 
167
  wire        host_ack;
168
  wire [15:0] host_dout;
169
  wire        host_cyc;
170
  wire        host_stb;
171
  wire        host_we;
172
  wire [ 1:0] host_sel;
173
  wire [31:0] host_adr;
174
  wire [15:0] host_din;
175
 
176
  wire        xgate_ack;
177
  wire [15:0] xgate_dout;
178
  wire        xgate_cyc;
179
  wire        xgate_stb;
180
  wire        xgate_we;
181
  wire [ 1:0] xgate_sel;
182
  wire [15:0] xgate_adr;
183
  wire [15:0] xgate_din;
184
 
185
  wire        xgate_s_stb;
186
  wire        xgate_s_ack;
187
  wire [15:0] xgate_s_dout;
188
 
189
  wire        slv2_stb;
190
  wire        ram_ack;
191
  wire [15:0] ram_dout;
192
 
193 2 rehayes
  // initial values and testbench setup
194
  initial
195
    begin
196
      mstr_test_clk = 0;
197
      vector = 0;
198
      test_num = 0;
199
      por_reset_b = 0;
200 36 rehayes
      stop_mode  = 0;
201
      wait_mode  = 0;
202 2 rehayes
      debug_mode = 0;
203
      scantestmode = 0;
204 5 rehayes
      check_point_reg = 0;
205
      channel_ack_reg = 0;
206
      channel_err_reg = 0;
207
      error_count = 0;
208 11 rehayes
      wbm_ack_i = 1;
209
      mem_wait_state_enable = 0;
210 2 rehayes
      // channel_req = 0;
211
 
212
      `ifdef WAVES
213
           $shm_open("waves");
214
           $shm_probe("AS",tst_bench_top,"AS");
215
           $display("\nINFO: Signal dump enabled ...\n\n");
216
      `endif
217
 
218
      `ifdef WAVES_V
219
           $dumpfile ("xgate_wave_dump.lxt");
220
           $dumpvars (0, tst_bench_top);
221
           $dumpon;
222
           $display("\nINFO: VCD Signal dump enabled ...\n\n");
223
      `endif
224
 
225
    end
226
 
227
  // generate clock
228
  always #20 mstr_test_clk = ~mstr_test_clk;
229
 
230 5 rehayes
  // Keep a count of how many clocks we've simulated
231 2 rehayes
  always @(posedge mstr_test_clk)
232 11 rehayes
    begin
233
      vector <= vector + 1;
234
      if (vector > MAX_VECTOR)
235 21 rehayes
        begin
236
          error_count <= error_count + 1;
237
          $display("\n ------ !!!!! Simulation Timeout at vector=%d\n -------", vector);
238
          wrap_up;
239
        end
240 11 rehayes
    end
241 2 rehayes
 
242 50 rehayes
  // Add up errors that come from WISHBONE read compares
243 36 rehayes
  always @host.cmp_error_detect
244 21 rehayes
    begin
245
      error_count <= error_count + 1;
246
    end
247 11 rehayes
 
248 21 rehayes
 
249 5 rehayes
  // Throw in some wait states from the memory
250
  always @(posedge mstr_test_clk)
251 11 rehayes
    if (((vector % 5) == 0) && (xgate.risc.load_next_inst || xgate.risc.data_access))
252
//    if ((vector % 5) == 0)
253 50 rehayes
      wbm_ack_i <= 1'b1;
254 21 rehayes
    else
255 5 rehayes
      wbm_ack_i <= 1'b1;
256 2 rehayes
 
257 36 rehayes
 
258 2 rehayes
  // Special Memory Mapped Testbench Registers
259
  always @(posedge mstr_test_clk or negedge rstn)
260
    begin
261
      if (!rstn)
262 21 rehayes
        begin
263
          check_point_reg <= 0;
264
          channel_ack_reg <= 0;
265
          channel_err_reg <= 0;
266
        end
267 36 rehayes
      if (wbm_sel_o[0] && wbm_ack_i && (wbm_adr_o == CHECK_POINT))
268 21 rehayes
        begin
269
          check_point_reg <= wbm_dat_o[7:0];
270
          #1;
271
          -> check_point_wrt;
272
        end
273 36 rehayes
      if (wbm_sel_o[0] && wbm_ack_i && (wbm_adr_o == CHANNEL_ACK))
274 21 rehayes
        begin
275
          channel_ack_reg <= wbm_dat_o[7:0];
276
          #1;
277
          -> channel_ack_wrt;
278
        end
279 36 rehayes
      if (wbm_sel_o[0] && wbm_ack_i && (wbm_adr_o == CHANNEL_ERR))
280 21 rehayes
        begin
281
          channel_err_reg <= wbm_dat_o[7:0];
282
          #1;
283
          -> channel_err_wrt;
284
        end
285 2 rehayes
    end
286
 
287 5 rehayes
  always @check_point_wrt
288 11 rehayes
    $display("\nSoftware Checkpoint #%h -- at vector=%d\n", check_point_reg, vector);
289 2 rehayes
 
290 5 rehayes
  always @channel_err_wrt
291
    begin
292 41 rehayes
      $display("\n ------ !!!!! Software Checkpoint Error #%d -- at vector=%d\n  -------", channel_err_reg, vector);
293 5 rehayes
      error_count = error_count + 1;
294
      if (STOP_ON_ERROR == 1'b1)
295 21 rehayes
        wrap_up;
296 5 rehayes
    end
297
 
298 2 rehayes
  wire [ 6:0] current_active_channel = xgate.risc.xgchid;
299 5 rehayes
  always @channel_ack_wrt
300 2 rehayes
    clear_channel(current_active_channel);
301 21 rehayes
 
302 36 rehayes
 
303 2 rehayes
  // Address decoding for different XGATE module instances
304 36 rehayes
  wire stb0 = host_stb && ~host_adr[6] && ~host_adr[5] && ~|host_adr[31:16];
305
  wire stb1 = host_stb && ~host_adr[6] &&  host_adr[5] && ~|host_adr[31:16];
306
  wire stb2 = host_stb &&  host_adr[6] && ~host_adr[5] && ~|host_adr[31:16];
307
  wire stb3 = host_stb &&  host_adr[6] &&  host_adr[5] && ~|host_adr[31:16];
308
 
309 2 rehayes
  assign dat1_i = 16'h0000;
310
  assign dat2_i = 16'h0000;
311
  assign dat3_i = 16'h0000;
312
  assign ack_2 = 1'b0;
313
  assign ack_3 = 1'b0;
314
  assign ack_4 = 1'b0;
315
 
316
  // Create the Read Data Bus
317 36 rehayes
  assign dat_i = ({16{stb0}} & xgate_s_dout) |
318 2 rehayes
                 ({16{stb1}} & dat1_i) |
319
                 ({16{stb2}} & dat2_i) |
320
                 ({16{stb3}} & {8'b0, dat3_i[7:0]});
321 21 rehayes
 
322 36 rehayes
  assign ack = xgate_s_ack || ack_2 || ack_3 || ack_4;
323 2 rehayes
 
324 36 rehayes
  // Aribartration Logic for Testbench RAM access
325
  assign sys_addr     = 1'b1 ? {16'b0, wbm_adr_o} : host_adr;
326
 
327 21 rehayes
 
328 36 rehayes
  // Testbench RAM for Xgate program storage and Load/Store instruction tests
329
  ram p_ram
330
  (
331
    // Outputs
332
    .ram_out( ram_dout ),
333
    // inputs
334
    .address( sys_addr[15:0] ),  // sys_addr  sys_adr
335
    .ram_in( sys_dout ),
336
    .we( sys_we ),
337
    .ce( 1'b1 ),
338
    .stb( mstr_test_clk ),
339
    .sel( sys_sel ) // wbm_sel_o sys_sel
340
  );
341
 
342
  // hookup wishbone master model
343
  wb_master_model #(.dwidth(16), .awidth(32))
344
    host(
345
    // Outputs
346
    .cyc( host_cyc ),
347
    .stb( host_stb ),
348
    .we( host_we ),
349
    .sel( host_sel ),
350
    .adr( host_adr ),
351
    .dout( host_dout ),
352
    // inputs
353
    .din(host_din),
354
    .clk(mstr_test_clk),
355
    .ack(host_ack),
356
    .rst(rstn),
357
    .err(1'b0),
358
    .rty(1'b0)
359
  );
360
 
361
  bus_arbitration  #(.dwidth(16),
362
                     .awidth(32))
363
    arb(
364
    // System bus I/O
365
    .sys_cyc( sys_cyc ),
366
    .sys_stb( sys_stb ),
367
    .sys_we( sys_we ),
368
    .sys_sel( sys_sel ),
369
    .sys_adr( sys_adr ),
370
    .sys_dout( sys_dout ),
371
    // Host bus I/O
372
    .host_ack( host_ack ),
373
    .host_dout( host_din ),
374
    .host_cyc( host_cyc ),
375
    .host_stb( host_stb ),
376
    .host_we( host_we ),
377
    .host_sel( host_sel ),
378
    .host_adr( host_adr ),
379
    .host_din( host_dout ),
380
    // Alternate Bus Master #1 Bus I/O
381
    .alt1_ack( xgate_ack ),
382
    .alt1_dout( xgate_din ),
383
    .alt1_cyc( wbm_cyc_o ),
384
    .alt1_stb( wbm_stb_o ),
385
    .alt1_we( wbm_we_o ),
386
    .alt1_sel( wbm_sel_o ),
387
    .alt1_adr( {16'h0001, wbm_adr_o} ),
388
    .alt1_din( wbm_dat_o ),
389
    // Slave #1 Bus I/O
390
    .slv1_stb( xgate_s_stb ),
391
    .slv1_ack( xgate_s_ack ),
392
    .slv1_din( xgate_s_dout ),
393
    // Slave #2 Bus I/O
394
    .slv2_stb( slv2_stb ),
395
    .slv2_ack( wbm_ack_i ),
396
    .slv2_din( ram_dout ),
397
    // Miscellaneous
398
    .host_clk( mstr_test_clk ),
399
    .risc_clk( mstr_test_clk ),
400
    .rst( rstn ),  // No Connect
401
    .err( 1'b0 ),  // No Connect
402
    .rty( 1'b0 )   // No Connect
403
  );
404 5 rehayes
  // hookup XGATE core - Parameters take all default values
405 36 rehayes
  //  Async Reset, 16 bit Bus, 8 bit Granularity
406 11 rehayes
  xgate_top  #(.SINGLE_CYCLE(1'b1),
407 21 rehayes
               .MAX_CHANNEL(MAX_CHANNEL))    // Max XGATE Interrupt Channel Number
408 2 rehayes
          xgate(
409 5 rehayes
          // Wishbone slave interface
410
          .wbs_clk_i( mstr_test_clk ),
411
          .wbs_rst_i( 1'b0 ),         // sync_reset
412
          .arst_i( rstn ),            // async resetn
413 41 rehayes
          .wbs_adr_i( sys_adr[5:1] ),
414 36 rehayes
          .wbs_dat_i( sys_dout ),
415
          .wbs_dat_o( xgate_s_dout ),
416
          .wbs_we_i( sys_we ),
417
          .wbs_stb_i( xgate_s_stb ),
418
          .wbs_cyc_i( sys_cyc ),
419
          .wbs_sel_i( sys_sel ),
420
          .wbs_ack_o( xgate_s_ack ),
421 2 rehayes
 
422 5 rehayes
          // Wishbone master Signals
423 21 rehayes
          .wbm_dat_o( wbm_dat_o ),
424 5 rehayes
          .wbm_we_o( wbm_we_o ),
425
          .wbm_stb_o( wbm_stb_o ),
426
          .wbm_cyc_o( wbm_cyc_o ),
427
          .wbm_sel_o( wbm_sel_o ),
428 21 rehayes
          .wbm_adr_o( wbm_adr_o ),
429 36 rehayes
          .wbm_dat_i( ram_dout ),
430 5 rehayes
          .wbm_ack_i( wbm_ack_i ),
431
 
432 21 rehayes
          .xgif( xgif ),             // XGATE Interrupt Flag output
433
          .xg_sw_irq( xg_sw_irq ),   // XGATE Software Error Interrupt Flag output
434
          .xgswt( xgswt ),
435 2 rehayes
          .risc_clk( mstr_test_clk ),
436 21 rehayes
          .chan_req_i( {channel_req[MAX_CHANNEL:40], xgswt, channel_req[31:0]} ),
437 2 rehayes
          .scantestmode( scantestmode )
438
  );
439
 
440
 
441
 
442
////////////////////////////////////////////////////////////////////////////////
443
////////////////////////////////////////////////////////////////////////////////
444
////////////////////////////////////////////////////////////////////////////////
445
 
446
// Test Program
447
initial
448
  begin
449 36 rehayes
    $display("\nstatus at time: %t Testbench started", $time);
450 2 rehayes
 
451 36 rehayes
    // reset system
452
    rstn = 1'b1; // negate reset
453
    channel_req = 1; //
454
    repeat(1) @(posedge mstr_test_clk);
455
    sync_reset = 1'b1;  // Make the sync reset 1 clock cycle long
456
    #2;          // move the async reset away from the clock edge
457
    rstn = 1'b0; // assert async reset
458
    #5;          // Keep the async reset pulse with less than a clock cycle
459
    rstn = 1'b1; // negate async reset
460
    por_reset_b = 1'b1;
461
    channel_req = 0; //
462
    repeat(1) @(posedge mstr_test_clk);
463
    sync_reset = 1'b0;
464
    channel_req = 0; //
465 2 rehayes
 
466 36 rehayes
    $display("\nstatus at time: %t done reset", $time);
467 21 rehayes
 
468 36 rehayes
    test_inst_set;
469 21 rehayes
 
470 36 rehayes
    test_debug_mode;
471 2 rehayes
 
472 36 rehayes
    test_debug_bit;
473 21 rehayes
 
474 36 rehayes
    test_chid_debug;
475 21 rehayes
 
476 41 rehayes
    reg_test_16;
477
 
478 36 rehayes
    // host_ram;
479
    // End testing
480
    wrap_up;
481 2 rehayes
 
482 21 rehayes
 
483 36 rehayes
    repeat(10) @(posedge mstr_test_clk);
484 2 rehayes
 
485 36 rehayes
    wrap_up;
486 2 rehayes
  end
487
 
488 36 rehayes
////////////////////////////////////////////////////////////////////////////////
489 21 rehayes
// Test CHID Debug mode operation
490
task test_chid_debug;
491
  begin
492
    test_num = test_num + 1;
493
    $display("\nTEST #%d Starts at vector=%d, test_chid_debug", test_num, vector);
494 36 rehayes
    $readmemh("../../../bench/verilog/debug_test.v", p_ram.ram_8);
495 21 rehayes
 
496
    data_xgmctl = XGMCTL_XGBRKIEM | XGMCTL_XGBRKIE;
497 36 rehayes
    host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD);   // Enable interrupt on BRK instruction
498 21 rehayes
 
499
    activate_thread_sw(3);
500
 
501
    wait_debug_set;   // Debug Status bit is set by BRK instruction
502
 
503 36 rehayes
    host.wb_cmp(0, XGATE_XGPC,     16'h20c6, WORD);      // See Program code (BRK).
504
    host.wb_cmp(0, XGATE_XGR3,     16'h0001, WORD);      // See Program code.R3 = 1
505
    host.wb_cmp(0, XGATE_XGCHID,   16'h0003, WORD);      // Check for Correct CHID
506 21 rehayes
 
507
    channel_req[5] = 1'b1; //
508
    repeat(7) @(posedge mstr_test_clk);
509 36 rehayes
    host.wb_cmp(0, XGATE_XGCHID,   16'h0003, WORD);      // Check for Correct CHID
510 21 rehayes
 
511 41 rehayes
    host.wb_write(0, XGATE_XGCHID, 16'h000f, H_BYTE);    // Check byte select lines
512
    repeat(4) @(posedge mstr_test_clk);
513
    host.wb_cmp(0, XGATE_XGCHID,   16'h0003, WORD);      // Verify CHID is unchanged
514
 
515
    host.wb_write(0, XGATE_XGCHID, 16'h000f, L_BYTE);    // Change CHID
516 36 rehayes
    host.wb_cmp(0, XGATE_XGCHID,   16'h000f, WORD);      // Check for Correct CHID
517 21 rehayes
 
518 36 rehayes
    host.wb_write(0, XGATE_XGCHID, 16'h0000, WORD);      // Change CHID to 00, RISC should go to IDLE state
519 21 rehayes
 
520
    repeat(1) @(posedge mstr_test_clk);
521
 
522 36 rehayes
    host.wb_write(0, XGATE_XGCHID, 16'h0004, WORD);      // Change CHID
523 21 rehayes
 
524
    repeat(8) @(posedge mstr_test_clk);
525
 
526
    data_xgmctl = XGMCTL_XGDBGM;
527 36 rehayes
    host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD);   // Clear Debug Mode Control Bit
528 21 rehayes
 
529
    wait_debug_set;   // Debug Status bit is set by BRK instruction
530 36 rehayes
    host.wb_cmp(0, XGATE_XGCHID,   16'h0004, WORD);      // Check for Correct CHID
531
    host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD);   // Clear Debug Mode Control Bit (Excape from Break State and run)
532 21 rehayes
 
533
    wait_debug_set;   // Debug Status bit is set by BRK instruction
534 36 rehayes
    host.wb_cmp(0, XGATE_XGCHID,   16'h0005, WORD);      // Check for Correct CHID
535 21 rehayes
    activate_channel(6);
536 36 rehayes
    host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD);   // Clear Debug Mode Control Bit (Excape from Break State and run)
537 21 rehayes
 
538
    wait_debug_set;   // Debug Status bit is set by BRK instruction
539 36 rehayes
    host.wb_cmp(0, XGATE_XGCHID,   16'h0006, WORD);      // Check for Correct CHID
540
    host.wb_cmp(0, XGATE_XGPC,     16'h211c, WORD);      // See Program code (BRK)
541 21 rehayes
    data_xgmctl = XGMCTL_XGSSM | XGMCTL_XGSS;
542 36 rehayes
    host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD);   // Do a Single Step
543 21 rehayes
    repeat(8) @(posedge mstr_test_clk);
544 36 rehayes
    host.wb_cmp(0, XGATE_XGPC,     16'h211e, WORD);      // See Program code (BRA)
545
    host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD);   // Do a Single Step
546 21 rehayes
    repeat(8) @(posedge mstr_test_clk);
547 36 rehayes
    host.wb_cmp(0, XGATE_XGPC,     16'h2122, WORD);      // See Program code ()
548 21 rehayes
 
549
    repeat(20) @(posedge mstr_test_clk);
550
 
551
    data_xgmctl = XGMCTL_XGDBGM;
552 36 rehayes
    host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD);   // Clear Debug Mode Control Bit
553 21 rehayes
 
554
    repeat(50) @(posedge mstr_test_clk);
555
 
556 36 rehayes
    p_ram.dump_ram(0);
557
 
558 41 rehayes
    read_ram_cmp(16'h0000,16'h7b55);
559
    read_ram_cmp(16'h0004,16'h7faa);
560
    read_ram_cmp(16'h0006,16'h6f55);
561
    read_ram_cmp(16'h0008,16'h00c3);
562
    read_ram_cmp(16'h000a,16'h5f66);
563
    read_ram_cmp(16'h000c,16'h0003);
564
    read_ram_cmp(16'h0022,16'hccxx);
565
    read_ram_cmp(16'h0026,16'hxx99);
566
    read_ram_cmp(16'h0032,16'h1fcc);
567
    read_ram_cmp(16'h0038,16'h2f99);
568
    read_ram_cmp(16'h0042,16'h33xx);
569
    read_ram_cmp(16'h0046,16'hxx55);
570
    read_ram_cmp(16'h0052,16'hxx66);
571
    read_ram_cmp(16'h0058,16'h99xx);
572
    read_ram_cmp(16'h0062,16'h1faa);
573
    read_ram_cmp(16'h0068,16'h2fcc);
574
 
575 21 rehayes
  end
576
endtask
577
 
578 36 rehayes
////////////////////////////////////////////////////////////////////////////////
579 11 rehayes
// Test Debug bit operation
580
task test_debug_bit;
581 2 rehayes
  begin
582 11 rehayes
    test_num = test_num + 1;
583 21 rehayes
    $display("\nTEST #%d Starts at vector=%d, test_debug_bit", test_num, vector);
584 36 rehayes
    $readmemh("../../../bench/verilog/debug_test.v", p_ram.ram_8);
585 21 rehayes
 
586 11 rehayes
    data_xgmctl = XGMCTL_XGBRKIEM | XGMCTL_XGBRKIE;
587 36 rehayes
    host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD);   // Enable interrupt on BRK instruction
588 11 rehayes
 
589
    activate_thread_sw(2);
590 21 rehayes
 
591 11 rehayes
    repeat(25) @(posedge mstr_test_clk);
592
 
593
    data_xgmctl = XGMCTL_XGDBGM | XGMCTL_XGDBG;
594 36 rehayes
    host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD);   // Set Debug Mode Control Bit
595 21 rehayes
    repeat(5) @(posedge mstr_test_clk);
596
 
597 36 rehayes
    host.wb_read(1, XGATE_XGR3, q, WORD);
598 21 rehayes
    data_xgmctl = XGMCTL_XGSSM | XGMCTL_XGSS;
599
    qq = q;
600
 
601
    // The Xgate test program is in an infinate loop incrementing R3
602
    while (qq == q)  // Look for change in R3 register
603
      begin
604 36 rehayes
        host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD);   // Do a Single Step
605 21 rehayes
        repeat(5) @(posedge mstr_test_clk);
606 36 rehayes
        host.wb_read(1, XGATE_XGR3, q, WORD);
607 21 rehayes
      end
608
    if (q != (qq+1))
609
      begin
610
        $display("Error! - Unexpected value of R3 at vector=%d", vector);
611
        error_count = error_count + 1;
612
      end
613
 
614
 
615 36 rehayes
    host.wb_write(1, XGATE_XGPC, 16'h2094, WORD);        // Write to PC to force exit from infinate loop
616 21 rehayes
    repeat(5) @(posedge mstr_test_clk);
617
 
618
    data_xgmctl = XGMCTL_XGSSM | XGMCTL_XGSS;
619 36 rehayes
    host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD);   // Do a Single Step (Load ADDL instruction)
620 21 rehayes
    repeat(5) @(posedge mstr_test_clk);
621 36 rehayes
    host.wb_cmp(0, XGATE_XGR4,     16'h0002, WORD);      // See Program code.(R4 <= R4 + 1)
622 21 rehayes
 
623 36 rehayes
    host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD);   // Do a Single Step (Load ADDL instruction)
624 21 rehayes
    repeat(5) @(posedge mstr_test_clk);
625 36 rehayes
    host.wb_cmp(0, XGATE_XGR4,     16'h0003, WORD);      // See Program code.(R4 <= R4 + 1)
626 21 rehayes
 
627
    data_xgmctl = XGMCTL_XGDBGM;
628 36 rehayes
    host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD);   // Clear Debug Mode Control Bit
629 11 rehayes
                                                 // Should be back in Run Mode
630 21 rehayes
 
631
//    data_xgmctl = XGMCTL_XGSWEIFM | XGMCTL_XGSWEIF | XGMCTL_XGBRKIEM;
632 36 rehayes
//    host.wb_write(0, XGATE_XGMCTL, data_xgmctl);   // Clear Software Interrupt and BRK Interrupt Enable Bit
633 11 rehayes
    repeat(15) @(posedge mstr_test_clk);
634 21 rehayes
 
635 2 rehayes
  end
636
endtask
637
 
638 36 rehayes
////////////////////////////////////////////////////////////////////////////////
639 11 rehayes
// Test Debug mode operation
640
task test_debug_mode;
641 2 rehayes
  begin
642 11 rehayes
    test_num = test_num + 1;
643
    $display("\nTEST #%d Starts at vector=%d, test_debug_mode", test_num, vector);
644 36 rehayes
    $readmemh("../../../bench/verilog/debug_test.v", p_ram.ram_8);
645 21 rehayes
 
646 11 rehayes
    data_xgmctl = XGMCTL_XGBRKIEM | XGMCTL_XGBRKIE;
647 36 rehayes
    host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD);   // Enable interrupt on BRK instruction
648 11 rehayes
 
649
    activate_thread_sw(1);
650 21 rehayes
 
651 11 rehayes
    wait_debug_set;   // Debug Status bit is set by BRK instruction
652
 
653 36 rehayes
    host.wb_cmp(0, XGATE_XGPC,     16'h203a, WORD);      // See Program code (BRK).
654
    host.wb_cmp(0, XGATE_XGR3,     16'h0001, WORD);      // See Program code.R3 = 1
655 11 rehayes
 
656
    data_xgmctl = XGMCTL_XGSSM | XGMCTL_XGSS;
657
 
658 36 rehayes
    host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD);   // Do a Single Step (Load ADDL instruction)
659 11 rehayes
    repeat(5) @(posedge mstr_test_clk);
660 36 rehayes
    host.wb_cmp(0, XGATE_XGPC,     16'h203c, WORD);      // PC + 2.
661 11 rehayes
 
662 36 rehayes
    host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD);   // Do a Single Step (Load NOP instruction)
663
    repeat(5) @(posedge mstr_test_clk);                  // Execute ADDL instruction
664
    host.wb_cmp(0, XGATE_XGR3,     16'h0002, WORD);      // See Program code.(R3 <= R3 + 1)
665
    host.wb_cmp(0, XGATE_XGCCR,    16'h0000, WORD);      // See Program code.
666
    host.wb_cmp(0, XGATE_XGPC,     16'h203e, WORD);      // PC + 2.
667 11 rehayes
    repeat(5) @(posedge mstr_test_clk);
668 36 rehayes
    host.wb_cmp(0, XGATE_XGPC,     16'h203e, WORD);      // Still no change.
669 11 rehayes
 
670 36 rehayes
    host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD);   // Do a Single Step (Load BRA instruction)
671
    repeat(9) @(posedge mstr_test_clk);                  // Execute NOP instruction
672
    host.wb_cmp(0, XGATE_XGPC,     16'h2040, WORD);      // See Program code.
673 11 rehayes
 
674
 
675 36 rehayes
    host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD);   // Do a Single Step
676
    repeat(5) @(posedge mstr_test_clk);                  // Execute BRA instruction
677
    host.wb_cmp(0, XGATE_XGPC,     16'h2064, WORD);      // PC = Branch destination.
678
                                                         // Load ADDL instruction
679 21 rehayes
 
680 36 rehayes
    host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD);   // Do a Single Step (Load LDW R7 instruction)
681
    repeat(5) @(posedge mstr_test_clk);                  // Execute ADDL instruction
682
    host.wb_cmp(0, XGATE_XGPC,     16'h2066, WORD);      // PC + 2.
683
    host.wb_cmp(0, XGATE_XGR3,     16'h0003, WORD);      // See Program code.(R3 <= R3 + 1)
684 11 rehayes
 
685 36 rehayes
    host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD);   // Do a Single Step (LDW R7)
686 11 rehayes
    repeat(5) @(posedge mstr_test_clk);
687 36 rehayes
    host.wb_cmp(0, XGATE_XGPC,     16'h2068, WORD);      // PC + 2.
688
    host.wb_cmp(0, XGATE_XGR7,     16'h00c3, WORD);      // See Program code
689 11 rehayes
 
690
    repeat(1) @(posedge mstr_test_clk);
691 36 rehayes
    host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD);   // Do a Single Step (BRA)
692 11 rehayes
    repeat(9) @(posedge mstr_test_clk);
693 36 rehayes
    host.wb_cmp(0, XGATE_XGPC,     16'h2048, WORD);      // See Program code.
694 11 rehayes
 
695 36 rehayes
    host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD);   // Do a Single Step (STW R3)
696 11 rehayes
    repeat(5) @(posedge mstr_test_clk);
697 36 rehayes
    host.wb_cmp(0, XGATE_XGPC,     16'h204a, WORD);      // PC + 2.
698
    host.wb_cmp(0, XGATE_XGR3,     16'h0003, WORD);      // See Program code.(R3 <= R3 + 1)
699 11 rehayes
 
700 36 rehayes
    host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD);   // Do a Single Step (R3 <= R3 + 1)
701 11 rehayes
    repeat(5) @(posedge mstr_test_clk);
702 36 rehayes
    host.wb_cmp(0, XGATE_XGPC,     16'h204c, WORD);      // PC + 2.
703 11 rehayes
 
704
    repeat(5) @(posedge mstr_test_clk);
705
 
706
    data_xgmctl = XGMCTL_XGDBGM;
707 36 rehayes
    host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD);   // Clear Debug Mode Control Bit
708
                                                         // Should be back in Run Mode
709 11 rehayes
    wait_irq_set(1);
710 36 rehayes
    host.wb_write(1, XGATE_XGIF_0, 16'h0002, WORD);
711 21 rehayes
 
712 11 rehayes
    data_xgmctl = XGMCTL_XGSWEIFM | XGMCTL_XGSWEIF | XGMCTL_XGBRKIEM;
713 36 rehayes
    host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD);   // Clear Software Interrupt and BRK Interrupt Enable Bit
714 11 rehayes
    repeat(15) @(posedge mstr_test_clk);
715 21 rehayes
 
716 2 rehayes
  end
717
endtask
718
 
719 36 rehayes
////////////////////////////////////////////////////////////////////////////////
720 11 rehayes
// Test instruction set
721
task test_inst_set;
722
  begin
723 36 rehayes
    $readmemh("../../../bench/verilog/inst_test.v", p_ram.ram_8);
724 11 rehayes
    test_num = test_num + 1;
725
    $display("\nTEST #%d Starts at vector=%d, inst_test", test_num, vector);
726 21 rehayes
    repeat(1) @(posedge mstr_test_clk);
727 11 rehayes
 
728
    activate_thread_sw(1);
729
    wait_irq_set(1);
730 36 rehayes
    host.wb_write(1, XGATE_XGIF_0, 16'h0002, WORD);
731 21 rehayes
 
732 11 rehayes
    activate_thread_sw(2);
733
    wait_irq_set(2);
734 36 rehayes
    host.wb_write(1, XGATE_XGIF_0, 16'h0004, WORD);
735 11 rehayes
 
736
    activate_thread_sw(3);
737
    wait_irq_set(3);
738 36 rehayes
    host.wb_write(1, XGATE_XGIF_0, 16'h0008, WORD);
739 21 rehayes
 
740 11 rehayes
    activate_thread_sw(4);
741
    wait_irq_set(4);
742 36 rehayes
    host.wb_write(1, XGATE_XGIF_0, 16'h0010, WORD);
743 21 rehayes
 
744 11 rehayes
    activate_thread_sw(5);
745
    wait_irq_set(5);
746 36 rehayes
    host.wb_write(1, XGATE_XGIF_0, 16'h0020, WORD);
747 21 rehayes
 
748 11 rehayes
    activate_thread_sw(6);
749
    wait_irq_set(6);
750 36 rehayes
    host.wb_write(1, XGATE_XGIF_0, 16'h0040, WORD);
751 21 rehayes
 
752 11 rehayes
    activate_thread_sw(7);
753
    wait_irq_set(7);
754 36 rehayes
    host.wb_write(1, XGATE_XGIF_0, 16'h0080, WORD);
755 21 rehayes
 
756 11 rehayes
    activate_thread_sw(8);
757
    wait_irq_set(8);
758 36 rehayes
    host.wb_write(1, XGATE_XGIF_0, 16'h0100, WORD);
759 21 rehayes
 
760 11 rehayes
    activate_thread_sw(9);
761
    wait_irq_set(9);
762 36 rehayes
    host.wb_write(1, XGATE_XGIF_0, 16'h0200, WORD);
763 21 rehayes
 
764 36 rehayes
    host.wb_write(1, XGATE_XGSEM, 16'h5050, WORD);
765
    host.wb_cmp(0, XGATE_XGSEM,    16'h0050, WORD);   //
766 11 rehayes
    activate_thread_sw(10);
767
    wait_irq_set(10);
768 36 rehayes
    host.wb_write(1, XGATE_XGIF_0, 16'h0400, WORD);
769 21 rehayes
 
770 36 rehayes
    host.wb_write(1, XGATE_XGSEM, 16'hff00, WORD);    // clear the old settings
771
    host.wb_cmp(0, XGATE_XGSEM,    16'h0000, WORD);   //
772
    host.wb_write(1, XGATE_XGSEM, 16'ha0a0, WORD);    // Verify that bits were unlocked by RISC
773
    host.wb_cmp(0, XGATE_XGSEM,    16'h00a0, WORD);   // Verify bits were set
774
    host.wb_write(1, XGATE_XGSEM, 16'hff08, WORD);    // Try to set the bit that was left locked by the RISC
775
    host.wb_cmp(0, XGATE_XGSEM,    16'h0000, WORD);   // Verify no bits were set
776 21 rehayes
 
777 11 rehayes
    repeat(20) @(posedge mstr_test_clk);
778
 
779 36 rehayes
    p_ram.dump_ram(0);
780 41 rehayes
 
781
    read_ram_cmp(16'h0000,16'haa55);
782
    read_ram_cmp(16'h0004,16'h7faa);
783
    read_ram_cmp(16'h0006,16'h6f55);
784
    read_ram_cmp(16'h000a,16'h5f66);
785
    read_ram_cmp(16'h0032,16'h1fcc);
786
    read_ram_cmp(16'h0038,16'h2f99);
787
    read_ram_cmp(16'h0062,16'h1faa);
788
    read_ram_cmp(16'h0068,16'h2fcc);
789
    read_ram_cmp(16'h0022,16'hccxx);
790
    read_ram_cmp(16'h0026,16'hxx99);
791
    read_ram_cmp(16'h0052,16'hxx66);
792
    read_ram_cmp(16'h0058,16'h99xx);
793 50 rehayes
 
794
    data_xgmctl = 16'hff00;
795
    host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD);   // Disable XGATE
796
 
797 11 rehayes
  end
798
endtask
799
 
800 36 rehayes
////////////////////////////////////////////////////////////////////////////////
801 2 rehayes
// check register bits - reset, read/write
802
task reg_test_16;
803
  begin
804
      test_num = test_num + 1;
805
      $display("TEST #%d Starts at vector=%d, reg_test_16", test_num, vector);
806 41 rehayes
 
807
      system_reset;
808
 
809 36 rehayes
      host.wb_cmp(0, XGATE_XGMCTL,   16'h0000, WORD);   // verify reset
810
      host.wb_cmp(0, XGATE_XGCHID,   16'h0000, WORD);   // verify reset
811
      host.wb_cmp(0, XGATE_XGISPHI,  16'h0000, WORD);   // verify reset
812
      host.wb_cmp(0, XGATE_XGISPLO,  16'h0000, WORD);   // verify reset
813 41 rehayes
      host.wb_cmp(0, XGATE_XGVBR,    16'hfe00, WORD);   // verify reset
814 36 rehayes
      host.wb_cmp(0, XGATE_XGIF_7,   16'h0000, WORD);   // verify reset
815
      host.wb_cmp(0, XGATE_XGIF_6,   16'h0000, WORD);   // verify reset
816
      host.wb_cmp(0, XGATE_XGIF_5,   16'h0000, WORD);   // verify reset
817
      host.wb_cmp(0, XGATE_XGIF_4,   16'h0000, WORD);   // verify reset
818
      host.wb_cmp(0, XGATE_XGIF_3,   16'h0000, WORD);   // verify reset
819
      host.wb_cmp(0, XGATE_XGIF_2,   16'h0000, WORD);   // verify reset
820
      host.wb_cmp(0, XGATE_XGIF_1,   16'h0000, WORD);   // verify reset
821 41 rehayes
      host.wb_cmp(0, XGATE_XGIF_0,   16'h0001, WORD);   // verify reset
822 36 rehayes
      host.wb_cmp(0, XGATE_XGSWT,    16'h0000, WORD);   // verify reset
823
      host.wb_cmp(0, XGATE_XGSEM,    16'h0000, WORD);   // verify reset
824
      host.wb_cmp(0, XGATE_XGCCR,    16'h0000, WORD);   // verify reset
825
      host.wb_cmp(0, XGATE_XGPC,     16'h0000, WORD);   // verify reset
826
      host.wb_cmp(0, XGATE_XGR1,     16'h0000, WORD);   // verify reset
827
      host.wb_cmp(0, XGATE_XGR2,     16'h0000, WORD);   // verify reset
828
      host.wb_cmp(0, XGATE_XGR3,     16'h0000, WORD);   // verify reset
829
      host.wb_cmp(0, XGATE_XGR4,     16'h0000, WORD);   // verify reset
830
      host.wb_cmp(0, XGATE_XGR5,     16'h0000, WORD);   // verify reset
831
      host.wb_cmp(0, XGATE_XGR6,     16'h0000, WORD);   // verify reset
832
      host.wb_cmp(0, XGATE_XGR7,     16'h0000, WORD);   // verify reset
833 2 rehayes
 
834 41 rehayes
/*
835
  parameter XGMCTL_XGDBGM   = 15'h2000;
836
  parameter XGMCTL_XGSSM    = 15'h1000;
837
  parameter XGMCTL_XGBRKIEM = 15'h0400;
838
  parameter XGMCTL_XGSWEIFM = 15'h0200;
839
  parameter XGMCTL_XGIEM    = 15'h0100;
840 2 rehayes
 
841 41 rehayes
  parameter XGMCTL_XGDBG    = 15'h0020;
842
  parameter XGMCTL_XGSS     = 15'h0010;
843
  parameter XGMCTL_XGBRKIE  = 15'h0004;
844
  parameter XGMCTL_XGSWEIF  = 15'h0002;
845
  parameter XGMCTL_XGIE     = 15'h0001;
846
*/
847
      // Test bits in the Xgate Control Register (XGMCTL)
848
      data_xgmctl = XGMCTL_XGEM | XGMCTL_XGFRZM | XGMCTL_XGFACTM | XGMCTL_XGFRZ | XGMCTL_XGFACT | XGMCTL_XGE;
849
      host.wb_write(0, XGATE_XGMCTL,   data_xgmctl, WORD);   //
850
      data_xgmctl = XGMCTL_XGFRZ | XGMCTL_XGFACT | XGMCTL_XGE;
851
      host.wb_cmp(  0, XGATE_XGMCTL, data_xgmctl, WORD);
852 2 rehayes
 
853 41 rehayes
      data_xgmctl = XGMCTL_XGEM;
854
      host.wb_write(0, XGATE_XGMCTL,   data_xgmctl, WORD);   //
855
      data_xgmctl = XGMCTL_XGFRZ | XGMCTL_XGFACT;
856
      host.wb_cmp(  0, XGATE_XGMCTL, data_xgmctl, WORD);
857 2 rehayes
 
858 41 rehayes
      data_xgmctl = XGMCTL_XGFRZM | XGMCTL_XGFACTM;
859
      host.wb_write(0, XGATE_XGMCTL,   data_xgmctl, WORD);   //
860
      data_xgmctl = 16'h0000;
861
      host.wb_cmp(  0, XGATE_XGMCTL, data_xgmctl, WORD);
862
 
863
      data_xgmctl = 16'hffff;
864
      host.wb_write(0, XGATE_XGMCTL,   data_xgmctl, H_BYTE);   //
865
      data_xgmctl = 16'h0000;
866
      host.wb_cmp(  0, XGATE_XGMCTL, data_xgmctl, WORD);
867
 
868
      data_xgmctl = 16'hffff;
869
      host.wb_write(0, XGATE_XGMCTL,   data_xgmctl, L_BYTE);   //
870
      data_xgmctl = 16'h0000;
871
      host.wb_cmp(  0, XGATE_XGMCTL, data_xgmctl, WORD);
872
 
873
      // Test the Xgate Vector Base Address Register (XGVBR)
874
      host.wb_write(0, XGATE_XGVBR,  16'h5555, WORD);
875
      host.wb_cmp(0, XGATE_XGVBR,    16'h5554, WORD);
876
 
877
      host.wb_write(0, XGATE_XGVBR,  16'hAAAA, WORD);
878
      host.wb_cmp(0, XGATE_XGVBR,    16'hAAAA, WORD);
879
 
880
      host.wb_write(0, XGATE_XGVBR,  16'hFF55, L_BYTE);
881
      host.wb_cmp(0, XGATE_XGVBR,    16'hAA54, WORD);
882
 
883
      host.wb_write(0, XGATE_XGVBR,  16'h55AA, H_BYTE);
884
      host.wb_cmp(0, XGATE_XGVBR,    16'h5554, WORD);
885
 
886
      data_xgmctl = XGMCTL_XGEM | XGMCTL_XGE;
887
      host.wb_write(0, XGATE_XGMCTL,   data_xgmctl, WORD);   //
888
      data_xgmctl = XGMCTL_XGE;
889
      host.wb_cmp(  0, XGATE_XGMCTL, data_xgmctl, WORD);
890
      host.wb_write(0, XGATE_XGVBR,  16'hFFFF, WORD);
891
      host.wb_cmp(0, XGATE_XGVBR,    16'h5554, WORD);
892
 
893
      data_xgmctl = XGMCTL_XGEM;
894
      host.wb_write(0, XGATE_XGMCTL,   data_xgmctl, WORD);   //
895
 
896
      // Test the Xgate Software Trigger Register (XGSWT)
897
      host.wb_write(0, XGATE_XGSWT,  16'hFFFF, WORD);
898
      host.wb_cmp(0, XGATE_XGSWT,    16'h00FF, WORD);
899
      host.wb_write(0, XGATE_XGSWT,  16'hFF00, WORD);
900
      host.wb_cmp(0, XGATE_XGSWT,    16'h0000, WORD);
901
 
902
      host.wb_write(0, XGATE_XGSWT,  16'hFF55, L_BYTE);
903
      host.wb_cmp(0, XGATE_XGSWT,    16'h0000, WORD);
904
      host.wb_write(0, XGATE_XGSWT,  16'hFF55, H_BYTE);
905
      host.wb_cmp(0, XGATE_XGSWT,    16'h0000, WORD);
906
 
907
      // Test the Xgate Semaphore Register (XGSEM)
908
      host.wb_write(0, XGATE_XGSEM,  16'hFFFF, WORD);
909
      host.wb_cmp(0, XGATE_XGSEM,    16'h00FF, WORD);
910
      host.wb_write(0, XGATE_XGSEM,  16'hFF00, WORD);
911
      host.wb_cmp(0, XGATE_XGSEM,    16'h0000, WORD);
912
 
913
      host.wb_write(0, XGATE_XGSEM,  16'hFFFF, L_BYTE);
914
      host.wb_cmp(0, XGATE_XGSEM,    16'h0000, WORD);
915
      host.wb_write(0, XGATE_XGSEM,  16'hFFFF, H_BYTE);
916
      host.wb_cmp(0, XGATE_XGSEM,    16'h0000, WORD);
917
 
918
      // Test the Xgate Condition Code Register (XGCCR)
919
      host.wb_write(0, XGATE_XGCCR,  16'hFFFF, L_BYTE);
920
      host.wb_cmp(0, XGATE_XGCCR,    16'h000F, WORD);
921
      host.wb_write(0, XGATE_XGCCR,  16'hFFF0, WORD);
922
      host.wb_cmp(0, XGATE_XGCCR,    16'h0000, WORD);
923
 
924
      // Test the Xgate Program Counter Register (XGPC)
925
      host.wb_write(0, XGATE_XGPC,  16'hFF55, L_BYTE);
926
      host.wb_cmp(0, XGATE_XGPC,    16'h0055, WORD);
927
      host.wb_write(0, XGATE_XGPC,  16'hAAFF, H_BYTE);
928
      host.wb_cmp(0, XGATE_XGPC,    16'hAA55, WORD);
929
      host.wb_write(0, XGATE_XGPC,  16'h9966, WORD);
930
      host.wb_cmp(0, XGATE_XGPC,    16'h9966, WORD);
931
 
932
      // Test the Xgate Register #1 (XGR1)
933
      host.wb_write(0, XGATE_XGR1,  16'hFF33, L_BYTE);
934
      host.wb_cmp(0, XGATE_XGR1,    16'h0033, WORD);
935
      host.wb_write(0, XGATE_XGR1,  16'hccFF, H_BYTE);
936
      host.wb_cmp(0, XGATE_XGR1,    16'hcc33, WORD);
937
      host.wb_write(0, XGATE_XGR1,  16'hf11f, WORD);
938
      host.wb_cmp(0, XGATE_XGR1,    16'hf11f, WORD);
939
 
940
      // Test the Xgate Register #2 (XGR2)
941
      host.wb_write(0, XGATE_XGR2,  16'hFF11, L_BYTE);
942
      host.wb_cmp(0, XGATE_XGR2,    16'h0011, WORD);
943
      host.wb_write(0, XGATE_XGR2,  16'h22FF, H_BYTE);
944
      host.wb_cmp(0, XGATE_XGR2,    16'h2211, WORD);
945
      host.wb_write(0, XGATE_XGR2,  16'hddee, WORD);
946
      host.wb_cmp(0, XGATE_XGR2,    16'hddee, WORD);
947
 
948
      // Test the Xgate Register #3 (XGR3)
949
      host.wb_write(0, XGATE_XGR3,  16'hFF43, L_BYTE);
950
      host.wb_cmp(0, XGATE_XGR3,    16'h0043, WORD);
951
      host.wb_write(0, XGATE_XGR3,  16'h54FF, H_BYTE);
952
      host.wb_cmp(0, XGATE_XGR3,    16'h5443, WORD);
953
      host.wb_write(0, XGATE_XGR3,  16'habbc, WORD);
954
      host.wb_cmp(0, XGATE_XGR3,    16'habbc, WORD);
955
 
956
      // Test the Xgate Register #4 (XGR4)
957
      host.wb_write(0, XGATE_XGR4,  16'hFF54, L_BYTE);
958
      host.wb_cmp(0, XGATE_XGR4,    16'h0054, WORD);
959
      host.wb_write(0, XGATE_XGR4,  16'h65FF, H_BYTE);
960
      host.wb_cmp(0, XGATE_XGR4,    16'h6554, WORD);
961
      host.wb_write(0, XGATE_XGR4,  16'h9aab, WORD);
962
      host.wb_cmp(0, XGATE_XGR4,    16'h9aab, WORD);
963
 
964
      // Test the Xgate Register #5 (XGR5)
965
      host.wb_write(0, XGATE_XGR5,  16'hFF65, L_BYTE);
966
      host.wb_cmp(0, XGATE_XGR5,    16'h0065, WORD);
967
      host.wb_write(0, XGATE_XGR5,  16'h76FF, H_BYTE);
968
      host.wb_cmp(0, XGATE_XGR5,    16'h7665, WORD);
969
      host.wb_write(0, XGATE_XGR5,  16'h899a, WORD);
970
      host.wb_cmp(0, XGATE_XGR5,    16'h899a, WORD);
971
 
972
      // Test the Xgate Register #6 (XGR6)
973
      host.wb_write(0, XGATE_XGR6,  16'hFF76, L_BYTE);
974
      host.wb_cmp(0, XGATE_XGR6,    16'h0076, WORD);
975
      host.wb_write(0, XGATE_XGR6,  16'h87FF, H_BYTE);
976
      host.wb_cmp(0, XGATE_XGR6,    16'h8776, WORD);
977
      host.wb_write(0, XGATE_XGR6,  16'h7889, WORD);
978
      host.wb_cmp(0, XGATE_XGR6,    16'h7889, WORD);
979
 
980
      // Test the Xgate Register #7 (XGR7)
981
      host.wb_write(0, XGATE_XGR7,  16'hFF87, L_BYTE);
982
      host.wb_cmp(0, XGATE_XGR7,    16'h0087, WORD);
983
      host.wb_write(0, XGATE_XGR7,  16'h98FF, H_BYTE);
984
      host.wb_cmp(0, XGATE_XGR7,    16'h9887, WORD);
985
      host.wb_write(0, XGATE_XGR7,  16'h6778, WORD);
986
      host.wb_cmp(0, XGATE_XGR7,    16'h6778, WORD);
987
 
988
      host.wb_cmp(0, XGATE_XGPC,    16'h9966, WORD);
989
      host.wb_cmp(0, XGATE_XGR1,    16'hf11f, WORD);
990
      host.wb_cmp(0, XGATE_XGR2,    16'hddee, WORD);
991
      host.wb_cmp(0, XGATE_XGR3,    16'habbc, WORD);
992
      host.wb_cmp(0, XGATE_XGR4,    16'h9aab, WORD);
993
      host.wb_cmp(0, XGATE_XGR5,    16'h899a, WORD);
994
      host.wb_cmp(0, XGATE_XGR6,    16'h7889, WORD);
995
      host.wb_cmp(0, XGATE_XGR7,    16'h6778, WORD);
996
 
997 2 rehayes
  end
998
endtask
999
 
1000
 
1001 36 rehayes
////////////////////////////////////////////////////////////////////////////////
1002
// check RAM Read/Write from host
1003
task host_ram;
1004
  begin
1005
    test_num = test_num + 1;
1006
    $display("TEST #%d Starts at vector=%d, host_ram", test_num, vector);
1007
 
1008
    host.wb_write(1, SYS_RAM_BASE, 16'h5555, WORD);
1009
    host.wb_cmp(  0, SYS_RAM_BASE, 16'h5555, WORD);
1010
 
1011
    repeat(5) @(posedge mstr_test_clk);
1012
    p_ram.dump_ram(0);
1013
 
1014
  end
1015
endtask
1016
 
1017
////////////////////////////////////////////////////////////////////////////////
1018 11 rehayes
// Poll for XGATE Interrupt set
1019
task wait_irq_set;
1020
  input [ 6:0] chan_val;
1021
  begin
1022
    while(!xgif[chan_val])
1023
      @(posedge mstr_test_clk); // poll it until it is set
1024
    $display("XGATE Interrupt Request #%d set detected at vector =%d", chan_val, vector);
1025
  end
1026
endtask
1027 2 rehayes
 
1028 36 rehayes
////////////////////////////////////////////////////////////////////////////////
1029 11 rehayes
// Poll for debug bit set
1030
task wait_debug_set;
1031
  begin
1032 36 rehayes
    host.wb_read(1, XGATE_XGMCTL, q, WORD);
1033 11 rehayes
    while(~|(q & XGMCTL_XGDBG))
1034 36 rehayes
      host.wb_read(1, XGATE_XGMCTL, q, WORD); // poll it until it is set
1035 11 rehayes
    $display("DEBUG Flag set detected at vector =%d", vector);
1036
  end
1037
endtask
1038 2 rehayes
 
1039 11 rehayes
 
1040 36 rehayes
////////////////////////////////////////////////////////////////////////////////
1041 2 rehayes
task system_reset;  // reset system
1042
  begin
1043
      repeat(1) @(posedge mstr_test_clk);
1044
      sync_reset = 1'b1;  // Make the sync reset 1 clock cycle long
1045
      #2;                 // move the async reset away from the clock edge
1046
      rstn = 1'b0;        // assert async reset
1047
      #5;                 // Keep the async reset pulse with less than a clock cycle
1048
      rstn = 1'b1;        // negate async reset
1049
      repeat(1) @(posedge mstr_test_clk);
1050
      sync_reset = 1'b0;
1051
 
1052
      $display("\nstatus: %t System Reset Task Done", $time);
1053
      test_num = test_num + 1;
1054
 
1055
      repeat(2) @(posedge mstr_test_clk);
1056
   end
1057
endtask
1058
 
1059
 
1060 36 rehayes
////////////////////////////////////////////////////////////////////////////////
1061 2 rehayes
task activate_channel;
1062
  input [ 6:0] chan_val;
1063
  begin
1064 21 rehayes
    $display("Activating Channel %d", chan_val);
1065 2 rehayes
 
1066 21 rehayes
    channel_req[chan_val] = 1'b1; //
1067
    repeat(1) @(posedge mstr_test_clk);
1068 2 rehayes
  end
1069
endtask
1070
 
1071
 
1072 36 rehayes
////////////////////////////////////////////////////////////////////////////////
1073 2 rehayes
task clear_channel;
1074
  input [ 6:0] chan_val;
1075
  begin
1076 21 rehayes
    $display("Clearing Channel interrupt input #%d", chan_val);
1077 2 rehayes
 
1078 21 rehayes
    channel_req[chan_val] = 1'b0; //
1079
    repeat(1) @(posedge mstr_test_clk);
1080
  end
1081 2 rehayes
endtask
1082
 
1083
 
1084 36 rehayes
////////////////////////////////////////////////////////////////////////////////
1085 2 rehayes
task clear_irq_flag;
1086
  input [ 6:0] chan_val;
1087
  begin
1088
      $display("Clearing Channel interrupt flag #%d", chan_val);
1089
      if (0 < chan_val < 16)
1090 36 rehayes
        host.wb_write(1, XGATE_XGIF_0, 16'hffff, WORD);
1091 2 rehayes
      if (15 < chan_val < 32)
1092 36 rehayes
        host.wb_write(1, XGATE_XGIF_1, 16'hffff, WORD);
1093 2 rehayes
      if (31 < chan_val < 48)
1094 36 rehayes
        host.wb_write(1, XGATE_XGIF_2, 16'hffff, WORD);
1095 2 rehayes
      if (47 < chan_val < 64)
1096 36 rehayes
        host.wb_write(1, XGATE_XGIF_3, 16'hffff, WORD);
1097 2 rehayes
      if (63 < chan_val < 80)
1098 36 rehayes
        host.wb_write(1, XGATE_XGIF_4, 16'hffff, WORD);
1099 2 rehayes
      if (79 < chan_val < 96)
1100 36 rehayes
        host.wb_write(1, XGATE_XGIF_5, 16'hffff, WORD);
1101 2 rehayes
      if (95 < chan_val < 112)
1102 36 rehayes
        host.wb_write(1, XGATE_XGIF_6, 16'hffff, WORD);
1103 2 rehayes
      if (111 < chan_val < 128)
1104 36 rehayes
        host.wb_write(1, XGATE_XGIF_7, 16'hffff, WORD);
1105 2 rehayes
 
1106 21 rehayes
      channel_req[chan_val] = 1'b0; //
1107 2 rehayes
      repeat(1) @(posedge mstr_test_clk);
1108
   end
1109
endtask
1110
 
1111
 
1112 36 rehayes
////////////////////////////////////////////////////////////////////////////////
1113 2 rehayes
task activate_thread_sw;
1114
  input [ 6:0] chan_val;
1115
  begin
1116 50 rehayes
      $display("Activating Software Thread - Channel #%d", chan_val);
1117 2 rehayes
 
1118 11 rehayes
      data_xgmctl = XGMCTL_XGEM | XGMCTL_XGE;
1119 36 rehayes
      host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD);   // Enable XGATE
1120 2 rehayes
 
1121 21 rehayes
      channel_req[chan_val] = 1'b1; //
1122 2 rehayes
      repeat(1) @(posedge mstr_test_clk);
1123
   end
1124
endtask
1125
 
1126 36 rehayes
////////////////////////////////////////////////////////////////////////////////
1127 41 rehayes
task read_ram_cmp;
1128
  input [15:0] address;
1129
  input [15:0] value;
1130
  reg   [15:0] q;
1131
  begin
1132
 
1133
      // BIGENDIAN
1134
      q = {p_ram.ram_8[address], p_ram.ram_8[address+1]};
1135
      // "X" compares don't work, "X" in value or q always match
1136
      if (value != q)
1137
        begin
1138
          error_count = error_count + 1;
1139
          $display("RAM Data compare error at address %h. Received %h, expected %h at time %t", address, q, value, $time);
1140
        end
1141
   end
1142
endtask
1143
 
1144
////////////////////////////////////////////////////////////////////////////////
1145 5 rehayes
task wrap_up;
1146
  begin
1147 21 rehayes
    test_num = test_num + 1;
1148
    repeat(10) @(posedge mstr_test_clk);
1149 5 rehayes
    $display("\nSimulation Finished!! - vector =%d", vector);
1150
    if (error_count == 0)
1151
      $display("Simulation Passed");
1152
    else
1153 21 rehayes
      $display("Simulation Failed  --- Errors =%d", error_count);
1154 5 rehayes
 
1155
    $finish;
1156
  end
1157
endtask
1158
 
1159 36 rehayes
////////////////////////////////////////////////////////////////////////////////
1160 2 rehayes
function [15:0] four_2_16;
1161
  input [3:0] vector;
1162
  begin
1163
    case (vector)
1164
      4'h0 : four_2_16 = 16'b0000_0000_0000_0001;
1165
      4'h1 : four_2_16 = 16'b0000_0000_0000_0010;
1166
      4'h2 : four_2_16 = 16'b0000_0000_0000_0100;
1167
      4'h3 : four_2_16 = 16'b0000_0000_0000_1000;
1168
      4'h4 : four_2_16 = 16'b0000_0000_0001_0000;
1169
      4'h5 : four_2_16 = 16'b0000_0000_0010_0000;
1170
      4'h6 : four_2_16 = 16'b0000_0000_0100_0000;
1171
      4'h7 : four_2_16 = 16'b0000_0000_1000_0000;
1172
      4'h8 : four_2_16 = 16'b0000_0001_0000_0000;
1173
      4'h9 : four_2_16 = 16'b0000_0010_0000_0000;
1174
      4'ha : four_2_16 = 16'b0000_0100_0000_0000;
1175
      4'hb : four_2_16 = 16'b0000_1000_0000_0000;
1176
      4'hc : four_2_16 = 16'b0001_0000_0000_0000;
1177
      4'hd : four_2_16 = 16'b0010_0000_0000_0000;
1178
      4'he : four_2_16 = 16'b0100_0000_0000_0000;
1179
      4'hf : four_2_16 = 16'b1000_0000_0000_0000;
1180
    endcase
1181
  end
1182
endfunction
1183
 
1184
endmodule  // tst_bench_top
1185
 
1186 36 rehayes
////////////////////////////////////////////////////////////////////////////////
1187
////////////////////////////////////////////////////////////////////////////////
1188
////////////////////////////////////////////////////////////////////////////////
1189
module bus_arbitration  #(parameter dwidth = 32,
1190
                          parameter awidth = 32)
1191
  (
1192
  // System bus I/O
1193
  output                     sys_cyc,
1194
  output                     sys_stb,
1195
  output                     sys_we,
1196
  output     [dwidth/8 -1:0] sys_sel,
1197
  output     [awidth   -1:0] sys_adr,
1198
  output     [dwidth   -1:0] sys_dout,
1199
 
1200
  // Host bus I/O
1201
  output                     host_ack,
1202
  output     [dwidth   -1:0] host_dout,
1203
  input                      host_cyc,
1204
  input                      host_stb,
1205
  input                      host_we,
1206
  input      [dwidth/8 -1:0] host_sel,
1207
  input      [awidth   -1:0] host_adr,
1208
  input      [dwidth   -1:0] host_din,
1209
 
1210
  // Alternate Bus Master #1 Bus I/O
1211
  output                     alt1_ack,
1212
  output     [dwidth   -1:0] alt1_dout,
1213
  input                      alt1_cyc,
1214
  input                      alt1_stb,
1215
  input                      alt1_we,
1216
  input      [dwidth/8 -1:0] alt1_sel,
1217
  input      [awidth   -1:0] alt1_adr,
1218
  input      [dwidth   -1:0] alt1_din,
1219
 
1220
  // Slave #1 Bus I/O
1221
  output                     slv1_stb,
1222
  input                      slv1_ack,
1223
  input      [dwidth   -1:0] slv1_din,
1224
 
1225
  // Slave #2 Bus I/O
1226
  output                     slv2_stb,
1227
  input                      slv2_ack,
1228
  input      [dwidth   -1:0] slv2_din,
1229
 
1230
  // Miscellaneous
1231
  input                      host_clk,
1232
  input                      risc_clk,
1233
  input                      rst,  // No Connect
1234
  input                      err,  // No Connect
1235
  input                      rty   // No Connect
1236
  );
1237
 
1238
  //////////////////////////////////////////////////////////////////////////////
1239
  //
1240
  // Local Wires and Registers
1241
  //
1242
  wire       host_lock;      // Host has the slave bus
1243
  reg        host_lock_ext;  // Host lock extend, Hold the bus till the transaction complets
1244
  reg  [3:0] host_cycle_cnt; // Used to count the cycle the host and break the lock if the risc needs access
1245
 
1246
  wire       risc_lock;      // RISC has the slave bus
1247
  reg        risc_lock_ext;  // RISC lock extend, Hold the bus till the transaction complets
1248
  reg  [3:0] risc_cycle_cnt; // Used to count the cycle the risc and break the lock if the host needs access
1249
 
1250
  // Aribartration Logic for System Bus access
1251
  always @(posedge host_clk or negedge rst)
1252
    if (!rst)
1253
      host_lock_ext <= 1'b0;
1254
    else
1255
      host_lock_ext <= host_cyc && !host_ack;
1256
 
1257
  always @(posedge host_clk or negedge rst)
1258
    if (!rst)
1259
      risc_lock_ext <= 1'b0;
1260
    else
1261
      risc_lock_ext <= alt1_cyc && !alt1_ack;
1262
 
1263
      // Start counting cycles the host has the bus if the risc is also requesting the bus
1264
  always @(posedge host_clk or negedge rst)
1265
    if (!rst)
1266
      host_cycle_cnt <= 0;
1267
    else
1268
      host_cycle_cnt <= (host_lock && alt1_cyc) ? (host_cycle_cnt + 1'b1) : 0;
1269
 
1270
  // Start counting cycles the risc has the bus if the host is also requesting the bus
1271
  always @(posedge host_clk or negedge rst)
1272
    if (!rst)
1273
      risc_cycle_cnt <= 0;
1274
    else
1275
      risc_cycle_cnt <= (risc_lock && host_cyc) ? (risc_cycle_cnt + 1'b1) : 0;
1276
 
1277
  assign host_lock = ((host_cyc && !risc_lock_ext) || host_lock_ext) && (host_cycle_cnt < 5);
1278
  assign risc_lock = !host_lock;
1279
 
1280
  wire alt1_master = !host_lock;
1281
 
1282
  // Address decoding for different XGATE module instances
1283 41 rehayes
  assign slv1_stb = sys_stb && ~sys_adr[7] && ~sys_adr[6] && ~|sys_adr[31:8];
1284
  wire slv3_stb = sys_stb && ~sys_adr[7] &&  sys_adr[6] && ~|sys_adr[31:8];
1285
  wire slv4_stb = sys_stb &&  sys_adr[7] && ~sys_adr[6] && ~|sys_adr[31:8];
1286
  wire slv5_stb = sys_stb &&  sys_adr[7] &&  sys_adr[6] && ~|sys_adr[31:8];
1287 36 rehayes
 
1288
  // Address decoding for Testbench access to RAM
1289
  assign slv2_stb = alt1_master ? (alt1_stb && sys_adr[16] && ~|sys_adr[31:17]) :
1290
                                  (host_stb && ~sys_adr[16] && sys_adr[17] && ~|sys_adr[31:18]);
1291
 
1292
 
1293
  // Create the Host Read Data Bus
1294
  assign host_dout = ({dwidth{slv1_stb}} & slv1_din) |
1295
                     ({dwidth{slv2_stb}} & slv2_din);
1296
 
1297
  // Create the Alternate #1 Read Data Bus
1298
  assign alt1_dout = ({dwidth{slv1_stb}} & slv1_din) |
1299
                     ({dwidth{slv2_stb}} & slv2_din);
1300
 
1301
  assign host_ack = host_lock && (slv1_ack || slv2_ack);
1302
  assign alt1_ack = risc_lock && (slv1_ack || slv2_ack);
1303
 
1304
 
1305
  // Mux for System Bus access
1306
  assign sys_cyc   = alt1_cyc || host_cyc;
1307
  assign sys_stb   = alt1_master ? alt1_stb  : host_stb;
1308
  assign sys_we    = alt1_master ? alt1_we   : host_we;
1309
  assign sys_sel   = alt1_master ? alt1_sel  : host_sel;
1310
  assign sys_adr   = alt1_master ? alt1_adr  : host_adr;
1311
  assign sys_dout  = alt1_master ? alt1_din  : host_din;
1312
 
1313
endmodule   // bus_arbitration
1314
 
1315
 
1316
 

powered by: WebSVN 2.1.0

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