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

Subversion Repositories pci_mini

[/] [pci_mini/] [trunk/] [pci-33.v] - Blame information for rev 9

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

Line No. Rev Author Line
1 7 ocadmin
// *************************************************************** //
2
//                                                                                                                                                                               //
3
//                      PCI_TARGET-Wishbone_MASTER INTERFACE MODULE     (PCI-mini)       //
4
//                                                                                      v2.0                                                                             //
5
//                                                                                                                                                                               //
6
//   The original PCI module is from:   Ben Jackson                                              //
7
//                              http://www.ben.com/minipci/verilog.php                                           //
8
//                                                                                                                                                                               //
9
//        Redesigned for wishbone : Istvan Nagy, buenos@freemail.hu              //
10
//                                              PEC Products, Industrial Technologies                            //
11
//                                                                                                                                                                               //
12
// *************************************************************** //
13
 
14
// The core implements a 16MB relocable memory image. Relocable on the
15
//   wb bus. the wb address = 4M*wb_baseaddr_reg + PCI_addr[23:2]
16
//   Only Dword aligned Dword accesses allowed on the PCI. This way
17
//   we can access to the 4GB wb-space through a 16MB PCI-window.
18
//   The addressing on the wb-bus, is Dword addressing, while on the
19
//   PCI bus, the addressing is byte addressing. A(pci)=A(wb)*4
20
//   The PCI address is increasing by 4, and we get 4 bytes. The wb
21
//   address is increasing by 1, and we get 1 Dword (= 4 bytes also).
22
//   The wb_baseaddr_reg is the wb image relocation register, can be
23
//   accessed at 50h address in the PCI configuration space.
24
//   Other bridge status and command is at the 54h and 58h addresses.
25
//   if access fails with timeout, then the address will be in the 
26
//   wb address will be stored in the failed_addr_reg at 5Ch address.
27
//
28
// Wishbone compatibility:
29
//  Wishbone signals: wb_address, wb_dat_o, wb_dat_i, wb_sel_o, wb_cyc_o, 
30
//  wb_stb_o, wb_wr_o, wb_reset_o, wb_clk_o, wb_ack_i.
31
//  Not implemented wb signals: error, lock, retry, tag-signals.
32
//  The peripheral has to response with ack in 16 clk cycles.
33
//  The core has wishbone clk and reset outputs, just like a Syscon module.
34
//  The core generates single reads/writes. These are made of 4 phases, so
35
//  dont write new data, until internal data movement finishes: about 300...500ns
36
//
37
// PCI compatibility: 
38
// Only single DWORD reads/writes are supported. between them, the software has 
39
//   to wait 300...500nsec, to prevent data corrupting. STOP signaling is not 
40
//   implemented, so target terminations also not. 
41
//   Single Byte access is NOT supported! It may cause corrupt data.
42
//   The core uses INTA interrupt signal. There are some special PCI config
43
//   registers, from 50h...60h config-space addresses.
44
//   PCI-parity: it generates parity, but doesnt check incoming parity.
45
//   Because of the PC chipset, if you read a value and write it back,
46
//   the chipset will not write anything, because it can see the data is not 
47
//   changed. This is important at some peripherals, where you write, to control.
48
// Device specific PCI config header registers:
49
//   name:                                      addr:           function:
50
//   wb_baseaddr_reg;   50h             A(wb)=(A(pci)-BAR0)/4 + wb_baseaddr_reg
51
//   user_status_reg;   54h             not used yet
52
//   user_command_reg;  58h             not used yet
53
//   failed_addr_reg;   5Ch             address, when timeout occurs on the wb bus.
54
//
55
// Local bus arbitration: 
56
// This is not really wishbone compatible, but needed for the PCI.
57
//  The method is: "brute force". it means if the PCI interface wants to
58
//  be mastering on the local (wishbone) bus, then it will be mastering,
59
//  so, the other master(s) must stop anything immediately. The req signal
60
//  goes high when there is an Address hit on teh PCI bus. so the other
61
//  master has few clk cycles to finish.
62
// Restrictions: the peripherals have to be fast: If the other master
63
//  starts a transaction before req goes high, the ack has to arrive before 
64
//  the PCI interface starts its own transaction. (max 4clk ACK delay)
65
//  The other master or the bus unit must sense the req, and give bus
66
//  mastering to the PCI-IF immediatelly, not just when the other master
67
//  finished everything, like at normal arbitration schemes.
68
//
69
// Buffering:
70
//  There is a single Dword buffering only.
71
//
72
// The led_out interface: 
73
//  only for system-debug: we can write to the LEDs, at any address. 
74
//  (in the same time there is a wishbone write also)
75
//
76
// Changes since original version: wishbone interface,
77
//  bigger memory-image, parity-generation,
78
//  interrupt handling. Code size is 3x bigger. New registers, 
79
//
80
// *************************************************************** //
81
 
