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

Subversion Repositories pcie_sg_dma

[/] [pcie_sg_dma/] [trunk/] [sim/] [tf64_pcie_trn.v] - Blame information for rev 5

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

Line No. Rev Author Line
1 3 weng_ziti
`timescale 1ns / 1ps
2
 
3
////////////////////////////////////////////////////////////////////////////////
4
// Company:  ziti, Uni. HD
5
// Engineer:  wgao
6
//            weng.ziti@gmail.com
7
// 
8
// Create Date:   16:54:18 04 Nov 2008
9
// Design Name:   tlpControl
10
// Module Name:   tf64_pcie_trn.v
11
// Project Name:  PCIE_SG_DMA
12
// Target Device:  
13
// Tool versions:  
14
// Description:  PIO and DMA are both simulated.
15
//
16
// Verilog Test Fixture created by ISE for module: tlpControl
17
//
18
// Dependencies:
19
// 
20
// Revision:
21
// Revision 0.01 - File Created
22
// 
23
// Revision 1.00 - Released to OpenCores.org   14.09.2011
24
// 
25
// Additional Comments:
26
// 
27
////////////////////////////////////////////////////////////////////////////////
28
 
29
 
30
//`define  RANDOM_SEQUENCE
31
 
32
  /*  Time parameters  */
33
`define  T_HALF_CYCLE_CLK                   4.0
34
`define  T_HALF_CYCLE_MEMCLK                5.0
35
`define  T_DELAY_AFTER                      0.0
36
`define  T_DELTA                            0.1
37
`define  T_PIO_INTERVAL                    50.0
38
`define  T_DMA_INTERVAL                   300.0
39
`define  T_RX_NO_FC_PERIOD            1900000.0
40
`define  T_TX_NO_FC_PERIOD            1500000.0
41
 
42
  /* Memory size for simulation */
43
`define  C_ARRAY_DIMENSION              4096
44
 
45
  /* Start indices */
46
`define  PIO_START_INDEX                'H0300
47
`define  DMA_START_INDEX                'H0000
48
 
49
  /* Request completion boundary */
50
`define  C_RCB_16_DW                    'H10
51
`define  C_RCB_32_DW                    'H20
52
 
53
  /* BAR */
54
`define  C_BAR0_HIT                    7'H7E
55
`define  C_BAR1_HIT                    7'H7D
56
`define  C_BAR2_HIT                    7'H7B
57
`define  C_BAR3_HIT                    7'H77
58
`define  C_BAR4_HIT                    7'H6F
59
`define  C_BAR5_HIT                    7'H5F
60
`define  C_BAR6_HIT                    7'H3F
61
`define  C_NO_BAR_HIT                  7'H7F
62
 
63
 
64
  /* Requester ID and Completer ID */
65
`define  C_HOST_WRREQ_ID              16'H0ABC
66
`define  C_HOST_RDREQ_ID              16'HE1E2
67
`define  C_HOST_CPLD_ID               16'HC01D
68
 
69
  /* 1st header */
70
`define  HEADER0_MWR3_                32'H40000000
71
`define  HEADER0_MWR4_                32'H60000000
72
`define  HEADER0_MRD3_                32'H00000000
73
`define  HEADER0_MRD4_                32'H20000000
74
`define  HEADER0_CPLD                 32'H4A000000
75
`define  HEADER0_CPL                  32'H0A000000
76
`define  HEADER0_MSG                  32'H34000001
77
 
78
  /* Message codes */
79
`define  C_MSG_CODE_INTA               8'H20
80
`define  C_MSG_CODE_INTA_N             8'H24
81
 
82
  /* Payload type */
83
`define  USE_PRIVATE                    1
84
`define  USE_PUBLIC                     0
85
 
86
  /* General registers */
87
`define  C_ADDR_VERSION                 32'H0000
88
`define  C_ADDR_IRQ_STAT                32'H0008
89
`define  C_ADDR_IRQ_EN                  32'H0010
90
`define  C_ADDR_GSR                     32'H0020
91
`define  C_ADDR_GCR                     32'H0028
92
 
93
  /* Control registers for special ports */
94
`define  C_ADDR_MRD_CTRL                32'H0074
95
`define  C_ADDR_TX_CTRL                 32'H0078
96
`define  C_ADDR_ICAP                    32'H007C
97
`define  C_ADDR_EB_STACON               32'H0090
98
 
99
  /* Downstream DMA channel registers */
100
`define  C_ADDR_DMA_DS_PAH              32'H0050
101
`define  C_ADDR_DMA_DS_CTRL             32'H006C
102
`define  C_ADDR_DMA_DS_STA              32'H0070
103
 
104
  /* Upstream DMA channel registers */
105
`define  C_ADDR_DMA_US_PAH              32'H002C
106
`define  C_ADDR_DMA_US_CTRL             32'H0048
107
`define  C_ADDR_DMA_US_STA              32'H004C
108
 
109
  /* DMA-specific constants */
110
`define  C_DMA_RST_CMD                  32'H0200000A
111
 
112
 
113
module tf64_pcie_trn();
114
 
115
   // Inputs
116
   reg  trn_reset_n;
117
   reg  trn_lnk_up_n;
118
   reg  trn_clk;
119
   reg  trn_rsof_n;
120
   reg  trn_reof_n;
121
   reg  [63:0] trn_rd;
122
   reg  [7:0] trn_rrem_n;
123
   reg  trn_rsrc_rdy_n;
124
   wire trn_rdst_rdy_n;
125
   reg  [6:0] trn_rbar_hit_n;
126
   wire trn_rnp_ok_n;
127
   reg  trn_rerrfwd_n;
128
   reg  trn_rsrc_dsc_n;
129
   wire trn_tsof_n;
130
   wire trn_teof_n;
131
   wire [63:0] trn_td;
132
   wire [7:0] trn_trem_n;
133
   wire trn_tsrc_rdy_n;
134
   reg  trn_tdst_rdy_n;
135
   wire trn_terrfwd_n;
136
   wire trn_tsrc_dsc_n;
137
   reg  trn_tdst_dsc_n;
138
   reg  [3:0] trn_tbuf_av;
139
//   reg cfg_interrupt_rdy_n;
140
//   reg [2:0] cfg_interrupt_mmenable;
141
//   reg cfg_interrupt_msienable;
142
//   reg [7:0] cfg_interrupt_do;
143
   reg [5:0] pcie_link_width;
144
   reg [15:0] cfg_dcommand;
145
   reg [15:0] localID;
146
 
147
   // Outputs
148
   wire DDR_wr_v;
149
   wire DDR_wr_sof;
150
   wire DDR_wr_eof;
151
   wire DDR_wr_Shift;
152
   wire [1:0] DDR_wr_Mask;
153
   wire [63:0] DDR_wr_din;
154
   wire DDR_wr_full;
155
   wire DDR_rdc_v;
156
   wire DDR_rdc_sof;
157
   wire DDR_rdc_eof;
158
   wire DDR_rdc_Shift;
159
   wire [63:0] DDR_rdc_din;
160
   wire DDR_rdc_full;
161
   wire DDR_FIFO_RdEn;
162
   wire DDR_FIFO_Empty;
163
   wire [63:0] DDR_FIFO_RdQout;
164
   reg  mbuf_UserFull;
165
   wire DDR_Ready;
166
   wire trn_Blinker;
167
   reg  mem_clk;
168
 
169
   // FIFO
170
   wire           eb_FIFO_we;
171
   wire [64-1:00] eb_FIFO_din;
172
   wire           eb_FIFO_re;
173
   wire [72-1:00] eb_FIFO_qout;
174
   wire [64-1:00] eb_FIFO_Status;
175
   wire           eb_FIFO_Rst;
176
 
177
   wire           eb_pfull;
178
   wire           eb_full;
179
   wire           eb_pempty;
180
   wire           eb_empty;
181
 
182
   wire [27-1:0]  eb_FIFO_Data_Count;
183
 
184
   // flow control toggles
185
   reg            Rx_No_Flow_Control;
186
   reg            Tx_No_Flow_Control;
187
 
188
   // message counters 
189
   reg  [31:00] Accum_Msg_INTA        = 0;
190
   reg  [31:00] Accum_Msg_INTA_n      = 0;
191
 
192
   // random seed
193
   reg [127: 0]  Op_Random;
194
 
195
   // Generated Array
196
   reg [15:00]  ii;
197
   reg [31:00]  D_Array[`C_ARRAY_DIMENSION-1:00];
198
 
199
   //
200
   reg  [ 7: 0] FSM_Trn;
201
   reg  [31: 0] Hdr_Array[3:0];
202
   reg  [31: 0] Private_Array[15:0];
203
   reg  [10: 0] Rx_TLP_Length;
204
   reg  [ 7: 0] Rx_MWr_Tag;
205
   reg  [ 4: 0] Rx_MRd_Tag;
206
   reg  [31:00] Tx_MRd_Addr;
207
   reg  [31:00] Tx_MRd_Leng;
208
   reg  [10: 0] tx_MRd_Length;
209
   reg  [ 7: 0] tx_MRd_Tag;
210
   reg  [ 7: 0] tx_MRd_Tag_k;
211
 
212
   reg  [31:00] DMA_PA;
213
   reg  [63:00] DMA_HA;
214
   reg  [63:00] DMA_BDA;
215
   reg  [31:00] DMA_Leng;
216
   reg  [31:00] DMA_L1;
217
   reg  [31:00] DMA_L2;
218
   reg  [02:00] DMA_bar;
219
   reg          DMA_ds_is_Last;
220
   reg          DMA_us_is_Last;
221
   reg  [31:00] CplD_Index;
222
 
223
   reg          Desc_tx_MRd_Valid;
224
   reg  [10:00] Desc_tx_MRd_Leng;
225
   reg  [31:00] Desc_tx_MRd_Addr;
226
   reg  [07:00] Desc_tx_MRd_TAG;
227
   reg          tx_MRd_come;
228
 
229
   reg  [63:00] PIO_Addr;
230
   reg  [31:00] PIO_Leng;
231
   reg  [ 3:00] PIO_1st_BE;
232
   reg  [ 6:00] PIO_bar;
233
 
234
   //
235
   wire           DBG_dma_start;
236
 
237
 
238
 
239
        // Instantiate the Unit Under Test (UUT)
240
        tlpControl uut (
241
                .mbuf_UserFull(mbuf_UserFull),
242
                .trn_Blinker(trn_Blinker),
243
      .eb_FIFO_we     (eb_FIFO_we    ) , //          : OUT std_logic; 
244
      .eb_FIFO_din    (eb_FIFO_din   ) , //          : OUT std_logic_vector(C_DBUS_WIDTH-1 downto 0);
245
      .eb_FIFO_re     (eb_FIFO_re    ) , //          : OUT std_logic; 
246
      .eb_FIFO_empty  (eb_empty      ) , //          : IN  std_logic; 
247
      .eb_FIFO_qout   (eb_FIFO_qout[63:0]  ) , //          : IN  std_logic_vector(C_DBUS_WIDTH-1 downto 0);
248
      .eb_FIFO_Data_Count   (eb_FIFO_Data_Count  ) , //          : IN  std_logic_vector(C_DBUS_WIDTH-1 downto 0);
249
      .eb_FIFO_Status (eb_FIFO_Status) , //          : IN  std_logic_vector(C_DBUS_WIDTH-1 downto 0);
250
      .eb_FIFO_Rst    (eb_FIFO_Rst   ) , //          : OUT std_logic;
251
      .Link_Buf_full  (eb_pfull   ) ,
252
      .DMA_ds_Start   (DBG_dma_start),
253
                .DDR_Ready      (DDR_Ready),
254
                .DDR_wr_sof(DDR_wr_sof),
255
                .DDR_wr_eof(DDR_wr_eof),
256
                .DDR_wr_v(DDR_wr_v),
257
                .DDR_wr_FA(   ),
258
                .DDR_wr_Shift(DDR_wr_Shift),
259
                .DDR_wr_Mask(DDR_wr_Mask),
260
                .DDR_wr_din(DDR_wr_din),
261
                .DDR_wr_full(DDR_wr_full),
262
                .DDR_rdc_sof(DDR_rdc_sof),
263
                .DDR_rdc_eof(DDR_rdc_eof),
264
                .DDR_rdc_v(DDR_rdc_v),
265
                .DDR_rdc_FA(   ),
266
      .DDR_rdc_Shift(DDR_rdc_Shift),
267
                .DDR_rdc_din(DDR_rdc_din),
268
                .DDR_rdc_full(DDR_rdc_full),
269
                .DDR_FIFO_RdEn(DDR_FIFO_RdEn),
270
                .DDR_FIFO_Empty(DDR_FIFO_Empty),
271
                .DDR_FIFO_RdQout(DDR_FIFO_RdQout),
272
                .trn_clk(trn_clk),
273
                .trn_reset_n(trn_reset_n),
274
                .trn_lnk_up_n(trn_lnk_up_n),
275
                .trn_rsof_n(trn_rsof_n),
276
                .trn_reof_n(trn_reof_n),
277
                .trn_rd(trn_rd),
278
      .trn_rrem_n(trn_rrem_n),
279
                .trn_rerrfwd_n(trn_rerrfwd_n),
280
                .trn_rsrc_rdy_n(trn_rsrc_rdy_n),
281
                .trn_rdst_rdy_n(trn_rdst_rdy_n),
282
                .trn_rnp_ok_n(trn_rnp_ok_n),
283
                .trn_rsrc_dsc_n(trn_rsrc_dsc_n),
284
                .trn_rbar_hit_n(trn_rbar_hit_n),
285
                .trn_tsof_n(trn_tsof_n),
286
                .trn_teof_n(trn_teof_n),
287
                .trn_td(trn_td),
288
      .trn_trem_n(trn_trem_n),
289
                .trn_terrfwd_n(trn_terrfwd_n),
290
                .trn_tsrc_rdy_n(trn_tsrc_rdy_n),
291
                .trn_tdst_rdy_n(trn_tdst_rdy_n),
292
                .trn_tsrc_dsc_n(trn_tsrc_dsc_n),
293
                .trn_tdst_dsc_n(trn_tdst_dsc_n),
294
                .trn_tbuf_av(trn_tbuf_av),
295
//              .cfg_interrupt_n(cfg_interrupt_n), 
296
//              .cfg_interrupt_rdy_n(cfg_interrupt_rdy_n), 
297
//              .cfg_interrupt_mmenable(cfg_interrupt_mmenable), 
298
//              .cfg_interrupt_msienable(cfg_interrupt_msienable), 
299
//              .cfg_interrupt_di(cfg_interrupt_di), 
300
//              .cfg_interrupt_do(cfg_interrupt_do), 
301
//              .cfg_interrupt_assert_n(cfg_interrupt_assert_n), 
302
                .pcie_link_width(pcie_link_width),
303
                .cfg_dcommand(cfg_dcommand),
304
                .localID(localID)
305
        );
