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

Subversion Repositories pcie_sg_dma

[/] [pcie_sg_dma/] [branches/] [Virtex6/] [ML605_ISE13.3/] [MySource/] [DMA_FSM.vhd] - Blame information for rev 13

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 13 barabba
----------------------------------------------------------------------------------
2
-- Company: 
3
-- Engineer: 
4
-- 
5
-- Design Name: 
6
-- Module Name:    DMA_FSM - Behavioral 
7
-- Project Name: 
8
-- Target Devices: 
9
-- Tool versions: 
10
-- Description: 
11
--               The state machine controls the DMA routine, writes the channel
12
--               buffer, as well as outputs DMA stata.
13
--
14
-- Dependencies: 
15
--
16
-- Revision 1.00 - Created. 25.07.2007
17
-- 
18
-- Additional Comments: 
19
--
20
----------------------------------------------------------------------------------
21
 
22
library IEEE;
23
use IEEE.STD_LOGIC_1164.ALL;
24
use IEEE.STD_LOGIC_ARITH.ALL;
25
use IEEE.STD_LOGIC_UNSIGNED.ALL;
26
 
27
library work;
28
use work.abb64Package.all;
29
 
30
 
31
-- Uncomment the following library declaration if instantiating
32
-- any Xilinx primitives in this code.
33
--library UNISIM;
34
--use UNISIM.VComponents.all;
35
 
36
entity DMA_FSM is
37
    port (
38
      -- Fixed word for 1st header of TLP: MRd/MWr
39
      TLP_Has_Payload    : IN  std_logic;
40
      TLP_Hdr_is_4DW     : IN  std_logic;
41
      DMA_Addr_Inc       : IN  std_logic;
42
 
43
      DMA_BAR_Number     : IN  std_logic_vector(C_ENCODE_BAR_NUMBER-1 downto 0);
44
 
45
      -- FSM control signals
46
      DMA_Start          : IN  std_logic;
47
      DMA_Start2         : IN  std_logic;
48
      DMA_Stop           : IN  std_logic;
49
      DMA_Stop2          : IN  std_logic;
50
 
51
      No_More_Bodies     : IN  std_logic;
52
      ThereIs_Snout      : IN  std_logic;
53
      ThereIs_Body       : IN  std_logic;
54
      ThereIs_Tail       : IN  std_logic;
55
      ThereIs_Dex        : IN  std_logic;
56
 
57
      -- Parameters to be written into ChBuf
58
      DMA_PA_Loaded      : IN  std_logic_vector(C_DBUS_WIDTH-1 downto 0);
59
      DMA_PA_Var         : IN  std_logic_vector(C_DBUS_WIDTH-1 downto 0);
60
      DMA_HA_Var         : IN  std_logic_vector(C_DBUS_WIDTH-1 downto 0);
61
 
62
      DMA_BDA_fsm        : IN  std_logic_vector(C_DBUS_WIDTH-1 downto 0);
63
      BDA_is_64b_fsm     : IN  std_logic;
64
 
65
      DMA_Snout_Length   : IN  std_logic_vector(C_MAXSIZE_FLD_BIT_TOP downto  0);
66
      DMA_Body_Length    : IN  std_logic_vector(C_MAXSIZE_FLD_BIT_TOP downto 0);
67
      DMA_Tail_Length    : IN  std_logic_vector(C_TLP_FLD_WIDTH_OF_LENG+1 downto  0);
68
 
69
      -- Busy/Done conditions
70
      Done_Condition_1   : IN  std_logic;
71
      Done_Condition_2   : IN  std_logic;
72
      Done_Condition_3   : IN  std_logic;
73
      Done_Condition_4   : IN  std_logic;
74
      Done_Condition_5   : IN  std_logic;
75
 
76
 
77
      -- Channel buffer write
78
      us_MWr_Param_Vec   : IN  std_logic_vector(6-1   downto 0);
79
      ChBuf_aFull        : IN  std_logic;
80
      ChBuf_WrEn         : OUT std_logic;
81
      ChBuf_WrDin        : OUT std_logic_vector(C_CHANNEL_BUF_WIDTH-1 downto 0);
82
 
83
 
84
      -- FSM indicators
85
      State_Is_LoadParam : OUT std_logic;
86
      State_Is_Snout     : OUT std_logic;
87
      State_Is_Body      : OUT std_logic;
88
      State_Is_Tail      : OUT std_logic;
89
      DMA_Cmd_Ack        : OUT std_logic;
90
 
91
      -- To Tx Port
92
      ChBuf_ValidRd      : IN  std_logic;
93
      BDA_nAligned       : OUT std_logic;
94
      DMA_TimeOut        : OUT std_logic;
95
      DMA_Busy           : OUT std_logic;
96
      DMA_Done           : OUT std_logic;
97
--      DMA_Done_Rise      : OUT std_logic;
98
 
99
      -- Tags
100
      Pkt_Tag            : IN  std_logic_vector(C_TAG_WIDTH-1 downto 0);
101
      Dex_Tag            : IN  std_logic_vector(C_TAG_WIDTH-1 downto 0);
102
 
103
      -- Common ports
104
      dma_clk            : IN  std_logic;
105
      dma_reset          : IN  std_logic
106
    );
107
 
108
end entity DMA_FSM;
109
 
110
 
111
 
112
architecture Behavioral of DMA_FSM is
113
 
114
  --   DMA operation control FSM