82
 
83
 
84
module pci(reset,clk,frame,irdy,trdy,devsel,idsel,ad,cbe,par,stop,inta,serr,perr,led_out, wb_address, wb_dat_o, wb_dat_i, wb_sel_o, wb_cyc_o, wb_stb_o, wb_wr_o, wb_reset_o, wb_clk_o, wb_ack_i, wb_irq, wb_req, wb_gnt, wb_req_other, contr_o);
85
    input reset;
86
    input clk;
87
    input frame;
88
    input irdy;
89
    output trdy;
90
    output devsel;
91
    input idsel;
92
    inout [31:0] ad;
93
    input [3:0] cbe;
94
    inout par;
95
    output stop;
96
    output inta;
97
    output serr;
98
    output perr;
99
    output [3:0] led_out;
100
                output [31:0] wb_address;
101
                output [31:0] wb_dat_o;
102
                input [31:0] wb_dat_i;
103
                output [3:0] wb_sel_o;
104
                output wb_cyc_o;
105
                output wb_stb_o;
106
                output wb_wr_o;
107
                output wb_reset_o;
108
                output wb_clk_o;
109
                input wb_ack_i;
110
                input wb_irq;
111
                output wb_req;
112
                input wb_gnt;
113
                input wb_req_other;
114
        output [7:0] contr_o;
115
 
116
 
117
 
118
parameter DEVICE_ID = 16'h9500;
119
parameter VENDOR_ID = 16'h10EE; //       16'h10EE=xilinx, 16'h106d; // Sequent!
120
parameter DEVICE_CLASS = 24'h068000;    // Bridge device - other_bridge_type (original:FF0000 Misc)
121
parameter DEVICE_REV = 8'h01;
122
parameter SUBSYSTEM_ID = 16'h0001;      // Card identifier
123
parameter SUBSYSTEM_VENDOR_ID = 16'hBEBE; // Card identifier
124
parameter DEVSEL_TIMING = 2'b00;        // Fast!
125
 
126
reg [2:0] state;
127
reg [31:0] data;
128
 
129
reg [1:0] enable;
130
parameter EN_NONE = 0;
131
parameter EN_RD = 1;
132
parameter EN_WR = 2;
133
parameter EN_TR = 3;
134
 
135
reg memen; // respond to baseaddr?
136
reg [7:0] baseaddr;
137
reg [5:0] address;
138
 
139
reg [9:0] wb_baseaddr_reg; //remap the image on the wishbone bus
140
reg [31:0] wb_address_1;
141
reg [31:0] user_status_reg;
142
reg [31:0] user_command_reg;
143
reg [31:0] failed_addr_reg;
144
reg [31:0] dummy_reg;
145
reg [31:0] pci_read_reg;
146
reg [31:0] pci_write_reg;
147
reg [31:0] wb_read_reg;
148
reg [31:0] wb_write_reg;
149
reg [3:0] pci_read_sel_reg;
150
reg [3:0] pci_write_sel_reg;
151
reg [3:0] wb_read_sel_reg;
152
reg [3:0] wb_write_sel_reg;
153
 
154
assign contr_o = user_command_reg [7:0];
155
 
156
parameter ST_IDLE = 3'b000;
157
parameter ST_BUSY = 3'b010;
158
parameter ST_MEMREAD = 3'b100;
159
parameter ST_MEMWRITE = 3'b101;
160
parameter ST_CFGREAD = 3'b110;
161
parameter ST_CFGWRITE = 3'b111;
162
 