306
 
307
 
308
 
309
        // Instantiate the BRAM module
310
   bram_Control
311
   bram_controller(
312
    .DDR_wr_sof(DDR_wr_sof),
313
    .DDR_wr_eof(DDR_wr_eof),
314
    .DDR_wr_v(DDR_wr_v),
315
    .DDR_wr_FA(1'b0),
316
    .DDR_wr_Shift(DDR_wr_Shift),
317
    .DDR_wr_Mask(DDR_wr_Mask),
318
    .DDR_wr_din(DDR_wr_din),
319
//    .DDR_wr_full(DDR_wr_full), 
320
    .DDR_rdc_sof(DDR_rdc_sof),
321
    .DDR_rdc_eof(DDR_rdc_eof),
322
    .DDR_rdc_v(DDR_rdc_v),
323
    .DDR_rdc_FA(1'b0),
324
    .DDR_rdc_Shift(DDR_rdc_Shift),
325
    .DDR_rdc_din(DDR_rdc_din),
326
    .DDR_rdc_full(DDR_rdc_full),
327
    .DDR_FIFO_RdEn(DDR_FIFO_RdEn),
328
    .DDR_FIFO_Empty(DDR_FIFO_Empty),
329
    .DDR_FIFO_RdQout(DDR_FIFO_RdQout),
330
    .DBG_dma_start(DBG_dma_start),
331
    .DDR_Ready(DDR_Ready),
332
    .DDR_blinker(DDR_blinker),
333
    .Sim_Zeichen(Sim_Zeichen),
334
    .mem_clk(mem_clk),
335
    .trn_clk(trn_clk),
336
    .trn_reset_n(trn_reset_n)
337
    );
338
 
339
   assign  DDR_wr_full = 0;
340
 
341
 
342
        // Instantiate the FIFO module
343
   FIFO_wrapper
344
   queue_buffer(
345
         .wr_clk     (  trn_clk        ),
346
         .wr_en      (  eb_FIFO_we     ),
347
         .din        (  {8'H0, eb_FIFO_din}    ),
348
         .pfull      (  eb_pfull       ),
349
         .full       (  eb_full        ),
350
 
351
         .rd_clk     (  trn_clk        ),
352
         .rd_en      (  eb_FIFO_re     ),
353
         .dout       (  eb_FIFO_qout   ),
354
         .pempty     (  eb_pempty      ),
355
         .empty      (  eb_empty       ),
356
         .data_count (  eb_FIFO_Data_Count[14:1]),
357
 
358
         .rst        (  eb_FIFO_Rst    )
359
         );
360
 
361
   assign  eb_FIFO_Data_Count[26:15] = 0;
362
   assign  eb_FIFO_Data_Count[0] = 0;
363
   assign  eb_FIFO_Status = {34'H0, eb_FIFO_Data_Count, eb_pfull, eb_empty};
364
 
365
 
366
 
367
   // initialiation
368
        initial begin
369
                // Initialize Inputs
370
                trn_clk = 0;
371
      mem_clk = 1;
372
                trn_reset_n = 0;
373
                trn_lnk_up_n = 1;
374
                trn_rerrfwd_n = 1;
375
                trn_rsrc_dsc_n = 1;
376
                trn_tdst_dsc_n = 1;
377
                trn_tbuf_av = -1;
378
 
379
//              cfg_interrupt_rdy_n = 0;
380
//              cfg_interrupt_mmenable = 0;
381
//              cfg_interrupt_msienable = 0;
382
//              cfg_interrupt_do = 0;
383
 
384
                mbuf_UserFull = 0;
385
                pcie_link_width = 'H19;
386
      cfg_dcommand = 'H2000;
387
                localID = 'HD841;
388
 
389 4 weng_ziti
      Rx_No_Flow_Control = 1;    // = 0;  // Set to 0 to enable the Rx throttling
390
      Tx_No_Flow_Control = 1;    // = 0;  // Set to 0 to enable the Tx throttling
391 3 weng_ziti
 
392
                // Wait some nanoseconds for global reset to finish
393
                #100;
394
                trn_reset_n = 1;
395
                trn_lnk_up_n = 0;
396
 
397
                #10000;
398
//      $stop();
399
 
400
        end
401
 
402
   // trn_clk toggles
403
   always #`T_HALF_CYCLE_CLK
404
   trn_clk = ~trn_clk;
405
 
406
   // mem_clk toggles
407
   always #`T_HALF_CYCLE_MEMCLK
408
   mem_clk = ~mem_clk;
409
 
410
   // Randoms generated for process flow
411
   always @(posedge trn_clk) begin
412
     Op_Random[ 31:00] = $random();
413
     Op_Random[ 63:32] = $random();
414
     Op_Random[ 95:64] = $random();
415
     Op_Random[127:96] = $random();
416
   end
417
 
418
 
419
   /// Rx Flow Control
420
   always # `T_RX_NO_FC_PERIOD
421
   Rx_No_Flow_Control = ~Rx_No_Flow_Control;
422
 
423
   /// Tx Flow Control
424
   always # `T_TX_NO_FC_PERIOD
425
   Tx_No_Flow_Control = ~Tx_No_Flow_Control;
426
 
427
   // Signal prepared for trn_rsrc_rdy_n
428
   reg trn_rsrc_rdy_n_seed;
429
   always @(posedge trn_clk) begin
430
     trn_rsrc_rdy_n_seed <= Op_Random[8] & Op_Random[10] & ~Rx_No_Flow_Control;
431
   end
432
 
433
   // trn_tdst_rdy_n
434
   always @(posedge trn_clk )
435
   begin
436
     # `T_DELAY_AFTER
437
      trn_tdst_rdy_n <= (Op_Random[24] & Op_Random[21] & ~Tx_No_Flow_Control) | ~trn_reset_n;
438
   end
439
 
440
 
441
 
442
   // Initialization mem in host
443
   initial begin
444
     for (ii = 0; ii< `C_ARRAY_DIMENSION; ii= ii+1) begin
445
`ifdef  RANDOM_SEQUENCE
446
        D_Array[ii]    <= $random ();
447
`else
448
        D_Array[ii]    <= Inv_Endian ('H8760_0000 + ii + 1);
449
`endif
450
     end
451
   end
452
 
453
 
454
  //  Simulation procedure
455
  initial begin
456
 
457
    // Simulation Initialization
458
    FSM_Trn               <= 'H00;
459
    Gap_Insert_Rx;
460
 
461
    PIO_bar               <= -1;
462
    DMA_bar               <= 'H1;
463
    Rx_MWr_Tag            <= 'H80;
464 4 weng_ziti
    Rx_MRd_Tag            <= 'H10;
465 3 weng_ziti
 
466
 
467
    // Initialization: TLP
468
    # 400
469
      Rx_TLP_Length    <= 'H01;
470
 
471
    # `T_DELTA    // reset TX module
472
      Hdr_Array[0] <= `HEADER0_MWR3_ | Rx_TLP_Length[9:0];
473
      Hdr_Array[1] <= {`C_HOST_WRREQ_ID, Rx_MWr_Tag, 4'Hf, 4'Hf};
474
      Hdr_Array[2] <= `C_ADDR_TX_CTRL;
475
      Private_Array[0] <= 'H0000000A;
476
 
477
    # `T_DELTA
478
      TLP_Feed_Rx(`USE_PRIVATE, 'H0, `C_BAR0_HIT);
479
      Rx_MWr_Tag   <= Rx_MWr_Tag + 1;
480
      Gap_Insert_Rx;
481
 
482
 
483
    # `T_DELTA     // Test MRd with 4-DW header  BAR[0]
484
      Hdr_Array[0] <= `HEADER0_MRD4_ | Rx_TLP_Length[9:0];
485
      Hdr_Array[1] <= {`C_HOST_RDREQ_ID, 8'HA1, 4'Hf, 4'Hf};
486
      Hdr_Array[2] <= -1;
487
      Hdr_Array[3] <= `C_ADDR_VERSION;
488
 
489
 
490
    # `T_DELTA
491
      TLP_Feed_Rx(`USE_PRIVATE, 'H0, `C_BAR0_HIT);
492
      Gap_Insert_Rx;
493
 
494
 
495
    # 100
496
      Rx_TLP_Length    <= 'H01;
497
 
498
 
499
    # `T_DELTA    // reset upstream DMA channel
500
      Hdr_Array[0] <= `HEADER0_MWR3_ | Rx_TLP_Length[9:0];
501
      Hdr_Array[1] <= {`C_HOST_WRREQ_ID, Rx_MWr_Tag, 4'Hf, 4'Hf};
502
      Hdr_Array[2] <= `C_ADDR_DMA_US_CTRL;
503
      Private_Array[0] <= `C_DMA_RST_CMD;
504
 
505
    # `T_DELTA
506
      TLP_Feed_Rx(`USE_PRIVATE, 'H0, `C_BAR0_HIT);
507
      Rx_MWr_Tag   <= Rx_MWr_Tag + 1;
508
      Gap_Insert_Rx;
509
 
510
    # `T_DELTA    // reset downstream DMA channel
511
      Hdr_Array[0] <= `HEADER0_MWR4_ | Rx_TLP_Length[9:0];
512
      Hdr_Array[1] <= {`C_HOST_WRREQ_ID, Rx_MWr_Tag, 4'Hf, 4'Hf};
513
      Hdr_Array[2] <= -1;
514
      Hdr_Array[3] <= `C_ADDR_DMA_DS_CTRL;
515
      Private_Array[0] <= `C_DMA_RST_CMD;
516
 
517
    # `T_DELTA
518
      TLP_Feed_Rx(`USE_PRIVATE, 'H0, `C_BAR0_HIT);
519
      Rx_MWr_Tag   <= Rx_MWr_Tag + 1;
520
      Gap_Insert_Rx;
521
 
522
 
523
    # `T_DELTA    // reset Event Buffer FIFO
524
      Hdr_Array[0] <= `HEADER0_MWR3_ | Rx_TLP_Length[9:0];
525
      Hdr_Array[1] <= {`C_HOST_WRREQ_ID, Rx_MWr_Tag, 4'Hf, 4'Hf};
526
      Hdr_Array[2] <= `C_ADDR_EB_STACON;
527
      Private_Array[0] <= 'H0000000A;
528
 
529
    # `T_DELTA
530
      TLP_Feed_Rx(`USE_PRIVATE, 'H0, `C_BAR0_HIT);
531
      Rx_MWr_Tag   <= Rx_MWr_Tag + 1;
532
      Gap_Insert_Rx;
533
 
534
 
535
    # `T_DELTA    // Enable INTerrupts
536
      Hdr_Array[0] <= `HEADER0_MWR3_ | Rx_TLP_Length[9:0];
537
      Hdr_Array[1] <= {`C_HOST_WRREQ_ID, Rx_MWr_Tag, 4'Hf, 4'Hf};
538
      Hdr_Array[2] <= `C_ADDR_IRQ_EN;
539
      Private_Array[0] <= 'H0000_0003;
540
 
541
    # `T_DELTA
542
      TLP_Feed_Rx(`USE_PRIVATE, 'H0, `C_BAR0_HIT);
543
      Rx_MWr_Tag   <= Rx_MWr_Tag + 1;
544
      Gap_Insert_Rx;
545
 
546
 
547
 
548
 
549
    /////////////////////////////////////////////////////////////////////
550
    //                       PIO simulation                            //
551
    /////////////////////////////////////////////////////////////////////
552
 
553
 
554
     # `T_PIO_INTERVAL
555
       ;
556
 
557
       FSM_Trn          <= 'H04;
558
 
559
    //  ///////////////////////////////////////////////////////////////////
560
    //  PIO write & read BAR[0]
561
 
562
       PIO_Addr         <= `C_ADDR_DMA_US_PAH + 'H8;
563
       PIO_bar          <= `C_BAR0_HIT;
564
       PIO_1st_BE       <= 4'Hf;
565
       Gap_Insert_Rx;
566
       Hdr_Array[0]     <= `HEADER0_MWR3_ | Rx_TLP_Length[9:0];
567
       Hdr_Array[1]     <= {`C_HOST_WRREQ_ID, Rx_MWr_Tag, 4'Hf, PIO_1st_BE};
568
       Hdr_Array[2]     <= {PIO_Addr[31:2], 2'b00};
569
       Private_Array[0] <= 'HF000_8888;
570
       Rx_TLP_Length    <= 'H01;
571
     # `T_DELTA
572
       TLP_Feed_Rx(`USE_PRIVATE, 'H0, PIO_bar);
573
       Rx_MWr_Tag   <= Rx_MWr_Tag + 1;
574
       Gap_Insert_Rx;
575
 
576
     # `T_PIO_INTERVAL
577
       ;
578
 
579
     # `T_DELTA
580
       Hdr_Array[0]     <= `HEADER0_MRD3_ | Rx_TLP_Length[9:0];
581
       Hdr_Array[1]     <= {`C_HOST_RDREQ_ID, 3'H3, Rx_MRd_Tag, 4'Hf, PIO_1st_BE};
582
       Hdr_Array[2]     <= {PIO_Addr[31:2], 2'b00};
583
 
584
     # `T_DELTA
585
       TLP_Feed_Rx(`USE_PUBLIC, `PIO_START_INDEX, PIO_bar);
586
       Rx_MRd_Tag       <= Rx_MRd_Tag + 1;
587
       Gap_Insert_Rx;
588
 
589
       FSM_Trn          <= 'H08;
590
 
591
 
592
 
593
    //  ///////////////////////////////////////////////////////////////////
594
    //  PIO write & read BAR[1]
595
       PIO_Addr         <= 'H8000;
596
       PIO_bar          <= `C_BAR1_HIT;
597
       PIO_1st_BE       <= 4'Hf;
598
       Gap_Insert_Rx;
599
       Hdr_Array[0]     <= `HEADER0_MWR3_ | Rx_TLP_Length[9:0];
600
       Hdr_Array[1]     <= {`C_HOST_WRREQ_ID, Rx_MWr_Tag, 4'Hf, PIO_1st_BE};
601
       Hdr_Array[2]     <= {PIO_Addr[31:2], 2'b00};
602
       Private_Array[0] <= 'HA1111111;
603
       Rx_TLP_Length    <= 'H01;
604
     # `T_DELTA
605
       TLP_Feed_Rx(`USE_PRIVATE, 'H0, PIO_bar);
606
       Rx_MWr_Tag   <= Rx_MWr_Tag + 1;
607
       Gap_Insert_Rx;
608
 
609
     # `T_PIO_INTERVAL
610
       ;
611
 
612
     # `T_DELTA
613
       Hdr_Array[0]     <= `HEADER0_MRD3_ | Rx_TLP_Length[9:0];
614
       Hdr_Array[1]     <= {`C_HOST_RDREQ_ID, 3'H3, Rx_MRd_Tag, 4'Hf, PIO_1st_BE};
615
       Hdr_Array[2]     <= {PIO_Addr[31:2], 2'b00};
616
 
617
     # `T_DELTA
618
       TLP_Feed_Rx(`USE_PRIVATE, `PIO_START_INDEX, PIO_bar);
619
       Rx_MRd_Tag       <= Rx_MRd_Tag + 1;
620
       Gap_Insert_Rx;
621
 
622
       FSM_Trn          <= 'H10;
623
 
624
 
625
 
626
    //  ///////////////////////////////////////////////////////////////////
627
    //  PIO write & read BAR[2]
628
    //  NOTE:  FIFO address is 64-bit aligned, only the lower 32-bit is
629
    //         accessible by BAR[2] PIO write and is returned in BAR[2] 
630
    //         PIO read.
631
       PIO_Addr         <= 'H0;
632
       PIO_bar          <= `C_BAR2_HIT;
633
       PIO_1st_BE       <= 4'Hf;
634
       Gap_Insert_Rx;
635
       Hdr_Array[0]     <= `HEADER0_MWR3_ | Rx_TLP_Length[9:0];
636
       Hdr_Array[1]     <= {`C_HOST_WRREQ_ID, Rx_MWr_Tag, 4'Hf, PIO_1st_BE};
637
       Hdr_Array[2]     <= {PIO_Addr[31:2], 2'b00};
638
       Private_Array[0] <= 'HB222_2222;
639
       Rx_TLP_Length    <= 'H01;
640
     # `T_DELTA
641
       TLP_Feed_Rx(`USE_PRIVATE, 'H0, PIO_bar);
642
       Rx_MWr_Tag   <= Rx_MWr_Tag + 1;
643
       Gap_Insert_Rx;
644
 
645
     # `T_PIO_INTERVAL
646
       ;
647
 
648
     # `T_DELTA
649
       Hdr_Array[0]     <= `HEADER0_MRD3_ | Rx_TLP_Length[9:0];
650
       Hdr_Array[1]     <= {`C_HOST_RDREQ_ID, 3'H3, Rx_MRd_Tag, 4'Hf, PIO_1st_BE};
651
       Hdr_Array[2]     <= {PIO_Addr[31:2], 2'b00};
652
 
653
     # `T_DELTA
654
       TLP_Feed_Rx(`USE_PUBLIC, `PIO_START_INDEX, PIO_bar);
655
       Rx_MRd_Tag       <= Rx_MRd_Tag + 1;
656
       Gap_Insert_Rx;
657
 
658
       FSM_Trn          <= 'H14;
659
 
660
 
661
 
662
     # `T_DMA_INTERVAL
663
       ;
664
 
665
 
666
    //  ///////////////////////////////////////////////////////////////////
667
    //  DMA write & read BAR[1]
668
    //  Single-descriptor case
669
 
670
       DMA_PA   <= 'H1234;
671
       DMA_HA   <= 'H5000;
672
       DMA_BDA  <= 'Hffff;
673
                 DMA_Leng <= 'H0100;
674
       DMA_bar  <= 'H1;
675
       DMA_ds_is_Last  <= 'B1;
676
 
677
     # `T_DELTA
678
       // Initial DMA descriptor
679
       Private_Array[0] <= -1;
680
       Private_Array[1] <= DMA_PA[31:00];       //'H0300;
681
       Private_Array[2] <= DMA_HA[63:32];       // 0;
682
       Private_Array[3] <= DMA_HA[31:00];       // 'H4000;
683
       Private_Array[4] <= DMA_BDA[63:32];      // 0;
684
       Private_Array[5] <= DMA_BDA[31:00];      //'H0BDA0090;
685
       Private_Array[6] <= DMA_Leng;            //'H100;
686
       Private_Array[7] <=  {4'H0
687
                            ,3'H1, DMA_ds_is_Last
688
                            ,3'H0, 1'B1
689
                            ,1'B0, DMA_bar
690
                            ,1'B1
691
                            ,15'H0
692
                            };
693
 
694
 
695
       //  DMA write
696
 
697
       Rx_TLP_Length    <= 'H01;
698
 
699
     # `T_DELTA
700
       Hdr_Array[0] <= `HEADER0_MWR3_ | Rx_TLP_Length[9:0];
701
       Hdr_Array[1] <= {`C_HOST_WRREQ_ID, Rx_MWr_Tag, 4'Hf, 4'Hf};
702
       Hdr_Array[2] <= `C_ADDR_DMA_DS_PAH;
703
 
704
       //  Write PA_H
705
     # `T_DELTA
706
       TLP_Feed_Rx(`USE_PRIVATE, 'H0, `C_BAR0_HIT);
707
       Rx_MWr_Tag   <= Rx_MWr_Tag + 1;
708
       Gap_Insert_Rx;
709
       Gap_Insert_Rx;
710
 
711
       //  Write PA_L
712
       Hdr_Array[2] <= Hdr_Array[2] + 'H4;
713
     # `T_DELTA
714
       TLP_Feed_Rx(`USE_PRIVATE, 'H1, `C_BAR0_HIT);
715
       Rx_MWr_Tag   <= Rx_MWr_Tag + 1;
716
       Gap_Insert_Rx;
717
       Gap_Insert_Rx;
718
 
719
       //  Write HA_H
720
       Hdr_Array[2] <= Hdr_Array[2] + 'H4;
721
     # `T_DELTA
722
       TLP_Feed_Rx(`USE_PRIVATE, 'H2, `C_BAR0_HIT);
723
       Rx_MWr_Tag   <= Rx_MWr_Tag + 1;
724
       Gap_Insert_Rx;
725
       Gap_Insert_Rx;
726
 
727
       //  Write HA_L
728
       Hdr_Array[2] <= Hdr_Array[2] + 'H4;
729
     # `T_DELTA
730
       TLP_Feed_Rx(`USE_PRIVATE, 'H3, `C_BAR0_HIT);
731
       Rx_MWr_Tag   <= Rx_MWr_Tag + 1;
732
       Gap_Insert_Rx;
733
       Gap_Insert_Rx;
734
 
735
       //  Write BDA_H
736
       Hdr_Array[2] <= Hdr_Array[2] + 'H4;
737
     # `T_DELTA
738
       TLP_Feed_Rx(`USE_PRIVATE, 'H4, `C_BAR0_HIT);
739
       Rx_MWr_Tag   <= Rx_MWr_Tag + 1;
740
       Gap_Insert_Rx;
741
       Gap_Insert_Rx;
742
 
743
       //  Write BDA_L
744
       Hdr_Array[2] <= Hdr_Array[2] + 'H4;
745
     # `T_DELTA
746
       TLP_Feed_Rx(`USE_PRIVATE, 'H5, `C_BAR0_HIT);
747
       Rx_MWr_Tag   <= Rx_MWr_Tag + 1;
748
       Gap_Insert_Rx;
749
       Gap_Insert_Rx;
750
 
751
       //  Write LENG
752
       Hdr_Array[2] <= Hdr_Array[2] + 'H4;
753
     # `T_DELTA
754
       TLP_Feed_Rx(`USE_PRIVATE, 'H6, `C_BAR0_HIT);
755
       Rx_MWr_Tag   <= Rx_MWr_Tag + 1;
756
       Gap_Insert_Rx;
757
       Gap_Insert_Rx;
758
 
759
       //  Write CTRL and start the DMA
760
       Hdr_Array[2] <= Hdr_Array[2] + 'H4;
761
     # `T_DELTA
762
       TLP_Feed_Rx(`USE_PRIVATE, 'H7, `C_BAR0_HIT);
763
       Rx_MWr_Tag   <= Rx_MWr_Tag + 1;
764
       Gap_Insert_Rx;
765
       Gap_Insert_Rx;
766
 
767
 
768 4 weng_ziti
     # `T_DELTA     // Polling the DMA status
769
       Hdr_Array[0] <= `HEADER0_MRD3_ | Rx_TLP_Length[9:0];
770
       Hdr_Array[1] <= {`C_HOST_RDREQ_ID, 3'H3, Rx_MRd_Tag, 4'Hf, 4'Hf};
771
       Hdr_Array[2] <= `C_ADDR_DMA_DS_STA;
772
 
773
 
774
     # `T_DELTA
775
       TLP_Feed_Rx(`USE_PRIVATE, 'H0, `C_BAR0_HIT);
776
       Rx_MRd_Tag       <= Rx_MRd_Tag + 1;
777
       Gap_Insert_Rx;
778
 
779 3 weng_ziti
       FSM_Trn          <= 'H18;
780
 
781
 
782
       // feeding the payload CplD
783
       wait (tx_MRd_come);
784
       Gap_Insert_Rx;
785
       tx_MRd_come  <= 'B0;
786
       Tx_MRd_Leng  <= DMA_Leng>>2;
787
       Tx_MRd_Addr  <= DMA_HA[31:0];
788
       tx_MRd_Tag_k <= tx_MRd_Tag;
789
       CplD_Index   <= 'H0;
790
 
791
       Gap_Insert_Rx;
792
       Rx_TLP_Length    <= 'H10;
793
 
794
     # `T_DELTA
795
       Hdr_Array[0] <= `HEADER0_CPLD | Rx_TLP_Length[9:0];
796
       Hdr_Array[1] <= {`C_HOST_CPLD_ID, 4'H0, Tx_MRd_Leng[9:0], 2'b00};
797
       Hdr_Array[2] <= {localID, tx_MRd_Tag_k, 1'b0, Tx_MRd_Addr[6:0]};
798
       Tx_MRd_Leng  <= Tx_MRd_Leng - Rx_TLP_Length;
799
       Tx_MRd_Addr  <= Tx_MRd_Addr + Rx_TLP_Length;
800
     # `T_DELTA
801
       TLP_Feed_Rx(`USE_PUBLIC, CplD_Index, `C_NO_BAR_HIT);
802
       CplD_Index   <= CplD_Index + Rx_TLP_Length;
803
       Gap_Insert_Rx;
804
 
805
       Hdr_Array[0] <= `HEADER0_CPLD | Rx_TLP_Length[9:0];
806
       Hdr_Array[1] <= {`C_HOST_CPLD_ID, 4'H0, Tx_MRd_Leng[9:0], 2'b00};
807
       Hdr_Array[2] <= {localID, tx_MRd_Tag_k, 1'b0, Tx_MRd_Addr[6:0]};
808
       Tx_MRd_Leng  <= Tx_MRd_Leng - Rx_TLP_Length;
809
       Tx_MRd_Addr  <= Tx_MRd_Addr + Rx_TLP_Length;
810
     # `T_DELTA
811
       TLP_Feed_Rx(`USE_PUBLIC, CplD_Index, `C_NO_BAR_HIT);
812
       CplD_Index   <= CplD_Index + Rx_TLP_Length;
813
//       Gap_Insert_Rx;
814
 
815
       Hdr_Array[0] <= `HEADER0_CPLD | Rx_TLP_Length[9:0];
816
       Hdr_Array[1] <= {`C_HOST_CPLD_ID, 4'H0, Tx_MRd_Leng[9:0], 2'b00};
817
       Hdr_Array[2] <= {localID, tx_MRd_Tag_k, 1'b0, Tx_MRd_Addr[6:0]};
818
       Tx_MRd_Leng  <= Tx_MRd_Leng - Rx_TLP_Length;
819
       Tx_MRd_Addr  <= Tx_MRd_Addr + Rx_TLP_Length;
820
     # `T_DELTA
821
       TLP_Feed_Rx(`USE_PUBLIC, CplD_Index, `C_NO_BAR_HIT);
822
       CplD_Index   <= CplD_Index + Rx_TLP_Length;
823
       Gap_Insert_Rx;
824
 
825
       Hdr_Array[0] <= `HEADER0_CPLD | Rx_TLP_Length[9:0];
826
       Hdr_Array[1] <= {`C_HOST_CPLD_ID, 4'H0, Tx_MRd_Leng[9:0], 2'b00};
827
       Hdr_Array[2] <= {localID, tx_MRd_Tag_k, 1'b0, Tx_MRd_Addr[6:0]};
828
       Tx_MRd_Leng  <= Tx_MRd_Leng - Rx_TLP_Length;
829
       Tx_MRd_Addr  <= Tx_MRd_Addr + Rx_TLP_Length;
830
     # `T_DELTA
831
       TLP_Feed_Rx(`USE_PUBLIC, CplD_Index, `C_NO_BAR_HIT);
832
       CplD_Index   <= CplD_Index + Rx_TLP_Length;
833
       Gap_Insert_Rx;
834
 
835
 
836 4 weng_ziti
       Rx_TLP_Length    <= 'H01;
837
     # `T_DELTA     // Polling the DMA status
838
       Hdr_Array[0] <= `HEADER0_MRD3_ | Rx_TLP_Length[9:0];
839
       Hdr_Array[1] <= {`C_HOST_RDREQ_ID, 3'H3, Rx_MRd_Tag, 4'Hf, 4'Hf};
840
       Hdr_Array[2] <= `C_ADDR_DMA_DS_STA;
841
 
842
 
843
     # `T_DELTA
844
       TLP_Feed_Rx(`USE_PRIVATE, 'H0, `C_BAR0_HIT);
845
       Rx_MRd_Tag       <= Rx_MRd_Tag + 1;
846
       Gap_Insert_Rx;
847
 
848
 
849 3 weng_ziti
       FSM_Trn          <= 'H1C;
850
 
851
     # `T_DMA_INTERVAL
852
       ;
853
 
854
 
855
 
856
       //  DMA read
857
 
858
       Rx_TLP_Length    <= 'H01;
859
 
860
     # `T_DELTA
861
       Hdr_Array[0] <= `HEADER0_MWR3_ | Rx_TLP_Length[9:0];
862
       Hdr_Array[1] <= {`C_HOST_WRREQ_ID, Rx_MWr_Tag, 4'Hf, 4'Hf};
863
       Hdr_Array[2] <= `C_ADDR_DMA_US_PAH;
864
 
865
       //  Write PA_H
866
     # `T_DELTA
867
       TLP_Feed_Rx(`USE_PRIVATE, 'H0, `C_BAR0_HIT);
868
       Rx_MWr_Tag   <= Rx_MWr_Tag + 1;
869
       Gap_Insert_Rx;
870
       Gap_Insert_Rx;
871
 
872
       //  Write PA_L
873
       Hdr_Array[2] <= Hdr_Array[2] + 'H4;
874
     # `T_DELTA
875
       TLP_Feed_Rx(`USE_PRIVATE, 'H1, `C_BAR0_HIT);
876
       Rx_MWr_Tag   <= Rx_MWr_Tag + 1;
877
       Gap_Insert_Rx;
878
       Gap_Insert_Rx;
879
 
880
       //  Write HA_H
881
       Hdr_Array[2] <= Hdr_Array[2] + 'H4;
882
     # `T_DELTA
883
       TLP_Feed_Rx(`USE_PRIVATE, 'H2, `C_BAR0_HIT);
884
       Rx_MWr_Tag   <= Rx_MWr_Tag + 1;
885
       Gap_Insert_Rx;
886
       Gap_Insert_Rx;
887
 
888
       //  Write HA_L
889
       Hdr_Array[2] <= Hdr_Array[2] + 'H4;
890
     # `T_DELTA
891
       TLP_Feed_Rx(`USE_PRIVATE, 'H3, `C_BAR0_HIT);
892
       Rx_MWr_Tag   <= Rx_MWr_Tag + 1;
893
       Gap_Insert_Rx;
894
       Gap_Insert_Rx;
895
 
896
       //  Write BDA_H
897
       Hdr_Array[2] <= Hdr_Array[2] + 'H4;
898
     # `T_DELTA
899
       TLP_Feed_Rx(`USE_PRIVATE, 'H4, `C_BAR0_HIT);
900
       Rx_MWr_Tag   <= Rx_MWr_Tag + 1;
901
       Gap_Insert_Rx;
902
       Gap_Insert_Rx;
903
 
904
       //  Write BDA_L
905
       Hdr_Array[2] <= Hdr_Array[2] + 'H4;
906
     # `T_DELTA
907
       TLP_Feed_Rx(`USE_PRIVATE, 'H5, `C_BAR0_HIT);
908
       Rx_MWr_Tag   <= Rx_MWr_Tag + 1;
909
       Gap_Insert_Rx;
910
       Gap_Insert_Rx;
911
 
912
       //  Write LENG
913
       Hdr_Array[2] <= Hdr_Array[2] + 'H4;
914
     # `T_DELTA
915
       TLP_Feed_Rx(`USE_PRIVATE, 'H6, `C_BAR0_HIT);
916
       Rx_MWr_Tag   <= Rx_MWr_Tag + 1;
917
       Gap_Insert_Rx;
918
       Gap_Insert_Rx;
919
 
920
       //  Write CTRL and start the DMA
921
       Hdr_Array[2] <= Hdr_Array[2] + 'H4;
922
     # `T_DELTA
923
       TLP_Feed_Rx(`USE_PRIVATE, 'H7, `C_BAR0_HIT);
924
       Rx_MWr_Tag   <= Rx_MWr_Tag + 1;
925
       Gap_Insert_Rx;
926
       Gap_Insert_Rx;
927
 
928
 
929 4 weng_ziti
       Rx_TLP_Length    <= 'H01;
930
     # `T_DELTA     // Polling the DMA status
931
       Hdr_Array[0] <= `HEADER0_MRD3_ | Rx_TLP_Length[9:0];
932
       Hdr_Array[1] <= {`C_HOST_RDREQ_ID, 3'H3, Rx_MRd_Tag, 4'Hf, 4'Hf};
933
       Hdr_Array[2] <= `C_ADDR_DMA_US_STA;
934
 
935
 
936
     # `T_DELTA
937
       TLP_Feed_Rx(`USE_PRIVATE, 'H0, `C_BAR0_HIT);
938
       Rx_MRd_Tag       <= Rx_MRd_Tag + 1;
939
       Gap_Insert_Rx;
940
 
941 3 weng_ziti
       FSM_Trn          <= 'H20;
942
 
943
     # (`T_DMA_INTERVAL*4)
944
       ;
945
 
946
 
947
  //////////////////////////////////////////////////////////////////////////////////
948
 
949
       Rx_TLP_Length    <= 'H01;
950
     # `T_DELTA    // reset downstream DMA channel
951
       Hdr_Array[0] <= `HEADER0_MWR3_ | Rx_TLP_Length[9:0];
952
       Hdr_Array[1] <= {`C_HOST_WRREQ_ID, Rx_MWr_Tag, 4'Hf, 4'Hf};
953
       Hdr_Array[2] <= `C_ADDR_DMA_DS_CTRL;
954
       Private_Array[0] <= `C_DMA_RST_CMD;
955
 
956
     # `T_DELTA
957
       TLP_Feed_Rx(`USE_PRIVATE, 'H0, `C_BAR0_HIT);
958
       Rx_MWr_Tag   <= Rx_MWr_Tag + 1;
959
       Gap_Insert_Rx;
960
 
961
       Rx_TLP_Length    <= 'H01;
962
     # `T_DELTA    // reset upstream DMA channel
963
       Hdr_Array[0] <= `HEADER0_MWR3_ | Rx_TLP_Length[9:0];
964
       Hdr_Array[1] <= {`C_HOST_WRREQ_ID, Rx_MWr_Tag, 4'Hf, 4'Hf};
965
       Hdr_Array[2] <= `C_ADDR_DMA_US_CTRL;
966
       Private_Array[0] <= `C_DMA_RST_CMD;
967
 
968
     # `T_DELTA
969
       TLP_Feed_Rx(`USE_PRIVATE, 'H0, `C_BAR0_HIT);
970
       Rx_MWr_Tag   <= Rx_MWr_Tag + 1;
971
       Gap_Insert_Rx;
972
 
973
  //////////////////////////////////////////////////////////////////////////////////
974
 
975
 
976
       FSM_Trn          <= 'H24;
977
 
978
 
979
     # `T_PIO_INTERVAL
980
       ;
981
 
982
 
983
 
984
    //  ///////////////////////////////////////////////////////////////////
985
    //  DMA write & read BAR[2]
986
    //  Multiple-descriptor case
987
    //  
988
 
989
       DMA_PA   <= 'H789ABC;
990
       DMA_HA   <= 'HDF0000;
991
       DMA_BDA  <= 'H0BDABDA0;
992
                 DMA_Leng <= 'H0208;
993
     # `T_DELTA
994
                 DMA_L1   <= 'H0100;
995
     # `T_DELTA
996
                 DMA_L2   <= DMA_Leng - DMA_L1;
997
       DMA_bar  <= 'H2;
998
       DMA_ds_is_Last  <= 'B0;
999
 
1000
     # `T_DELTA
1001
       // Initial DMA descriptor
1002
       Private_Array[0] <= -1;
1003
       Private_Array[1] <= DMA_PA[31:00];
1004
       Private_Array[2] <= DMA_HA[63:32];       // 0;
1005
       Private_Array[3] <= DMA_HA[31:00];
1006
       Private_Array[4] <= DMA_BDA[63:32];      // 0;
1007
       Private_Array[5] <= DMA_BDA[31:00];
1008
       Private_Array[6] <= DMA_L1;
1009
       Private_Array[7] <=  {4'H0
1010
                            ,3'H1, DMA_ds_is_Last
1011
                            ,3'H0, 1'B1
1012
                            ,1'B0, DMA_bar
1013
                            ,1'B1
1014
                            ,15'H0
1015
                            };
1016
 
1017
       Rx_TLP_Length    <= 'H01;
1018
 
1019
     # `T_DELTA
1020
       Hdr_Array[0] <= `HEADER0_MWR3_ | Rx_TLP_Length[9:0];
1021
       Hdr_Array[1] <= {`C_HOST_WRREQ_ID, Rx_MWr_Tag, 4'Hf, 4'Hf};
1022
       Hdr_Array[2] <= `C_ADDR_DMA_DS_PAH;
1023
 
1024
       //  Write PA_H
1025
     # `T_DELTA
1026
       TLP_Feed_Rx(`USE_PRIVATE, 'H0, `C_BAR0_HIT);
1027
       Rx_MWr_Tag   <= Rx_MWr_Tag + 1;
1028
       Gap_Insert_Rx;
1029
       Gap_Insert_Rx;
1030
 
1031
       //  Write PA_L
1032
       Hdr_Array[2] <= Hdr_Array[2] + 'H4;
1033
     # `T_DELTA
1034
       TLP_Feed_Rx(`USE_PRIVATE, 'H1, `C_BAR0_HIT);
1035
       Rx_MWr_Tag   <= Rx_MWr_Tag + 1;
1036
       Gap_Insert_Rx;
1037
       Gap_Insert_Rx;
1038
 
1039
       //  Write HA_H
1040
       Hdr_Array[2] <= Hdr_Array[2] + 'H4;
1041
     # `T_DELTA
1042
       TLP_Feed_Rx(`USE_PRIVATE, 'H2, `C_BAR0_HIT);
1043
       Rx_MWr_Tag   <= Rx_MWr_Tag + 1;
1044
       Gap_Insert_Rx;
1045
       Gap_Insert_Rx;
1046
 
1047
       //  Write HA_L
1048
       Hdr_Array[2] <= Hdr_Array[2] + 'H4;
1049
     # `T_DELTA
1050
       TLP_Feed_Rx(`USE_PRIVATE, 'H3, `C_BAR0_HIT);
1051
       Rx_MWr_Tag   <= Rx_MWr_Tag + 1;
1052
       Gap_Insert_Rx;
1053
       Gap_Insert_Rx;
1054
 
1055
       //  Write BDA_H
1056
       Hdr_Array[2] <= Hdr_Array[2] + 'H4;
1057
     # `T_DELTA
1058
       TLP_Feed_Rx(`USE_PRIVATE, 'H4, `C_BAR0_HIT);
1059
       Rx_MWr_Tag   <= Rx_MWr_Tag + 1;
1060
       Gap_Insert_Rx;
1061
       Gap_Insert_Rx;
1062
 
1063
       //  Write BDA_L
1064
       Hdr_Array[2] <= Hdr_Array[2] + 'H4;
1065
     # `T_DELTA
1066
       TLP_Feed_Rx(`USE_PRIVATE, 'H5, `C_BAR0_HIT);
1067
       Rx_MWr_Tag   <= Rx_MWr_Tag + 1;
1068
       Gap_Insert_Rx;
1069
       Gap_Insert_Rx;
1070
 
1071
       //  Write LENG
1072
       Hdr_Array[2] <= Hdr_Array[2] + 'H4;
1073
     # `T_DELTA
1074
       TLP_Feed_Rx(`USE_PRIVATE, 'H6, `C_BAR0_HIT);
1075
       Rx_MWr_Tag   <= Rx_MWr_Tag + 1;
1076
       Gap_Insert_Rx;
1077
       Gap_Insert_Rx;
1078
 
1079
       //  Write CTRL and start the DMA
1080
       Hdr_Array[2] <= Hdr_Array[2] + 'H4;
1081
     # `T_DELTA
1082
       TLP_Feed_Rx(`USE_PRIVATE, 'H7, `C_BAR0_HIT);
1083
       Rx_MWr_Tag   <= Rx_MWr_Tag + 1;
1084
       Gap_Insert_Rx;
1085
       Gap_Insert_Rx;
1086
 
1087
 
1088
       FSM_Trn          <= 'H28;
1089
 
1090
 
1091
       // feeding the descriptor CplD
1092
       wait (Desc_tx_MRd_Valid);
1093
       Gap_Insert_Rx;
1094
       Desc_tx_MRd_Valid <= 'B0;
1095
       DMA_ds_is_Last    <= 'B1;
1096
       Gap_Insert_Rx;
1097
 
1098
       // Initial DMA descriptor
1099
       Private_Array[0] <= 0;
1100
       Private_Array[1] <= DMA_PA[31:00] + 'H500;
1101
       Private_Array[2] <= DMA_HA[63:32];          // 0;
1102
       Private_Array[3] <= DMA_HA[31:00] + 'H500;
1103
       Private_Array[4] <= -1;                     // dont-care
1104
       Private_Array[5] <= -1;                     // dont-care
1105
       Private_Array[6] <= DMA_L2;
1106
       Private_Array[7] <=  {4'H0
1107
                            ,3'H1, DMA_ds_is_Last
1108
                            ,3'H0, 1'B1
1109
                            ,1'B0, DMA_bar
1110
                            ,1'B1
1111
                            ,15'H0
1112
                            };
1113
 
1114
       Rx_TLP_Length    <= 'H08;
1115
       Gap_Insert_Rx;
1116
       Hdr_Array[0] <= `HEADER0_CPLD | Rx_TLP_Length[9:0];
1117
       Hdr_Array[1] <= {`C_HOST_CPLD_ID, 4'H0, Rx_TLP_Length[9:0], 2'b00};
1118
       Hdr_Array[2] <= {localID, Desc_tx_MRd_TAG, 1'b0, DMA_BDA[6:0]};
1119
     # `T_DELTA
1120
       TLP_Feed_Rx(`USE_PRIVATE, 0, `C_NO_BAR_HIT);
1121
       Gap_Insert_Rx;
1122
 
1123
 
1124
       // feeding the payload CplD
1125
       wait (tx_MRd_come);
1126
       Gap_Insert_Rx;
1127
       tx_MRd_come  <= 'B0;
1128
       Tx_MRd_Leng  <= DMA_L1>>2;
1129
       Tx_MRd_Addr  <= DMA_HA[31:0];
1130
       tx_MRd_Tag_k <= tx_MRd_Tag;
1131
       CplD_Index   <= 'H0;
1132
 
1133
       Gap_Insert_Rx;
1134
       Rx_TLP_Length    <= 'H10;
1135
 
1136
     # `T_DELTA
1137
       Hdr_Array[0] <= `HEADER0_CPLD | Rx_TLP_Length[9:0];
1138
       Hdr_Array[1] <= {`C_HOST_CPLD_ID, 4'H0, Tx_MRd_Leng[9:0], 2'b00};
1139
       Hdr_Array[2] <= {localID, tx_MRd_Tag_k, 1'b0, Tx_MRd_Addr[6:0]};
1140
       Tx_MRd_Leng  <= Tx_MRd_Leng - Rx_TLP_Length;
1141
       Tx_MRd_Addr  <= Tx_MRd_Addr + Rx_TLP_Length;
1142
     # `T_DELTA
1143
       TLP_Feed_Rx(`USE_PUBLIC, CplD_Index, `C_NO_BAR_HIT);
1144
       CplD_Index   <= CplD_Index + Rx_TLP_Length;
1145
       Gap_Insert_Rx;
1146
 
1147
       Hdr_Array[0] <= `HEADER0_CPLD | Rx_TLP_Length[9:0];
1148
       Hdr_Array[1] <= {`C_HOST_CPLD_ID, 4'H0, Tx_MRd_Leng[9:0], 2'b00};
1149
       Hdr_Array[2] <= {localID, tx_MRd_Tag_k, 1'b0, Tx_MRd_Addr[6:0]};
1150
       Tx_MRd_Leng  <= Tx_MRd_Leng - Rx_TLP_Length;
1151
       Tx_MRd_Addr  <= Tx_MRd_Addr + Rx_TLP_Length;
1152
     # `T_DELTA
1153
       TLP_Feed_Rx(`USE_PUBLIC, CplD_Index, `C_NO_BAR_HIT);
1154
       CplD_Index   <= CplD_Index + Rx_TLP_Length;
1155
//       Gap_Insert_Rx;
1156
 
1157
       Hdr_Array[0] <= `HEADER0_CPLD | Rx_TLP_Length[9:0];
1158
       Hdr_Array[1] <= {`C_HOST_CPLD_ID, 4'H0, Tx_MRd_Leng[9:0], 2'b00};
1159
       Hdr_Array[2] <= {localID, tx_MRd_Tag_k, 1'b0, Tx_MRd_Addr[6:0]};
1160
       Tx_MRd_Leng  <= Tx_MRd_Leng - Rx_TLP_Length;
1161
       Tx_MRd_Addr  <= Tx_MRd_Addr + Rx_TLP_Length;
1162
     # `T_DELTA
1163
       TLP_Feed_Rx(`USE_PUBLIC, CplD_Index, `C_NO_BAR_HIT);
1164
       CplD_Index   <= CplD_Index + Rx_TLP_Length;
1165
//       Gap_Insert_Rx;
1166
 
1167
       Hdr_Array[0] <= `HEADER0_CPLD | Rx_TLP_Length[9:0];
1168
       Hdr_Array[1] <= {`C_HOST_CPLD_ID, 4'H0, Tx_MRd_Leng[9:0], 2'b00};
1169
       Hdr_Array[2] <= {localID, tx_MRd_Tag_k, 1'b0, Tx_MRd_Addr[6:0]};
1170
       Tx_MRd_Leng  <= Tx_MRd_Leng - Rx_TLP_Length;
1171
       Tx_MRd_Addr  <= Tx_MRd_Addr + Rx_TLP_Length;
1172
     # `T_DELTA
1173
       TLP_Feed_Rx(`USE_PUBLIC, CplD_Index, `C_NO_BAR_HIT);
1174
       CplD_Index   <= CplD_Index + Rx_TLP_Length;
1175
       Gap_Insert_Rx;
1176
 
1177
 
1178 4 weng_ziti
       Rx_TLP_Length    <= 'H01;
1179
     # `T_DELTA     // Polling the DMA status
1180
       Hdr_Array[0] <= `HEADER0_MRD3_ | Rx_TLP_Length[9:0];
1181
       Hdr_Array[1] <= {`C_HOST_RDREQ_ID, 3'H3, Rx_MRd_Tag, 4'Hf, 4'Hf};
1182
       Hdr_Array[2] <= `C_ADDR_DMA_DS_STA;
1183
 
1184
 
1185
     # `T_DELTA
1186
       TLP_Feed_Rx(`USE_PRIVATE, 'H0, `C_BAR0_HIT);
1187
       Rx_MRd_Tag       <= Rx_MRd_Tag + 1;
1188
       Gap_Insert_Rx;
1189
 
1190
 
1191 3 weng_ziti
       FSM_Trn          <= 'H2C;
1192
 
1193
 
1194
       // feeding the payload CplD (2nd descriptor)
1195
       wait (tx_MRd_come);
1196
       Gap_Insert_Rx;
1197
       tx_MRd_come  <= 'B0;
1198
       Tx_MRd_Leng  <= (DMA_L2>>2) - 'H2;
1199
       Tx_MRd_Addr  <= DMA_HA[31:0] + 'H500;
1200
       tx_MRd_Tag_k <= tx_MRd_Tag_k + 'H1;
1201
       CplD_Index   <= 'H40;
1202
 
1203
       Gap_Insert_Rx;
1204
       Rx_TLP_Length    <= 'H10;
1205
 
1206
     # `T_DELTA
1207
       Hdr_Array[0] <= `HEADER0_CPLD | Rx_TLP_Length[9:0];
1208
       Hdr_Array[1] <= {`C_HOST_CPLD_ID, 4'H0, Tx_MRd_Leng[9:0], 2'b00};
1209
       Hdr_Array[2] <= {localID, tx_MRd_Tag_k, 1'b0, Tx_MRd_Addr[6:0]};
1210
       Tx_MRd_Leng  <= Tx_MRd_Leng - Rx_TLP_Length;
1211
       Tx_MRd_Addr  <= Tx_MRd_Addr + Rx_TLP_Length;
1212
     # `T_DELTA
1213
       TLP_Feed_Rx(`USE_PUBLIC, CplD_Index, `C_NO_BAR_HIT);
1214
       CplD_Index   <= CplD_Index + Rx_TLP_Length;
1215
       Gap_Insert_Rx;
1216
 
1217
       Hdr_Array[0] <= `HEADER0_CPLD | Rx_TLP_Length[9:0];
1218
       Hdr_Array[1] <= {`C_HOST_CPLD_ID, 4'H0, Tx_MRd_Leng[9:0], 2'b00};
1219
       Hdr_Array[2] <= {localID, tx_MRd_Tag_k, 1'b0, Tx_MRd_Addr[6:0]};
1220
       Tx_MRd_Leng  <= Tx_MRd_Leng - Rx_TLP_Length;
1221
       Tx_MRd_Addr  <= Tx_MRd_Addr + Rx_TLP_Length;
1222
     # `T_DELTA
1223
       TLP_Feed_Rx(`USE_PUBLIC, CplD_Index, `C_NO_BAR_HIT);
1224
       CplD_Index   <= CplD_Index + Rx_TLP_Length;
1225
//       Gap_Insert_Rx;
1226
 
1227
       Hdr_Array[0] <= `HEADER0_CPLD | Rx_TLP_Length[9:0];
1228
       Hdr_Array[1] <= {`C_HOST_CPLD_ID, 4'H0, Tx_MRd_Leng[9:0], 2'b00};
1229
       Hdr_Array[2] <= {localID, tx_MRd_Tag_k, 1'b0, Tx_MRd_Addr[6:0]};
1230
       Tx_MRd_Leng  <= Tx_MRd_Leng - Rx_TLP_Length;
1231
       Tx_MRd_Addr  <= Tx_MRd_Addr + Rx_TLP_Length;
1232
     # `T_DELTA
1233
       TLP_Feed_Rx(`USE_PUBLIC, CplD_Index, `C_NO_BAR_HIT);
1234
       CplD_Index   <= CplD_Index + Rx_TLP_Length;
1235
       Gap_Insert_Rx;
1236
 
1237
       Hdr_Array[0] <= `HEADER0_CPLD | Rx_TLP_Length[9:0];
1238
       Hdr_Array[1] <= {`C_HOST_CPLD_ID, 4'H0, Tx_MRd_Leng[9:0], 2'b00};
1239
       Hdr_Array[2] <= {localID, tx_MRd_Tag_k, 1'b0, Tx_MRd_Addr[6:0]};
1240
       Tx_MRd_Leng  <= Tx_MRd_Leng - Rx_TLP_Length;
1241
       Tx_MRd_Addr  <= Tx_MRd_Addr + Rx_TLP_Length;
1242
     # `T_DELTA
1243
       TLP_Feed_Rx(`USE_PUBLIC, CplD_Index, `C_NO_BAR_HIT);
1244
       CplD_Index   <= CplD_Index + Rx_TLP_Length;
1245
       Gap_Insert_Rx;
1246
 
1247
       Rx_TLP_Length    <= 'H02;
1248
       Tx_MRd_Leng      <= 'H2;
1249
       tx_MRd_Tag_k     <= tx_MRd_Tag_k + 'H1;
1250
     # `T_DELTA
1251
       Hdr_Array[0] <= `HEADER0_CPLD | Rx_TLP_Length[9:0];
1252
       Hdr_Array[1] <= {`C_HOST_CPLD_ID, 4'H0, Tx_MRd_Leng[9:0], 2'b00};
1253
       Hdr_Array[2] <= {localID, tx_MRd_Tag_k, 1'b0, Tx_MRd_Addr[6:0]};
1254
       Tx_MRd_Leng  <= Tx_MRd_Leng - Rx_TLP_Length;
1255
       Tx_MRd_Addr  <= Tx_MRd_Addr + Rx_TLP_Length;
1256
     # `T_DELTA
1257
       TLP_Feed_Rx(`USE_PUBLIC, CplD_Index, `C_NO_BAR_HIT);
1258
       CplD_Index   <= CplD_Index + Rx_TLP_Length;
1259
       Gap_Insert_Rx;
1260
 
1261
       FSM_Trn          <= 'H30;
1262
 
1263
 
1264
 
1265
     # (`T_DMA_INTERVAL*2)
1266
       ;
1267
 
1268
       DMA_us_is_Last   <= 'B0;
1269
     # `T_DELTA
1270
       //  DMA read
1271
       Private_Array[0] <= 0;
1272
       Private_Array[1] <= DMA_PA[31:00];
1273
       Private_Array[2] <= DMA_HA[63:32];          // 0;
1274
       Private_Array[3] <= DMA_HA[31:00];
1275
       Private_Array[4] <= DMA_BDA[63:32];         // 0;
1276
       Private_Array[5] <= DMA_BDA[31:00] + 'H10000;
1277
       Private_Array[6] <= DMA_L1;
1278
       Private_Array[7] <=  {4'H0
1279
                            ,3'H1, DMA_us_is_Last
1280
                            ,3'H0, 1'B1
1281
                            ,1'B0, DMA_bar
1282
                            ,1'B1
1283
                            ,15'H0
1284
                            };
1285
       Rx_TLP_Length    <= 'H01;
1286
 
1287
     # `T_DELTA
1288
       Hdr_Array[0] <= `HEADER0_MWR3_ | Rx_TLP_Length[9:0];
1289
       Hdr_Array[1] <= {`C_HOST_WRREQ_ID, Rx_MWr_Tag, 4'Hf, 4'Hf};
1290
       Hdr_Array[2] <= `C_ADDR_DMA_US_PAH;
1291
 
1292
       //  Write PA_H
1293
     # `T_DELTA
1294
       TLP_Feed_Rx(`USE_PRIVATE, 'H0, `C_BAR0_HIT);
1295
       Rx_MWr_Tag   <= Rx_MWr_Tag + 1;
1296
       Gap_Insert_Rx;
1297
       Gap_Insert_Rx;
1298
 
1299
       //  Write PA_L
1300
       Hdr_Array[2] <= Hdr_Array[2] + 'H4;
1301
     # `T_DELTA
1302
       TLP_Feed_Rx(`USE_PRIVATE, 'H1, `C_BAR0_HIT);
1303
       Rx_MWr_Tag   <= Rx_MWr_Tag + 1;
1304
       Gap_Insert_Rx;
1305
       Gap_Insert_Rx;
1306
 
1307
       //  Write HA_H
1308
       Hdr_Array[2] <= Hdr_Array[2] + 'H4;
1309
     # `T_DELTA
1310
       TLP_Feed_Rx(`USE_PRIVATE, 'H2, `C_BAR0_HIT);
1311
       Rx_MWr_Tag   <= Rx_MWr_Tag + 1;
1312
       Gap_Insert_Rx;
1313
       Gap_Insert_Rx;
1314
 
1315
       //  Write HA_L
1316
       Hdr_Array[2] <= Hdr_Array[2] + 'H4;
1317
     # `T_DELTA
1318
       TLP_Feed_Rx(`USE_PRIVATE, 'H3, `C_BAR0_HIT);
1319
       Rx_MWr_Tag   <= Rx_MWr_Tag + 1;
1320
       Gap_Insert_Rx;
1321
       Gap_Insert_Rx;
1322
 
1323
       //  Write BDA_H
1324
       Hdr_Array[2] <= Hdr_Array[2] + 'H4;
1325
     # `T_DELTA
1326
       TLP_Feed_Rx(`USE_PRIVATE, 'H4, `C_BAR0_HIT);
1327
       Rx_MWr_Tag   <= Rx_MWr_Tag + 1;
1328
       Gap_Insert_Rx;
1329
       Gap_Insert_Rx;
1330
 
1331
       //  Write BDA_L
1332
       Hdr_Array[2] <= Hdr_Array[2] + 'H4;
1333
     # `T_DELTA
1334
       TLP_Feed_Rx(`USE_PRIVATE, 'H5, `C_BAR0_HIT);
1335
       Rx_MWr_Tag   <= Rx_MWr_Tag + 1;
1336
       Gap_Insert_Rx;
1337
       Gap_Insert_Rx;
1338
 
1339
       //  Write LENG
1340
       Hdr_Array[2] <= Hdr_Array[2] + 'H4;
1341
     # `T_DELTA
1342
       TLP_Feed_Rx(`USE_PRIVATE, 'H6, `C_BAR0_HIT);
1343
       Rx_MWr_Tag   <= Rx_MWr_Tag + 1;
1344
       Gap_Insert_Rx;
1345
       Gap_Insert_Rx;
1346
 
1347
       //  Write CTRL and start the DMA
1348
       Hdr_Array[2] <= Hdr_Array[2] + 'H4;
1349
     # `T_DELTA
1350
       TLP_Feed_Rx(`USE_PRIVATE, 'H7, `C_BAR0_HIT);
1351
       Rx_MWr_Tag   <= Rx_MWr_Tag + 1;
1352
       Gap_Insert_Rx;
1353
       Gap_Insert_Rx;
1354
 
1355
 
1356 4 weng_ziti
       Rx_TLP_Length    <= 'H01;
1357
     # `T_DELTA     // Polling the DMA status
1358
       Hdr_Array[0] <= `HEADER0_MRD3_ | Rx_TLP_Length[9:0];
1359
       Hdr_Array[1] <= {`C_HOST_RDREQ_ID, 3'H3, Rx_MRd_Tag, 4'Hf, 4'Hf};
1360
       Hdr_Array[2] <= `C_ADDR_DMA_US_STA;
1361
 
1362
 
1363
     # `T_DELTA
1364
       TLP_Feed_Rx(`USE_PRIVATE, 'H0, `C_BAR0_HIT);
1365
       Rx_MRd_Tag       <= Rx_MRd_Tag + 1;
1366
       Gap_Insert_Rx;
1367
 
1368 3 weng_ziti
       FSM_Trn          <= 'H34;
1369
 
1370
 
1371
       // feeding the descriptor CplD
1372
       wait (Desc_tx_MRd_Valid);
1373
       Gap_Insert_Rx;
1374
       Desc_tx_MRd_Valid <= 'B0;
1375
       DMA_us_is_Last    <= 'B1;
1376
       Gap_Insert_Rx;
1377
 
1378
       // Initial DMA descriptor
1379
       Private_Array[0] <= 0;
1380
       Private_Array[1] <= DMA_PA[31:00] + 'H500;
1381
       Private_Array[2] <= DMA_HA[63:32];          // 0;
1382
       Private_Array[3] <= DMA_HA[31:00] + 'H500;
1383
       Private_Array[4] <= -1;                     // dont-care
1384
       Private_Array[5] <= -1;                     // dont-care
1385
       Private_Array[6] <= DMA_L2;
1386
       Private_Array[7] <=  {4'H0
1387
                            ,3'H1, DMA_us_is_Last
1388
                            ,3'H0, 1'B1
1389
                            ,1'B0, DMA_bar
1390
                            ,1'B1
1391
                            ,15'H0
1392
                            };
1393
 
1394
       Rx_TLP_Length    <= 'H08;
1395
       Gap_Insert_Rx;
1396
       Hdr_Array[0] <= `HEADER0_CPLD | Rx_TLP_Length[9:0];
1397
       Hdr_Array[1] <= {`C_HOST_CPLD_ID, 4'H0, Rx_TLP_Length[9:0], 2'b00};
