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 35

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

Line No. Rev Author Line
1 19 mihad
//===========================================================================
2 35 mihad
// $Id: pci_behaviorial_target.v,v 1.3 2002-03-21 07:35:50 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
  begin
598 26 mihad
    Read_Test_Device_SRAM (hold_target_address[11:2], ~cbe_l_now, target_read_data[PCI_BUS_DATA_RANGE:0]);
599
    hold_target_address[11:2] = hold_target_address[11:2] + 10'h001;  // addr++
600 19 mihad
  end
601
endtask
602
 
603
// The target is able to execute Delayed Reads,
604
// See the PCI Local Bus Spec Revision 2.2 section 3.3.3.3
605
// To allow a delayed read to complete, read data must be available.
606
// Also a PCI command matching in Address, Command, Byte Enables,
607
//   and parity on address.
608
// If the region of memory is prefetchable and always returns all
609
//   bytes, it is OK to disregard the Byte Enables.
610
  reg     Delayed_Read_Started, Delayed_Read_Pending, Delayed_Read_Finished;
611
  reg    [PCI_BUS_DATA_RANGE:0] Delayed_Read_Address;
612
  reg    [PCI_BUS_CBE_RANGE:0] Delayed_Read_Command;
613
  reg    [PCI_BUS_CBE_RANGE:0] Delayed_Read_Mask_L;
614
  reg    [14:0] Delayed_Read_Discard_Counter;
615
  wire   [14:0] Delayed_Read_Discard_Limit = 15'h7FFF;  // change for debugging
616
  always @(posedge pci_ext_clk or posedge pci_reset_comb)
617
  begin
618
    if (pci_reset_comb)
619
    begin
620
      Delayed_Read_Pending <= 1'b0;
621
    end
622
    else
623
    begin
624
      Delayed_Read_Pending <= Delayed_Read_Started
625
          | (Delayed_Read_Pending & ~Delayed_Read_Finished
626
              & (Delayed_Read_Discard_Counter[14:0] < Delayed_Read_Discard_Limit[14:0]));
627
    end
628
  end
629
 
630
  always @(posedge pci_ext_clk)
631
  begin
632
    Delayed_Read_Discard_Counter[14:0] <= Delayed_Read_Started
633
                    ? 15'h0000 : Delayed_Read_Discard_Counter[14:0] + 15'h0001;
634
`ifdef VERBOSE_TEST_DEVICE
635
    if (Delayed_Read_Pending & (Delayed_Read_Discard_Counter[14:0]
636
                                     >= Delayed_Read_Discard_Limit[14:0]))
637
    begin
638
      $display (" test target %h - Delayed Read Discarded, at %t",
639
                    test_device_id[2:0], $time);
640
    end
641
    `NO_ELSE;
642
`endif // VERBOSE_TEST_DEVICE
643
  end
644
 
645
// Target tasks.  These know how to respond to the external masters.
646
// NOTE all tasks end with an @(posedge pci_ext_clk) statement
647
//      to let any signals asserted during that task settle out.
648
// If a task DOESN'T end with @(posedge pci_ext_clk), then it must
649
//      be called just before some other task which does.
650
 
651
parameter TEST_TARGET_SPINLOOP_MAX = 20;
652
 
653
task Clock_Wait_Unless_Reset;
654
  begin
655
    if (~pci_reset_comb)
656
    begin
657
      @ (posedge pci_ext_clk or posedge pci_reset_comb) ;
658
    end
659
    `NO_ELSE;
660
  end
661
endtask
662
 
663
task Assert_DEVSEL;
664
  begin
665
    target_devsel_out <= 1'b1;
666
  end
667
endtask
668
 
669
task Assert_TRDY;
670
  begin
671
    target_trdy_out <= 1'b1;
672
  end
673
endtask
674
 
675
task Assert_STOP;
676
  begin
677
    target_stop_out <= 1'b1;
678
  end
679
endtask
680
 
681
task Deassert_DEVSEL;
682
  begin
683
    target_devsel_out <= 1'b0;
684
  end
685
endtask
686
 
687
task Deassert_TRDY;
688
  begin
689
    target_trdy_out <= 1'b0;
690
  end
691
endtask
692
 
693
task Deassert_STOP;
694
  begin
695
    target_stop_out <= 1'b0;
696
  end
697
endtask
698
 
699
task Assert_Target_Continue_Or_Disconnect;
700
  input   do_target_disconnect;
701
  begin
702
    if (do_target_disconnect)
703
    begin
704
      Assert_DEVSEL;    Assert_TRDY;    Assert_STOP;
705
    end
706
    else
707
    begin
708
      Assert_DEVSEL;    Assert_TRDY;    Deassert_STOP;
709
    end
710
  end
711
endtask
712
 
713
// Execute_Target_Retry is called with nothing or DEVSEL asserted
714
//   tasks can't have local storage!  have to be module global
715
  integer iiii;
716
task Execute_Target_Retry_Undrive_DEVSEL;
717
  input   drive_ad_bus;
718
  input   signal_starting_delayed_read;
719
  input   signal_satisfied_delayed_read;
720
  begin
721
    for (iiii = 0; iiii < TEST_TARGET_SPINLOOP_MAX; iiii = iiii + 1)
722
    begin
723
      if ((iiii == 0) | frame_now | ~irdy_now)  // At least one stop, then Not Finished
724
      begin
725
        target_ad_out <= `BUS_IMPOSSIBLE_VALUE;
726
        target_ad_oe <= drive_ad_bus;
727
        target_debug_force_bad_par <= 1'b0;
728
        target_perr_check_next <= ~drive_ad_bus;
729
        target_signaling_target_abort <= 1'b0;
730
        Delayed_Read_Started <= signal_starting_delayed_read;
731
        Delayed_Read_Finished <= signal_satisfied_delayed_read;
732
        Assert_DEVSEL;  // signal DEVSEL and Stop, indicating Retry
733
        Deassert_TRDY;
734
        Assert_STOP;
735
        if (signal_starting_delayed_read)
736
        begin
737
          Delayed_Read_Address[PCI_BUS_DATA_RANGE:0] = hold_target_address[PCI_BUS_DATA_RANGE:0];
738
          Delayed_Read_Command[PCI_BUS_CBE_RANGE:0] =  hold_target_command[PCI_BUS_CBE_RANGE:0];
739
          Delayed_Read_Mask_L[PCI_BUS_CBE_RANGE:0] = cbe_l_now[PCI_BUS_CBE_RANGE:0];
740
        end
741
        `NO_ELSE;
