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

Subversion Repositories pci

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

powered by: WebSVN 2.1.0

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