1398
       Hdr_Array[2] <= {localID, Desc_tx_MRd_TAG, 1'b0, DMA_BDA[6:0]};
1399
     # `T_DELTA
1400
       TLP_Feed_Rx(`USE_PRIVATE, 0, `C_NO_BAR_HIT);
1401
       Gap_Insert_Rx;
1402
 
1403
 
1404 4 weng_ziti
       Rx_TLP_Length    <= 'H01;
1405
     # `T_DELTA     // Polling the DMA status
1406
       Hdr_Array[0] <= `HEADER0_MRD3_ | Rx_TLP_Length[9:0];
1407
       Hdr_Array[1] <= {`C_HOST_RDREQ_ID, 3'H3, Rx_MRd_Tag, 4'Hf, 4'Hf};
1408
       Hdr_Array[2] <= `C_ADDR_DMA_US_STA;
1409
 
1410
 
1411
     # `T_DELTA
1412
       TLP_Feed_Rx(`USE_PRIVATE, 'H0, `C_BAR0_HIT);
1413
       Rx_MRd_Tag       <= Rx_MRd_Tag + 1;
1414
       Gap_Insert_Rx;
1415 3 weng_ziti
 
1416 4 weng_ziti
 
1417
     # (`T_DMA_INTERVAL*4)
1418
       ;
1419
 
1420
       Rx_TLP_Length    <= 'H01;
1421
     # `T_DELTA     // Polling the DMA status
1422
       Hdr_Array[0] <= `HEADER0_MRD3_ | Rx_TLP_Length[9:0];
1423
       Hdr_Array[1] <= {`C_HOST_RDREQ_ID, 3'H3, Rx_MRd_Tag, 4'Hf, 4'Hf};
1424
       Hdr_Array[2] <= `C_ADDR_DMA_US_STA;
1425
 
1426
 
1427
     # `T_DELTA
1428
       TLP_Feed_Rx(`USE_PRIVATE, 'H0, `C_BAR0_HIT);
1429
       Rx_MRd_Tag       <= Rx_MRd_Tag + 1;
1430
       Gap_Insert_Rx;
1431
 
1432 3 weng_ziti
       FSM_Trn          <= 'H38;
1433
 
1434 4 weng_ziti
     # (`T_DMA_INTERVAL*4)
1435 3 weng_ziti
       ;
1436
 
1437
 
1438
  //////////////////////////////////////////////////////////////////////////////////
1439
 
1440
       Rx_TLP_Length    <= 'H01;
1441
     # `T_DELTA    // reset downstream DMA channel
1442
       Hdr_Array[0] <= `HEADER0_MWR3_ | Rx_TLP_Length[9:0];
1443
       Hdr_Array[1] <= {`C_HOST_WRREQ_ID, Rx_MWr_Tag, 4'Hf, 4'Hf};