742
      end
743
      else
744
      begin
745
        target_ad_out[PCI_BUS_DATA_RANGE:0] <= `BUS_IMPOSSIBLE_VALUE;
746
        target_ad_oe <= 1'b0;  // unconditionally undrive ad bus
747
        target_debug_force_bad_par <= 1'b0;
748
        target_perr_check_next <= 1'b0;
749
        target_signaling_target_abort <= 1'b0;
750
        Delayed_Read_Started <= 1'b0;
751
        Delayed_Read_Finished <= 1'b0;
752
        Deassert_DEVSEL;  // Master saw us, so leave
753
        Deassert_TRDY;
754
        Deassert_STOP;
755
        iiii = TEST_TARGET_SPINLOOP_MAX + 1;  // break
756
      end
757
      Clock_Wait_Unless_Reset;  // wait for outputs to settle
758
      signal_satisfied_delayed_read = 1'b0;
759
    end
760
`ifdef NORMAL_PCI_CHECKS
761
    if (~pci_reset_comb & (iiii == TEST_TARGET_SPINLOOP_MAX))
762
    begin
763
      $display ("*** test target %h - Bus didn't go Idle during Target Retry, at %t",
764
                test_device_id[2:0], $time);
765
      error_detected <= ~error_detected;
766
    end
767
    `NO_ELSE;
768
    if (~pci_reset_comb & irdy_now)
769
    begin
770
      $display ("*** test target %h - IRDY didn't deassert at end of Target Retry, at %t",
771
                   test_device_id[2:0], $time);
772
      error_detected <= ~error_detected;
773
    end
774
    `NO_ELSE;
775
`endif // NORMAL_PCI_CHECKS
776
  end
777
endtask
778
 
779
// This Test Device is capable of doing Fast Decode.  To do this,
780
//   it must make sure not to cause conflicts on DEVSEL, IRDY,
781
//   STOP, or PERR.  To achieve this, the task must hold off on
782
//   making DEVSEL unless either
783
//   1) the bus was just Idle
784
//   2) this device also drove DEVSEL the previous clock (I presume this
785
//      means that DEVSEL was driven LOW!!  Would HIGH be an idle cycle?)
786
// See the PCI Local Bus Spec Revision 2.2 section 3.4.2
787
//
788
// See the PCI Local Bus Spec Revision 2.2 section 3.7.3 for what
789
//   to do if an Address Parity Error is detected.
790
// Since this behaviorial test knows that an address parity error is
791
//   comming, it holds off fast decode parity errors, and always
792
//   allows a master abort to happen.  This would not be possible in
793
//   a gate-level PCI interface.  For FAST decode, that interface would
794
//   have to continue on as if there was no error.  It would be nice
795
//   if it prevented any writes of data, or reads with side-effects.
796
task Wait_Till_DEVSEL_Possible;
797
  output  devsel_asserted;
798
  output  fast_devsel_asserted;
799
  output  signal_satisfied_delayed_read;
800
  begin
801
    if ((hold_target_devsel_speed[1:0] == `Test_Devsel_Fast) & ~Delayed_Read_Pending
802
          & (   (~frame_prev & ~irdy_prev)
803
              | (~frame_prev &  irdy_prev & This_Target_Drove_DEVSEL_Last_Clock) )
804
          & ~(hold_target_addr_par_err & Par_Err_En))
805
    begin
806
`ifdef VERBOSE_TEST_DEVICE
807
      $display (" test target %h - doing fast DEVSEL, at %t",
808
                    test_device_id[2:0], $time);
809
`endif // VERBOSE_TEST_DEVICE
810
      devsel_asserted = 1'b1;  // fast decode
811
      fast_devsel_asserted = 1'b1;  // fast decode
812
      signal_satisfied_delayed_read = 1'b0;
813
    end
814
    else
815
    begin
816
      target_ad_out <= `BUS_IMPOSSIBLE_VALUE;
817
      target_ad_oe <= 1'b0;  // Should this drive AD when not DEVSEL?
818
      target_debug_force_bad_par <= 1'b0;
819
      target_perr_check_next <= 1'b0;
820
      target_signaling_target_abort <= 1'b0;
821
      Delayed_Read_Started <= 1'b0;
822
      Delayed_Read_Finished <= 1'b0;
823
      Deassert_DEVSEL;
824
      Deassert_TRDY;
825
      Deassert_STOP;
826
      Clock_Wait_Unless_Reset;  // wait for outputs to settle
827
      if (Delayed_Read_Pending
828
            & (   (hold_target_command[3:0] == PCI_COMMAND_MEMORY_READ)
829
                | (hold_target_command[3:0] == PCI_COMMAND_MEMORY_READ_MULTIPLE)
830
                | (hold_target_command[3:0] == PCI_COMMAND_MEMORY_READ_LINE)
831
                | (hold_target_command[3:0] == PCI_COMMAND_CONFIG_READ) )
832
            & (   (    (hold_target_address[PCI_BUS_DATA_RANGE:0] & 32'hFF0000FF)  // partial test address match
833
                    != (Delayed_Read_Address[PCI_BUS_DATA_RANGE:0] & 32'hFF0000FF))
834
                | (hold_target_command[PCI_BUS_CBE_RANGE:0] != Delayed_Read_Command[PCI_BUS_CBE_RANGE:0])
835
                | (cbe_l_now[PCI_BUS_CBE_RANGE:0] != Delayed_Read_Mask_L[PCI_BUS_CBE_RANGE:0]) ) )
836
      begin
837
        Execute_Target_Retry_Undrive_DEVSEL (1'b1, 1'b0, 1'b0);
838
        devsel_asserted = 1'b0;  // tell calling routine to not claim DEVSEL.
839
        fast_devsel_asserted = 1'b0;
840
        signal_satisfied_delayed_read = 1'b0;
841
      end
842
      else
843
      begin
844
        if /*(*/(  (hold_target_devsel_speed[1:0] == `Test_Devsel_Fast)