115
  type DMAStates is            (
116
                                 -- dmaST_Init: Initial state at reset.
117
                                 dmaST_Init
118
 
119
                                 -- dmaST_Load_Param: Load DMA parameters (PA, HA, BDA and Leng).
120
                               , dmaST_Load_Param
121
 
122
                                 -- dmaST_Snout: 1st TLP might be non-integeral of MAX_SIZE.
123
                               , dmaST_Snout
124
 
125
                                 -- dmaST_Stomp: after every ChBuf write, pause a clock before taking
126
                                 --              next write.  This state checks the availability of 
127
                                 --              the ChBuf (channel buffer) for write.
128
                               , dmaST_Stomp
129
 
130
                                 -- dmaST_Body: TLP's in the middle, always integeral of MAX_SIZE.
131
                               , dmaST_Body
132
 
133
                                 -- dmaST_Tail: the last TLP, similar with the 1st one, whose size 
134
                                 --             should be specially calculated.
135
                               , dmaST_Tail
136
 
137
--                                 -- dmaST_Before_Dex: before writing the MRd TLP (for next descriptor)
138
--                                 --                   information for the next descriptor (if any), 
139
--                                 --                   a pause is needed to wait for the ChBuf available.
140
--                               , dmaST_Before_Dex
141
 
142
                                 -- dmaST_NextDex: writing the descriptor MRd TLP information to 
143
                                 --                the ChBuf.
144
                               , dmaST_NextDex
145
 
146
                                 -- dmaST_Await_Dex: after MRd(descriptor) info is written in the ChBuf, 
147
                                 --                  the state machine waits for the descriptor's 
148
                                 --                  arrival.
149
                               , dmaST_Await_Dex
150
                               );
151
 
152
  signal DMA_NextState         : DMAStates;
153
  signal DMA_State             : DMAStates;
154
 
155
 
156
  -- Busy/Done state bits generation
157
  type FSM_BusyDone is         (
158
                                 FSM_Idle
159
                               , FSM_Busy1
160
                               , FSM_Busy2
161
                               , FSM_Busy3
162
                               , FSM_Busy4
163
                               , FSM_Busy5
164
                               , FSM_Done
165
                               );
166
 
167
  signal BusyDone_NextState    : FSM_BusyDone;
168
  signal BusyDone_State        : FSM_BusyDone;
169
 
170
 
171
  -- Time-out state
172
  type FSM_Time_Out is         (
173
                                 toutSt_Idle
174
                               , toutSt_CountUp
175
                               , toutSt_Pause
176
                               );
177
 
178
  signal DMA_TimeOut_State     : FSM_Time_Out;
179
 
180
  --  DMA Start command from MWr channel
181
  signal  DMA_Start_r1         : std_logic;
182
  --  DMA Start command from CplD channel
183
  signal  DMA_Start2_r1        : std_logic;
184
  --  Registered Dex indicator
185
  signal  ThereIs_Dex_reg      : std_logic;
186
  signal  ThereIs_Snout_reg    : std_logic;
187
  signal  ThereIs_Body_reg     : std_logic;
188
  signal  ThereIs_Tail_reg     : std_logic;
189
 
190
  -- DMA Stutus monitor
191
  signal  BDA_nAligned_i       : std_logic;
192
  signal  DMA_Busy_i           : std_logic;
193
  signal  DMA_Done_i           : std_logic;
194
 
195
  -- FSM state indicators
196
  signal  State_Is_LoadParam_i : std_logic;
197
  signal  State_Is_Snout_i     : std_logic;
198
  signal  State_Is_Body_i      : std_logic;
199
  signal  State_Is_Tail_i      : std_logic;
200
  signal  State_Is_AwaitDex_i  : std_logic;
201
 
202
  --  Acknowledge for DMA_Start command
203
  signal  DMA_Cmd_Ack_i        : std_logic;
204
 
205
 
206
  -- channel FIFO Write control
207
  signal  ChBuf_WrDin_i        : std_logic_vector(C_CHANNEL_BUF_WIDTH-1 downto 0);
208
  signal  ChBuf_WrEn_i         : std_logic;
209
  signal  ChBuf_aFull_i        : std_logic;
210
 
211
 
212
  --  ---------------------------------------------------------------------------------
213
  --    Time-out calculation :  invisible to the user, so moved out of the abbPackage
214
  --  ---------------------------------------------------------------------------------
215
 
216
  signal  cnt_DMA_TO           : std_logic_vector(C_TOUT_WIDTH-1 downto  0);
217
  signal  Tout_Lo_Carry        : std_logic;
218
  signal  DMA_TimeOut_i        : std_logic;
219
 
220
  -- Carry bit, only for better timing
221
  Constant  CBIT_TOUT_CARRY    : integer  := C_TOUT_WIDTH/2;
222
 
223
begin
224
 
225
   -- As DMA Statuses
226
   BDA_nAligned       <=  BDA_nAligned_i ;
227
   DMA_Busy           <=  DMA_Busy_i     ;
228
   DMA_Done           <=  DMA_Done_i     ;
229
--   DMA_Done_Rise      <=  DMA_Done_Rise_i;
230
   DMA_TimeOut        <=  DMA_TimeOut_i  ;
231
 
232
 
233
   -- Abstract buffer write control
234
   ChBuf_WrEn         <=  ChBuf_WrEn_i;
235
   ChBuf_WrDin        <=  ChBuf_WrDin_i;
236
   ChBuf_aFull_i      <=  ChBuf_aFull;
237
 
238
 
239
   -- FSM State indicators
240
   State_Is_LoadParam <=  State_Is_LoadParam_i;
241
   State_Is_Snout     <=  State_Is_Snout_i;
242
   State_Is_Body      <=  State_Is_Body_i;
243
   State_Is_Tail      <=  State_Is_Tail_i;
244
 
245
   DMA_Cmd_Ack        <=  DMA_Cmd_Ack_i;
246
 
247
 
248
-- -----------------------------------------
249
-- Syn_Delay: DMA_Start
250
--            DMA_Start2
251
-- 
252
   Syn_Delay_DMA_Starts:
253
   process ( dma_clk)
254
   begin
255
      if dma_clk'event and dma_clk = '1' then
256
         DMA_Start_r1    <= DMA_Start;
257
         DMA_Start2_r1   <= DMA_Start2;
258
      end if;
259
 
260
   end process;
261
 
262
 
263
 
264
---- -----------------------------------------
265
---- -----------------------------------------
266
---- 
267
-- States synchronous: DMA
268
---- 
269
   Syn_DMA_States:
270
   process ( dma_clk, dma_reset)
271
   begin
272
      if dma_reset = '1' then
273
         DMA_State   <= dmaST_Init;
274
      elsif dma_clk'event and dma_clk = '1' then
275
         DMA_State   <= DMA_NextState;
276
      end if;
277
 
278
   end process;
279
 
280
 
281
 
282
-- Next States: DMA
283
   Comb_DMA_NextState:
284
   process (
285
             DMA_State
286
           , DMA_Start_r1
287
           , DMA_Start2_r1
288
           , ChBuf_aFull_i
289
 
290
           , No_More_Bodies
291
           , ThereIs_Snout  --_reg
292
--           , ThereIs_Body
293
           , ThereIs_Tail_reg
294
           , ThereIs_Dex_reg
295
           )
296
   begin
297
     case DMA_State  is
298
 
299
       when dmaST_Init  =>
300
          if DMA_Start_r1 = '1' then
301
             DMA_NextState <= dmaST_Load_Param;
302
          else
303
             DMA_NextState <= dmaST_Init;
304
          end if;
305
 
306
 
307
       when dmaST_Load_Param  =>
308
          if ChBuf_aFull_i = '1' then
309
             DMA_NextState <= dmaST_Load_Param;
310
          elsif ThereIs_Dex_reg = '1' then
311
             DMA_NextState <= dmaST_NextDex;
312
          elsif ThereIs_Snout = '1' then
313
             DMA_NextState <= dmaST_Snout;
314
--          elsif ThereIs_Body = '1' then
315
--             DMA_NextState <= dmaST_Stomp;
316
          else
317
             DMA_NextState <= dmaST_Stomp;
318
          end if;
319
 
320
 
321
       when dmaST_NextDex  =>
322
          if ThereIs_Snout = '1' then
323
             DMA_NextState <= dmaST_Snout;
324
          elsif No_More_Bodies = '0' then
325
             DMA_NextState <= dmaST_Body;
326
          else
327
             DMA_NextState <= dmaST_Await_Dex;
328
          end if;
329
 
330
 
331
       when dmaST_Snout  =>
332
             DMA_NextState <= dmaST_Stomp;
333
 
334
 
335
       when dmaST_Stomp  =>
336
          if ChBuf_aFull_i = '1' then
337
             DMA_NextState <= dmaST_Stomp;
338
          elsif No_More_Bodies= '0' then
339
             DMA_NextState <= dmaST_Body;
340
          elsif ThereIs_Tail_reg= '1' then
341
             DMA_NextState <= dmaST_Tail;
342
          elsif ThereIs_Dex_reg= '1' then
343
             DMA_NextState <= dmaST_Await_Dex;
344
          else
345
             DMA_NextState <= dmaST_Init;
346
          end if;
347
 
348
 
349
       when dmaST_Body  =>
350
             DMA_NextState <= dmaST_Stomp;
351
 
352
 
353
       when dmaST_Tail  =>
354
          if ThereIs_Dex_reg = '1' then
355
            DMA_NextState <= dmaST_Await_Dex;
356
          else
357
            DMA_NextState <= dmaST_Init;
358
          end if;
359
 
360
 
361
       when dmaST_Await_Dex  =>
362
          if DMA_Start2_r1 = '1' then
363
             DMA_NextState <= dmaST_Load_Param;
364
          else
365
             DMA_NextState <= dmaST_Await_Dex;
366
          end if;
367
 
368
 
369
       when Others  =>
370
          DMA_NextState <= dmaST_Init;
371
 
372
 
373
     end case;   -- DMA_State
374
 
375
   end process;
376
 
377
 
378
 
379
-- ----------------------------------------------------
380
-- States synchronous: DMA_Cmd_Ack
381
--                     equivalent to State_Is_LoadParam
382
--
383
   Syn_DMA_Cmd_Ack:
384
   process ( dma_clk, dma_reset)
385
   begin
386
      if dma_reset = '1' then
387
         DMA_Cmd_Ack_i   <= '0';
388
      elsif dma_clk'event and dma_clk = '1' then
389
 
390
         if DMA_NextState = dmaST_Load_Param  then
391
            DMA_Cmd_Ack_i  <= '1';
392
         else
393
            DMA_Cmd_Ack_i  <= '0';
394
         end if;
395
      end if;
396
 
397
   end process;
398
 
399
 
400
-- ----------------------------------------------------
401
-- States synchronous: ThereIs_Dex_reg
402
--
403
   Syn_ThereIs_Dex_reg:
404
   process ( dma_clk, dma_reset)
405
   begin
406
      if dma_reset = '1' then
407
         ThereIs_Dex_reg   <= '0';
408
         ThereIs_Snout_reg <= '0';
409
         ThereIs_Body_reg  <= '0';
410
         ThereIs_Tail_reg  <= '0';
411
 
412
      elsif dma_clk'event and dma_clk = '1' then
413
 
414
         if    DMA_Start = '1'
415
            or State_Is_LoadParam_i = '1'
416
            or State_Is_AwaitDex_i ='1'
417
            then
418
            ThereIs_Dex_reg    <= ThereIs_Dex;
419
            ThereIs_Snout_reg  <= ThereIs_Snout;
420
            ThereIs_Body_reg   <= ThereIs_Body;
421
            ThereIs_Tail_reg   <= ThereIs_Tail;
422
         else
423
            ThereIs_Dex_reg    <= ThereIs_Dex_reg;
424
            ThereIs_Snout_reg  <= ThereIs_Snout_reg;
425
            ThereIs_Body_reg   <= ThereIs_Body_reg;
426
            ThereIs_Tail_reg   <= ThereIs_Tail_reg;
427
         end if;
428
      end if;
429
 
430
   end process;
431
 
432
 
433
 
434
-- -------------------------------------------------------------
435
-- Synchronous reg: 
436
--                  State_Is_LoadParam
437
--                  State_Is_Snout
438
--                  State_Is_Body
439
--                  State_Is_Tail
440
--                  State_Is_AwaitDex
441
--
442
   FSM_State_Is_i:
