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

Subversion Repositories pci

[/] [pci/] [tags/] [rel_5/] [bench/] [verilog/] [pci_behaviorial_target.v] - Blame information for rev 26

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

Line No. Rev Author Line
1 19 mihad
//===========================================================================
2 26 mihad
// $Id: pci_behaviorial_target.v,v 1.2 2002-02-19 16:32:29 mihad Exp $
3 19 mihad
//
4
// Copyright 2001 Blue Beaver.  All Rights Reserved.
5
//
6
// Summary:  A PCI Behaviorial Target.  This module receives commands over
7
//           the PCI Bus.  The PCI Master encodes commands in the middle
8
//           16 bits of the PCI Address.  This Target contains Config
9
//           registers and a 256 byte scratch SRAM.  It responds with data
10
//           when it is given a Read command, and checks data when it is
11
//           given a Write command.
12
//           This interface does implement a very simple Delayed Read
13
//           facility which is enough to let the user manually make the
14
//           PCI Bus look like a Delayed Read is begin done.  This will
15
//           probably not work when a synthesizable PCI Interface tries
16
//           to cause Delayed Reads.  But by then, a second synthesizable
17
//           PCI Core will be the more useful test target.
18
//
19
// This library is free software; you can distribute it and/or modify it
20
// under the terms of the GNU Lesser General Public License as published
21
// by the Free Software Foundation; either version 2.1 of the License, or
22
// (at your option) any later version.
23
//
24
// This library is distributed in the hope that it will be useful, but
25
// WITHOUT ANY WARRANTY; without even the implied warranty of
26
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
27
// See the GNU Lesser General Public License for more details.
28
//
29
// You should have received a copy of the GNU Lesser General Public License
30
// along with this library.  If not, write to
31
// Free Software Foundation, Inc.
32
// 59 Temple Place, Suite 330
33
// Boston, MA 02111-1307 USA
34
//
35
// Author's note about this license:  The intention of the Author and of
36
// the Gnu Lesser General Public License is that users should be able to
37
// use this code for any purpose, including combining it with other source
38
// code, combining it with other logic, translated it into a gate-level
39
// representation, or projected it into gates in a programmable or
40
// hardwired chip, as long as the users of the resulting source, compiled
41
// source, or chip are given the means to get a copy of this source code
42
// with no new restrictions on redistribution of this source.
43
//
44
// If you make changes, even substantial changes, to this code, or use
45
// substantial parts of this code as an inseparable part of another work
46
// of authorship, the users of the resulting IP must be given the means
47
// to get a copy of the modified or combined source code, with no new
48
// restrictions on redistribution of the resulting source.
49
//
50
// Separate parts of the combined source code, compiled code, or chip,
51
// which are NOT derived from this source code do NOT need to be offered
52
// to the final user of the chip merely because they are used in
53
// combination with this code.  Other code is not forced to fall under
54
// the GNU Lesser General Public License when it is linked to this code.
55
// The license terms of other source code linked to this code might require
56
// that it NOT be made available to users.  The GNU Lesser General Public
57
// License does not prevent this code from being used in such a situation,
58
// as long as the user of the resulting IP is given the means to get a
59
// copy of this component of the IP with no new restrictions on
60
// redistribution of this source.
61
//
62
// This code was developed using VeriLogger Pro, by Synapticad.
63
// Their support is greatly appreciated.
64
//
65
// NOTE:  This Test Chip instantiates one PCI interface and connects it
66
//        to its IO pads and to logic representing a real application.
67
//
68
// NOTE TODO: Horrible.  Tasks can't depend on their Arguments being safe
69
//        if there are several instances ofthe tasl running at once.
70
// NOTE TODO: need to check parity on writes, and report if error status wrong
71
// NOTE TODO: need to drive PERR and SERR lines
72
// NOTE TODO: need to start setting error bits in Config Register
73
// Need to detect Address Parity Errors, and report them  3.7.3
74
// Need to allow bad parity address decodes if Parity Error Response not set 3.7.3
75
// Need to act on Delayed Read commands
76
// Need to do retries on other READ commands when delayed read in progress
77
// Need to clear delayed read in progress bit when Config Register says to
78
// Need to consider holding PERR if asserted without regards to TRDY and IRDY
79
//   See 3.7.4.1 for details.  If done as now, no need to hold.
80
// Need to assert SERR on address parity errors  3.7.4.2
81
// Need to record errors.  3.7.4.3, 3.7.4.4
82
// Complain if address parity error not seen when expected
83
// Complain if data parity error not seen when expected
84
//
85
//===========================================================================
86
 
87
`timescale 1ns/1ps
88
 
89
module pci_behaviorial_target (
90
  ad_now, ad_prev, target_ad_out, target_ad_oe,
91
  cbe_l_now, cbe_l_prev, calc_input_parity_prev, par_now, par_prev,
92
  frame_now, frame_prev, irdy_now, irdy_prev,
93
  target_devsel_out, target_d_t_s_oe, target_trdy_out, target_stop_out,
94
  target_perr_out, target_perr_oe, target_serr_oe,
95
  idsel_now, idsel_prev,
96
  pci_reset_comb, pci_ext_clk,
97
// Signals from the master to the target to set bits in the Status Register
98
  master_got_parity_error, master_asserted_serr, master_got_master_abort,
99
  master_got_target_abort, master_caused_parity_error,
100
  master_enable, master_fast_b2b_en, master_perr_enable, master_serr_enable,
101
  master_latency_value,
102
// Signals used by the test bench instead of using "." notation
103
  target_debug_force_bad_par,
104
  test_error_event, test_device_id,
105
  test_response
106
);
107
 
108
`include "pci_blue_options.vh"
109
`include "pci_blue_constants.vh"
110
 
111
  input  [PCI_BUS_DATA_RANGE:0] ad_now;
112
  input  [PCI_BUS_DATA_RANGE:0] ad_prev;
113
  output [PCI_BUS_DATA_RANGE:0] target_ad_out;
114
  output  target_ad_oe;
115
  input  [PCI_BUS_CBE_RANGE:0] cbe_l_now;
116
  input  [PCI_BUS_CBE_RANGE:0] cbe_l_prev;
117
  input   calc_input_parity_prev;
118
  input   par_now, par_prev;
119
  input   frame_now, frame_prev, irdy_now, irdy_prev;
120
  output  target_devsel_out, target_d_t_s_oe, target_trdy_out, target_stop_out;
121
  output  target_perr_out, target_perr_oe, target_serr_oe;
122
  input   idsel_now, idsel_prev;
123
  input   pci_reset_comb, pci_ext_clk;
124
// Signals from the master to the target to set bits in the Status Register
125
  input   master_got_parity_error, master_asserted_serr, master_got_master_abort;
126
  input   master_got_target_abort, master_caused_parity_error;
127
  output  master_enable, master_fast_b2b_en, master_perr_enable, master_serr_enable;
128
  output [7:0] master_latency_value;
129
// Signals used by the test bench instead of using "." notation
130
  output  target_debug_force_bad_par;
131
  output  test_error_event;
132
  input  [2:0]  test_device_id;
133
  input  [25:0] test_response ;
134
 
135
  reg    [PCI_BUS_DATA_RANGE:0] target_ad_out;
136
  reg     target_ad_oe;
137
  reg     target_devsel_out, target_trdy_out, target_stop_out;
138
  wire    target_d_t_s_oe, target_perr_oe;
139
  reg     target_perr_out, target_serr_oe;
140
  reg     target_debug_force_bad_par;
141
  reg     test_error_event;
142
 
143
// Make temporary Bip every time an error is detected
144
  initial test_error_event <= 1'bZ;
145
  reg     error_detected;
146
  initial error_detected <= 1'b0;
147
  always @(error_detected)
148
  begin
149
    test_error_event <= 1'b0;
150
    #2;
151
    test_error_event <= 1'bZ;
152
  end
153
 
154
// Target Interface:
155
// This will have just enough memory to make debugging exciting.
156
// It will have 256 Bytes of SRAM.  The memory will be available
157
// BOTH as Config memory and as regular memory.
158
// Special regions of the memory will have special characteristics.
159
// Locations 0, 4, 8, A, 10, and 14 will be implemented as Control
160
//   registers.
161
// Locations 18 and 1C will be used for memory debugging (somehow!)
162
// All other locations will act as simple memory.
163
 
164
// Config Register Area consists of:
165
//    31  24 23  16 15   8  7   0
166
//   |  Device ID  |  Vendor ID  | 0x00
167
//   |   Status    |   Command   | 0x04
168
//   |       Class Code   | Rev  | 0x08
169
//   | BIST | HEAD | LTCY | CSize| 0x0A
170
//   |      Base Address 0       | 0x10
171
//   |      Base Address 1       | 0x14
172
//   |          Unused           | 0x18
173
//   |          Unused           | 0x1C
174
//   |          Unused           | 0x20
175
//   |          Unused           | 0x24
176
//   |      Cardbus Pointer      | 0x28
177
//   |  SubSys ID  |  SubVnd ID  | 0x2C
178
//   |   Expansion ROM Pointer   | 0x30
179
//   |    Reserved        | Cap  | 0x34
180
//   |          Reserved         | 0x38
181
//   | MLat | MGnt | IPin | ILine| 0x3C
182
//
183
// Command resets to 0 or maybe 0x80.  It consists of:
184
// {6'h00, FB2B_En, SERR_En,
185
//  Step_En, Par_Err_En, VGA_En, Mem_Write_Inv_En,
186
//  Special_En, Master_En, Target_En, IO_En}
187
//
188
// Status consists of:
189
// {Detected_Perr, Signaled_Serr, Got_Master_Abort, Got_Target_Abort,
190
//  Signaled_Target_Abort, Devsel_Timing[1:0], Master_Got_Perr,
191
//  FB2B_Capable, 1'b0, 66MHz_Capable, New_Capabilities,
192
//  4'h0}
193
//
194
// Got_Master_Abort is not set for Special Cycles.
195
// Devsel will be 2'h01 in this design.  New_Capabilities is 1'b0.
196
// All clearable bits in this register are cleared whenever the
197
//   register is written with the corresponding bit being 1'b1.
198
// See the PCI Local Bus Spec Revision 2.2 section 6.2.3.
199
 
200
  reg     FB2B_En, SERR_En, Par_Err_En, Master_En, Target_En;
201
  reg     Detected_PERR, Signaled_SERR, Received_Master_Abort, Received_Target_Abort;
202
  reg     Signaled_Target_Abort, Master_Caused_PERR;
203
  reg    [7:0] Latency_Timer;
204
  reg    [7:0] Cache_Line_Size;
205
  reg    [7:0] Interrupt_Line;
206
  reg    [`PCI_BASE_ADDR0_MATCH_RANGE] BAR0;  // Base Address Registers, used to match addresses