1444
       Hdr_Array[2] <= `C_ADDR_DMA_DS_CTRL;
1445
       Private_Array[0] <= `C_DMA_RST_CMD;
1446
 
1447
     # `T_DELTA
1448
       TLP_Feed_Rx(`USE_PRIVATE, 'H0, `C_BAR0_HIT);
1449
       Rx_MWr_Tag   <= Rx_MWr_Tag + 1;
1450
       Gap_Insert_Rx;
1451
 
1452
       Rx_TLP_Length    <= 'H01;
1453
     # `T_DELTA    // reset upstream DMA channel
1454
       Hdr_Array[0] <= `HEADER0_MWR3_ | Rx_TLP_Length[9:0];
1455
       Hdr_Array[1] <= {`C_HOST_WRREQ_ID, Rx_MWr_Tag, 4'Hf, 4'Hf};
1456
       Hdr_Array[2] <= `C_ADDR_DMA_US_CTRL;
1457
       Private_Array[0] <= `C_DMA_RST_CMD;
1458
 
1459
     # `T_DELTA
1460
       TLP_Feed_Rx(`USE_PRIVATE, 'H0, `C_BAR0_HIT);
1461
       Rx_MWr_Tag   <= Rx_MWr_Tag + 1;
1462
       Gap_Insert_Rx;