443
   process ( dma_clk, dma_reset)
444
   begin
445
      if dma_reset = '1' then
446
         State_Is_LoadParam_i <= '0';
447
         State_Is_Snout_i     <= '0';
448
         State_Is_Body_i      <= '0';
449
         State_Is_Tail_i      <= '0';
450
         State_Is_AwaitDex_i  <= '0';
451
 
452
      elsif dma_clk'event and dma_clk = '1' then
453
 
454
         if DMA_NextState= dmaST_Load_Param then
455
            State_Is_LoadParam_i <= '1';
456
         else
457
            State_Is_LoadParam_i <= '0';
458
         end if;
459
 
460
         if DMA_NextState= dmaST_Snout then
461
            State_Is_Snout_i <= '1';
462
         else
463
            State_Is_Snout_i <= '0';
464
         end if;
465
 
466
         if DMA_NextState= dmaST_Body then
467
            State_Is_Body_i <= '1';
468
         else
469
            State_Is_Body_i <= '0';
470
         end if;
471
 
472
         if DMA_NextState= dmaST_Tail then
473
            State_Is_Tail_i <= '1';
474
         else
475
            State_Is_Tail_i <= '0';
476
         end if;
477
 
478
         if DMA_NextState= dmaST_Await_Dex then
479
            State_Is_AwaitDex_i <= '1';
480
         else
481
            State_Is_AwaitDex_i <= '0';
482
         end if;
483
 
484
      end if;
485
   end process;
486
 
487
 
488
 
489
-------------------------------------------------------------------
490
-- Synchronous Output: DMA_Abstract_Buffer_Write
491
-- 
492
-- DMA Channel (downstream and upstream) Buffers (128-bit) definition:
493
--     Note: Type not shows in this buffer
494
--
495
--  127 ~ xxx : Peripheral address
496
--  xxy ~  96 : reserved
497
--         95 : Address increments
498
--         94 : Valid
499
--   93 ~  30 : Host Address
500
--   29 ~  27 : BAR number
501
--   26 ~  19 : Tag
502
-- 
503
--   18 ~  17 : Format
504
--   16 ~  14 : TC
505
--         13 : TD
506
--         12 : EP
507
--   11 ~  10 : Attribute
508
--    9 ~   0 : Length
509
-- 
510
   FSM_DMA_Abstract_Buffer_Write:
511
   process ( dma_clk, dma_reset)
512
   begin
513
      if dma_reset = '1' then
514
         ChBuf_WrEn_i   <= '0';
515
         ChBuf_WrDin_i  <= (OTHERS =>'0');
516
 
517
      elsif dma_clk'event and dma_clk = '1' then
518
 
519
         case DMA_State is
520
 
521
            when dmaST_NextDex =>
522
                 ChBuf_WrEn_i  <= '1';
523
 
524
                 ChBuf_WrDin_i   <= (OTHERS=>'0');   -- must be the first argument
525
                 ChBuf_WrDin_i(C_CHBUF_HA_BIT_TOP downto C_CHBUF_HA_BIT_BOT)            <= DMA_BDA_fsm;
526
                 ChBuf_WrDin_i(C_CHBUF_MA_BIT_TOP downto C_CHBUF_MA_BIT_BOT)            <= C_ALL_ZEROS(C_CHBUF_MA_BIT_TOP downto C_CHBUF_MA_BIT_BOT);    -- any value
527
                 ChBuf_WrDin_i(C_CHBUF_TAG_BIT_TOP downto C_CHBUF_TAG_BIT_BOT)          <= Dex_Tag;
528
                 ChBuf_WrDin_i(C_CHBUF_DMA_BAR_BIT_TOP downto C_CHBUF_DMA_BAR_BIT_BOT)  <= DMA_BAR_Number;
529
 
530
                 ChBuf_WrDin_i(C_CHBUF_FMT_BIT_TOP)                                     <= C_TLP_HAS_NO_DATA;  --C_MRD_HEAD0_WORD(C_TLP_FMT_BIT_TOP);
531
                 ChBuf_WrDin_i(C_CHBUF_FMT_BIT_BOT)                                     <= BDA_is_64b_fsm;
532
                 ChBuf_WrDin_i(C_CHBUF_LENG_BIT_TOP downto C_CHBUF_LENG_BIT_BOT)        <= C_NEXT_BD_LENGTH(C_TLP_FLD_WIDTH_OF_LENG+1 downto 2);
533
 
534
                 ChBuf_WrDin_i(C_CHBUF_QVALID_BIT)                                      <= '1';
535
                 ChBuf_WrDin_i(C_CHBUF_AINC_BIT)                                        <= DMA_Addr_Inc;  -- any value
536
 
537
                 ChBuf_WrDin_i(C_CHBUF_ATTR_BIT_TOP downto C_CHBUF_ATTR_BIT_BOT)        <= C_RELAXED_ORDERING & C_NO_SNOOP;
538
 
539
            when dmaST_Snout =>
540
                 ChBuf_WrEn_i   <= '1';
541
 
542
                 ChBuf_WrDin_i   <= (OTHERS=>'0');   -- must be the first argument
543
                 ChBuf_WrDin_i(C_CHBUF_HA_BIT_TOP downto C_CHBUF_HA_BIT_BOT)    <= DMA_HA_Var;
544
                 if    DMA_BAR_Number=CONV_STD_LOGIC_VECTOR(CINT_FIFO_SPACE_BAR, C_ENCODE_BAR_NUMBER) then
545
                   ChBuf_WrDin_i(C_CHBUF_PA_BIT_TOP downto C_CHBUF_PA_BIT_BOT)    <= DMA_PA_Loaded(C_EP_AWIDTH-1 downto 0);
546
                 elsif DMA_BAR_Number=CONV_STD_LOGIC_VECTOR(CINT_BRAM_SPACE_BAR, C_ENCODE_BAR_NUMBER) then