207
`ifdef PCI_BASE_ADDR1_MATCH_ENABLE
208
  reg    [`PCI_BASE_ADDR1_MATCH_RANGE] BAR1;
209
`endif  // PCI_BASE_ADDR1_MATCH_ENABLE
210
 
211
  wire   [15:0] Target_Command =
212
                     {4'b0000,
213
                      2'b00, FB2B_En, SERR_En,
214
                      1'b1, Par_Err_En, 2'b00,
215
                      1'b0, Master_En, Target_En, 1'b0};
216
`ifdef PCI_CLK_66
217
  wire   [15:0] Target_Status =
218
                     {Detected_PERR, Signaled_SERR, Received_Master_Abort,
219
                                                    Received_Target_Abort,
220
                      Signaled_Target_Abort, 2'b01, Master_Caused_PERR,
221
                      1'b1, 1'b0, 1'b1, 1'b0,
222
                      4'b0000};
223
`else  // PCI_CLK_66
224
  wire   [15:0] Target_Status =
225
                     {Detected_PERR, Signaled_SERR, Received_Master_Abort,
226
                                                    Received_Target_Abort,
227
                      Signaled_Target_Abort, 2'b01, Master_Caused_PERR,
228
                      1'b1, 1'b0, 1'b0, 1'b0,
229
                      4'b0000};
230
`endif  // PCI_CLK_66
231
 
232
  assign  master_enable = Master_En;
233
  assign  master_fast_b2b_en = FB2B_En;
234
  assign  master_perr_enable = Par_Err_En;
235
  assign  master_serr_enable = SERR_En;
236
  assign  master_latency_value[7:0] = Latency_Timer[7:0];
237
 
238
task Read_Test_Device_Config_Regs;
239
  input  [7:2] reg_number;
240
  output [PCI_BUS_DATA_RANGE:0] Read_Config_Reg;
241
  begin  // Addresses except 0, 4, 8, A, 10, 14, 3C all return 0x00
242
    case (reg_number[7:2])
243
    6'h00: Read_Config_Reg = 32'h8000AAAA
244
                           | {13'h0000, test_device_id[2:0], 16'h0000};
245
    6'h01: Read_Config_Reg = {Target_Status[15:0], Target_Command[15:0]};
246
    6'h02: Read_Config_Reg = 32'hFF000000;
247
    6'h03: Read_Config_Reg = {16'h0000, Latency_Timer[7:0], Cache_Line_Size[7:0]};
248
    6'h04: Read_Config_Reg = {BAR0[`PCI_BASE_ADDR0_MATCH_RANGE],
249
                              `PCI_BASE_ADDR0_FILL, `PCI_BASE_ADDR0_MAP_QUAL};
250
`ifdef PCI_BASE_ADDR1_MATCH_ENABLE
251
    6'h05: Read_Config_Reg = {BAR1[`PCI_BASE_ADDR1_MATCH_RANGE],
252
                              `PCI_BASE_ADDR1_FILL, `PCI_BASE_ADDR1_MAP_QUAL};
253
`else  // PCI_BASE_ADDR1_MATCH_ENABLE
254
    6'h05: Read_Config_Reg = 32'h00000000;
255
`endif  // PCI_BASE_ADDR1_MATCH_ENABLE
256
    6'h0F: Read_Config_Reg = {16'h0000, 8'h01, Interrupt_Line[7:0]};
257
    default: Read_Config_Reg = 32'h00000000;
258
    endcase
259
  end
260
endtask
261
 
262
// store info away so Config Register code can update register correctly
263
  reg    [7:2] pending_config_reg_write_address;
264
  reg    [PCI_BUS_CBE_RANGE:0] pending_config_reg_write_byte_enables;
265
  reg    [PCI_BUS_DATA_RANGE:0] pending_config_reg_write_data;
266
  reg     pending_config_write_request;
267
task Write_Test_Device_Config_Regs;
268
  input  [7:2] reg_number;
269
  input  [PCI_BUS_DATA_RANGE:0] data;
270
  input  [PCI_BUS_CBE_RANGE:0] master_mask_l;
271
  begin
272
    if (~pci_reset_comb)
273
    begin
274
      pending_config_reg_write_address[7:2] <= reg_number[7:2];
275
      pending_config_reg_write_byte_enables[PCI_BUS_CBE_RANGE:0] <= master_mask_l[PCI_BUS_CBE_RANGE:0];
276
      pending_config_reg_write_data[PCI_BUS_DATA_RANGE:0] <= data[PCI_BUS_DATA_RANGE:0];
277
      pending_config_write_request <= 1'b1;
278
    end
279
    `NO_ELSE;
280
  end
281
endtask
282
 
283
  wire    target_got_parity_error;
284
  wire    target_asserted_serr;
285
  reg     target_signaling_target_abort;
286
 
287
// Make a register transfer style Configuration Register, so it is easier to handle
288
//   simultaneous updates from the master and the target.
289
  always @(posedge pci_ext_clk or posedge pci_reset_comb)
290
  begin
291
    if (pci_reset_comb)
292
    begin
293
      FB2B_En <= 1'b0;
294
      SERR_En <= 1'b0;                Par_Err_En <= 1'b0;
295
      Master_En <= 1'b0;              Target_En <= 1'b0;
296
      Detected_PERR <= 1'b0;          Signaled_SERR <= 1'b0;
297
      Received_Master_Abort <= 1'b0;  Received_Target_Abort <= 1'b0;
298
      Signaled_Target_Abort <= 1'b0;
299
      Master_Caused_PERR <= 1'b0;
300
      Latency_Timer <= 8'h00;         Cache_Line_Size <= 8'h00;
301
      Interrupt_Line <= 8'h00;
302
      BAR0 <= 8'hXX;
303
`ifdef PCI_BASE_ADDR1_MATCH_ENABLE
304
      BAR1 <= 8'hXX;
305
`endif  // PCI_BASE_ADDR1_MATCH_ENABLE
306
      pending_config_write_request <= 1'b0;
307
    end
308
    else
309
    begin
310
      if (pending_config_write_request)
311
      begin
312
// Words 0 and 2 are not writable.  Only certain bits in word 1 are writable.
313
        FB2B_En    <= ((pending_config_reg_write_address[7:2] == 6'h01)
314
                        & ~pending_config_reg_write_byte_enables[1])
315
             ? ((pending_config_reg_write_data[PCI_BUS_DATA_RANGE:0] & CONFIG_CMD_FB2B_EN)
316
                        != `PCI_BUS_DATA_ZERO) : FB2B_En;