1463
 
1464
  //////////////////////////////////////////////////////////////////////////////////
1465
 
1466
 
1467
       FSM_Trn          <= 'H40;
1468
 
1469
 
1470
  end
1471
 
1472
 
1473
 
1474
 
1475
// ========================================== //
1476
//         Checking and verification          //
1477
//                                            //
1478
   reg           Err_signal;
1479
//                                            //
1480
//                                            //
1481
// ========================================== //
1482
 
1483
   // TLP format check out Rx
1484
   //  in case stimuli incorrect: verification over verification
1485
   reg [ 7: 0]   FSM_Rx_Fmt;
1486
   reg [10: 0]   rxchk_TLP_Length;
1487
   reg           rxchk_TLP_Has_Data;
1488
   reg           rxchk_TLP_4DW_Hdr;
1489
   reg           rxchk_Mem_TLP;
1490
   always @(negedge trn_clk )
1491
   if (!trn_reset_n) begin
1492
      FSM_Rx_Fmt      <= 0;
1493
   end
1494
   else begin
1495
 
1496
      case (FSM_Rx_Fmt)
1497
 
1498
        'H00: begin
1499
            FSM_Rx_Fmt    <= 'H010;
1500
         end
1501
 
1502
        'H10: begin
1503
            if ( trn_rsrc_rdy_n | trn_rdst_rdy_n) begin