547
                   ChBuf_WrDin_i(C_CHBUF_MA_BIT_TOP downto C_CHBUF_MA_BIT_BOT)    <= DMA_PA_Loaded(C_PRAM_AWIDTH-1+2 downto 0);
548
                 elsif DMA_BAR_Number=CONV_STD_LOGIC_VECTOR(CINT_DDR_SPACE_BAR, C_ENCODE_BAR_NUMBER) then
549
                   ChBuf_WrDin_i(C_CHBUF_DDA_BIT_TOP downto C_CHBUF_DDA_BIT_BOT)  <= DMA_PA_Loaded(C_DDR_IAWIDTH-1 downto 0);
550
                 else
551
                   ChBuf_WrDin_i(C_CHBUF_MA_BIT_TOP downto C_CHBUF_MA_BIT_BOT)    <= C_ALL_ZEROS(C_CHBUF_MA_BIT_TOP downto C_CHBUF_MA_BIT_BOT);
552
                 end if;
553
 
554
                 ChBuf_WrDin_i(C_CHBUF_TAG_BIT_TOP downto C_CHBUF_TAG_BIT_BOT)          <= Pkt_Tag;
555
                 ChBuf_WrDin_i(C_CHBUF_DMA_BAR_BIT_TOP downto C_CHBUF_DMA_BAR_BIT_BOT)  <= DMA_BAR_Number;
556
 
557
                 ChBuf_WrDin_i(C_CHBUF_FMT_BIT_TOP)                                     <= TLP_Has_Payload;
558
                 ChBuf_WrDin_i(C_CHBUF_FMT_BIT_BOT)                                     <= TLP_Hdr_is_4DW;
559
 
560
                 if DMA_BAR_Number=CONV_STD_LOGIC_VECTOR(CINT_FIFO_SPACE_BAR, C_ENCODE_BAR_NUMBER) then
561
                   ChBuf_WrDin_i(C_CHBUF_LENG_BIT_TOP downto C_CHBUF_LENG_BIT_BOT)        <= DMA_Snout_Length(C_TLP_FLD_WIDTH_OF_LENG+1 downto 3) & '0';
562
                 else
563
                   ChBuf_WrDin_i(C_CHBUF_LENG_BIT_TOP downto C_CHBUF_LENG_BIT_BOT)        <= DMA_Snout_Length(C_TLP_FLD_WIDTH_OF_LENG+1 downto 2);
564
                 end if;
565
 
566
                 ChBuf_WrDin_i(C_CHBUF_QVALID_BIT)                                      <= '1';
567
                 ChBuf_WrDin_i(C_CHBUF_AINC_BIT)                                        <= DMA_Addr_Inc;
568
 
569
                 ChBuf_WrDin_i(C_CHBUF_TC_BIT_TOP downto C_CHBUF_TC_BIT_BOT)            <= us_MWr_Param_Vec(2 downto 0);
570
                 ChBuf_WrDin_i(C_CHBUF_ATTR_BIT_TOP downto C_CHBUF_ATTR_BIT_BOT)        <= us_MWr_Param_Vec(5 downto 4);  -- C_RELAXED_ORDERING & C_NO_SNOOP;
571
 
572
            when dmaST_Body =>
573
                 ChBuf_WrEn_i   <= '1';
574
 
575
                 ChBuf_WrDin_i   <= (OTHERS=>'0');   -- must be the first argument
576
                 ChBuf_WrDin_i(C_CHBUF_HA_BIT_TOP downto C_CHBUF_HA_BIT_BOT)     <= DMA_HA_Var;
577
                 if    DMA_BAR_Number=CONV_STD_LOGIC_VECTOR(CINT_FIFO_SPACE_BAR, C_ENCODE_BAR_NUMBER) then
578
                   ChBuf_WrDin_i(C_CHBUF_PA_BIT_TOP downto C_CHBUF_PA_BIT_BOT)   <= DMA_PA_Var(C_EP_AWIDTH-1 downto 0);
579
                 elsif DMA_BAR_Number=CONV_STD_LOGIC_VECTOR(CINT_BRAM_SPACE_BAR, C_ENCODE_BAR_NUMBER) then
580
                   ChBuf_WrDin_i(C_CHBUF_MA_BIT_TOP downto C_CHBUF_MA_BIT_BOT)   <= DMA_PA_Var(C_PRAM_AWIDTH-1+2 downto 0);
581
                 elsif DMA_BAR_Number=CONV_STD_LOGIC_VECTOR(CINT_DDR_SPACE_BAR, C_ENCODE_BAR_NUMBER) then
582
                   ChBuf_WrDin_i(C_CHBUF_DDA_BIT_TOP downto C_CHBUF_DDA_BIT_BOT) <= DMA_PA_Var(C_DDR_IAWIDTH-1 downto 0);
583
                 else
584
                   ChBuf_WrDin_i(C_CHBUF_MA_BIT_TOP downto C_CHBUF_MA_BIT_BOT)   <= C_ALL_ZEROS(C_CHBUF_MA_BIT_TOP downto C_CHBUF_MA_BIT_BOT);
585
                 end if;
586
 
587
                 ChBuf_WrDin_i(C_CHBUF_TAG_BIT_TOP downto C_CHBUF_TAG_BIT_BOT)          <= Pkt_Tag;
588
                 ChBuf_WrDin_i(C_CHBUF_DMA_BAR_BIT_TOP downto C_CHBUF_DMA_BAR_BIT_BOT)  <= DMA_BAR_Number;
589
 
590
                 ChBuf_WrDin_i(C_CHBUF_FMT_BIT_TOP)                                     <= TLP_Has_Payload;
591
                 ChBuf_WrDin_i(C_CHBUF_FMT_BIT_BOT)                                     <= TLP_Hdr_is_4DW;
592
 
593
                 if DMA_BAR_Number=CONV_STD_LOGIC_VECTOR(CINT_FIFO_SPACE_BAR, C_ENCODE_BAR_NUMBER) then