845
             | (hold_target_devsel_speed[1:0] == `Test_Devsel_Medium) )
846
             /*  & ((calc_input_parity_prev == par_now) | ~Par_Err_En))*/
847
        begin
848
          devsel_asserted = 1'b1;  // medium decode
849
          fast_devsel_asserted = 1'b0;  // medium decode
850
          signal_satisfied_delayed_read = Delayed_Read_Pending
851
                & (   (hold_target_command[3:0] == PCI_COMMAND_MEMORY_READ)
852
                    | (hold_target_command[3:0] == PCI_COMMAND_MEMORY_READ_MULTIPLE)
853
                    | (hold_target_command[3:0] == PCI_COMMAND_MEMORY_READ_LINE)
854
                    | (hold_target_command[3:0] == PCI_COMMAND_CONFIG_READ) );
855
        end
856
        else
857
        begin
858
          target_ad_out <= `BUS_IMPOSSIBLE_VALUE;
859
          target_ad_oe <= 1'b0;  // Should this drive AD when not DEVSEL?
860
          target_debug_force_bad_par <= 1'b0;
861
          target_perr_check_next <= 1'b0;
862
          target_signaling_target_abort <= 1'b0;
863
          Delayed_Read_Started <= 1'b0;
864
          Delayed_Read_Finished <= 1'b0;
865
          Deassert_DEVSEL;
866
          Deassert_TRDY;
867
          Deassert_STOP;
868
          Clock_Wait_Unless_Reset;
869
          if /*(*/(hold_target_devsel_speed[1:0] == `Test_Devsel_Slow)
870
                /*& (prev_bus_par_ok | ~Par_Err_En))*/
871
          begin
872
            devsel_asserted = 1'b1;  // slow decode
873
            fast_devsel_asserted = 1'b0;  // slow decode
874
            signal_satisfied_delayed_read = Delayed_Read_Pending
875
                & (   (hold_target_command[3:0] == PCI_COMMAND_MEMORY_READ)
876
                    | (hold_target_command[3:0] == PCI_COMMAND_MEMORY_READ_MULTIPLE)
877
                    | (hold_target_command[3:0] == PCI_COMMAND_MEMORY_READ_LINE)
878
                    | (hold_target_command[3:0] == PCI_COMMAND_CONFIG_READ) );
879
          end
880
          else
881
          begin
882
            target_ad_out <= `BUS_IMPOSSIBLE_VALUE;
883
            target_ad_oe <= 1'b0;  // Should this drive AD when not DEVSEL?
884
            target_debug_force_bad_par <= 1'b0;
885
            target_perr_check_next <= 1'b0;
886
            target_signaling_target_abort <= 1'b0;
887
            Delayed_Read_Started <= 1'b0;
888
            Delayed_Read_Finished <= 1'b0;
889
            Deassert_DEVSEL;
890
            Deassert_TRDY;
891
            Deassert_STOP;
892
            Clock_Wait_Unless_Reset;  // wait for outputs to settle
893
            if (/*(*/hold_target_devsel_speed[1:0] == `Test_Devsel_Subtractive)
894
                  /*& (prev_prev_bus_par_ok | ~Par_Err_En))*/
895
            begin
896
              devsel_asserted = 1'b1;  // subtractive decode
897
              fast_devsel_asserted = 1'b0;  // subtractive decode
898
              signal_satisfied_delayed_read = Delayed_Read_Pending
899
                & (   (hold_target_command[3:0] == PCI_COMMAND_MEMORY_READ)
900
                    | (hold_target_command[3:0] == PCI_COMMAND_MEMORY_READ_MULTIPLE)
901
                    | (hold_target_command[3:0] == PCI_COMMAND_MEMORY_READ_LINE)
902
                    | (hold_target_command[3:0] == PCI_COMMAND_CONFIG_READ) );
903
 
904
            end
905
            else
906
            begin
907
              devsel_asserted = 1'b0;  // must have had bad parity
908
              fast_devsel_asserted = 1'b0;
909
              signal_satisfied_delayed_read = 1'b0;
910
            end
911
          end
912
        end
913
      end
914
    end
915
`ifdef NORMAL_PCI_CHECKS
916
    if (~pci_reset_comb & (devsel_asserted == 1'b1)
917
                        & (hold_target_addr_par_err == 1'b1))
918
    begin
919
      $display ("*** test target %h - DEVSEL Asserted when Address Parity Error expected, at %t",
920
                   test_device_id[2:0], $time);
921
      error_detected <= ~error_detected;
922
    end
923
    `NO_ELSE;
924
`endif // NORMAL_PCI_CHECKS
925
  end
926
endtask
927
 
928
// While asserting DEVSEL, wait zero or more clocks as commanded by master
929
// This might be called with 1 waitstate before the read data can be OE'd
930
//    or before the Master Parity can be checked.
931
// Tasks can't have local storage!  have to be module global
932
  reg    [3:0] cnt1;
933
task Execute_Target_Waitstates;
934
  input   drive_ad_bus;
935
  input   enable_parity_check;
936
  input  [3:0] num_waitstates;
937
  begin
938
    for (cnt1 = 4'h0; cnt1 < num_waitstates[3:0]; cnt1 = cnt1 + 4'h1)
939
    begin
940
`ifdef NORMAL_PCI_CHECKS
941
    if (!pci_reset_comb & ~frame_now & ~irdy_now)
942
    begin
943
      $display ("*** test target %h - Execute Target Waitstates Wait States called when no Master, at %t",
944
                   test_device_id[2:0], $time);
945
      error_detected <= ~error_detected;
946
    end
947
    `NO_ELSE;
948
`endif // NORMAL_PCI_CHECKS
949
      target_ad_out <= `BUS_WAIT_STATE_VALUE;
950
      target_ad_oe <= drive_ad_bus;
951
      target_debug_force_bad_par <= 1'b0;
952
      target_perr_check_next <= enable_parity_check;
953
      target_signaling_target_abort <= 1'b0;
954
      Delayed_Read_Started <= 1'b0;
955
      Delayed_Read_Finished <= 1'b0;
956
      Assert_DEVSEL;
957
      Deassert_TRDY;
958
      Deassert_STOP;
959
      Clock_Wait_Unless_Reset;  // wait for outputs to settle
960
    end
961
  end
962
endtask
963
 
964
// DEVSEL already asserted upon entry to this task.  OK to watch Parity
965
// Tasks can't have local storage!  have to be module global
966
  integer ii;
967
task Linger_Until_Master_Waitstates_Done;
968
  input   drive_ad_bus;
969
  input  [PCI_BUS_DATA_RANGE:0] target_read_data;
970
  input   do_target_disconnect;
971
  begin
972
    for (ii = 0; ii < TEST_TARGET_SPINLOOP_MAX; ii = ii + 1)
973
    begin
974
      if (frame_now & ~irdy_now)  // master executing wait states
975
      begin
976
        target_ad_out[PCI_BUS_DATA_RANGE:0] <= target_read_data[PCI_BUS_DATA_RANGE:0];
977
        target_ad_oe <= drive_ad_bus;
978
        target_debug_force_bad_par <= hold_target_data_par_err;
979
        target_perr_check_next <= ~drive_ad_bus;
980
        target_signaling_target_abort <= 1'b0;
981
        Delayed_Read_Started <= 1'b0;
982
        Delayed_Read_Finished <= 1'b0;
983
        Assert_Target_Continue_Or_Disconnect (do_target_disconnect);
984
        Clock_Wait_Unless_Reset;  // wait for outputs to settle
985
      end
986
      else
987
      begin
988
      ii = TEST_TARGET_SPINLOOP_MAX + 1;  // break
989
      end
990
    end
991
`ifdef NORMAL_PCI_CHECKS
992
    if (~pci_reset_comb & ~frame_now & ~irdy_now)
993
    begin
994
      $display ("*** test target %h - Linger during Master Wait States called when no Master, at %t",
995
                   test_device_id[2:0], $time);
996
      error_detected <= ~error_detected;
997
    end
998
    `NO_ELSE;
999
    if (~pci_reset_comb & (ii == TEST_TARGET_SPINLOOP_MAX))
1000
    begin
1001
      $display ("*** test target %h - Bus stuck in Master Wait States during Target ref, at %t",
1002
                   test_device_id[2:0], $time);
1003
      error_detected <= ~error_detected;
1004
    end
1005
    `NO_ELSE;
1006
`endif // NORMAL_PCI_CHECKS
1007
  end
1008
endtask
1009
 
1010
// Execute_Target_Abort.  This must be called with DEVSEL asserted
1011
// Tasks can't have local storage!  have to be module global
1012
  integer iii;
1013
task Execute_Target_Abort_Undrive_DEVSEL;
1014
  input   drive_ad_bus;
1015
  input   signal_satisfied_delayed_read;
1016
  begin
1017
`ifdef NORMAL_PCI_CHECKS
1018
    if (~pci_reset_comb & (target_devsel_out == 1'b0))
1019
    begin
1020
      $display ("*** test target %h - DEVSEL not asserted when starting Target Abort, at %t",
1021
                   test_device_id[2:0], $time);
1022
      error_detected <= ~error_detected;
1023
    end
1024
    `NO_ELSE;
1025
`endif // NORMAL_PCI_CHECKS
1026
    for (iii = 0; iii < TEST_TARGET_SPINLOOP_MAX; iii = iii + 1)
1027
    begin
1028
      if ((iii == 0) | frame_now | ~irdy_now)  // At least one stop, Master Not Finished
1029
      begin
1030
        target_ad_out[PCI_BUS_DATA_RANGE:0] <= `BUS_IMPOSSIBLE_VALUE;
1031
        target_ad_oe <= 1'b0;  // Should this drive AD when not DEVSEL?
1032
        target_debug_force_bad_par <= 1'b0;
1033
        target_perr_check_next <= 1'b0;
1034
        target_signaling_target_abort <= 1'b1;
1035
        Delayed_Read_Started <= 1'b0;
1036
        Delayed_Read_Finished <= signal_satisfied_delayed_read;
1037
        Deassert_DEVSEL;  // Signal Target Abort
1038
        Deassert_TRDY;
1039
        Assert_STOP;
1040
      end
1041
      else
1042
      begin
1043
        target_ad_out[PCI_BUS_DATA_RANGE:0] <= `BUS_IMPOSSIBLE_VALUE;
1044
        target_ad_oe <= 1'b0;  // unconditionally undrive ad bus
1045
        target_debug_force_bad_par <= 1'b0;
1046
        target_perr_check_next <= 1'b0;
1047
        target_signaling_target_abort <= 1'b0;
1048
        Delayed_Read_Started <= 1'b0;
1049
        Delayed_Read_Finished <= 1'b0;
1050
        Deassert_DEVSEL;  // Signal Target Abort
1051
        Deassert_TRDY;
1052
        Deassert_STOP;  // Master saw us, so leave
1053
        iii = TEST_TARGET_SPINLOOP_MAX + 1;  // break
1054
      end
1055
      Clock_Wait_Unless_Reset;  // wait for outputs to settle
1056
      signal_satisfied_delayed_read = 1'b0;
1057
    end
1058
`ifdef NORMAL_PCI_CHECKS
1059
    if (~pci_reset_comb & irdy_now)
1060
    begin
1061
      $display ("*** test target %h - Master didn't deassert IRDY at end of Target Abort, at %t",
1062
                   test_device_id[2:0], $time);
1063
      error_detected <= ~error_detected;
1064
    end
1065
    `NO_ELSE;
1066
    if (~pci_reset_comb & (iii == TEST_TARGET_SPINLOOP_MAX))
1067
    begin
1068
      $display ("*** test target %h - Bus didn't go Idle during Target Abort, at %t",
1069
                   test_device_id[2:0], $time);
1070
      error_detected <= ~error_detected;
1071
    end
1072
    `NO_ELSE;
1073
`endif // NORMAL_PCI_CHECKS
1074
  end
1075
endtask
1076
 
1077
// Transfer a word with or without target termination, and act on Master Termination
1078
task Execute_Target_Ref_Undrive_DEVSEL_On_Any_Termination;
1079
  input   drive_ad_bus;
1080
  input   do_target_disconnect;
1081
  input   signal_satisfied_delayed_read;
1082
  input  [PCI_BUS_DATA_RANGE:0] target_read_data;
1083
  output [PCI_BUS_DATA_RANGE:0] master_write_data;
1084
  output [PCI_BUS_CBE_RANGE:0] master_mask_l;
1085
  output  target_was_terminated;
1086
  begin
1087
    target_ad_out[PCI_BUS_DATA_RANGE:0] <= target_read_data[PCI_BUS_DATA_RANGE:0];
1088
    target_ad_oe <= drive_ad_bus;
1089
    target_debug_force_bad_par <= hold_target_data_par_err;
1090
    target_perr_check_next <= ~drive_ad_bus;
1091
    target_signaling_target_abort <= 1'b0;
1092
    Delayed_Read_Started <= 1'b0;
1093
    Delayed_Read_Finished <= signal_satisfied_delayed_read;
1094
    Assert_Target_Continue_Or_Disconnect (do_target_disconnect);
1095
    Clock_Wait_Unless_Reset;  // wait for outputs to settle
1096
    Linger_Until_Master_Waitstates_Done (drive_ad_bus,
1097
                       target_read_data[PCI_BUS_DATA_RANGE:0], do_target_disconnect);
1098
    master_write_data[PCI_BUS_DATA_RANGE:0] = ad_now[PCI_BUS_DATA_RANGE:0];  // unconditionally grab.
1099
    master_mask_l[PCI_BUS_CBE_RANGE:0] = cbe_l_now[PCI_BUS_CBE_RANGE:0];
1100
    if (frame_now & irdy_now & ~do_target_disconnect)
1101
    begin
1102
        target_was_terminated = 1'b0;
1103
    end
1104
    else
1105
    begin
1106
      if (frame_now & irdy_now & do_target_disconnect)  // doing Target Termination
1107
      begin
1108
        target_ad_out <= `BUS_IMPOSSIBLE_VALUE;
1109
        target_ad_oe <= drive_ad_bus;
1110
        target_debug_force_bad_par <= 1'b0;
1111
        target_perr_check_next <= ~drive_ad_bus;
1112
        target_signaling_target_abort <= 1'b0;
1113
        Delayed_Read_Started <= 1'b0;
1114
        Delayed_Read_Finished <= 1'b0;
1115
        Assert_DEVSEL;
1116
        Deassert_TRDY;
1117
        Assert_STOP;
1118
        Clock_Wait_Unless_Reset;  // give master a chance to turn FRAME around
1119
      end
1120
      `NO_ELSE;
1121
`ifdef NORMAL_PCI_CHECKS
1122
      if (~pci_reset_comb & ~(~frame_now & irdy_now))  // error if not last master data phase
1123
      begin
1124
        $display ("*** test target %h - Master entered fatally odd state in Target Ref, at %t",
1125
                     test_device_id[2:0], $time);
1126
        error_detected <= ~error_detected;
1127
      end
1128
      `NO_ELSE;
1129
`endif // NORMAL_PCI_CHECKS
1130
      target_ad_out <= `BUS_IMPOSSIBLE_VALUE;
1131
      target_ad_oe <= 1'b0;  // unconditionally undrive ad bus
1132
      target_debug_force_bad_par <= 1'b0;
1133
      target_perr_check_next <= 1'b0;
1134
      target_signaling_target_abort <= 1'b0;
1135
      Delayed_Read_Started <= 1'b0;
1136
      Delayed_Read_Finished <= 1'b0;
1137
      Deassert_DEVSEL;
1138
      Deassert_TRDY;
1139
      Deassert_STOP;
1140
      Clock_Wait_Unless_Reset;
1141
`ifdef NORMAL_PCI_CHECKS
1142
      if (~pci_reset_comb & irdy_now)
1143
      begin
1144
        $display ("*** test target %h - IRDY didn't deassert at end of Master Termination, at %t",
1145
                     test_device_id[2:0], $time);
1146
        error_detected <= ~error_detected;
1147
      end
1148
      `NO_ELSE;
1149
`endif // NORMAL_PCI_CHECKS
1150
      target_was_terminated = 1'b1;
1151
    end
1152
  end
1153
endtask
1154
 
1155
`define TEST_TARGET_DOING_CONFIG_READ   2'b00
1156
`define TEST_TARGET_DOING_CONFIG_WRITE  2'b01
1157
`define TEST_TARGET_DOING_SRAM_READ     2'b10
1158
`define TEST_TARGET_DOING_SRAM_WRITE    2'b11
1159
 
1160
task Report_On_Target_PCI_Ref_Start;
1161
  input  [1:0] reference_type;
1162
  begin
1163
    case (reference_type[1:0])
1164
    `TEST_TARGET_DOING_CONFIG_READ:
1165
      $display (" test target %h - Starting Config Read, at %t",
1166
                    test_device_id[2:0], $time);
1167
    `TEST_TARGET_DOING_CONFIG_WRITE:
1168
      $display (" test target %h - Starting Config Write, at %t",
1169
                    test_device_id[2:0], $time);
1170
    `TEST_TARGET_DOING_SRAM_READ:
1171
      $display (" test target %h - Starting Memory Read, at %t",
1172
                    test_device_id[2:0], $time);
1173
    `TEST_TARGET_DOING_SRAM_WRITE:
1174
      $display (" test target %h - Starting Memory Write, at %t",
1175
                    test_device_id[2:0], $time);
1176
    default:
1177
      $display ("*** test target %h - Doing Unknown Reference, at %t",
1178
                    test_device_id[2:0], $time);
1179
    endcase
1180
`ifdef VERBOSE_TEST_DEVICE
1181
    Report_Target_Reference_Paramaters;
1182
`endif // VERBOSE_TEST_DEVICE
1183
  end
1184
endtask
1185
 
1186
// Transfer either a burst of Config Registers or SRAM Contents across the PCI Bus
1187
// Tasks can't have local storage!  have to be module global
1188
  reg     devsel_asserted, fast_devsel_asserted, target_was_terminated;
1189
  reg    [3:0] wait_states_this_time;
1190
  reg     do_abort_this_time, do_retry_this_time, do_disconnect_this_time;
1191
  reg     abort_needs_waitstate;
1192
  reg    [PCI_BUS_DATA_RANGE:0] master_write_data;
1193
  reg    [PCI_BUS_DATA_RANGE:0] target_read_data;
1194
  reg    [PCI_BUS_CBE_RANGE:0] master_mask_l;
1195
  reg     drive_ad_bus;
1196
  reg     signal_satisfied_delayed_read;
1197
task Execute_Target_PCI_Ref;
1198
  input  [1:0] reference_type;
1199
  output  saw_fast_back_to_back;
1200
  reg     [9:0] number_of_transfers ;
1201
  begin
1202
 
1203
    number_of_transfers = 0 ;
1204
`ifdef REPORT_TEST_DEVICE
1205
    Report_On_Target_PCI_Ref_Start (reference_type[1:0]);
1206
`endif // REPORT_TEST_DEVICE
1207
    Wait_Till_DEVSEL_Possible (devsel_asserted, fast_devsel_asserted,
1208
                                          signal_satisfied_delayed_read);
1209
    if (devsel_asserted == 1'b1)
1210
    begin
1211
// Target must drive AD bus even if it is going to do an abort or retry.
1212
// See the PCI Local Bus Spec Revision 2.2 section 3.3.1
1213
      drive_ad_bus = (reference_type[1:0] == `TEST_TARGET_DOING_CONFIG_READ)
1214
                   | (reference_type[1:0] == `TEST_TARGET_DOING_SRAM_READ);
1215
      wait_states_this_time[3:0] = hold_target_initial_waitstates[3:0];
1216
      abort_needs_waitstate = (hold_target_initial_waitstates[3:0] == 4'h0);
1217
 
1218
      do_abort_this_time = ( (hold_target_termination[2:0] == `Test_Target_Abort) && (hold_target_terminate_on == 1) );
1219
 
1220
      do_retry_this_time = ( (hold_target_termination[2:0] == `Test_Target_Retry_Before) && (hold_target_terminate_on == 1) ) |
1221
                           (hold_target_termination[2:0] == `Test_Target_Start_Delayed_Read) ;
1222
 
1223
      do_disconnect_this_time = ( (hold_target_termination[2:0] == `Test_Target_Disc_With) && (hold_target_terminate_on == 1) ) ;
1224
 
1225
// If the bottom 2 bits of the Address aren't 2'b00, only transfer 1 word.
1226
// See the PCI Local Bus Spec Revision 2.2 section 3.2.2.2
1227
      do_disconnect_this_time = do_disconnect_this_time
1228
                              | (hold_target_address[1:0] != 2'b00);
1229
// If Fast Decode and it's a read, don't drive data for 1 clock to avoid AD bus fight
1230
// See the PCI Local Bus Spec Revision 2.2 section 3.3.1
1231
      if (fast_devsel_asserted & drive_ad_bus)
1232
      begin
1233
        Execute_Target_Waitstates (1'b0, 1'b0, 4'h1);  // avoid collisions on AD bus
1234
        if (wait_states_this_time[3:0] != 4'h0)
1235
        begin
1236
          wait_states_this_time[3:0] = wait_states_this_time[3:0] - 4'h1;
1237
        end
1238
        `NO_ELSE;
1239
      end
1240
      `NO_ELSE;
1241
      target_was_terminated = 1'b0;
1242
      while (target_was_terminated == 1'b0)
1243
      begin
1244
        Execute_Target_Waitstates (drive_ad_bus, ~drive_ad_bus,
1245
                                            wait_states_this_time[3:0]);
1246
        if (do_abort_this_time)
1247
        begin
1248
          if (abort_needs_waitstate)
1249
          begin
1250
            Execute_Target_Waitstates (drive_ad_bus, ~drive_ad_bus, 4'h1);
1251
          end
1252
          `NO_ELSE;
1253
          Execute_Target_Abort_Undrive_DEVSEL (drive_ad_bus,
1254
                                               signal_satisfied_delayed_read);
1255
          target_was_terminated = 1'b1;
1256
        end
1257
        else if (do_retry_this_time)
1258
        begin
1259
          Execute_Target_Retry_Undrive_DEVSEL (drive_ad_bus,
1260
                (hold_target_termination[2:0] == `Test_Target_Start_Delayed_Read)
1261
              & (   (hold_target_command[PCI_BUS_CBE_RANGE:0] ==
1262
                                              PCI_COMMAND_MEMORY_READ)
1263
                  | (hold_target_command[PCI_BUS_CBE_RANGE:0] ==
1264
                                              PCI_COMMAND_MEMORY_READ_MULTIPLE)
1265
                  | (hold_target_command[PCI_BUS_CBE_RANGE:0] ==
1266
                                              PCI_COMMAND_MEMORY_READ_LINE)
1267
                  | (hold_target_command[PCI_BUS_CBE_RANGE:0] ==
1268
                                              PCI_COMMAND_CONFIG_READ) ),
1269
                                               signal_satisfied_delayed_read);
1270
          target_was_terminated = 1'b1;
1271
        end
1272
        else  // at least one data item should be read out of this device
1273
        begin
1274
//          do_disconnect_this_time = do_disconnect_this_time  // prevent address roll-over
1275
//                            | (hold_target_address[7:2] == 6'h3F);
1276
          if (reference_type[1:0] == `TEST_TARGET_DOING_CONFIG_READ)
1277
          begin
1278
            Fetch_Config_Reg_Data_For_Read_Onto_AD_Bus (target_read_data[PCI_BUS_DATA_RANGE:0]);
1279
          end
1280
          `NO_ELSE;
1281
          if (reference_type[1:0] == `TEST_TARGET_DOING_SRAM_READ)
1282
          begin
1283
            Fetch_SRAM_Data_For_Read_Onto_AD_Bus (target_read_data[PCI_BUS_DATA_RANGE:0]);
1284
          end
1285
          `NO_ELSE;
1286
          Execute_Target_Ref_Undrive_DEVSEL_On_Any_Termination
1287
                           (drive_ad_bus, do_disconnect_this_time,
1288
                            signal_satisfied_delayed_read,
1289
                            target_read_data[PCI_BUS_DATA_RANGE:0],
1290
                            master_write_data[PCI_BUS_DATA_RANGE:0],
1291
                            master_mask_l[PCI_BUS_CBE_RANGE:0],
1292
                            target_was_terminated);
1293
          number_of_transfers = number_of_transfers + 1 ;
1294
 
1295
          if (reference_type[1:0] == `TEST_TARGET_DOING_CONFIG_WRITE)
1296
          begin
1297
            Capture_Config_Reg_Data_From_AD_Bus (master_write_data[PCI_BUS_DATA_RANGE:0],
1298
                                                 master_mask_l[PCI_BUS_CBE_RANGE:0]);
1299
          end
1300
          `NO_ELSE;
1301
          if (reference_type[1:0] == `TEST_TARGET_DOING_SRAM_WRITE)
1302
          begin
1303
            Capture_SRAM_Data_From_AD_Bus (master_write_data[PCI_BUS_DATA_RANGE:0],
1304
                                           master_mask_l[PCI_BUS_CBE_RANGE:0]);
1305
          end
1306
 
1307
          `NO_ELSE;
1308
// set up for the next transfer
1309
          wait_states_this_time[3:0] = hold_target_subsequent_waitstates[3:0];
1310
          abort_needs_waitstate = 1'b0;
1311
          /*do_abort_this_time = (hold_target_termination[2:0]
1312
                                            == `Test_Target_Abort_Before_Second);
1313
          do_retry_this_time = (hold_target_termination[2:0]
1314
                                            == `Test_Target_Retry_Before_Second);
1315
          do_disconnect_this_time = (hold_target_termination[2:0]
1316
                                      == `Test_Target_Disc_With_Second);*/
1317
 
1318
          do_abort_this_time = ( (hold_target_termination[2:0] == `Test_Target_Abort) && (hold_target_terminate_on == (number_of_transfers + 1)) );
1319
 
1320
          do_retry_this_time = ( (hold_target_termination[2:0] == `Test_Target_Retry_Before) && (hold_target_terminate_on == (number_of_transfers + 1)) ) ;
1321
 
1322
          do_disconnect_this_time = ( (hold_target_termination[2:0] == `Test_Target_Disc_With) && (hold_target_terminate_on == (number_of_transfers + 1)) ) ;
1323
 
1324
          signal_satisfied_delayed_read = 1'b0;
1325
        end
1326
      end
1327
// Watch for Fast Back-to-Back reference.  If seen, do not go to the top
1328
//   of the Target Idle Loop, which automatically waits for one clock.
1329
// Instead go directly to see if this device is addressed.
1330
// This transition is manditory even if the device can't do
1331
//   fast-back-to-back transfers!
1332
// See the PCI Local Bus Spec Revision 2.2 section 3.4.2.
1333
      saw_fast_back_to_back = frame_now & ~irdy_now;
1334
// No clock here to let this dovetail with the next reference?
1335
    end
1336
    else
1337
    begin  // no devsel, so it must have been an address parity error
1338
      saw_fast_back_to_back = 1'b0;
1339
    end
1340
  end
1341
endtask
1342
 
1343
// Task to print debug info
1344
// NOTE This must change if bit allocation changes
1345
task Report_Target_Reference_Paramaters;
1346
  begin
1347
    if (hold_target_address[23:9] != 15'h0000)
1348
    begin
1349
      $display ("  Target Devsel Speed %h, Target Termination %h,",
1350
            hold_target_devsel_speed[1:0], hold_target_termination[2:0]);
1351
      $display ("  First Target Data Wait States %h, Subsequent Target Data Wait States %h",
1352
            hold_target_initial_waitstates[3:0],
1353
            hold_target_subsequent_waitstates[3:0]);
1354
      $display ("  Addr Par Error %h, Data Par Error %h",
1355
            hold_target_addr_par_err, hold_target_data_par_err);
1356
    end
1357
    `NO_ELSE;
1358
  end
1359
endtask
1360
 
1361
task Reset_Target_To_Idle;
1362
  begin
1363
    Init_Test_Device_SRAM;
1364
    target_ad_oe <= 1'b0;
1365
    target_devsel_out <= 1'b0;
1366
    target_trdy_out <= 1'b0;
1367
    target_stop_out <= 1'b0;
1368
    target_perr_check_next <= 1'b0;
1369
    target_signaling_target_abort <= 1'b0;
1370
    Delayed_Read_Started <= 1'b0;
1371
    Delayed_Read_Finished <= 1'b0;
1372
  end
1373
endtask
1374
 
1375
// Config References are described in PCI Local Bus Spec
1376
// Revision 2.2 section 3.2.2.3.4
1377
// The idea is that a Config command must be seen, IDSEL must be LOW,
1378
// AD[1:0] must be 2'b00, and either AD[10:8] should be ignored
1379
//   for a single function device, or only implemented devices should
1380
//   respond.  Function 0 is required to be detected.
1381
 
1382
// Make a fake version just to make the charts pop:
1383
 
1384
// Fire off Target tasks in response to PCI Bus Activity
1385
  reg     saw_fast_back_to_back;
1386
  always @(posedge pci_ext_clk or posedge pci_reset_comb)
1387
  begin
1388
    if (~pci_reset_comb)
1389
    begin
1390
      saw_fast_back_to_back = 1'b1;
1391
      while (saw_fast_back_to_back == 1'b1)  // whats the value of this loop?  Does it reset correctly?
1392
      begin
1393
        hold_target_address[PCI_BUS_DATA_RANGE:0] = ad_now[PCI_BUS_DATA_RANGE:0];  // intentionally use "="
1394
        hold_target_command[PCI_BUS_CBE_RANGE:0]  = cbe_l_now[PCI_BUS_CBE_RANGE:0];
1395
        if (test_response[`TARGET_ENCODED_PARAMATERS_ENABLE] != 1'b0)
1396
        begin
1397
          hold_target_initial_waitstates    = test_response[`TARGET_ENCODED_INIT_WAITSTATES];
1398
          hold_target_subsequent_waitstates = test_response[`TARGET_ENCODED_SUBS_WAITSTATES];
1399
          hold_target_termination           = test_response[`TARGET_ENCODED_TERMINATION];
1400
          hold_target_devsel_speed          = test_response[`TARGET_ENCODED_DEVSEL_SPEED];
1401
          hold_target_data_par_err          = test_response[`TARGET_ENCODED_DATA_PAR_ERR];
1402
          hold_target_addr_par_err          = test_response[`TARGET_ENCODED_ADDR_PAR_ERR];
1403
          hold_target_terminate_on          = test_response[`TARGET_ENCODED_TERMINATE_ON];
1404
        end
1405
        else
1406
        begin
1407
          hold_target_initial_waitstates    = 4'h0;
1408
          hold_target_subsequent_waitstates = 4'h0;
1409
          hold_target_termination           = `Test_Target_Normal_Completion;
1410
          hold_target_devsel_speed          = `Test_Devsel_Medium;
1411
          hold_target_data_par_err          = `Test_No_Data_Perr;
1412
          hold_target_addr_par_err          = `Test_No_Addr_Perr;
1413
          hold_target_terminate_on          = 0 ;
1414
        end
1415
 
1416
        if (~frame_prev & frame_now & Target_En
1417
`ifdef SIMULTANEOUS_MASTER_TARGET
1418
// don't check for reads to self
1419
`else // SIMULTANEOUS_MASTER_TARGET
1420
// check for, and don't respond to, reads to self
1421
`endif //SIMULTANEOUS_MASTER_TARGET
1422
            & (   (cbe_l_now[PCI_BUS_CBE_RANGE:0] == PCI_COMMAND_MEMORY_WRITE)
1423
                | (cbe_l_now[PCI_BUS_CBE_RANGE:0] == PCI_COMMAND_MEMORY_WRITE_INVALIDATE) )
1424
            & (   (ad_now[`PCI_BASE_ADDR0_MATCH_RANGE] == BAR0[`PCI_BASE_ADDR0_MATCH_RANGE])
1425
`ifdef PCI_BASE_ADDR1_MATCH_ENABLE
1426
                | (ad_now[`PCI_BASE_ADDR1_MATCH_RANGE] == BAR1[`PCI_BASE_ADDR1_MATCH_RANGE])
1427
`endif  // PCI_BASE_ADDR1_MATCH_ENABLE
1428
              ) )
1429
        begin
1430
          Execute_Target_PCI_Ref (`TEST_TARGET_DOING_SRAM_WRITE,
1431
                                                 saw_fast_back_to_back);
1432
        end
1433
        else if (~frame_prev & frame_now & (idsel_now == 1'b1)
1434
               & (cbe_l_now[PCI_BUS_CBE_RANGE:0] == PCI_COMMAND_CONFIG_WRITE)
1435
               & (ad_now[1:0]  == 2'b00) )
1436
        begin
1437
          Execute_Target_PCI_Ref (`TEST_TARGET_DOING_CONFIG_WRITE,
1438
                                                 saw_fast_back_to_back);
1439
        end
1440
        else if (~frame_prev & frame_now & Target_En
1441
`ifdef SIMULTANEOUS_MASTER_TARGET
1442
// Don't check for reads to self
1443
`else // SIMULTANEOUS_MASTER_TARGET
1444
// Check for, and don't respond to, reads to self
1445
`endif //SIMULTANEOUS_MASTER_TARGET
1446
            & (   (cbe_l_now[PCI_BUS_CBE_RANGE:0] == PCI_COMMAND_MEMORY_READ)
1447
                | (cbe_l_now[PCI_BUS_CBE_RANGE:0] == PCI_COMMAND_MEMORY_READ_MULTIPLE)
1448
                | (cbe_l_now[PCI_BUS_CBE_RANGE:0] == PCI_COMMAND_MEMORY_READ_LINE) )
1449
            & (   (ad_now[`PCI_BASE_ADDR0_MATCH_RANGE] == BAR0[`PCI_BASE_ADDR0_MATCH_RANGE])
1450
`ifdef PCI_BASE_ADDR1_MATCH_ENABLE
1451
                | (ad_now[`PCI_BASE_ADDR1_MATCH_RANGE] == BAR1[`PCI_BASE_ADDR1_MATCH_RANGE])
1452
`endif  // PCI_BASE_ADDR1_MATCH_ENABLE
1453
              ) )
1454
        begin
1455
          Execute_Target_PCI_Ref (`TEST_TARGET_DOING_SRAM_READ,
1456
                                                 saw_fast_back_to_back);
1457
        end
1458
        else if (~frame_prev & frame_now & (idsel_now == 1'b1)
1459
               & (cbe_l_now[PCI_BUS_CBE_RANGE:0] == PCI_COMMAND_CONFIG_READ)
1460
               & (ad_now[1:0]  == 2'b00) )
1461
        begin
1462
          Execute_Target_PCI_Ref (`TEST_TARGET_DOING_CONFIG_READ,
1463
                                                 saw_fast_back_to_back);
1464
        end
1465
        else
1466
        begin
1467
          saw_fast_back_to_back = 1'b0;
1468
        end
1469
        if (pci_reset_comb)
1470
        begin
1471
          saw_fast_back_to_back = 1'b0;
1472
        end
1473
      end  // saw_fast_back_to_back
1474
    end
1475
    `NO_ELSE;
1476
// Because this is sequential code, have to reset all regs if the above falls
1477
// through due to a reset.  This would not be needed in synthesizable code.
1478
    if (pci_reset_comb)
1479
    begin
1480
      Reset_Target_To_Idle;
1481
    end
1482
    `NO_ELSE;
1483
  end
1484
endmodule
1485
 

powered by: WebSVN 2.1.0

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