317
        SERR_En    <= ((pending_config_reg_write_address[7:2] == 6'h01)
318
                        & ~pending_config_reg_write_byte_enables[1])
319
             ? ((pending_config_reg_write_data[PCI_BUS_DATA_RANGE:0] & CONFIG_CMD_SERR_EN)
320
                        != `PCI_BUS_DATA_ZERO) : SERR_En;
321
        Par_Err_En <= ((pending_config_reg_write_address[7:2] == 6'h01)
322
                        & ~pending_config_reg_write_byte_enables[0])
323
             ? ((pending_config_reg_write_data[PCI_BUS_DATA_RANGE:0] & CONFIG_CMD_PAR_ERR_EN)
324
                        != `PCI_BUS_DATA_ZERO) : Par_Err_En;
325
        Master_En  <= ((pending_config_reg_write_address[7:2] == 6'h01)
326
                        & ~pending_config_reg_write_byte_enables[0])
327
             ? ((pending_config_reg_write_data[PCI_BUS_DATA_RANGE:0] & CONFIG_CMD_MASTER_EN)
328
                        != `PCI_BUS_DATA_ZERO) : Master_En;
329
        Target_En  <= ((pending_config_reg_write_address[7:2] == 6'h01)
330
                        & ~pending_config_reg_write_byte_enables[0])
331
             ? ((pending_config_reg_write_data[PCI_BUS_DATA_RANGE:0] & CONFIG_CMD_TARGET_EN)
332
                        != `PCI_BUS_DATA_ZERO) : Target_En;
333
// Certain bits in word 1 are only clearable, not writable.
334
        Detected_PERR    <= ((pending_config_reg_write_address[7:2] == 6'h01)
335
                        & ~pending_config_reg_write_byte_enables[3]
336
                    & ((pending_config_reg_write_data[PCI_BUS_DATA_RANGE:0] & CONFIG_STAT_DETECTED_PERR) != `PCI_BUS_DATA_ZERO))
337
             ? 1'b0 : Detected_PERR | master_got_parity_error | target_got_parity_error;
338
        Signaled_SERR    <= ((pending_config_reg_write_address[7:2] == 6'h01)
339
                        & ~pending_config_reg_write_byte_enables[3]
340
                    & ((pending_config_reg_write_data[PCI_BUS_DATA_RANGE:0] & CONFIG_STAT_DETECTED_SERR) != `PCI_BUS_DATA_ZERO))
341
             ? 1'b0 : Signaled_SERR | master_asserted_serr | target_asserted_serr;
342
        Received_Master_Abort <= ((pending_config_reg_write_address[7:2] == 6'h01)
343
                        & ~pending_config_reg_write_byte_enables[3]
344
                    & ((pending_config_reg_write_data[PCI_BUS_DATA_RANGE:0] & CONFIG_STAT_GOT_MABORT) != `PCI_BUS_DATA_ZERO))
345
             ? 1'b0 : Received_Master_Abort | master_got_master_abort;
346
        Received_Target_Abort <= ((pending_config_reg_write_address[7:2] == 6'h01)
347
                        & ~pending_config_reg_write_byte_enables[3]
348
                    & ((pending_config_reg_write_data[PCI_BUS_DATA_RANGE:0] & CONFIG_STAT_GOT_TABORT) != `PCI_BUS_DATA_ZERO))
349
             ? 1'b0 : Received_Target_Abort | master_got_target_abort;
350
        Signaled_Target_Abort <= ((pending_config_reg_write_address[7:2] == 6'h01)
351
                        & ~pending_config_reg_write_byte_enables[3]
352
                    & ((pending_config_reg_write_data[PCI_BUS_DATA_RANGE:0] & CONFIG_STAT_CAUSED_TABORT) != `PCI_BUS_DATA_ZERO))
353
             ? 1'b0 : Signaled_Target_Abort | target_signaling_target_abort;
354
        Master_Caused_PERR <= (  (pending_config_reg_write_address[7:2] == 6'h01)
355
                        & ~pending_config_reg_write_byte_enables[3]
356
                    & ((pending_config_reg_write_data[PCI_BUS_DATA_RANGE:0] & CONFIG_STAT_CAUSED_PERR) != `PCI_BUS_DATA_ZERO))
357
             ? 1'b0 : Master_Caused_PERR | master_caused_parity_error;
358
// Certain bytes in higher words are writable
359
        Latency_Timer    <= (  (pending_config_reg_write_address[7:2] == 6'h03)
360
                              & ~pending_config_reg_write_byte_enables[1])
361
                          ? pending_config_reg_write_data[15:8] : Latency_Timer;
362
        Cache_Line_Size  <= (  (pending_config_reg_write_address[7:2] == 6'h03)
363
                              & ~pending_config_reg_write_byte_enables[0])
364
                          ? pending_config_reg_write_data[7:0] : Cache_Line_Size;
365
 
366
        BAR0             <= (  (pending_config_reg_write_address[7:2] == 6'h04)
367
                              & ~pending_config_reg_write_byte_enables[3])
368
                          ? pending_config_reg_write_data[`PCI_BASE_ADDR0_MATCH_RANGE] : BAR0;
369
`ifdef PCI_BASE_ADDR1_MATCH_ENABLE
370
        BAR1             <= (  (pending_config_reg_write_address[7:2] == 6'h05)
371
                              & ~pending_config_reg_write_byte_enables[3])
372
                          ? pending_config_reg_write_data[`PCI_BASE_ADDR1_MATCH_RANGE] : BAR1;
373
`endif  // PCI_BASE_ADDR1_MATCH_ENABLE
374
        Interrupt_Line   <= (  (pending_config_reg_write_address[7:2] == 6'h0F)
375
                              & ~pending_config_reg_write_byte_enables[0])
376
                          ? pending_config_reg_write_data[7:0] : Interrupt_Line;
377
        pending_config_write_request <= 1'b0;  // NOTE this seems to prevent back-to-back writes.
378
      end
379
      else
380
      begin  // not writing from PCI side
381
// Words 0 and 2 are not writable.  Only certain bits in word 1 are writable.
382
        FB2B_En    <= FB2B_En;
383
        SERR_En    <= SERR_En;
384
        Par_Err_En <= Par_Err_En;
385
        Master_En  <= Master_En;
386
        Target_En  <= Target_En;
387
// Certain bits in word 1 are only clearable, not writable.
388
        Detected_PERR    <= Detected_PERR | master_got_parity_error | target_got_parity_error;
389
        Signaled_SERR    <= Signaled_SERR | master_asserted_serr | target_asserted_serr;
390
        Received_Master_Abort <= Received_Master_Abort | master_got_master_abort;
391
        Received_Target_Abort <= Received_Target_Abort | master_got_target_abort;
392
        Signaled_Target_Abort <= Signaled_Target_Abort | target_signaling_target_abort;
393
        Master_Caused_PERR <= Master_Caused_PERR | master_caused_parity_error;
394
// Certain bytes in higher words are writable
395
        Latency_Timer    <= Latency_Timer;
396
        Cache_Line_Size  <= Cache_Line_Size;
397
        BAR0             <= BAR0;
398
`ifdef PCI_BASE_ADDR1_MATCH_ENABLE
399
        BAR1             <= BAR1;
400
`endif  // PCI_BASE_ADDR1_MATCH_ENABLE
401
        Interrupt_Line   <= Interrupt_Line;
402
      end
403
    end
404
  end
405
 
406
// Tasks to manage the small SRAM visible in Memory Space
407 26 mihad
  reg    [PCI_BUS_DATA_RANGE:0] Test_Device_Mem [0:1023];  // address limits, not bits in address
408 19 mihad
// Tasks can't have local storage!  have to be module global
409 26 mihad
  reg    [9:0] sram_addr;
410 19 mihad
task Init_Test_Device_SRAM;
411
  begin
412 26 mihad
    for (sram_addr = 10'h000; sram_addr < 10'h3FF; sram_addr = sram_addr + 10'h001)
413 19 mihad
    begin
414
      Test_Device_Mem[sram_addr] = `BUS_IMPOSSIBLE_VALUE;
415
    end
416 26 mihad
    sram_addr = 10'h3FF; // maximum value must also be written!
417
    Test_Device_Mem[sram_addr] = `BUS_IMPOSSIBLE_VALUE;
418 19 mihad
  end
419
endtask
420
 
421
task Read_Test_Device_SRAM;
422 26 mihad
  input  [11:2] sram_address;
423 19 mihad
  input  [PCI_BUS_CBE_RANGE:0] byte_sel ;
424
  output [PCI_BUS_DATA_RANGE:0] target_read_data;
425
  reg    [PCI_BUS_DATA_RANGE:0] temp_val ;
426
  begin
427
    temp_val                = Test_Device_Mem[sram_address] ;
428
    target_read_data[7:0]   = byte_sel[0] ? temp_val[7:0]   : 0 ;
429
    target_read_data[15:8]  = byte_sel[1] ? temp_val[15:8]  : 0 ;
430
    target_read_data[23:16] = byte_sel[2] ? temp_val[23:16] : 0 ;
431
    target_read_data[31:24] = byte_sel[3] ? temp_val[31:24] : 0 ;
432
  end
433
endtask
434
 
435
// Tasks can't have local storage!  have to be module global
436
  reg    [PCI_BUS_DATA_RANGE:0] sram_temp;
437
task Write_Test_Device_SRAM;
438 26 mihad
  input  [11:2] sram_address;
439 19 mihad
  input  [PCI_BUS_DATA_RANGE:0] master_write_data;
440
  input  [PCI_BUS_CBE_RANGE:0] master_mask_l;
441
  begin
442
    sram_temp = Test_Device_Mem[sram_address];
443
    sram_temp[7:0]   = (~master_mask_l[0]) ? master_write_data[7:0]   : sram_temp[7:0];
444
    sram_temp[15:8]  = (~master_mask_l[1]) ? master_write_data[15:8]  : sram_temp[15:8];
445
    sram_temp[23:16] = (~master_mask_l[2]) ? master_write_data[23:16] : sram_temp[23:16];
446
    sram_temp[31:24] = (~master_mask_l[3]) ? master_write_data[31:24] : sram_temp[31:24];
447
    Test_Device_Mem[sram_address] = sram_temp[PCI_BUS_DATA_RANGE:0];
448
  end
449
endtask
450
 
451
// Make the DEVSEL_TRDY_STOP_OE output enable signal.  It must become
452
//   asserted as soon as one of those signals become asserted, and
453
//   must stay asserted one clock after the last one becomes deasserted.
454
  reg     prev_d_t_s_asserted;
455
  always @(posedge pci_ext_clk or posedge pci_reset_comb)
456
  begin
457
    if (pci_reset_comb)
458
    begin
459
      prev_d_t_s_asserted <= 1'b0;
460
    end
461
    else
462
    begin
463
      prev_d_t_s_asserted <= target_devsel_out | target_trdy_out | target_stop_out;
464
    end
465
  end
466
  assign  target_d_t_s_oe = target_devsel_out | target_trdy_out | target_stop_out
467
                          | prev_d_t_s_asserted;
468
 
469
// Make the PERR_OE signal.
470
// See the PCI Local Bus Spec Revision 2.2 section 3.7.4.1
471
// At time N, target_perr_check_next is set
472
// At time N+1, external data is latched, and irdy is also latched
473
// At time N+1, target_perr_check is latched
474
// At time N+2, calc_input_parity_prev is valid
475
// Also at N+2, external parity is valid
476
  reg     target_perr_prev, target_perr_check_next, target_perr_check;
477
  reg     target_perr_detected;
478
  reg     target_debug_force_bad_perr ;
479
 
480
  always @(posedge pci_ext_clk or posedge pci_reset_comb)
481
  begin
482
    if (pci_reset_comb)
483
        target_debug_force_bad_perr <= 1'b0 ;
484
    else
485
        target_debug_force_bad_perr <= target_debug_force_bad_par ;
486
  end
487
 
488
  always @(posedge pci_ext_clk or posedge pci_reset_comb)
489
  begin
490
    if (pci_reset_comb)
491
    begin
492
      target_perr_check <= 1'b0;
493
      target_perr_detected <= 1'b0;
494
      target_perr_out <= 1'b0;
495
      target_perr_prev <= 1'b0;
496
    end
497
    else
498
    begin
499
      target_perr_check <= target_perr_check_next;
500
      target_perr_detected <= target_perr_check & irdy_prev
501
                         & (calc_input_parity_prev != par_now);
502
      target_perr_out <= target_perr_check & irdy_prev & Par_Err_En
503
                                                                 // mihad - bad perr generation
504
                         & (calc_input_parity_prev != (par_now ^ target_debug_force_bad_perr));
505
      target_perr_prev <= target_perr_out;
506
    end
507
  end
508
  assign  target_perr_oe = target_perr_out | target_perr_prev;
509
 
510
// Make the SERR_OE signal
511
// See the PCI Local Bus Spec Revision 2.2 section 6.2.3.
512
  reg prev_prev_frame;
513
  always @(posedge pci_ext_clk or posedge pci_reset_comb)
514
  begin
515
    if (pci_reset_comb)
516
    begin
517
      prev_prev_frame <= 1'b0;
518
      target_serr_oe <= 1'b0;
519
    end
520
    else
521
    begin
522
      prev_prev_frame <= frame_prev;
523
      target_serr_oe <= ~prev_prev_frame & frame_prev
524
                      & SERR_En & Par_Err_En
525
                      & (calc_input_parity_prev != par_now);
526
    end
527
  end
528
  assign  target_asserted_serr = target_serr_oe;
529
  assign  target_got_parity_error = target_perr_detected | target_serr_oe;
530
 
531
// Remember whether this device drove DEVSEL last clock, which allows
532
// Zero-Wait-State Back-to-Back references
533
  wire    This_Target_Drove_DEVSEL_Last_Clock = target_d_t_s_oe;
534
 
535
// Remember whether the bus has correct parity.
536
// Used by Medium, slower Address Decode to prevent DEVSEL on bad Address Parity
537
  reg     prev_bus_par_ok, prev_prev_bus_par_ok;
538
  always @(posedge pci_ext_clk)
539
  begin
540
    prev_bus_par_ok <= (calc_input_parity_prev == par_now);
541
    prev_prev_bus_par_ok <= prev_bus_par_ok;
542
  end
543
 
544
// We want the Target to do certain behavior to let us test the interface.
545
// See the note in the Master section about the use of Address Bits to
546
//   encode Target Wait State, Target Completion, and Target Error info.
547
 
548
// signals used by Target test code to apply correct info to the PCI bus
549
  reg    [PCI_BUS_DATA_RANGE:0] hold_target_address;
550
  reg    [PCI_BUS_CBE_RANGE:0] hold_target_command;
551
  reg    [3:0] hold_target_initial_waitstates;
552
  reg    [3:0] hold_target_subsequent_waitstates;
553
  reg    [2:0] hold_target_termination;
554
  reg    [1:0] hold_target_devsel_speed;
555
  reg    [9:0] hold_target_terminate_on ;
556
  reg     hold_target_data_par_err;
557
  reg     hold_target_addr_par_err;
558
 
559
// Tasks which use the held PCI address to access internal info.  These tasks
560
//   update the address counter, emulating the target address counter during bursts.
561
// Store data from PCI bus into Config Register, and increment Write Pointer
562
task Capture_Config_Reg_Data_From_AD_Bus;
563
  input  [PCI_BUS_DATA_RANGE:0] master_write_data;
564
  input  [PCI_BUS_CBE_RANGE:0] master_mask_l;
565
  begin
566
    Write_Test_Device_Config_Regs (hold_target_address[7:2],
567
                           master_write_data[PCI_BUS_DATA_RANGE:0], master_mask_l[PCI_BUS_CBE_RANGE:0]);
568
    hold_target_address[7:2] = hold_target_address[7:2] + 6'h01;  // addr++
569
  end
570
endtask
571
 
572
// Drive Config Register Data onto AD bus, and increment Read Pointer
573
task Fetch_Config_Reg_Data_For_Read_Onto_AD_Bus;
574
  output [PCI_BUS_DATA_RANGE:0] target_read_data;
575
  begin
576
    Read_Test_Device_Config_Regs (hold_target_address[7:2], target_read_data[PCI_BUS_DATA_RANGE:0]);
577
    hold_target_address[7:2] = hold_target_address[7:2] + 6'h01;  // addr++
578
  end
579
endtask
580
 
581
// Store data from PCI bus into SRAM, and increment Write Pointer
582
task Capture_SRAM_Data_From_AD_Bus;
583
  input  [PCI_BUS_DATA_RANGE:0] master_write_data;
584
  input  [PCI_BUS_CBE_RANGE:0] master_mask_l;
585
  begin
586 26 mihad
    Write_Test_Device_SRAM (hold_target_address[11:2],
587 19 mihad
                            master_write_data[PCI_BUS_DATA_RANGE:0], master_mask_l[PCI_BUS_CBE_RANGE:0]);
588 26 mihad
    hold_target_address[11:2] = hold_target_address[11:2] + 10'h001;  // addr++
589 19 mihad
  end
590
endtask
591
 
592
// Drive SRAM Data onto AD bus, and increment Read Pointer
593
task Fetch_SRAM_Data_For_Read_Onto_AD_Bus;
594
  output [PCI_BUS_DATA_RANGE:0] target_read_data;
595
  begin
596 26 mihad
    Read_Test_Device_SRAM (hold_target_address[11:2], ~cbe_l_now, target_read_data[PCI_BUS_DATA_RANGE:0]);
597
    hold_target_address[11:2] = hold_target_address[11:2] + 10'h001;  // addr++
598 19 mihad
  end
599
endtask
600
 
601
// The target is able to execute Delayed Reads,
602
// See the PCI Local Bus Spec Revision 2.2 section 3.3.3.3
603
// To allow a delayed read to complete, read data must be available.
604
// Also a PCI command matching in Address, Command, Byte Enables,
605
//   and parity on address.
606
// If the region of memory is prefetchable and always returns all
607
//   bytes, it is OK to disregard the Byte Enables.
608
  reg     Delayed_Read_Started, Delayed_Read_Pending, Delayed_Read_Finished;
609
  reg    [PCI_BUS_DATA_RANGE:0] Delayed_Read_Address;
610
  reg    [PCI_BUS_CBE_RANGE:0] Delayed_Read_Command;
611
  reg    [PCI_BUS_CBE_RANGE:0] Delayed_Read_Mask_L;
612
  reg    [14:0] Delayed_Read_Discard_Counter;
613
  wire   [14:0] Delayed_Read_Discard_Limit = 15'h7FFF;  // change for debugging
614
  always @(posedge pci_ext_clk or posedge pci_reset_comb)
615
  begin
616
    if (pci_reset_comb)
617
    begin
618
      Delayed_Read_Pending <= 1'b0;
619
    end
620
    else
621
    begin
622
      Delayed_Read_Pending <= Delayed_Read_Started
623
          | (Delayed_Read_Pending & ~Delayed_Read_Finished
624
              & (Delayed_Read_Discard_Counter[14:0] < Delayed_Read_Discard_Limit[14:0]));
625
    end
626
  end
627
 
628
  always @(posedge pci_ext_clk)
629
  begin
630
    Delayed_Read_Discard_Counter[14:0] <= Delayed_Read_Started
631
                    ? 15'h0000 : Delayed_Read_Discard_Counter[14:0] + 15'h0001;
632
`ifdef VERBOSE_TEST_DEVICE
633
    if (Delayed_Read_Pending & (Delayed_Read_Discard_Counter[14:0]
634
                                     >= Delayed_Read_Discard_Limit[14:0]))
635
    begin
636
      $display (" test target %h - Delayed Read Discarded, at %t",
637
                    test_device_id[2:0], $time);
638
    end
639
    `NO_ELSE;
640
`endif // VERBOSE_TEST_DEVICE
641
  end
642
 
643
// Target tasks.  These know how to respond to the external masters.
644
// NOTE all tasks end with an @(posedge pci_ext_clk) statement
645
//      to let any signals asserted during that task settle out.
646
// If a task DOESN'T end with @(posedge pci_ext_clk), then it must
647
//      be called just before some other task which does.
648
 
649
parameter TEST_TARGET_SPINLOOP_MAX = 20;
650
 
651
task Clock_Wait_Unless_Reset;
652
  begin
653
    if (~pci_reset_comb)
654
    begin
655
      @ (posedge pci_ext_clk or posedge pci_reset_comb) ;
656
    end
657
    `NO_ELSE;
658
  end
659
endtask
660
 
661
task Assert_DEVSEL;
662
  begin
663
    target_devsel_out <= 1'b1;
664
  end
665
endtask
666
 
667
task Assert_TRDY;
668
  begin
669
    target_trdy_out <= 1'b1;
670
  end
671
endtask
672
 
673
task Assert_STOP;
674
  begin
675
    target_stop_out <= 1'b1;
676
  end
677
endtask
678
 
679
task Deassert_DEVSEL;
680
  begin
681
    target_devsel_out <= 1'b0;
682
  end
683
endtask
684
 
685
task Deassert_TRDY;
686
  begin
687
    target_trdy_out <= 1'b0;
688
  end
689
endtask
690
 
691
task Deassert_STOP;
692
  begin
693
    target_stop_out <= 1'b0;
694
  end
695
endtask
696
 
697
task Assert_Target_Continue_Or_Disconnect;
698
  input   do_target_disconnect;
699
  begin
700
    if (do_target_disconnect)
701
    begin
702
      Assert_DEVSEL;    Assert_TRDY;    Assert_STOP;
703
    end
704
    else
705
    begin
706
      Assert_DEVSEL;    Assert_TRDY;    Deassert_STOP;
707
    end
708
  end
709
endtask
710
 
711
// Execute_Target_Retry is called with nothing or DEVSEL asserted
712
//   tasks can't have local storage!  have to be module global
713
  integer iiii;
714
task Execute_Target_Retry_Undrive_DEVSEL;
715
  input   drive_ad_bus;
716
  input   signal_starting_delayed_read;
717
  input   signal_satisfied_delayed_read;
718
  begin
719
    for (iiii = 0; iiii < TEST_TARGET_SPINLOOP_MAX; iiii = iiii + 1)
720
    begin
721
      if ((iiii == 0) | frame_now | ~irdy_now)  // At least one stop, then Not Finished
722
      begin
723
        target_ad_out <= `BUS_IMPOSSIBLE_VALUE;
724
        target_ad_oe <= drive_ad_bus;
725
        target_debug_force_bad_par <= 1'b0;
726
        target_perr_check_next <= ~drive_ad_bus;
727
        target_signaling_target_abort <= 1'b0;
728
        Delayed_Read_Started <= signal_starting_delayed_read;
729
        Delayed_Read_Finished <= signal_satisfied_delayed_read;
730
        Assert_DEVSEL;  // signal DEVSEL and Stop, indicating Retry
731
        Deassert_TRDY;
732
        Assert_STOP;
733
        if (signal_starting_delayed_read)
734
        begin
735
          Delayed_Read_Address[PCI_BUS_DATA_RANGE:0] = hold_target_address[PCI_BUS_DATA_RANGE:0];
736
          Delayed_Read_Command[PCI_BUS_CBE_RANGE:0] =  hold_target_command[PCI_BUS_CBE_RANGE:0];
737
          Delayed_Read_Mask_L[PCI_BUS_CBE_RANGE:0] = cbe_l_now[PCI_BUS_CBE_RANGE:0];
738
        end
739
        `NO_ELSE;
740
      end
741
      else
742
      begin
743
        target_ad_out[PCI_BUS_DATA_RANGE:0] <= `BUS_IMPOSSIBLE_VALUE;
744
        target_ad_oe <= 1'b0;  // unconditionally undrive ad bus
745
        target_debug_force_bad_par <= 1'b0;
746
        target_perr_check_next <= 1'b0;
747
        target_signaling_target_abort <= 1'b0;
748
        Delayed_Read_Started <= 1'b0;
749
        Delayed_Read_Finished <= 1'b0;
750
        Deassert_DEVSEL;  // Master saw us, so leave
751
        Deassert_TRDY;
752
        Deassert_STOP;
753
        iiii = TEST_TARGET_SPINLOOP_MAX + 1;  // break
754
      end
755
      Clock_Wait_Unless_Reset;  // wait for outputs to settle
756
      signal_satisfied_delayed_read = 1'b0;
757
    end
758
`ifdef NORMAL_PCI_CHECKS
759
    if (~pci_reset_comb & (iiii == TEST_TARGET_SPINLOOP_MAX))
760
    begin
761
      $display ("*** test target %h - Bus didn't go Idle during Target Retry, at %t",
762
                test_device_id[2:0], $time);
763
      error_detected <= ~error_detected;
764
    end
765
    `NO_ELSE;
766
    if (~pci_reset_comb & irdy_now)
767
    begin
768
      $display ("*** test target %h - IRDY didn't deassert at end of Target Retry, at %t",
769
                   test_device_id[2:0], $time);
770
      error_detected <= ~error_detected;
771
    end
772
    `NO_ELSE;
773
`endif // NORMAL_PCI_CHECKS
774
  end
775
endtask
776
 
777
// This Test Device is capable of doing Fast Decode.  To do this,
778
//   it must make sure not to cause conflicts on DEVSEL, IRDY,
779
//   STOP, or PERR.  To achieve this, the task must hold off on
780
//   making DEVSEL unless either
781
//   1) the bus was just Idle
782
//   2) this device also drove DEVSEL the previous clock (I presume this
783
//      means that DEVSEL was driven LOW!!  Would HIGH be an idle cycle?)
784
// See the PCI Local Bus Spec Revision 2.2 section 3.4.2
785
//
786
// See the PCI Local Bus Spec Revision 2.2 section 3.7.3 for what
787
//   to do if an Address Parity Error is detected.
788
// Since this behaviorial test knows that an address parity error is
789
//   comming, it holds off fast decode parity errors, and always
790
//   allows a master abort to happen.  This would not be possible in
791
//   a gate-level PCI interface.  For FAST decode, that interface would
792
//   have to continue on as if there was no error.  It would be nice
793
//   if it prevented any writes of data, or reads with side-effects.
794
task Wait_Till_DEVSEL_Possible;
795
  output  devsel_asserted;
796
  output  fast_devsel_asserted;
797
  output  signal_satisfied_delayed_read;
798
  begin
799
    if ((hold_target_devsel_speed[1:0] == `Test_Devsel_Fast) & ~Delayed_Read_Pending
800
          & (   (~frame_prev & ~irdy_prev)
801
              | (~frame_prev &  irdy_prev & This_Target_Drove_DEVSEL_Last_Clock) )
802
          & ~(hold_target_addr_par_err & Par_Err_En))
803
    begin
804
`ifdef VERBOSE_TEST_DEVICE
805
      $display (" test target %h - doing fast DEVSEL, at %t",
806
                    test_device_id[2:0], $time);
807
`endif // VERBOSE_TEST_DEVICE
808
      devsel_asserted = 1'b1;  // fast decode
809
      fast_devsel_asserted = 1'b1;  // fast decode
810
      signal_satisfied_delayed_read = 1'b0;
811
    end
812
    else
813
    begin
814
      target_ad_out <= `BUS_IMPOSSIBLE_VALUE;
815
      target_ad_oe <= 1'b0;  // Should this drive AD when not DEVSEL?
816
      target_debug_force_bad_par <= 1'b0;
817
      target_perr_check_next <= 1'b0;
818
      target_signaling_target_abort <= 1'b0;
819
      Delayed_Read_Started <= 1'b0;
820
      Delayed_Read_Finished <= 1'b0;
821
      Deassert_DEVSEL;
822
      Deassert_TRDY;
823
      Deassert_STOP;
824
      Clock_Wait_Unless_Reset;  // wait for outputs to settle
825
      if (Delayed_Read_Pending
826
            & (   (hold_target_command[3:0] == PCI_COMMAND_MEMORY_READ)
827
                | (hold_target_command[3:0] == PCI_COMMAND_MEMORY_READ_MULTIPLE)
828
                | (hold_target_command[3:0] == PCI_COMMAND_MEMORY_READ_LINE)
829
                | (hold_target_command[3:0] == PCI_COMMAND_CONFIG_READ) )
830
            & (   (    (hold_target_address[PCI_BUS_DATA_RANGE:0] & 32'hFF0000FF)  // partial test address match
831
                    != (Delayed_Read_Address[PCI_BUS_DATA_RANGE:0] & 32'hFF0000FF))
832
                | (hold_target_command[PCI_BUS_CBE_RANGE:0] != Delayed_Read_Command[PCI_BUS_CBE_RANGE:0])
833
                | (cbe_l_now[PCI_BUS_CBE_RANGE:0] != Delayed_Read_Mask_L[PCI_BUS_CBE_RANGE:0]) ) )
834
      begin
835
        Execute_Target_Retry_Undrive_DEVSEL (1'b1, 1'b0, 1'b0);
836
        devsel_asserted = 1'b0;  // tell calling routine to not claim DEVSEL.
837
        fast_devsel_asserted = 1'b0;
838
        signal_satisfied_delayed_read = 1'b0;
839
      end
840
      else
841
      begin
842
        if /*(*/(  (hold_target_devsel_speed[1:0] == `Test_Devsel_Fast)
843
             | (hold_target_devsel_speed[1:0] == `Test_Devsel_Medium) )
844
             /*  & ((calc_input_parity_prev == par_now) | ~Par_Err_En))*/
845
        begin
846
          devsel_asserted = 1'b1;  // medium decode
847
          fast_devsel_asserted = 1'b0;  // medium decode
848
          signal_satisfied_delayed_read = Delayed_Read_Pending
849
                & (   (hold_target_command[3:0] == PCI_COMMAND_MEMORY_READ)
850
                    | (hold_target_command[3:0] == PCI_COMMAND_MEMORY_READ_MULTIPLE)
851
                    | (hold_target_command[3:0] == PCI_COMMAND_MEMORY_READ_LINE)
852
                    | (hold_target_command[3:0] == PCI_COMMAND_CONFIG_READ) );
853
        end
854
        else
855
        begin
856
          target_ad_out <= `BUS_IMPOSSIBLE_VALUE;
857
          target_ad_oe <= 1'b0;  // Should this drive AD when not DEVSEL?
858
          target_debug_force_bad_par <= 1'b0;
859
          target_perr_check_next <= 1'b0;
860
          target_signaling_target_abort <= 1'b0;
861
          Delayed_Read_Started <= 1'b0;
862
          Delayed_Read_Finished <= 1'b0;
863
          Deassert_DEVSEL;
864
          Deassert_TRDY;
865
          Deassert_STOP;
866
          Clock_Wait_Unless_Reset;
867
          if /*(*/(hold_target_devsel_speed[1:0] == `Test_Devsel_Slow)
868
                /*& (prev_bus_par_ok | ~Par_Err_En))*/
869
          begin
870
            devsel_asserted = 1'b1;  // slow decode
871
            fast_devsel_asserted = 1'b0;  // slow decode
872
            signal_satisfied_delayed_read = Delayed_Read_Pending
873
                & (   (hold_target_command[3:0] == PCI_COMMAND_MEMORY_READ)
874
                    | (hold_target_command[3:0] == PCI_COMMAND_MEMORY_READ_MULTIPLE)
875
                    | (hold_target_command[3:0] == PCI_COMMAND_MEMORY_READ_LINE)
876
                    | (hold_target_command[3:0] == PCI_COMMAND_CONFIG_READ) );
877
          end
878
          else
879
          begin
880
            target_ad_out <= `BUS_IMPOSSIBLE_VALUE;
881
            target_ad_oe <= 1'b0;  // Should this drive AD when not DEVSEL?
882
            target_debug_force_bad_par <= 1'b0;
883
            target_perr_check_next <= 1'b0;
884
            target_signaling_target_abort <= 1'b0;
885
            Delayed_Read_Started <= 1'b0;
886
            Delayed_Read_Finished <= 1'b0;
887
            Deassert_DEVSEL;
888
            Deassert_TRDY;
889
            Deassert_STOP;
890
            Clock_Wait_Unless_Reset;  // wait for outputs to settle
891
            if (/*(*/hold_target_devsel_speed[1:0] == `Test_Devsel_Subtractive)
892
                  /*& (prev_prev_bus_par_ok | ~Par_Err_En))*/
893
            begin
894
              devsel_asserted = 1'b1;  // subtractive decode
895
              fast_devsel_asserted = 1'b0;  // subtractive decode
896
              signal_satisfied_delayed_read = Delayed_Read_Pending
897
                & (   (hold_target_command[3:0] == PCI_COMMAND_MEMORY_READ)
898
                    | (hold_target_command[3:0] == PCI_COMMAND_MEMORY_READ_MULTIPLE)
899
                    | (hold_target_command[3:0] == PCI_COMMAND_MEMORY_READ_LINE)
900
                    | (hold_target_command[3:0] == PCI_COMMAND_CONFIG_READ) );
901
 
902
            end
903
            else
904
            begin
905
              devsel_asserted = 1'b0;  // must have had bad parity
906
              fast_devsel_asserted = 1'b0;
907
              signal_satisfied_delayed_read = 1'b0;
908
            end
909
          end
910
        end
911
      end
912
    end
913
`ifdef NORMAL_PCI_CHECKS
914
    if (~pci_reset_comb & (devsel_asserted == 1'b1)
915
                        & (hold_target_addr_par_err == 1'b1))
916
    begin
917
      $display ("*** test target %h - DEVSEL Asserted when Address Parity Error expected, at %t",
918
                   test_device_id[2:0], $time);
919
      error_detected <= ~error_detected;
920
    end
921
    `NO_ELSE;
922
`endif // NORMAL_PCI_CHECKS
923
  end
924
endtask
925
 
926
// While asserting DEVSEL, wait zero or more clocks as commanded by master
927
// This might be called with 1 waitstate before the read data can be OE'd
928
//    or before the Master Parity can be checked.
929
// Tasks can't have local storage!  have to be module global
930
  reg    [3:0] cnt1;
931
task Execute_Target_Waitstates;
932
  input   drive_ad_bus;
933
  input   enable_parity_check;
934
  input  [3:0] num_waitstates;
935
  begin
936
    for (cnt1 = 4'h0; cnt1 < num_waitstates[3:0]; cnt1 = cnt1 + 4'h1)
937
    begin
938
`ifdef NORMAL_PCI_CHECKS
939
    if (!pci_reset_comb & ~frame_now & ~irdy_now)
940
    begin
941
      $display ("*** test target %h - Execute Target Waitstates Wait States called when no Master, at %t",
942
                   test_device_id[2:0], $time);
943
      error_detected <= ~error_detected;
944
    end
945
    `NO_ELSE;
946
`endif // NORMAL_PCI_CHECKS
947
      target_ad_out <= `BUS_WAIT_STATE_VALUE;
948
      target_ad_oe <= drive_ad_bus;
949
      target_debug_force_bad_par <= 1'b0;
950
      target_perr_check_next <= enable_parity_check;
951
      target_signaling_target_abort <= 1'b0;
952
      Delayed_Read_Started <= 1'b0;
953
      Delayed_Read_Finished <= 1'b0;
954
      Assert_DEVSEL;
955
      Deassert_TRDY;
956
      Deassert_STOP;
957
      Clock_Wait_Unless_Reset;  // wait for outputs to settle
958
    end
959
  end
960
endtask
961
 
962
// DEVSEL already asserted upon entry to this task.  OK to watch Parity
963
// Tasks can't have local storage!  have to be module global
964
  integer ii;
965
task Linger_Until_Master_Waitstates_Done;
966
  input   drive_ad_bus;
967
  input  [PCI_BUS_DATA_RANGE:0] target_read_data;
968
  input   do_target_disconnect;
969
  begin
970
    for (ii = 0; ii < TEST_TARGET_SPINLOOP_MAX; ii = ii + 1)
971
    begin
972
      if (frame_now & ~irdy_now)  // master executing wait states
973
      begin
974
        target_ad_out[PCI_BUS_DATA_RANGE:0] <= target_read_data[PCI_BUS_DATA_RANGE:0];
975
        target_ad_oe <= drive_ad_bus;
976
        target_debug_force_bad_par <= hold_target_data_par_err;
977
        target_perr_check_next <= ~drive_ad_bus;
978
        target_signaling_target_abort <= 1'b0;
979
        Delayed_Read_Started <= 1'b0;
980
        Delayed_Read_Finished <= 1'b0;
981
        Assert_Target_Continue_Or_Disconnect (do_target_disconnect);
982
        Clock_Wait_Unless_Reset;  // wait for outputs to settle
983
      end
984
      else
985
      begin
986
      ii = TEST_TARGET_SPINLOOP_MAX + 1;  // break
987
      end
988
    end
989
`ifdef NORMAL_PCI_CHECKS
990
    if (~pci_reset_comb & ~frame_now & ~irdy_now)
991
    begin
992
      $display ("*** test target %h - Linger during Master Wait States called when no Master, at %t",
993
                   test_device_id[2:0], $time);
994
      error_detected <= ~error_detected;
995
    end
996
    `NO_ELSE;
997
    if (~pci_reset_comb & (ii == TEST_TARGET_SPINLOOP_MAX))
998
    begin
999
      $display ("*** test target %h - Bus stuck in Master Wait States during Target ref, at %t",
1000
                   test_device_id[2:0], $time);
1001
      error_detected <= ~error_detected;
1002
    end
1003
    `NO_ELSE;
1004
`endif // NORMAL_PCI_CHECKS
1005
  end
1006
endtask
1007
 
1008
// Execute_Target_Abort.  This must be called with DEVSEL asserted
1009
// Tasks can't have local storage!  have to be module global
1010
  integer iii;
1011
task Execute_Target_Abort_Undrive_DEVSEL;
1012
  input   drive_ad_bus;
1013
  input   signal_satisfied_delayed_read;
1014
  begin
1015
`ifdef NORMAL_PCI_CHECKS
1016
    if (~pci_reset_comb & (target_devsel_out == 1'b0))
1017
    begin
1018
      $display ("*** test target %h - DEVSEL not asserted when starting Target Abort, at %t",
1019
                   test_device_id[2:0], $time);
1020
      error_detected <= ~error_detected;
1021
    end
1022
    `NO_ELSE;
1023
`endif // NORMAL_PCI_CHECKS
1024
    for (iii = 0; iii < TEST_TARGET_SPINLOOP_MAX; iii = iii + 1)
1025
    begin
1026
      if ((iii == 0) | frame_now | ~irdy_now)  // At least one stop, Master Not Finished
1027
      begin
1028
        target_ad_out[PCI_BUS_DATA_RANGE:0] <= `BUS_IMPOSSIBLE_VALUE;
1029
        target_ad_oe <= 1'b0;  // Should this drive AD when not DEVSEL?
1030
        target_debug_force_bad_par <= 1'b0;
1031
        target_perr_check_next <= 1'b0;
1032
        target_signaling_target_abort <= 1'b1;
1033
        Delayed_Read_Started <= 1'b0;
1034
        Delayed_Read_Finished <= signal_satisfied_delayed_read;
1035
        Deassert_DEVSEL;  // Signal Target Abort
1036
        Deassert_TRDY;
1037
        Assert_STOP;
1038
      end
1039
      else
1040
      begin
1041
        target_ad_out[PCI_BUS_DATA_RANGE:0] <= `BUS_IMPOSSIBLE_VALUE;
1042
        target_ad_oe <= 1'b0;  // unconditionally undrive ad bus
1043
        target_debug_force_bad_par <= 1'b0;
1044
        target_perr_check_next <= 1'b0;
1045
        target_signaling_target_abort <= 1'b0;
1046
        Delayed_Read_Started <= 1'b0;
1047
        Delayed_Read_Finished <= 1'b0;
1048
        Deassert_DEVSEL;  // Signal Target Abort
1049
        Deassert_TRDY;
1050
        Deassert_STOP;  // Master saw us, so leave
1051
        iii = TEST_TARGET_SPINLOOP_MAX + 1;  // break
1052
      end
1053
      Clock_Wait_Unless_Reset;  // wait for outputs to settle
1054
      signal_satisfied_delayed_read = 1'b0;
1055
    end
1056
`ifdef NORMAL_PCI_CHECKS
1057
    if (~pci_reset_comb & irdy_now)
1058
    begin
1059
      $display ("*** test target %h - Master didn't deassert IRDY at end of Target Abort, at %t",
1060
                   test_device_id[2:0], $time);
1061
      error_detected <= ~error_detected;
1062
    end
1063
    `NO_ELSE;
1064
    if (~pci_reset_comb & (iii == TEST_TARGET_SPINLOOP_MAX))
1065
    begin
1066
      $display ("*** test target %h - Bus didn't go Idle during Target Abort, at %t",
1067
                   test_device_id[2:0], $time);
1068
      error_detected <= ~error_detected;
1069
    end
1070
    `NO_ELSE;
1071
`endif // NORMAL_PCI_CHECKS
1072
  end
1073
endtask
1074
 
1075
// Transfer a word with or without target termination, and act on Master Termination
1076
task Execute_Target_Ref_Undrive_DEVSEL_On_Any_Termination;
1077
  input   drive_ad_bus;
1078
  input   do_target_disconnect;
1079
  input   signal_satisfied_delayed_read;
1080
  input  [PCI_BUS_DATA_RANGE:0] target_read_data;
1081
  output [PCI_BUS_DATA_RANGE:0] master_write_data;
1082
  output [PCI_BUS_CBE_RANGE:0] master_mask_l;
1083
  output  target_was_terminated;
1084
  begin
1085
    target_ad_out[PCI_BUS_DATA_RANGE:0] <= target_read_data[PCI_BUS_DATA_RANGE:0];
1086
    target_ad_oe <= drive_ad_bus;
1087
    target_debug_force_bad_par <= hold_target_data_par_err;
1088
    target_perr_check_next <= ~drive_ad_bus;
1089
    target_signaling_target_abort <= 1'b0;
1090
    Delayed_Read_Started <= 1'b0;
1091
    Delayed_Read_Finished <= signal_satisfied_delayed_read;
1092
    Assert_Target_Continue_Or_Disconnect (do_target_disconnect);
1093
    Clock_Wait_Unless_Reset;  // wait for outputs to settle
1094
    Linger_Until_Master_Waitstates_Done (drive_ad_bus,
1095
                       target_read_data[PCI_BUS_DATA_RANGE:0], do_target_disconnect);
1096
    master_write_data[PCI_BUS_DATA_RANGE:0] = ad_now[PCI_BUS_DATA_RANGE:0];  // unconditionally grab.
1097
    master_mask_l[PCI_BUS_CBE_RANGE:0] = cbe_l_now[PCI_BUS_CBE_RANGE:0];
1098
    if (frame_now & irdy_now & ~do_target_disconnect)
1099
    begin
1100
        target_was_terminated = 1'b0;
1101
    end
1102
    else
1103
    begin
1104
      if (frame_now & irdy_now & do_target_disconnect)  // doing Target Termination
1105
      begin
1106
        target_ad_out <= `BUS_IMPOSSIBLE_VALUE;
1107
        target_ad_oe <= drive_ad_bus;
1108
        target_debug_force_bad_par <= 1'b0;
1109
        target_perr_check_next <= ~drive_ad_bus;
1110
        target_signaling_target_abort <= 1'b0;
1111
        Delayed_Read_Started <= 1'b0;
1112
        Delayed_Read_Finished <= 1'b0;
1113
        Assert_DEVSEL;
1114
        Deassert_TRDY;
1115
        Assert_STOP;
1116
        Clock_Wait_Unless_Reset;  // give master a chance to turn FRAME around
1117
      end
1118
      `NO_ELSE;
1119
`ifdef NORMAL_PCI_CHECKS
1120
      if (~pci_reset_comb & ~(~frame_now & irdy_now))  // error if not last master data phase
1121
      begin
1122
        $display ("*** test target %h - Master entered fatally odd state in Target Ref, at %t",
1123
                     test_device_id[2:0], $time);
1124
        error_detected <= ~error_detected;
1125
      end
1126
      `NO_ELSE;
1127
`endif // NORMAL_PCI_CHECKS
1128
      target_ad_out <= `BUS_IMPOSSIBLE_VALUE;
1129
      target_ad_oe <= 1'b0;  // unconditionally undrive ad bus
1130
      target_debug_force_bad_par <= 1'b0;
1131
      target_perr_check_next <= 1'b0;
1132
      target_signaling_target_abort <= 1'b0;
1133
      Delayed_Read_Started <= 1'b0;
1134
      Delayed_Read_Finished <= 1'b0;
1135
      Deassert_DEVSEL;
1136
      Deassert_TRDY;
1137
      Deassert_STOP;
1138
      Clock_Wait_Unless_Reset;
1139
`ifdef NORMAL_PCI_CHECKS
1140
      if (~pci_reset_comb & irdy_now)
1141
      begin
1142
        $display ("*** test target %h - IRDY didn't deassert at end of Master Termination, at %t",
1143
                     test_device_id[2:0], $time);
1144
        error_detected <= ~error_detected;
1145
      end
1146
      `NO_ELSE;
1147
`endif // NORMAL_PCI_CHECKS
1148
      target_was_terminated = 1'b1;
1149
    end
1150
  end
1151
endtask
1152
 
1153
`define TEST_TARGET_DOING_CONFIG_READ   2'b00
1154
`define TEST_TARGET_DOING_CONFIG_WRITE  2'b01
1155
`define TEST_TARGET_DOING_SRAM_READ     2'b10
1156
`define TEST_TARGET_DOING_SRAM_WRITE    2'b11
1157
 
1158
task Report_On_Target_PCI_Ref_Start;
1159
  input  [1:0] reference_type;
1160
  begin
1161
    case (reference_type[1:0])
1162
    `TEST_TARGET_DOING_CONFIG_READ:
1163
      $display (" test target %h - Starting Config Read, at %t",
1164
                    test_device_id[2:0], $time);
1165
    `TEST_TARGET_DOING_CONFIG_WRITE:
1166
      $display (" test target %h - Starting Config Write, at %t",
1167
                    test_device_id[2:0], $time);
1168
    `TEST_TARGET_DOING_SRAM_READ:
1169
      $display (" test target %h - Starting Memory Read, at %t",
1170
                    test_device_id[2:0], $time);
1171
    `TEST_TARGET_DOING_SRAM_WRITE:
1172
      $display (" test target %h - Starting Memory Write, at %t",
1173
                    test_device_id[2:0], $time);
1174
    default:
1175
      $display ("*** test target %h - Doing Unknown Reference, at %t",
1176
                    test_device_id[2:0], $time);
1177
    endcase
1178
`ifdef VERBOSE_TEST_DEVICE
1179
    Report_Target_Reference_Paramaters;
1180
`endif // VERBOSE_TEST_DEVICE
1181
  end
1182
endtask
1183
 
1184
// Transfer either a burst of Config Registers or SRAM Contents across the PCI Bus
1185
// Tasks can't have local storage!  have to be module global
1186
  reg     devsel_asserted, fast_devsel_asserted, target_was_terminated;
1187
  reg    [3:0] wait_states_this_time;
1188
  reg     do_abort_this_time, do_retry_this_time, do_disconnect_this_time;
1189
  reg     abort_needs_waitstate;
1190
  reg    [PCI_BUS_DATA_RANGE:0] master_write_data;
1191
  reg    [PCI_BUS_DATA_RANGE:0] target_read_data;
1192
  reg    [PCI_BUS_CBE_RANGE:0] master_mask_l;
1193
  reg     drive_ad_bus;
1194
  reg     signal_satisfied_delayed_read;
1195
task Execute_Target_PCI_Ref;
1196
  input  [1:0] reference_type;
1197
  output  saw_fast_back_to_back;
1198
  reg     [9:0] number_of_transfers ;
1199
  begin
1200
 
1201
    number_of_transfers = 0 ;
1202
`ifdef REPORT_TEST_DEVICE
1203
    Report_On_Target_PCI_Ref_Start (reference_type[1:0]);
1204
`endif // REPORT_TEST_DEVICE
1205
    Wait_Till_DEVSEL_Possible (devsel_asserted, fast_devsel_asserted,
1206
                                          signal_satisfied_delayed_read);
1207
    if (devsel_asserted == 1'b1)
1208
    begin
1209
// Target must drive AD bus even if it is going to do an abort or retry.
1210
// See the PCI Local Bus Spec Revision 2.2 section 3.3.1
1211
      drive_ad_bus = (reference_type[1:0] == `TEST_TARGET_DOING_CONFIG_READ)
1212
                   | (reference_type[1:0] == `TEST_TARGET_DOING_SRAM_READ);
1213
      wait_states_this_time[3:0] = hold_target_initial_waitstates[3:0];
1214
      abort_needs_waitstate = (hold_target_initial_waitstates[3:0] == 4'h0);
1215
 
1216
      do_abort_this_time = ( (hold_target_termination[2:0] == `Test_Target_Abort) && (hold_target_terminate_on == 1) );
1217
 
1218
      do_retry_this_time = ( (hold_target_termination[2:0] == `Test_Target_Retry_Before) && (hold_target_terminate_on == 1) ) |
1219
                           (hold_target_termination[2:0] == `Test_Target_Start_Delayed_Read) ;
1220
 
1221
      do_disconnect_this_time = ( (hold_target_termination[2:0] == `Test_Target_Disc_With) && (hold_target_terminate_on == 1) ) ;
1222
 
1223
// If the bottom 2 bits of the Address aren't 2'b00, only transfer 1 word.
1224
// See the PCI Local Bus Spec Revision 2.2 section 3.2.2.2
1225
      do_disconnect_this_time = do_disconnect_this_time
1226
                              | (hold_target_address[1:0] != 2'b00);
1227
// If Fast Decode and it's a read, don't drive data for 1 clock to avoid AD bus fight
1228
// See the PCI Local Bus Spec Revision 2.2 section 3.3.1
1229
      if (fast_devsel_asserted & drive_ad_bus)
1230
      begin
1231
        Execute_Target_Waitstates (1'b0, 1'b0, 4'h1);  // avoid collisions on AD bus
1232
        if (wait_states_this_time[3:0] != 4'h0)
1233
        begin
1234
          wait_states_this_time[3:0] = wait_states_this_time[3:0] - 4'h1;
1235
        end
1236
        `NO_ELSE;
1237
      end
1238
      `NO_ELSE;
1239
      target_was_terminated = 1'b0;
1240
      while (target_was_terminated == 1'b0)
1241
      begin
1242
        Execute_Target_Waitstates (drive_ad_bus, ~drive_ad_bus,
1243
                                            wait_states_this_time[3:0]);
1244
        if (do_abort_this_time)
1245
        begin
1246
          if (abort_needs_waitstate)
1247
          begin
1248
            Execute_Target_Waitstates (drive_ad_bus, ~drive_ad_bus, 4'h1);
1249
          end
1250
          `NO_ELSE;
1251
          Execute_Target_Abort_Undrive_DEVSEL (drive_ad_bus,
1252
                                               signal_satisfied_delayed_read);
1253
          target_was_terminated = 1'b1;
1254
        end
1255
        else if (do_retry_this_time)
1256
        begin
1257
          Execute_Target_Retry_Undrive_DEVSEL (drive_ad_bus,
1258
                (hold_target_termination[2:0] == `Test_Target_Start_Delayed_Read)
1259
              & (   (hold_target_command[PCI_BUS_CBE_RANGE:0] ==
1260
                                              PCI_COMMAND_MEMORY_READ)
1261
                  | (hold_target_command[PCI_BUS_CBE_RANGE:0] ==
1262
                                              PCI_COMMAND_MEMORY_READ_MULTIPLE)
1263
                  | (hold_target_command[PCI_BUS_CBE_RANGE:0] ==
1264
                                              PCI_COMMAND_MEMORY_READ_LINE)
1265
                  | (hold_target_command[PCI_BUS_CBE_RANGE:0] ==
1266
                                              PCI_COMMAND_CONFIG_READ) ),
1267
                                               signal_satisfied_delayed_read);
1268
          target_was_terminated = 1'b1;
1269
        end
1270
        else  // at least one data item should be read out of this device
1271
        begin
1272
//          do_disconnect_this_time = do_disconnect_this_time  // prevent address roll-over
1273
//                            | (hold_target_address[7:2] == 6'h3F);
1274
          if (reference_type[1:0] == `TEST_TARGET_DOING_CONFIG_READ)
1275
          begin
1276
            Fetch_Config_Reg_Data_For_Read_Onto_AD_Bus (target_read_data[PCI_BUS_DATA_RANGE:0]);
1277
          end
1278
          `NO_ELSE;
1279
          if (reference_type[1:0] == `TEST_TARGET_DOING_SRAM_READ)
1280
          begin
1281
            Fetch_SRAM_Data_For_Read_Onto_AD_Bus (target_read_data[PCI_BUS_DATA_RANGE:0]);
1282
          end
1283
          `NO_ELSE;
1284
          Execute_Target_Ref_Undrive_DEVSEL_On_Any_Termination
1285
                           (drive_ad_bus, do_disconnect_this_time,
1286
                            signal_satisfied_delayed_read,
1287
                            target_read_data[PCI_BUS_DATA_RANGE:0],
1288
                            master_write_data[PCI_BUS_DATA_RANGE:0],
1289
                            master_mask_l[PCI_BUS_CBE_RANGE:0],
1290
                            target_was_terminated);
1291
          number_of_transfers = number_of_transfers + 1 ;
1292
 
1293
          if (reference_type[1:0] == `TEST_TARGET_DOING_CONFIG_WRITE)
1294
          begin
1295
            Capture_Config_Reg_Data_From_AD_Bus (master_write_data[PCI_BUS_DATA_RANGE:0],
1296
                                                 master_mask_l[PCI_BUS_CBE_RANGE:0]);
1297
          end
1298
          `NO_ELSE;
1299
          if (reference_type[1:0] == `TEST_TARGET_DOING_SRAM_WRITE)
1300
          begin
1301
            Capture_SRAM_Data_From_AD_Bus (master_write_data[PCI_BUS_DATA_RANGE:0],
1302
                                           master_mask_l[PCI_BUS_CBE_RANGE:0]);
1303
          end
1304
 
1305
          `NO_ELSE;
1306
// set up for the next transfer
1307
          wait_states_this_time[3:0] = hold_target_subsequent_waitstates[3:0];
1308
          abort_needs_waitstate = 1'b0;
1309
          /*do_abort_this_time = (hold_target_termination[2:0]
1310
                                            == `Test_Target_Abort_Before_Second);
1311
          do_retry_this_time = (hold_target_termination[2:0]
1312
                                            == `Test_Target_Retry_Before_Second);
1313
          do_disconnect_this_time = (hold_target_termination[2:0]
1314
                                      == `Test_Target_Disc_With_Second);*/
1315
 
1316
          do_abort_this_time = ( (hold_target_termination[2:0] == `Test_Target_Abort) && (hold_target_terminate_on == (number_of_transfers + 1)) );
1317
 
1318
          do_retry_this_time = ( (hold_target_termination[2:0] == `Test_Target_Retry_Before) && (hold_target_terminate_on == (number_of_transfers + 1)) ) ;
1319
 
1320
          do_disconnect_this_time = ( (hold_target_termination[2:0] == `Test_Target_Disc_With) && (hold_target_terminate_on == (number_of_transfers + 1)) ) ;
1321
 
1322
          signal_satisfied_delayed_read = 1'b0;
1323
        end
1324
      end
1325
// Watch for Fast Back-to-Back reference.  If seen, do not go to the top
1326
//   of the Target Idle Loop, which automatically waits for one clock.
1327
// Instead go directly to see if this device is addressed.
1328
// This transition is manditory even if the device can't do
1329
//   fast-back-to-back transfers!
1330
// See the PCI Local Bus Spec Revision 2.2 section 3.4.2.
1331
      saw_fast_back_to_back = frame_now & ~irdy_now;
1332
// No clock here to let this dovetail with the next reference?
1333
    end
1334
    else
1335
    begin  // no devsel, so it must have been an address parity error
1336
      saw_fast_back_to_back = 1'b0;
1337
    end
1338
  end
1339
endtask
1340
 
1341
// Task to print debug info
1342
// NOTE This must change if bit allocation changes
1343
task Report_Target_Reference_Paramaters;
1344
  begin
1345
    if (hold_target_address[23:9] != 15'h0000)
1346
    begin
1347
      $display ("  Target Devsel Speed %h, Target Termination %h,",
1348
            hold_target_devsel_speed[1:0], hold_target_termination[2:0]);
1349
      $display ("  First Target Data Wait States %h, Subsequent Target Data Wait States %h",
1350
            hold_target_initial_waitstates[3:0],
1351
            hold_target_subsequent_waitstates[3:0]);
1352
      $display ("  Addr Par Error %h, Data Par Error %h",
1353
            hold_target_addr_par_err, hold_target_data_par_err);
1354
    end
1355
    `NO_ELSE;
1356
  end
1357
endtask
1358
 
1359
task Reset_Target_To_Idle;
1360
  begin
1361
    Init_Test_Device_SRAM;
1362
    target_ad_oe <= 1'b0;
1363
    target_devsel_out <= 1'b0;
1364
    target_trdy_out <= 1'b0;
1365
    target_stop_out <= 1'b0;
1366
    target_perr_check_next <= 1'b0;
1367
    target_signaling_target_abort <= 1'b0;
1368
    Delayed_Read_Started <= 1'b0;
1369
    Delayed_Read_Finished <= 1'b0;
1370
  end
1371
endtask
1372
 
1373
// Config References are described in PCI Local Bus Spec
1374
// Revision 2.2 section 3.2.2.3.4
1375
// The idea is that a Config command must be seen, IDSEL must be LOW,
1376
// AD[1:0] must be 2'b00, and either AD[10:8] should be ignored
1377
//   for a single function device, or only implemented devices should
1378
//   respond.  Function 0 is required to be detected.
1379
 
1380
// Make a fake version just to make the charts pop:
1381
 
1382
// Fire off Target tasks in response to PCI Bus Activity
1383
  reg     saw_fast_back_to_back;
1384
  always @(posedge pci_ext_clk or posedge pci_reset_comb)
1385
  begin
1386
    if (~pci_reset_comb)
1387
    begin
1388
      saw_fast_back_to_back = 1'b1;
1389
      while (saw_fast_back_to_back == 1'b1)  // whats the value of this loop?  Does it reset correctly?
1390
      begin
1391
        hold_target_address[PCI_BUS_DATA_RANGE:0] = ad_now[PCI_BUS_DATA_RANGE:0];  // intentionally use "="
1392
        hold_target_command[PCI_BUS_CBE_RANGE:0]  = cbe_l_now[PCI_BUS_CBE_RANGE:0];
1393
        if (test_response[`TARGET_ENCODED_PARAMATERS_ENABLE] != 1'b0)
1394
        begin
1395
          hold_target_initial_waitstates    = test_response[`TARGET_ENCODED_INIT_WAITSTATES];
1396
          hold_target_subsequent_waitstates = test_response[`TARGET_ENCODED_SUBS_WAITSTATES];
1397
          hold_target_termination           = test_response[`TARGET_ENCODED_TERMINATION];
1398
          hold_target_devsel_speed          = test_response[`TARGET_ENCODED_DEVSEL_SPEED];
1399
          hold_target_data_par_err          = test_response[`TARGET_ENCODED_DATA_PAR_ERR];
1400
          hold_target_addr_par_err          = test_response[`TARGET_ENCODED_ADDR_PAR_ERR];
1401
          hold_target_terminate_on          = test_response[`TARGET_ENCODED_TERMINATE_ON];
1402
        end
1403
        else
1404
        begin
1405
          hold_target_initial_waitstates    = 4'h0;
1406
          hold_target_subsequent_waitstates = 4'h0;
1407
          hold_target_termination           = `Test_Target_Normal_Completion;
1408
          hold_target_devsel_speed          = `Test_Devsel_Medium;
1409
          hold_target_data_par_err          = `Test_No_Data_Perr;
1410
          hold_target_addr_par_err          = `Test_No_Addr_Perr;
1411
          hold_target_terminate_on          = 0 ;
1412
        end
1413
 
1414
        if (~frame_prev & frame_now & Target_En
1415
`ifdef SIMULTANEOUS_MASTER_TARGET
1416
// don't check for reads to self
1417
`else // SIMULTANEOUS_MASTER_TARGET
1418
// check for, and don't respond to, reads to self
1419
`endif //SIMULTANEOUS_MASTER_TARGET
1420
            & (   (cbe_l_now[PCI_BUS_CBE_RANGE:0] == PCI_COMMAND_MEMORY_WRITE)
1421
                | (cbe_l_now[PCI_BUS_CBE_RANGE:0] == PCI_COMMAND_MEMORY_WRITE_INVALIDATE) )
1422
            & (   (ad_now[`PCI_BASE_ADDR0_MATCH_RANGE] == BAR0[`PCI_BASE_ADDR0_MATCH_RANGE])
1423
`ifdef PCI_BASE_ADDR1_MATCH_ENABLE
1424
                | (ad_now[`PCI_BASE_ADDR1_MATCH_RANGE] == BAR1[`PCI_BASE_ADDR1_MATCH_RANGE])
1425
`endif  // PCI_BASE_ADDR1_MATCH_ENABLE
1426
              ) )
1427
        begin
1428
          Execute_Target_PCI_Ref (`TEST_TARGET_DOING_SRAM_WRITE,
1429
                                                 saw_fast_back_to_back);
1430
        end
1431
        else if (~frame_prev & frame_now & (idsel_now == 1'b1)
1432
               & (cbe_l_now[PCI_BUS_CBE_RANGE:0] == PCI_COMMAND_CONFIG_WRITE)
1433
               & (ad_now[1:0]  == 2'b00) )
1434
        begin
1435
          Execute_Target_PCI_Ref (`TEST_TARGET_DOING_CONFIG_WRITE,
1436
                                                 saw_fast_back_to_back);
1437
        end
1438
        else if (~frame_prev & frame_now & Target_En
1439
`ifdef SIMULTANEOUS_MASTER_TARGET
1440
// Don't check for reads to self
1441
`else // SIMULTANEOUS_MASTER_TARGET
1442
// Check for, and don't respond to, reads to self
1443
`endif //SIMULTANEOUS_MASTER_TARGET
1444
            & (   (cbe_l_now[PCI_BUS_CBE_RANGE:0] == PCI_COMMAND_MEMORY_READ)
1445
                | (cbe_l_now[PCI_BUS_CBE_RANGE:0] == PCI_COMMAND_MEMORY_READ_MULTIPLE)
1446
                | (cbe_l_now[PCI_BUS_CBE_RANGE:0] == PCI_COMMAND_MEMORY_READ_LINE) )
1447
            & (   (ad_now[`PCI_BASE_ADDR0_MATCH_RANGE] == BAR0[`PCI_BASE_ADDR0_MATCH_RANGE])
1448
`ifdef PCI_BASE_ADDR1_MATCH_ENABLE
1449
                | (ad_now[`PCI_BASE_ADDR1_MATCH_RANGE] == BAR1[`PCI_BASE_ADDR1_MATCH_RANGE])
1450
`endif  // PCI_BASE_ADDR1_MATCH_ENABLE
1451
              ) )
1452
        begin
1453
          Execute_Target_PCI_Ref (`TEST_TARGET_DOING_SRAM_READ,
1454
                                                 saw_fast_back_to_back);
1455
        end
1456
        else if (~frame_prev & frame_now & (idsel_now == 1'b1)
1457
               & (cbe_l_now[PCI_BUS_CBE_RANGE:0] == PCI_COMMAND_CONFIG_READ)
1458
               & (ad_now[1:0]  == 2'b00) )
1459
        begin
1460
          Execute_Target_PCI_Ref (`TEST_TARGET_DOING_CONFIG_READ,
1461
                                                 saw_fast_back_to_back);
1462
        end
1463
        else
1464
        begin
1465
          saw_fast_back_to_back = 1'b0;
1466
        end
1467
        if (pci_reset_comb)
1468
        begin
1469
          saw_fast_back_to_back = 1'b0;
1470
        end
1471
      end  // saw_fast_back_to_back
1472
    end
1473
    `NO_ELSE;
1474
// Because this is sequential code, have to reset all regs if the above falls
1475
// through due to a reset.  This would not be needed in synthesizable code.
1476
    if (pci_reset_comb)
1477
    begin
1478
      Reset_Target_To_Idle;
1479
    end
1480
    `NO_ELSE;
1481
  end
1482
endmodule
1483
 

powered by: WebSVN 2.1.0

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