594
                   ChBuf_WrDin_i(C_CHBUF_LENG_BIT_TOP downto C_CHBUF_LENG_BIT_BOT)        <= DMA_Body_Length(C_TLP_FLD_WIDTH_OF_LENG+1 downto 3) & '0';
595
                 else
596
                   ChBuf_WrDin_i(C_CHBUF_LENG_BIT_TOP downto C_CHBUF_LENG_BIT_BOT)        <= DMA_Body_Length(C_TLP_FLD_WIDTH_OF_LENG+1 downto 2);
597
                 end if;
598
 
599
                 ChBuf_WrDin_i(C_CHBUF_QVALID_BIT)                                      <= '1';
600
                 ChBuf_WrDin_i(C_CHBUF_AINC_BIT)                                        <= DMA_Addr_Inc;
601
 
602
                 ChBuf_WrDin_i(C_CHBUF_TC_BIT_TOP downto C_CHBUF_TC_BIT_BOT)            <= us_MWr_Param_Vec(2 downto 0);
603
                 ChBuf_WrDin_i(C_CHBUF_ATTR_BIT_TOP downto C_CHBUF_ATTR_BIT_BOT)        <= us_MWr_Param_Vec(5 downto 4);  -- C_RELAXED_ORDERING & C_NO_SNOOP;
604
 
605
 
606
            when dmaST_Tail =>
607
                 ChBuf_WrEn_i   <= '1';
608
 
609
                 ChBuf_WrDin_i   <= (OTHERS=>'0');   -- must be the first argument
610
                 ChBuf_WrDin_i(C_CHBUF_HA_BIT_TOP downto C_CHBUF_HA_BIT_BOT)     <= DMA_HA_Var;
611
                 if    DMA_BAR_Number=CONV_STD_LOGIC_VECTOR(CINT_FIFO_SPACE_BAR, C_ENCODE_BAR_NUMBER) then
612
                   ChBuf_WrDin_i(C_CHBUF_PA_BIT_TOP downto C_CHBUF_PA_BIT_BOT)   <= DMA_PA_Var(C_EP_AWIDTH-1 downto 0);
613
                 elsif DMA_BAR_Number=CONV_STD_LOGIC_VECTOR(CINT_BRAM_SPACE_BAR, C_ENCODE_BAR_NUMBER) then
614
                   ChBuf_WrDin_i(C_CHBUF_MA_BIT_TOP downto C_CHBUF_MA_BIT_BOT)   <= DMA_PA_Var(C_PRAM_AWIDTH-1+2 downto 0);
615
                 elsif DMA_BAR_Number=CONV_STD_LOGIC_VECTOR(CINT_DDR_SPACE_BAR, C_ENCODE_BAR_NUMBER) then
616
                   ChBuf_WrDin_i(C_CHBUF_DDA_BIT_TOP downto C_CHBUF_DDA_BIT_BOT) <= DMA_PA_Var(C_DDR_IAWIDTH-1 downto 0);
617
                 else
618
                   ChBuf_WrDin_i(C_CHBUF_MA_BIT_TOP downto C_CHBUF_MA_BIT_BOT)   <= C_ALL_ZEROS(C_CHBUF_MA_BIT_TOP downto C_CHBUF_MA_BIT_BOT);
619
                 end if;
620
 
621
                 ChBuf_WrDin_i(C_CHBUF_TAG_BIT_TOP downto C_CHBUF_TAG_BIT_BOT)          <= Pkt_Tag;
622
                 ChBuf_WrDin_i(C_CHBUF_DMA_BAR_BIT_TOP downto C_CHBUF_DMA_BAR_BIT_BOT)  <= DMA_BAR_Number;
623
 
624
                 ChBuf_WrDin_i(C_CHBUF_FMT_BIT_TOP)                                     <= TLP_Has_Payload;
625
                 ChBuf_WrDin_i(C_CHBUF_FMT_BIT_BOT)                                     <= TLP_Hdr_is_4DW;
626
 
627
                 if DMA_BAR_Number=CONV_STD_LOGIC_VECTOR(CINT_FIFO_SPACE_BAR, C_ENCODE_BAR_NUMBER) then
628
                   ChBuf_WrDin_i(C_CHBUF_LENG_BIT_TOP downto C_CHBUF_LENG_BIT_BOT)        <= DMA_Tail_Length(C_TLP_FLD_WIDTH_OF_LENG+1 downto 3) & '0';
629
                 else
630
                   ChBuf_WrDin_i(C_CHBUF_LENG_BIT_TOP downto C_CHBUF_LENG_BIT_BOT)        <= DMA_Tail_Length(C_TLP_FLD_WIDTH_OF_LENG+1 downto 2);
631
                 end if;
632
 
633
                 ChBuf_WrDin_i(C_CHBUF_QVALID_BIT)                                      <= '1';
634
                 ChBuf_WrDin_i(C_CHBUF_AINC_BIT)                                        <= DMA_Addr_Inc;
635
 
636
                 ChBuf_WrDin_i(C_CHBUF_TC_BIT_TOP downto C_CHBUF_TC_BIT_BOT)            <= us_MWr_Param_Vec(2 downto 0);
637
                 ChBuf_WrDin_i(C_CHBUF_ATTR_BIT_TOP downto C_CHBUF_ATTR_BIT_BOT)        <= us_MWr_Param_Vec(5 downto 4);  -- C_RELAXED_ORDERING & C_NO_SNOOP;
638
 
639
 
640
            when OTHERS =>
641
                 ChBuf_WrEn_i   <= '0';
642
                 ChBuf_WrDin_i  <= ChBuf_WrDin_i;
643
 
644
         end case;
645
 
646
      end if;
647
   end process;
648
 
649
 
650
 
651
-- ----------------------------------------------
652
-- Synchronous Latch: BDA_nAligned_i
653
--                  : Capture design defect
654
-- 
655
   Latch_BDA_nAligned:
656
   process ( dma_clk, dma_reset)