1504
              FSM_Rx_Fmt        <= 'H10;
1505
            end
1506
            else if (~trn_reof_n) begin
1507
                  $display ("\n %t:\n !! Unexpected trn_reof_n !!", $time);
1508
                  Err_signal <= 1;
1509
            end
1510
            else if (~trn_rsof_n&trn_reof_n) begin
1511
                rxchk_TLP_Has_Data    <= trn_rd[30+32];
1512
                rxchk_TLP_4DW_Hdr     <= trn_rd[29+32];
1513
                rxchk_TLP_Length[10]  <= (trn_rd[9+32:0+32]=='H0);
1514
                rxchk_TLP_Length[9:0] <= trn_rd[9+32:0+32];
1515
                if (trn_rd[28+32:25+32]) rxchk_Mem_TLP    <= 0;    // Msg or MsgD
1516
                else                     rxchk_Mem_TLP    <= 1;    // MWr, MRd or Cpl/D
1517
                FSM_Rx_Fmt        <= 'H12;
1518
            end
1519
            else begin
1520
                $display ("\n %t:\n !! trn_rsof_n error!", $time);
1521
                Err_signal <= 1;
1522
            end
1523
         end
1524
 
1525
 
1526
        'H12: begin
1527
            if ( trn_rsrc_rdy_n | trn_rdst_rdy_n) begin
1528
              FSM_Rx_Fmt        <= 'H12;
1529
            end
1530
            else if (!trn_rsof_n) begin
1531
              $display ("\n %t:\n !! trn_rsof_n error! should be 1.", $time);
1532
              Err_signal <= 1;
1533
            end
1534
            else begin
1535
              if (rxchk_TLP_4DW_Hdr & rxchk_TLP_Has_Data) begin
1536
                if (trn_reof_n) begin
1537
                  Err_signal <= 0;
1538
                  FSM_Rx_Fmt        <= 'H20;
1539
                end
1540
                else begin
1541
                  Err_signal <= 1;
1542
                  $display ("\n %t:\n !! trn_reof_n error (4-Header, with Payload)! should be 1.", $time);
1543
                end
1544
              end
1545
              else if (rxchk_TLP_4DW_Hdr & !rxchk_TLP_Has_Data) begin
1546
                if (trn_reof_n) begin
1547
                  Err_signal <= 1;
1548
                  $display ("\n %t:\n !! trn_reof_n error (4-Header, no Payload)! should be 0.", $time);
1549
                end
1550
                else if (trn_rrem_n=='H00) begin
1551
                    Err_signal <= 0;
1552
                    FSM_Rx_Fmt        <= 'H10;
1553
                end
1554
                else begin
1555
                    Err_signal <= 1;
1556
                    $display ("\n %t:\n !! trn_rrem_n error (4-Header, no Payload)!", $time);
1557
                end
1558
              end
1559
              else if (!rxchk_TLP_4DW_Hdr & !rxchk_TLP_Has_Data) begin
1560
                if (trn_reof_n) begin
1561
                  Err_signal <= 1;
1562
                  $display ("\n %t:\n !! trn_reof_n error (3-Header, with Payload)! should be 0.", $time);
1563
                end
1564
                else if (trn_rrem_n=='H0f) begin
1565
                  Err_signal <= 0;
1566
                  FSM_Rx_Fmt        <= 'H10;
1567
                end
1568
                else begin
1569
                  Err_signal <= 1;
1570
                  $display ("\n %t:\n !! trn_rrem_n error (3-Header, no Payload)!", $time);
1571
                end
1572
              end
1573
              else if (rxchk_TLP_Length=='H1) begin  // (!rxchk_TLP_4DW_Hdr & rxchk_TLP_Has_Data)
1574
                if (trn_reof_n) begin
1575
                  Err_signal <= 1;
1576
                  $display ("\n %t:\n !! trn_reof_n error (3-Header, with Payload)! should be 0.", $time);
1577
                end
1578
                else if (trn_rrem_n=='H00) begin
1579
                  Err_signal <= 0;
1580
                  FSM_Rx_Fmt        <= 'H10;
1581
                end
1582
                else begin
1583
                  Err_signal <= 1;
1584
                  $display ("\n %t:\n !! trn_rrem_n error (3-Header, no Payload)!", $time);
1585
                end
1586
              end
1587
              else begin  // (!rxchk_TLP_4DW_Hdr & rxchk_TLP_Has_Data) & (rxchk_TLP_Length>'H1)
1588
                if (trn_reof_n) begin
1589
                  Err_signal <= 0;
1590
                  rxchk_TLP_Length      <= rxchk_TLP_Length - 1;
1591
                  FSM_Rx_Fmt        <= 'H20;
1592
                end
1593
                else begin
1594
                  Err_signal <= 1;
1595
                  $display ("\n %t:\n !! trn_reof_n error (3-Header, no Payload)! should be 1.", $time);
1596
                end
1597
              end
1598
 
1599
              // Address-Length combination check
1600
              if (rxchk_TLP_4DW_Hdr) begin
1601
                if (({1'b0, trn_rd[11:2]} + rxchk_TLP_Length[9:0])>11'H400) begin
1602
                  $display ("\n\n %t:\n !! Rx 4KB straddled !!", $time);
1603
                  $display ("\n Address=%08X  Length=%04X (%04X bytes)\n\n", trn_rd[31:0], rxchk_TLP_Length, rxchk_TLP_Length<<2);
1604
//                  Err_signal <= 1;
1605
                end
1606
                if (trn_rd[63:32]=='H0 && rxchk_Mem_TLP==1) begin
1607
                  $display ("\n %t:\n !! Rx TLP should not be 4-DW headher !!", $time);
1608
                  Err_signal <= 1;
1609
                end
1610
              end
1611
              else begin
1612
                if (({1'b0, trn_rd[11+32:2+32]} + rxchk_TLP_Length[9:0])>11'H400) begin
1613
                  $display ("\n\n %t:\n !! Rx 4KB straddled !!", $time);
1614
                  $display ("\n Address=%08X  Length=%04X (%04X bytes)\n\n", trn_rd[63:32], rxchk_TLP_Length, rxchk_TLP_Length<<2);
1615
//                  Err_signal <= 1;
1616
                end
1617
              end
1618
            end
1619
          end
1620
 
1621
 
1622
        'H20: begin
1623
            if ( trn_rsrc_rdy_n | trn_rdst_rdy_n) begin
1624
              FSM_Rx_Fmt        <= 'H20;
1625
            end
1626
            else if (rxchk_TLP_Length==2) begin
1627
              if (trn_rrem_n=='H00 && trn_reof_n==0) begin
1628
                FSM_Rx_Fmt        <= 'H10;
1629
              end
1630
              else begin
1631
                $display ("\n %t:\n !! trn_reof_n/trn_rrem_n error !!", $time);
1632
                Err_signal <= 1;
1633
              end
1634
            end
1635
            else if (rxchk_TLP_Length==1) begin
1636
              if (trn_rrem_n=='H0f && trn_reof_n==0) begin
1637
                FSM_Rx_Fmt        <= 'H10;
1638
              end
1639
              else begin
1640
                $display ("\n %t:\n !! trn_reof_n/trn_rrem_n error !!", $time);
1641
                Err_signal <= 1;
1642
              end
1643
            end
1644
            else if (rxchk_TLP_Length==0) begin
1645
              $display ("\n %t:\n !! Rx TLP Length error !!", $time);
1646
              Err_signal <= 1;
1647
            end
1648
            else if (!trn_reof_n) begin
1649
              $display ("\n %t:\n !! trn_reof_n too early !!", $time);
1650
              Err_signal <= 1;
1651
            end
1652
            else begin
1653
              rxchk_TLP_Length      <= rxchk_TLP_Length - 2;
1654
              FSM_Rx_Fmt        <= 'H20;
1655
            end
1656
         end
1657
 
1658
        default: begin
1659
           FSM_Rx_Fmt     <= 'H00;
1660
         end
1661
 
1662
      endcase
1663
   end
1664
 
1665
 
1666
 
1667
 
1668
   // TLP format check by Tx
1669
   reg [ 7: 0]   FSM_TLP_Fmt;
1670
   reg [10: 0]   tx_TLP_Length;
1671
   reg [12: 0]   tx_TLP_Address;
1672
   reg           tx_TLP_Has_Data;
1673
   reg           tx_TLP_is_CplD;
1674
   reg           tx_TLP_4DW_Hdr;
1675
   reg           tx_Mem_TLP;
1676
   always @(negedge trn_clk )
1677
   if (!trn_reset_n) begin
1678
      FSM_TLP_Fmt      <= 0;
1679
   end
1680
   else begin
1681
 
1682
      case (FSM_TLP_Fmt)
1683
 
1684
        'H00: begin
1685
            FSM_TLP_Fmt    <= 'H010;
1686
         end
1687
 
1688
        'H10: begin
1689
            if ( trn_tsrc_rdy_n | trn_tdst_rdy_n) begin
1690
              FSM_TLP_Fmt        <= 'H10;
1691
            end
1692
            else if (~trn_teof_n) begin
1693
                  $display ("\n %t:\n !! Unexpected trn_teof_n !!", $time);
1694
                  Err_signal <= 1;
1695
            end
1696
            else if (~trn_tsof_n&trn_teof_n) begin
1697
                tx_TLP_Has_Data    <= trn_td[30+32];
1698
                tx_TLP_4DW_Hdr     <= trn_td[29+32];
1699
                tx_TLP_Length[10]  <= (trn_td[9+32:0+32]=='H0);
1700
                tx_TLP_Length[9:0] <= trn_td[9+32:0+32];
1701
                tx_TLP_is_CplD     <= trn_td[27+32];
1702
                if (trn_td[28+32:25+32]) tx_Mem_TLP    <= 0;    // Msg or MsgD
1703
                else                     tx_Mem_TLP    <= 1;    // MWr, MRd or Cpl/D
1704
                FSM_TLP_Fmt        <= 'H12;
1705
                if (trn_td[31:16] == localID) begin
1706
                   Err_signal <= 0;
1707
                end
1708
                else begin
1709
                   $display ("\n %t:\n !! Tx Bad TLP ReqID for TLP !!", $time);
1710
                   Err_signal <= 1;
1711
                end
1712
            end
1713
            else begin
1714
                $display ("\n %t:\n !! trn_tsof_n error!", $time);
1715
                Err_signal <= 1;
1716
            end
1717
         end
1718
 
1719
 
1720
        'H12: begin
1721
            if ( trn_tsrc_rdy_n | trn_tdst_rdy_n) begin
1722
              FSM_TLP_Fmt        <= 'H12;
1723
            end
1724
            else if (!trn_tsof_n) begin
1725
              $display ("\n %t:\n !! trn_tsof_n error! should be 1.", $time);
1726
              Err_signal <= 1;
1727
            end
1728
            else begin
1729
              if (tx_TLP_4DW_Hdr & tx_TLP_Has_Data) begin
1730
                if (trn_teof_n) begin
1731
                  Err_signal   <= 0;
1732
                  FSM_TLP_Fmt        <= 'H20;
1733
                end
1734
                else begin
1735
                  Err_signal   <= 1;
1736
                  $display ("\n %t:\n !! trn_teof_n error (4-Header, with Payload)! should be 1.", $time);
1737
                end
1738
              end
1739
              else if (tx_TLP_4DW_Hdr & !tx_TLP_Has_Data) begin
1740
                if (trn_teof_n) begin
1741
                  Err_signal <= 1;
1742
                  $display ("\n %t:\n !! trn_teof_n error (4-Header, no Payload)! should be 0.", $time);
1743
                end
1744
                else if (trn_trem_n=='H00) begin
1745
                    Err_signal <= 0;
1746
                    FSM_TLP_Fmt        <= 'H10;
1747
                end
1748
                else begin
1749
                    Err_signal <= 1;
1750
                    $display ("\n %t:\n !! trn_trem_n error (4-Header, no Payload)!", $time);
1751
                end
1752
              end
1753
              else if (!tx_TLP_4DW_Hdr & !tx_TLP_Has_Data) begin
1754
                if (trn_teof_n) begin
1755
                  Err_signal <= 1;
1756
                  $display ("\n %t:\n !! trn_teof_n error (3-Header, with Payload)! should be 0.", $time);
1757
                end
1758
                else if (trn_trem_n=='H0f) begin
1759
                  Err_signal <= 0;
1760
                  FSM_TLP_Fmt        <= 'H10;
1761
                end
1762
                else begin
1763
                  Err_signal <= 1;
1764
                  $display ("\n %t:\n !! trn_trem_n error (3-Header, no Payload)!", $time);
1765
                end
1766
              end
1767
              else if (tx_TLP_Length=='H1) begin  // (!tx_TLP_4DW_Hdr & tx_TLP_Has_Data)
1768
                if (trn_teof_n) begin
1769
                  Err_signal <= 1;
1770
                  $display ("\n %t:\n !! trn_teof_n error (3-Header, with Payload)! should be 0.", $time);
1771
                end
1772
                else if (trn_trem_n=='H00) begin
1773
                  if (tx_TLP_is_CplD && (trn_td[31+32:16+32]==`C_HOST_RDREQ_ID)) begin
1774
                    Err_signal    <= 0;
1775
                    FSM_TLP_Fmt      <= 'H10;
1776
                  end
1777
                  else if (tx_TLP_is_CplD) begin
1778
                    Err_signal   <= 1;
1779 4 weng_ziti
                    $display ("\n %t:\n !! Tx CplD Requester ID Wrong (TLP Length ==1 )!! ", $time);
1780
                    FSM_TLP_Fmt      <= 'H10;
1781 3 weng_ziti
                  end
1782
                  else begin
1783
                    Err_signal    <= 0;
1784
                    FSM_TLP_Fmt      <= 'H10;
1785
                  end
1786
                end
1787
                else begin
1788
                  Err_signal <= 1;
1789
                  $display ("\n %t:\n !! trn_trem_n error (3-Header, no Payload)!", $time);
1790
                end
1791
              end
1792
              else begin  // (!tx_TLP_4DW_Hdr & tx_TLP_Has_Data) & (tx_TLP_Length>'H1)
1793
                if (trn_teof_n) begin
1794
                  if (tx_TLP_is_CplD && (trn_td[31+32:16+32]==`C_HOST_RDREQ_ID)) begin
1795
                    tx_TLP_Length      <= tx_TLP_Length - 1;
1796
                    FSM_TLP_Fmt        <= 'H20;
1797
                  end
1798
                  else if (tx_TLP_is_CplD) begin
1799
                    Err_signal   <= 1;
1800 4 weng_ziti
                    $display ("\n %t:\n !! Tx CplD Requester ID Wrong (TLP Length !=1 )!! ", $time);
1801
                    FSM_TLP_Fmt        <= 'H20;
1802 3 weng_ziti
                  end
1803
                  else begin
1804
                    tx_TLP_Length      <= tx_TLP_Length - 1;
1805
                    FSM_TLP_Fmt        <= 'H20;
1806
                  end
1807
                end
1808
                else begin
1809
                  Err_signal <= 1;
1810
                  $display ("\n %t:\n !! trn_teof_n error (3-Header, no Payload)! should be 1.", $time);
1811
                end
1812
              end
1813
 
1814
              // Address-Length combination check
1815
              if (tx_TLP_4DW_Hdr) begin
1816
                if (({1'b0, trn_td[11:2]} + tx_TLP_Length[9:0])>11'H400) begin
1817
                  $display ("\n %t:\n !! Tx 4KB straddled !!", $time);
1818
                  $display ("\n Address=%08X  Length=%04X (%04X bytes)\n", trn_td[31:0], tx_TLP_Length, tx_TLP_Length<<2);
1819
                  Err_signal <= 1;
1820
                end
1821
                if (trn_td[63:32]=='H0 && tx_Mem_TLP==1) begin
1822
                  $display ("\n %t:\n !! Tx TLP should not be 4-DW headher !!", $time);
1823
                  Err_signal <= 1;
1824
                end
1825
              end
1826
              else begin
1827
                if (({1'b0, trn_td[11+32:2+32]} + tx_TLP_Length[9:0])>11'H400) begin
1828
                  $display ("\n %t:\n !! Tx 4KB straddled !!", $time);
1829
                  $display ("\n Address=%08X  Length=%04X (%04X bytes)\n", trn_td[63:32], tx_TLP_Length, tx_TLP_Length<<2);
1830
                  Err_signal <= 1;
1831
                end
1832
              end
1833
 
1834
            end
1835
          end
1836
 
1837
 
1838
        'H20: begin
1839
            if ( trn_tsrc_rdy_n | trn_tdst_rdy_n) begin
1840
              FSM_TLP_Fmt        <= 'H20;
1841
            end
1842
            else if (tx_TLP_Length==2) begin
1843
              if (trn_trem_n=='H00 && trn_teof_n==0) begin
1844
                FSM_TLP_Fmt        <= 'H10;
1845
              end
1846
              else begin
1847
                $display ("\n %t:\n !! trn_teof_n/trn_trem_n error !!\n", $time);
1848
                Err_signal <= 1;
1849
              end
1850
            end
1851
            else if (tx_TLP_Length==1) begin
1852
              if (trn_trem_n=='H0f && trn_teof_n==0) begin
1853
                FSM_TLP_Fmt        <= 'H10;
1854
              end
1855
              else begin
1856
                $display ("\n %t:\n !! trn_teof_n/trn_trem_n error !!\n", $time);
1857
                Err_signal <= 1;
1858
              end
1859
            end
1860
            else if (tx_TLP_Length==0) begin
1861
              $display ("\n %t:\n !! Tx TLP Length error !!", $time);
1862
              Err_signal <= 1;
1863
            end
1864
            else if (!trn_teof_n) begin
1865
              $display ("\n %t:\n !! trn_teof_n too early !!", $time);
1866
              Err_signal <= 1;
1867
            end
1868
            else begin
1869
              tx_TLP_Length      <= tx_TLP_Length - 2;
1870
              FSM_TLP_Fmt        <= 'H20;
1871
            end
1872
         end
1873
 
1874
        default: begin
1875
           FSM_TLP_Fmt     <= 'H00;
1876
         end
1877
 
1878
      endcase
1879
   end
1880
 
1881
 
1882
 
1883
 
1884
   //************************************************//
1885
   //************************************************//
1886
   //************************************************//
1887
 
1888
   reg  [ 7:00] FSM_Tx_Desc_MRd;
1889
  // Descriptors MRd
1890
   always @(negedge trn_clk )
1891
   if (!trn_reset_n) begin
1892
      FSM_Tx_Desc_MRd        <= 0;
1893
      Desc_tx_MRd_Valid      <= 0;
1894
   end
1895
   else begin
1896
 
1897
      case (FSM_Tx_Desc_MRd)
1898
 
1899
        'H00: begin
1900
            FSM_Tx_Desc_MRd       <= 'H10;
1901
         end
1902
 
1903
        'H10: begin
1904
           case ({ trn_tsrc_rdy_n
1905
                 , trn_tdst_rdy_n
1906
                 , trn_tsof_n
1907
                 , trn_td[15]
1908
                 })
1909
 
1910
             'B0001:
1911
                 if ( (trn_td[31+32:24+32]=='H00 || trn_td[31+32:24+32]=='H20)
1912
                    &&(trn_td[9+32:32]=='H8)) begin
1913
                      Desc_tx_MRd_Leng[10]  <= (trn_td[9+32:32]==0);
1914
                      Desc_tx_MRd_Leng[9:0] <= trn_td[9+32:32];
1915
                      Desc_tx_MRd_TAG       <= trn_td[15:8];
1916
                      FSM_Tx_Desc_MRd <= 'H31;
1917
                 end
1918
                 else begin
1919
                      FSM_Tx_Desc_MRd <= 'H10;
1920
                 end
1921
 
1922
              default: begin
1923
                 FSM_Tx_Desc_MRd <= 'H10;
1924
              end
1925
 
1926
           endcase
1927
         end
1928
 
1929
 
1930
        'H31: begin   // Low 32 bits Address
1931
           if (trn_tsrc_rdy_n|trn_tdst_rdy_n) begin
1932
             FSM_Tx_Desc_MRd   <= 'H31;
1933
           end
1934
           else begin
1935
               Desc_tx_MRd_Addr      <= trn_td[31:00];
1936
               Desc_tx_MRd_Valid     <= 1;
1937
               FSM_Tx_Desc_MRd       <= 'H10;
1938
           end
1939
         end
1940
 
1941
 
1942
        default: begin
1943
           FSM_Tx_Desc_MRd <= 'H00;
1944
         end
1945
 
1946
      endcase
1947
   end
1948
 
1949
 
1950
 
1951
   // DMA MRd out of Tx
1952
   reg [ 7: 0]   FSM_Tx_MRd;
1953
   reg           tx_DMA_MRd_A64b;
1954
   always @(negedge trn_clk )
1955
   if (!trn_reset_n) begin
1956
      FSM_Tx_MRd      <= 0;
1957
      tx_MRd_come     <= 0;
1958
   end
1959
   else begin
1960
 
1961
      case (FSM_Tx_MRd)
1962
 
1963
        'H00: begin
1964
            FSM_Tx_MRd       <= 'H10;
1965
         end
1966
 
1967
        'H10: begin
1968
           case ({ trn_tsrc_rdy_n
1969
                 , trn_tdst_rdy_n
1970
                 , trn_tsof_n
1971
                 , trn_td[15]
1972
                 })
1973
 
1974
             'B0000:
1975
                 case (trn_td[31+32:24+32])
1976
                   'H00: begin   // 3-dw header
1977
                      tx_MRd_Length[9:0] <= trn_td[9+32:32];
1978
                      tx_MRd_Length[10]  <= (trn_td[9+32:32]=='H0)?1:0;
1979
                      tx_MRd_Tag         <= trn_td[15:8];
1980
                      FSM_Tx_MRd         <= 'H30;
1981
                      tx_DMA_MRd_A64b    <= 0;
1982
                    end
1983
 
1984
                   'H20: begin   // 4-dw header
1985
                      tx_MRd_Length[9:0] <= trn_td[9+32:32];
1986
                      tx_MRd_Length[10]  <= (trn_td[9+32:32]=='H0)?1:0;
1987
                      tx_MRd_Tag         <= trn_td[15:8];
1988
                      FSM_Tx_MRd         <= 'H30;
1989
                      tx_DMA_MRd_A64b    <= 1;
1990
                    end
1991
 
1992
                   default: begin
1993
                      FSM_Tx_MRd <= 'H10;   // Idle
1994
                    end
1995
                 endcase
1996
 
1997
              default: begin
1998
                 FSM_Tx_MRd <= 'H10;
1999
              end
2000
 
2001
           endcase
2002
         end
2003
 
2004
 
2005
        'H30: begin
2006
           if (trn_tsrc_rdy_n|trn_tdst_rdy_n) begin
2007
             FSM_Tx_MRd <= 'H30;
2008
           end
2009
           else if( trn_td[1:0]==0) begin
2010
             FSM_Tx_MRd <= 'H10;
2011
             tx_MRd_come <= 'B1;
2012
           end
2013
           else begin
2014
             $display ("\n %t:\n !! Bad TLP Address for Tx MRd !!", $time);
2015
             Err_signal <= 1;
2016
           end
2017
        end
2018
 
2019
        default: begin
2020
           FSM_Tx_MRd <= 'H00;
2021
         end
2022
 
2023
      endcase
2024
   end
2025
 
2026
 
2027
 
2028
   // Msg checking ...
2029
   reg [7: 0] fsm_Tx_Msg;
2030
   reg [3: 0] tx_Msg_Tag_Lo;
2031
   always @(negedge trn_clk )
2032
   if (!trn_reset_n) begin
2033
      fsm_Tx_Msg      <= 0;
2034
      tx_Msg_Tag_Lo   <= 1;
2035
   end
2036
 
2037
   else begin
2038
 
2039
      case (fsm_Tx_Msg)
2040
 
2041
        'H00: begin
2042
            fsm_Tx_Msg    <= 'H10;
2043
         end
2044
 
2045
        'H10: begin
2046
           case ({ trn_tsrc_rdy_n
2047
                 , trn_tdst_rdy_n
2048
                 , trn_tsof_n
2049
                 })
2050
 
2051
             'B000:
2052
                 if (trn_td[31+32:28+32]=='H3) begin
2053
                    fsm_Tx_Msg    <= 'H30;
2054
                    if ( trn_td[11:8] != tx_Msg_Tag_Lo ) begin
2055
                      $display ("\n %t:\n !! Msg Tag bad !!", $time, trn_td[11:8]);
2056
                      Err_signal <= 1;
2057
                    end
2058
                    else if ( trn_td[7:0] == `C_MSG_CODE_INTA ) begin
2059
//                      fsm_Tx_Msg   <= 'H30;
2060
                      Accum_Msg_INTA <= Accum_Msg_INTA + 1;
2061
                    end
2062
                    else if ( trn_td[7:0] == `C_MSG_CODE_INTA_N ) begin
2063
//                      fsm_Tx_Msg   <= 'H30;
2064
                      Accum_Msg_INTA_n <= Accum_Msg_INTA_n + 1;
2065
                    end
2066
                    else begin
2067
                      $display ("\n %t:\n !! Bad Msg code (0x%2x) !!", $time, trn_td[7:0]);
2068
                      Err_signal <= 1;
2069
                    end
2070
                 end
2071
                 else begin
2072
                      fsm_Tx_Msg    <= 'H10;
2073
                 end
2074
 
2075
              default: begin
2076
                 fsm_Tx_Msg    <= 'H10;
2077
              end
2078
 
2079
           endcase
2080
         end
2081
 
2082
 
2083
        'H30: begin
2084
           if (trn_tsrc_rdy_n|trn_tdst_rdy_n) begin
2085
             fsm_Tx_Msg <= 'H30;
2086
           end
2087
           else if (trn_td) begin
2088
             $display ("\n %t:\n !! Msg data bad!!", $time);
2089
             Err_signal <= 1;
2090
           end
2091
           else begin
2092
             fsm_Tx_Msg <= 'H10;
2093
             tx_Msg_Tag_Lo  <= tx_Msg_Tag_Lo + 1;
2094
           end
2095
         end
2096
 
2097
 
2098
        default: begin
2099
           fsm_Tx_Msg  <= 'H00;
2100
         end
2101
 
2102
      endcase
2103
   end
2104
 
2105
 
2106
 
2107
   // ================================================= //
2108
   // =======     Interrupt uneven checking     ======= //
2109
   // ================================================= //
2110
   always @ Accum_Msg_INTA
2111
     if (Accum_Msg_INTA>Accum_Msg_INTA_n+1) begin
2112
        $display("\n\n  INTA overrun at %t\n\n", $time);
2113
        Err_signal <= 1;
2114
     end
2115
 
2116
   // 
2117
   always @ Accum_Msg_INTA_n
2118
     if (Accum_Msg_INTA_n>Accum_Msg_INTA) begin
2119
        $display("\n\n  #INTA overrun at %t\n\n", $time);
2120
        Err_signal <= 1;
2121
     end
2122
 
2123
 
2124
 
2125
 
2126
  // ***************************************** //
2127
  //                   Tasks                   //
2128
  // ***************************************** //
2129
 
2130
  ///////////////////////////////////////////////
2131
  //   Wait for the next positive clock event  //
2132
  ///////////////////////////////////////////////
2133
  task To_the_next_Event;
2134
  begin
2135
    wait (!trn_clk);
2136
    wait (trn_clk);
2137
    # `T_DELAY_AFTER ;
2138
  end
2139
  endtask
2140
 
2141
  ///////////////////////////////////////////////
2142
  //   Wait for the next negative clock event  //
2143
  ///////////////////////////////////////////////
2144
  task To_the_next_Tx_Data;
2145
  begin
2146
    wait (trn_clk);
2147
    wait (!trn_clk);
2148
    # `T_DELAY_AFTER ;
2149
  end
2150
  endtask
2151
 
2152
 
2153
  ///////////////////////////////////////////////
2154
  //   Insert GAP                              //
2155
  ///////////////////////////////////////////////
2156
  task Gap_Insert_Rx;
2157
  begin
2158
    To_the_next_Event;
2159
    trn_rsof_n <= 1;
2160
    trn_reof_n <= 1;
2161
    trn_rsrc_rdy_n <= 1;
2162
    trn_rbar_hit_n <= `C_NO_BAR_HIT;
2163
    trn_rd <= -1;
2164
    trn_rrem_n <= -1;
2165
  end
2166
  endtask
2167
 
2168
 
2169
  ///////////////////////////////////////////////
2170
  //                                           //
2171
  //   Feed TLP to Rx: MRd, MWr, Cpl/D, Msg    //
2172
  //                                           //
2173
  ///////////////////////////////////////////////
2174
  task TLP_Feed_Rx;
2175
    input         Use_Private_Array;   // Public or private
2176
    input [11:0]  IndexA;              // Start point in the Array
2177
    input [ 6:0]  BAR_Hit_N;           // Which BAR is hit
2178
 
2179
//    integer       hdr_Leng;
2180
    reg           TLP_has_Payload;
2181
    reg           TLP_hdr_4DW;
2182
    reg   [10:0]  jr;
2183
    reg   [10:0]  payload_Leng;
2184
 
2185
  begin
2186
 
2187
    // TLP format extraction
2188
    TLP_has_Payload     <= Hdr_Array[0][30] ;
2189
//    hdr_Leng            <= Hdr_Array[0][29] + 3;
2190
    TLP_hdr_4DW         <= Hdr_Array[0][29];
2191
 
2192
    // Header #0
2193
    To_the_next_Event;
2194
    trn_rsof_n          <= 0;
2195
    trn_reof_n          <= 1;
2196
    trn_rsrc_rdy_n      <= 0;
2197
    trn_rbar_hit_n      <= BAR_Hit_N;
2198
    trn_rd              <= {Hdr_Array[0], Hdr_Array[1]};
2199
    trn_rrem_n          <= 0;
2200
 
2201
    payload_Leng        <= {Hdr_Array[0][9:0]?1'b0:1'b1, Hdr_Array[0][9:0]};
2202
 
2203
    // Header words # 1
2204
    for (jr=1; jr<2; jr=jr+1) begin
2205
      To_the_next_Event;
2206
      trn_rsrc_rdy_n  <= trn_rsrc_rdy_n_seed;
2207
      if (trn_rsrc_rdy_n_seed) begin
2208
          trn_rsof_n    <= trn_rsof_n;
2209
          trn_rd        <= trn_rd;
2210
          trn_rrem_n    <= trn_rrem_n;
2211
          trn_reof_n    <= trn_reof_n;
2212
//          #0.1    jr    <= jr-1;
2213
          jr             = jr-1;      // !! not <= !!
2214
        end
2215
      else begin
2216
          trn_rsof_n    <= 1;
2217
          if (TLP_hdr_4DW) begin
2218
            trn_rrem_n    <= 'H00;
2219
            trn_rd        <= {Hdr_Array[2], Hdr_Array[3]};
2220
          end
2221
          else if (TLP_has_Payload) begin
2222
            trn_rrem_n    <= 'H00;
2223
            if (Use_Private_Array)
2224
              trn_rd        <= {Hdr_Array[2],Inv_Endian (Private_Array[IndexA])};
2225
            else
2226
              trn_rd        <= {Hdr_Array[2],Inv_Endian (D_Array[IndexA])};
2227
          end
2228
          else begin
2229
            trn_rrem_n    <= 'H0f;
2230
            trn_rd        <= {Hdr_Array[2], 32'H0};
2231
          end
2232
          if (payload_Leng<='H1 && TLP_hdr_4DW==0) begin
2233
            trn_reof_n    <= 0;
2234
          end
2235
          else if (!TLP_has_Payload) begin
2236
            trn_reof_n    <= 0;
2237
          end
2238
          else begin
2239
            trn_reof_n    <= 1;
2240
          end
2241
        end
2242
    end    // Header done.
2243
 
2244
    // Payload data ...
2245
    if ((TLP_has_Payload && TLP_hdr_4DW) || (TLP_has_Payload && (payload_Leng>'H1) && !TLP_hdr_4DW))
2246
 
2247
       for (jr=(!TLP_hdr_4DW); jr<payload_Leng; jr=jr+2) begin
2248
         To_the_next_Event;
2249
         trn_rsrc_rdy_n <= trn_rsrc_rdy_n_seed;
2250
         if (trn_rsrc_rdy_n_seed) begin
2251
           trn_rd       <= trn_rd;
2252
           trn_rrem_n   <= trn_rrem_n;
2253
           trn_reof_n   <= trn_reof_n;
2254
//           #0.1    jr   <= jr-1;
2255
           jr            = jr-2;      // !! not <= !!
2256
         end
2257
         else begin
2258
           if (jr==payload_Leng-1 || jr==payload_Leng-2) begin
2259
             trn_reof_n   <= 0;
2260
           end
2261
           else begin
2262
             trn_reof_n   <= 1;
2263
           end
2264
 
2265
           if (jr==payload_Leng-1) begin
2266
             trn_rrem_n   <= 'H0f;
2267
             if (Use_Private_Array)
2268
               trn_rd     <= {Inv_Endian(Private_Array[IndexA+jr]), 32'Hffff_ffff};
2269
             else
2270
               trn_rd     <= {Inv_Endian(D_Array[IndexA+jr]), 32'Hffff_ffff};
2271
           end
2272
           else begin
2273
             trn_rrem_n   <= 'H00;
2274
             if (Use_Private_Array)
2275
               trn_rd     <= {Inv_Endian(Private_Array[IndexA+jr]), Inv_Endian(Private_Array[IndexA+jr+1])};
2276
             else
2277
               trn_rd     <= {Inv_Endian(D_Array[IndexA+jr]), Inv_Endian(D_Array[IndexA+jr+1])};
2278
           end
2279
 
2280
 
2281
         end
2282
       end
2283
    // Payload done.
2284
 
2285
  end
2286
  endtask
2287
 
2288
 
2289
    /////////////////////////////////////////////
2290
   //                                         //
2291
  //   Function -  Endian Inversion 64-bit   //
2292
 //                                         //
2293
/////////////////////////////////////////////
2294
   function [31:00] Inv_Endian;
2295
   input [31:00] Data;
2296
   begin
2297
      Inv_Endian = {Data[ 7: 0], Data[15: 8], Data[23:16], Data[31:24]};
2298
   end
2299
   endfunction
2300
 
2301
 
2302
endmodule

powered by: WebSVN 2.1.0

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