163
parameter MEMREAD = 4'b0110;
164
parameter MEMWRITE = 4'b0111;
165
parameter CFGREAD = 4'b1010;
166
parameter CFGWRITE = 4'b1011;
167
 
168
`define LED
169
`ifdef LED
170
reg [3:0] led;
171
`endif
172
 
173
`undef STATE_DEBUG_LED
174
`ifdef STATE_DEBUG_LED
175
assign led_out = ~state;
176
`else
177
`ifdef LED
178
assign led_out = ~led;
179
`endif
180
`endif
181
 
182
assign ad = (enable == EN_RD) ? data : 32'bZ;
183
assign trdy = (enable == EN_NONE) ? 'bZ : (enable == EN_TR ? 1 : 0);
184
//assign par = (enable == EN_RD) ? 0 : 'bZ;
185
reg devsel;
186
 
187
assign stop = 1'bZ;
188
//assign inta = 1'bZ;
189
assign serr = 1'bZ;
190
assign perr = 1'bZ;
191
 
192
 
193
wire cfg_hit = ((cbe == CFGREAD || cbe == CFGWRITE) && idsel && ad[1:0] == 2'b00);
194
wire addr_hit = ((cbe == MEMREAD || cbe == MEMWRITE) && memen && ad[31:24] == {baseaddr});
195
wire hit = cfg_hit | addr_hit;
196
 
197
// Wishbone SYSCON: output signals------------------------------------
198
assign wb_reset_o = ~reset;
199
assign wb_clk_o = clk;
200
//reg wb_clk_o;
201
   //always @(posedge clk)
202
                //wb_clk_o = wb_clk_o+ 1;
203
 
204
 
205
// PCI parity generation:---------------------------------------------
206
// during read, the parity on AD, and delayen by one clk.
207
reg par_en;
208
reg par_latched;
209
reg EN_RDd;
210
wire data_par = (data[31] ^ data[30] ^ data[29] ^ data[28]) ^
211
                (data[27] ^ data[26] ^ data[25] ^ data[24]) ^
212
                (data[23] ^ data[22] ^ data[21] ^ data[20]) ^
213
                (data[19] ^ data[18] ^ data[17] ^ data[16]) ^
214
                (data[15] ^ data[14] ^ data[13] ^ data[12]) ^
215
                (data[11] ^ data[10] ^ data[9]  ^ data[8])  ^
216
                (data[7]  ^ data[6]  ^ data[5]  ^ data[4])  ^
217
                                          (cbe[3]  ^ cbe[2]  ^ cbe[1]  ^ cbe[0])  ^
218
                (data[3]  ^ data[2]  ^ data[1]  ^ data[0]) ;
219
 
220
   always @(posedge clk) //delaying of parity
221
      if ((enable == EN_RD)|(enable == EN_TR)) begin
222
         par_latched = data_par; end
223
      else
224
         begin par_latched = 0; end
225
 
226
   always @(posedge clk) //delaying of EN_RD
227
                        EN_RDd = EN_RD;
228
 
229
        //assign par = (enable == EN_RD) ? 0 : 'bZ;
230
        assign par = ((enable == EN_RD)|(enable == EN_RDd)) ? par_latched : 'bZ; //output control
231
 
232
 
233
 
234
// Interrupt handling:--------------------------------------------------------------------
235
reg int_dis;
236
wire int_stat;
237
reg [7:0] int_line;
238
assign inta = ((wb_irq == 1) && (int_dis == 0)) ? 1'b0 : 1'bZ;
239
assign int_stat = wb_irq;
240
 
241
 
242
 
243
// WB bus arbitration:--------------------------------------------------------------------
244
//assign wb_req = mastering;
245
reg arb_start;
246
reg arb_stop;
247
reg wb_req;
248
 
249
   parameter arb_state1 = 2'b00;
250
   parameter arb_state2 = 2'b01;
251
   reg  arb_state = arb_state1;
252
   always@(posedge clk) begin
253
      if (wb_reset_o) begin
254
         arb_state <= arb_state1;
255
         wb_req <= 0;
256
      end
257
      else
258
         case (arb_state)
259
            arb_state1 : begin //arbitration is not needed: IDLE
260
               wb_req <= 0;
261
               if (arb_start == 1)
262
                  arb_state <= arb_state2;
263
            end
264
            arb_state2 : begin //arbitration is needed
265
               wb_req <= 1;
266
               if (arb_stop == 1)
267
                  arb_state <= arb_state1;
268
            end
269
            default : begin  // Fault Recovery
270
               arb_state <= arb_state1;
271
               wb_req <= 0;
272
            end
273
         endcase
274
                end
275
 
276
 
277
 
278
// -------------- wishbone state machine --------------------------------------------------
279
//write FIFO buffer:
280
reg [31:0] wb_wr_buf [5:0]; //64 Dwords wb write buffer: wb_wr_buf[index] <= value;
281
reg [3:0] wb_wr_sel_buf [5:0]; //select lines, write buffer: wb_wr_buf[index] <= value;
282
reg [31:0] fifo_start_wb_addr;
283
reg [31:0] fifo_act_wb_addr;
284
reg [5:0] fifo_max_count;
285
reg [5:0] fifo_wb_counter;
286
reg [5:0] fifo_wb_counter_o;
287
reg fifo_flush; //wb output mux control
288
reg fifo_flush_start; //start pulse
289
reg fifo_fill; //disable wb during filling fifo
290
reg [3:0] wbw_timeout_count_new;
291
reg [1:0] wbw_phase;
292
//read FIFO buffer:
293
reg [31:0] wb_rd_buf [5:0]; //64 Dwords wb read buffer: wb_rd_buf[index] <= value;
294
reg [3:0] wb_rd_sel_buf [5:0]; //select lines, write buffer: wb_wr_buf[index] <= value;
295
reg [31:0] fifo_start_wb_addr_rd;
296
reg [31:0] fifo_act_wb_addr_rd;
297
reg [5:0] fifo_max_count_rd;
298
reg [5:0] fifo_wb_counter_rd;
299
reg [5:0] fifo_wb_counter_o_rd;
300
reg fifo_flush_rd; //wb output mux control
301
reg fifo_fill_start_rd; //start pulse
302
reg fifo_fill_rd; //disable wb during filling fifo
303
reg [3:0] wbr_timeout_count_new;
304
reg [1:0] wbr_phase;
305
//
306
reg wb_cyc_o;
307
reg wb_stb_o;
308
reg wb_wr_o;
309
reg [31:0] wb_address;
310
reg [3:0] wb_sel_o;
311
reg [31:0] wb_dat_o;
312
reg machinereset;
313
reg mastering;
314
//assign wb_req = mastering;
315
 
316
 
317
   parameter machine_waiting = 2'b00;
318
   parameter machine_flushing = 2'b01;
319
   parameter machine_read_filling = 2'b11;
320
   reg [1:0] wbwf_state = machine_waiting;
321
 
322
   always@(posedge wb_clk_o)
323
      if (wb_reset_o) begin
324
         wbwf_state <= machine_waiting;
325
                         wbw_phase <= 0;
326
                        wbw_timeout_count_new <= 0;
327
                        fifo_wb_counter_o<=0;
328
                        fifo_flush <= 0;
329
                        wb_cyc_o <= 0;
330
                        wb_stb_o <= 0;
331
                        wb_wr_o <= 0;
332
                         wbr_phase <= 0;
333
                        wbr_timeout_count_new <= 0;
334
                        fifo_wb_counter_o_rd<=0;
335
                        fifo_fill_rd <= 0;
336
                        wb_address[31:0] = 32'b0;
337
                        wb_sel_o = 4'b0;
338
                        wb_dat_o = 32'b0;
339
                        pci_read_reg <= 0;
340
                        mastering <= 0;
341
                        arb_stop <= 0;
342
                        failed_addr_reg <= 0;
343
      end
344
      else
345
         case (wbwf_state)
346
 
347
            machine_waiting : begin //no operation on Wishbone bus **************
348
                                        wbw_phase <= 0;
349
                                        wbw_timeout_count_new <= 0;
350
                                        wbr_phase <= 0;
351
                                        wbr_timeout_count_new <= 0;
352
                                        wb_address[31:0] = 32'b0;
353
                                        wb_cyc_o <= 0;
354
                                        wb_stb_o <= 0;
355
                                        wb_wr_o <= 0;
356
                                        wb_sel_o = 4'b0;
357
                                        wb_dat_o = 32'b0;
358
                                        arb_stop <= 0;
359
               if (fifo_flush_start  == 1)
360
                  begin fifo_flush <= 1; wbwf_state <= machine_flushing; fifo_wb_counter_o<=0; mastering <= 1; end
361
                                        else if (fifo_fill_start_rd == 1)
362
                  begin fifo_fill_rd <= 1; wbwf_state <= machine_read_filling; fifo_wb_counter_o_rd<=0; mastering <= 1; end
363
            end
364
 
365
            machine_flushing : begin //wr-FIFO flushing: wb write***********************
366
                                        wb_sel_o = pci_write_sel_reg;
367
                                        wb_dat_o  = pci_write_reg; //wb_wr_buf[fifo_wb_counter_o];
368
                                        wb_address[31:0]  = fifo_start_wb_addr; //[31:0]+fifo_wb_counter_o ;
369
               if ( wbw_phase== 0 ) begin //phase 0: setup
370
                  wb_cyc_o <= 0;
371
                                                wb_stb_o <= 0;
372
                                                wb_wr_o <= 0;
373
                                                wbw_phase <= wbw_phase + 1;
374
                                                //address and data also changes now, from FIFO
375
                                        end
376
                                        else if ( wbw_phase== 1 ) begin //phase 1: access
377
                  wb_cyc_o <= 1;
378
                                                wb_stb_o <= 1;
379
                                                wb_wr_o <= 1;
380
                                                wbw_phase <= wbw_phase + 1;
381
                                        end
382
                                        else if ( wbw_phase== 2 ) begin //phase 2: wait for ack
383
                                                wbw_timeout_count_new <= wbw_timeout_count_new +1;
384
                                                if ((wb_ack_i==1) | (wbw_timeout_count_new==15)) begin
385
                                                        wbw_phase <= wbw_phase + 1;
386
                                                        wb_cyc_o <= 0;
387
                                                        wb_stb_o <= 0;
388
                                                        wb_wr_o <= 0;
389
                                                        if (wbw_timeout_count_new==15) begin failed_addr_reg <= wb_address; end
390
                                                        end
391
                                                else begin wb_cyc_o <= 1;       wb_stb_o <= 1;  wb_wr_o <= 1; end
392
                                        end
393
                                        else  if ( wbw_phase== 3 ) begin //phase 3: hold (finish)
394
                                           wb_cyc_o <= 0;
395
                                                wb_stb_o <= 0;
396
                                                wb_wr_o <= 0;
397
                                                wbw_phase <= wbw_phase + 1;
398
                                                wbw_timeout_count_new <=0;
399
                                                fifo_wb_counter_o <= fifo_wb_counter_o + 1; //for next word
400
                                                //if ((fifo_wb_counter_o == fifo_max_count-1)|(machinereset == 1)) begin 
401
                                                        fifo_flush <= 0;
402
                                                        wbwf_state <= machine_waiting;
403
                                                        fifo_wb_counter_o<=0;
404
                                                        mastering <= 0;
405
                                                        arb_stop <= 1;
406
                                                //end
407
                                        end
408
            end
409
 
410
            machine_read_filling : begin //rd-FIFO filling: wb read********************
411
                                   wb_sel_o = pci_read_sel_reg;
412
                                        wb_dat_o = 32'b0;
413
                                        wb_address[31:0]  = fifo_start_wb_addr_rd; //[31:0]+fifo_wb_counter_o_rd ;
414
               if ( wbr_phase== 0 ) begin //phase 0: setup
415
                  wb_cyc_o <= 0;
416
                                                wb_stb_o <= 0;
417
                                                wb_wr_o <= 0;
418
                                                wbr_phase <= wbr_phase + 1;
419
                                                //address and data also changes now, from FIFO
420
                                        end
421
                                        else if ( wbr_phase== 1 ) begin //phase 1: access
422
                  wb_cyc_o <= 1;
423
                                                wb_stb_o <= 1;
424
                                                wb_wr_o <= 0;
425
                                                wbr_phase <= wbr_phase + 1;
426
                                        end
427
                                        else if ( wbr_phase== 2 ) begin //phase 2: wait for ack
428
                                                wbr_timeout_count_new <= wbr_timeout_count_new +1;
429
                                                if ((wb_ack_i==1) | (wbr_timeout_count_new==15)) begin
430
                                                        //wb_rd_buf[fifo_wb_counter_o_rd] <= wb_dat_i; //sampling
431
                                                        pci_read_reg <= wb_dat_i; //sampling
432
                                                        wbr_phase <= wbr_phase + 1;
433
                                                        wb_cyc_o <= 0;
434
                                                        wb_stb_o <= 0;
435
                                                        wb_wr_o <= 0;
436
                                                        if (wbw_timeout_count_new==15) begin failed_addr_reg <= wb_address; end
437
                                                        end
438
                                                else begin wb_cyc_o <= 1;       wb_stb_o <= 1;  wb_wr_o <= 0; end
439
                                        end
440
                                        else  if ( wbr_phase== 3 ) begin //phase 3: hold (finish)
441
                                           wb_cyc_o <= 0;
442
                                                wb_stb_o <= 0;
443
                                                wb_wr_o <= 0;
444
                                                wbr_phase <= wbw_phase + 1;
445
                                                wbr_timeout_count_new <=0;
446
                                                fifo_wb_counter_o_rd <= fifo_wb_counter_o_rd + 1; //for next word
447
                                                //if ((fifo_wb_counter_o_rd == fifo_max_count_rd-1)|(machinereset == 1)) begin 
448
                                                        fifo_fill_rd <= 0;
449
                                                        wbwf_state <= machine_waiting;
450
                                                        fifo_wb_counter_o_rd<=0;
451
                                                        mastering <= 0;
452
                                                        arb_stop <= 1;
453
                                                //end
454
                                        end
455
            end
456
 
457
            default : begin  // Fault Recovery
458
               wbwf_state <= machine_waiting;
459
            end
460
 
461
 
462
         endcase
463
 
464
 
465
 
466
 
467
 
468
 
469
 
470
// main PCI state machine: ---------------------------------------------------------------
471
always @(posedge clk)
472
begin
473
    if (~reset) begin
474
        state <= ST_IDLE;
475
        enable <= EN_NONE;
476
        baseaddr <= 0;
477
        devsel <= 'bZ;
478
        memen <= 0;
479
                  int_line <= 8'b0;
480
                  int_dis <= 0;
481
                  wb_baseaddr_reg <= 0;
482
                  wb_address_1[31:0] <= 0;
483
                  user_status_reg <= 0;
484
                  user_command_reg <= 0;
485
                  fifo_flush_start <= 0;
486
                  fifo_fill_start_rd <= 0;
487
                  fifo_wb_counter <= 0;
488
                  fifo_wb_counter_rd <= 0;
489
                        dummy_reg  <= 0;
490
                        pci_write_reg <= 0;
491
                        machinereset   <= 0;
492
        led <= 0;
493
                  arb_start <= 0;
494
 
495
    end
496
    else    begin
497
 
498
    case (state)
499
        ST_IDLE: begin
500
            enable <= EN_NONE;
501
            devsel <= 'bZ;
502
                                fifo_flush_start <= 0;
503
                                fifo_fill_start_rd <= 0;
504
                                fifo_wb_counter <= 0;
505
                                fifo_wb_counter_rd <= 0;
506
                                machinereset   <= 0;
507
            if (~frame) begin
508
                address <= ad[7:2];
509
                if (hit) begin
510
                    state <= {1'b1, cbe[3], cbe[0]};
511
                                                  if (addr_hit) begin  arb_start <= 1; end
512
                    devsel <= 0;
513
                                                  wb_address_1[31:0] <= {wb_baseaddr_reg, ad[23:2]};
514
                                                  //if (wbwf_state == machine_waiting) begin //sample address, if FIFO is not busy
515
                                                                fifo_start_wb_addr <= {wb_baseaddr_reg, ad[23:2]};
516
                                                                fifo_start_wb_addr_rd <= {wb_baseaddr_reg, ad[23:2]};
517
                                                  //end         
518
                    // pipeline the write enable
519
                    if (cbe[0])
520
                        enable <= EN_WR;
521
                end
522
                else begin
523
                    state <= ST_BUSY;
524
                    enable <= EN_NONE;
525
                end
526
            end
527
        end
528
 
529
        ST_BUSY: begin
530
            devsel <= 'bZ;
531
            enable <= EN_NONE;
532
                                arb_start <= 0;
533
            if (frame)
534
                state <= ST_IDLE;
535
        end
536
 
537
        ST_CFGREAD: begin
538
            enable <= EN_RD;
539
            if (~irdy || trdy) begin
540
                case (address)
541
                    0: data <= { DEVICE_ID, VENDOR_ID };
542
                    1: data <= { 5'b0, DEVSEL_TIMING,  5'b0, int_stat, 8'b0, int_dis, 8'b0, memen, 1'b0};
543
                    2: data <= { DEVICE_CLASS, DEVICE_REV };
544
                    4: data <= { baseaddr, 12'b0, 8'b0, 4'b0000 }; // baseaddr + request mem < 1Mbyte
545
                    11: data <= {SUBSYSTEM_ID, SUBSYSTEM_VENDOR_ID };
546
                                                  15: data <= {16'b0, 7'b0, 1'b1, int_line}; //irq pin and line
547
                    16: data <= { 24'b0, baseaddr };
548
                                                  20: data <= { wb_baseaddr_reg, 22'b0}; //wb base address: for wb-local relocation
549
                                                  21: data <= user_status_reg;
550
                                                  22: data <= user_command_reg;
551
                                                  23: data <= failed_addr_reg; //actual addr, at a timeout
552
                    default: data <= 'h00000000;
553
                endcase
554
                address <= address + 1;
555
                                         arb_start <= 0;
556
            end
557
            if (frame && ~irdy && ~trdy) begin
558
                devsel <= 1;
559
                state <= ST_IDLE;
560
                enable <= EN_TR;
561
            end
562
        end
563
 
564
        ST_CFGWRITE: begin
565
            enable <= EN_WR;
566
            if (~irdy) begin
567
                case (address)
568
                    4: baseaddr <= ad[31:24];  // XXX examine cbe
569
                    1: begin memen <= ad[1]; int_dis <= ad[10]; end
570
                                                  15: int_line <= ad[7:0];
571
                                                  20: wb_baseaddr_reg <= ad[31:22];
572
                                                  22: user_command_reg  <= ad[31:0];
573
                                                  24: machinereset   <= 1;      //resetting the wb state machine (60h)
574
                    default: ;
575
                endcase
576
                address <= address + 1;
577
                                         arb_start <= 0;
578
                if (frame) begin
579
                    devsel <= 1;
580
                    state <= ST_IDLE;
581
                    enable <= EN_TR;
582
                end
583
            end
584
        end
585
 
586
        ST_MEMREAD: begin
587
            enable <= EN_RD;
588
                                arb_start <= 0;
589
            if (~irdy || trdy) begin
590
                address <= address + 1;
591
                                         data <= pci_read_reg;
592
                                         pci_read_sel_reg  <= ~cbe;
593
            end
594
            if (frame && ~irdy && ~trdy) begin
595
                devsel <= 1;
596
                state <= ST_IDLE;
597
                enable <= EN_TR;
598
                                                  fifo_fill_rd<=0;
599
                                                  //if (wbwf_state == machine_waiting) begin 
600
                                                                fifo_fill_start_rd <= 1;
601
                                                  //end                                          
602
            end
603
        end
604
 
605
        ST_MEMWRITE: begin
606
            enable <= EN_WR;
607
                                arb_start <= 0;
608
            if (~irdy) begin
609
                                         led <= ad[3:0];
610
                                         pci_write_reg  <= ad[31:0];
611
                                         pci_write_sel_reg <= ~cbe;
612
                address <= address + 1;
613
                if (frame) begin
614
                    devsel <= 1;
615
                    state <= ST_IDLE;
616
                    enable <= EN_TR;
617
                                                  fifo_fill<=0;
618
                                                  //if (wbwf_state == machine_waiting) begin 
619
                                                                fifo_flush_start <= 1;
620
                                                  //end         
621
               end
622
            end
623
 
624
        end
625
 
626
    endcase
627
    end
628
end
629
endmodule

powered by: WebSVN 2.1.0

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