657
   begin
658
      if dma_reset = '1' then
659
         BDA_nAligned_i <= '0';
660
 
661
      elsif dma_clk'event and dma_clk = '1' then
662
         -- If the lowest 2 bits are not zero, error bit set accordingly,
663
         --   because the logic can not deal with this situation.
664
         --   can be removed.
665
 
666
         if DMA_BDA_fsm(1) ='1' or DMA_BDA_fsm(0) ='1' then
667
            BDA_nAligned_i <= '1';
668
         else
669
            BDA_nAligned_i <= BDA_nAligned_i;
670
         end if;
671
 
672
      end if;
673
   end process;
674
 
675
 
676
-- States synchronous: BusyDone_States
677
   Syn_BusyDone_States:
678
   process ( dma_clk, dma_reset)
679
   begin
680
      if dma_reset = '1' then
681
         BusyDone_State   <= FSM_Idle;
682
      elsif dma_clk'event and dma_clk = '1' then
683
         BusyDone_State   <= BusyDone_NextState;
684
      end if;
685
 
686
   end process;
687
 
688
 
689
-- Next States: BusyDone_State
690
   Comb_BusyDone_State:
691
   process (
692
             BusyDone_State
693
           , DMA_State
694
--           , Done_Condition_1
695
           , Done_Condition_2
696
           , Done_Condition_3
697
           , Done_Condition_4
698
           , Done_Condition_5
699
           )
700
   begin
701
     case BusyDone_State  is
702
 
703
       when FSM_Idle  =>
704
          if DMA_State = dmaST_Load_Param then
705
             BusyDone_NextState <= FSM_Busy1;
706
          else
707
             BusyDone_NextState <= FSM_Idle;
708
          end if;
709
 
710
       when FSM_Busy1  =>
711
          if DMA_State = dmaST_Init      ---  Done_Condition_1='1'
712
             then
713
             BusyDone_NextState <= FSM_Busy2;
714
          else
715
             BusyDone_NextState <= FSM_Busy1;
716
          end if;
717
 
718
       when FSM_Busy2  =>
719
          if Done_Condition_2='1'
720
             then
721
             BusyDone_NextState <= FSM_Busy3;
722
          else
723
             BusyDone_NextState <= FSM_Busy2;
724
          end if;
725
 
726
       when FSM_Busy3  =>
727
          if Done_Condition_3='1'
728
             then
729
             BusyDone_NextState <= FSM_Busy4;
730
          else
731
             BusyDone_NextState <= FSM_Busy3;
732
          end if;
733
 
734
       when FSM_Busy4  =>
735
          if Done_Condition_4='1'
736
             then
737
             BusyDone_NextState <= FSM_Busy5;
738
          else
739
             BusyDone_NextState <= FSM_Busy4;
740
          end if;
741
 
742
       when FSM_Busy5  =>
743
          if Done_Condition_5='1'
744
             then
745
             BusyDone_NextState <= FSM_Done;
746
          else
747
             BusyDone_NextState <= FSM_Busy5;
748
          end if;
749
 
750
       when FSM_Done  =>
751
          if DMA_State = dmaST_Init then
752
             BusyDone_NextState <= FSM_Idle;
753
          else
754
             BusyDone_NextState <= FSM_Done;
755
          end if;
756
 
757
       when Others  =>
758
          BusyDone_NextState    <= FSM_Idle;
759
 
760
     end case;  -- BusyDone_State
761
 
762
   end process;
763
 
764
 
765
 
766
-- Synchronous Output: DMA_Busy_i
767
   FSM_Output_DMA_Busy:
768
   process ( dma_clk, dma_reset)
769
   begin
770
      if dma_reset = '1' then
771
         DMA_Busy_i     <= '0';
772
      elsif dma_clk'event and dma_clk = '1' then
773
 
774
        case BusyDone_State is
775
 
776
          when FSM_Idle =>
777
            DMA_Busy_i  <= '0';
778
 
779
          when FSM_Busy1 =>
780
            DMA_Busy_i  <= '1';
781
 
782
          when FSM_Busy2 =>
783
            DMA_Busy_i  <= '1';
784
 
785
          when FSM_Busy3 =>
786
            DMA_Busy_i  <= '1';
787
 
788
          when FSM_Busy4 =>
789
            DMA_Busy_i  <= '1';
790
 
791
          when FSM_Busy5 =>
792
            DMA_Busy_i  <= '1';
793
 
794
          when FSM_Done =>
795
            DMA_Busy_i  <= '0';
796
 
797
          when Others =>
798
            DMA_Busy_i  <= '0';
799
 
800
        end case; -- BusyDone_State
801
 
802
      end if;
803
   end process;
804
 
805
 
806
-- Synchronous Output: DMA_Done_i
807
   FSM_Output_DMA_Done:
808
   process ( dma_clk, dma_reset)
809
   begin
810
      if dma_reset = '1' then
811
         DMA_Done_i     <= '0';
812
      elsif dma_clk'event and dma_clk = '1' then
813
 
814
        case BusyDone_State is
815
 
816
--          when FSM_Busy1 =>
817
--            DMA_Done_i  <= '0';
818
--
819
--          when FSM_Busy2 =>
820
--            DMA_Done_i  <= '0';
821
--
822
--          when FSM_Busy3 =>
823
--            DMA_Done_i  <= '0';
824
--
825
          when FSM_Done =>
826
            DMA_Done_i  <= '1';
827
 
828
          when Others =>
829
            DMA_Done_i  <= DMA_Done_i;
830
 
831
        end case; -- BusyDone_State
832
 
833
      end if;
834
   end process;
835
 
836
 
837
 
838
-- ----------------------------------------------
839
-- Time out counter
840
-- Synchronous Output: Counter_DMA_TimeOut_i
841
   FSM_Counter_DMA_TimeOut_i:
842
   process ( dma_clk, dma_reset)
843
   begin
844
      if dma_reset = '1' then
