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 154

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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