845
         cnt_DMA_TO         <= (Others=>'0');
846
         Tout_Lo_Carry      <= '0';
847
         DMA_TimeOut_State  <= toutSt_Idle;
848
 
849
      elsif dma_clk'event and dma_clk = '1' then
850
 
851
        case DMA_TimeOut_State is
852
 
853
          when toutSt_Idle =>
854
            cnt_DMA_TO         <= (Others=>'0');
855
            Tout_Lo_Carry      <= '0';
856
            if DMA_Start='1' then
857
              DMA_TimeOut_State  <= toutSt_CountUp;
858
            else
859
              DMA_TimeOut_State  <= toutSt_Idle;
860
            end if;
861
 
862
          when toutSt_CountUp =>
863
            if DMA_Done_i='1' or DMA_Start='1' then
864
              cnt_DMA_TO         <= (Others=>'0');
865
              Tout_Lo_Carry      <= '0';
866
              DMA_TimeOut_State  <= toutSt_Idle;
867
            elsif DMA_Stop='1' then
868
              cnt_DMA_TO         <= cnt_DMA_TO;
869
              Tout_Lo_Carry      <= Tout_Lo_Carry;
870
              DMA_TimeOut_State  <= toutSt_Pause;
871
            elsif ChBuf_ValidRd='1' then
872
              cnt_DMA_TO         <= (Others=>'0');
873
              Tout_Lo_Carry      <= '0';
874
              DMA_TimeOut_State  <= toutSt_CountUp;
875
            else
876
              cnt_DMA_TO(CBIT_TOUT_CARRY-1 downto 0)  <= cnt_DMA_TO(CBIT_TOUT_CARRY-1 downto 0) + '1';
877
              if cnt_DMA_TO(CBIT_TOUT_CARRY-1 downto 0)=C_ALL_ONES(CBIT_TOUT_CARRY-1 downto 0) then
878
                 Tout_Lo_Carry    <= '1';
879
              else
880
                 Tout_Lo_Carry    <= '0';
881
              end if;
882
              if Tout_Lo_Carry='1' then
883
                 cnt_DMA_TO(C_TOUT_WIDTH-1 downto CBIT_TOUT_CARRY)  <= cnt_DMA_TO(C_TOUT_WIDTH-1 downto CBIT_TOUT_CARRY) + '1';
884
              else
885
                 cnt_DMA_TO(C_TOUT_WIDTH-1 downto CBIT_TOUT_CARRY)  <= cnt_DMA_TO(C_TOUT_WIDTH-1 downto CBIT_TOUT_CARRY);
886
              end if;
887
              DMA_TimeOut_State  <= toutSt_CountUp;
888
            end if;
889
 
890
          when toutSt_Pause =>
891
            cnt_DMA_TO         <= cnt_DMA_TO;
892
            Tout_Lo_Carry      <= Tout_Lo_Carry;
893
            if DMA_Start='1' then
894
              DMA_TimeOut_State  <= toutSt_CountUp;
895
            elsif DMA_Done_i='1' then
896
              DMA_TimeOut_State  <= toutSt_Idle;
897
            else
898
              DMA_TimeOut_State  <= toutSt_Pause;
899
            end if;
900
 
901
          when Others =>
902
            cnt_DMA_TO         <= cnt_DMA_TO;
903
            Tout_Lo_Carry      <= Tout_Lo_Carry;
904
            DMA_TimeOut_State  <= toutSt_Idle;
905
 
906
        end case;
907
 
908
 
909
 
910
--        case DMA_State is
911
--
912
--          when dmaST_Init =>
913
--            cnt_DMA_TO       <= (Others=>'0');
914
--            Tout_Lo_Carry    <= '0';
915
--
916
--          when dmaST_Snout =>
917
--            cnt_DMA_TO       <= (Others=>'0');
918
--            Tout_Lo_Carry    <= '0';
919
--
920
--
921
--          when Others =>
922
--            cnt_DMA_TO(CBIT_CARRY-1 downto 0)  <= cnt_DMA_TO(CBIT_CARRY-1 downto 0) + '1';
923
--
924
--            if cnt_DMA_TO(CBIT_CARRY-1 downto 0)=C_ALL_ONES(CBIT_CARRY-1 downto 0) then
925
--               Tout_Lo_Carry    <= '1';
926
--            else
927
--               Tout_Lo_Carry    <= '0';
928
--            end if;
929
--
930
--            if Tout_Lo_Carry='1' then
931
--               cnt_DMA_TO(C_TOUT_WIDTH-1 downto CBIT_CARRY)  <= cnt_DMA_TO(C_TOUT_WIDTH-1 downto CBIT_CARRY) + '1';
932
--            else
933
--               cnt_DMA_TO(C_TOUT_WIDTH-1 downto CBIT_CARRY)  <= cnt_DMA_TO(C_TOUT_WIDTH-1 downto CBIT_CARRY);
934
--            end if;
935
--
936
--        end case;
937
 
938
      end if;
939
   end process;
940
 
941
 
942
-- ----------------------------------------------
943
-- Time out state bit
944
-- Synchronous Output: DMA_TimeOut_i
945
   FSM_DMA_TimeOut:
946
   process ( dma_clk, dma_reset)
947
   begin
948
      if dma_reset = '1' then
949
         DMA_TimeOut_i     <= '0';
950
      elsif dma_clk'event and dma_clk = '1' then
951
         -- Capture the time-out trigger
952
--         if cnt_DMA_TO(CBIT_TOUT_BOT downto 0) = C_TIME_OUT_VALUE then
953
         if cnt_DMA_TO(C_TOUT_WIDTH-1 downto CBIT_TOUT_BOT) = C_TIME_OUT_VALUE then
954
            DMA_TimeOut_i  <= '1';
955
         else
956
            DMA_TimeOut_i  <= DMA_TimeOut_i;
957
         end if;
958
 
959
      end if;
960
   end process;
961
 
962
 
963
end architecture Behavioral;

powered by: WebSVN 2.1.0

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