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

Subversion Repositories funbase_ip_library

[/] [funbase_ip_library/] [trunk/] [TUT/] [ip.hwp.communication/] [packet_codec/] [1.0/] [vhd/] [pkt_enc.vhd] - Blame information for rev 145

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 145 lanttu
-------------------------------------------------------------------------------
2
-- File        : packet_encoder_ctrl.vhdl
3
-- Description : Control of the packet encoder
4
--
5
-- Author      : Vesa Lahtinen
6
-- Date        : 23.10.2003
7
-- Modified    : 
8
-- 19.02.2005 ES previous_addr <= previous_addr in comb process, seems like a
9
-- latch! 
10
-- 29.04.2005  ES Bug: If new addr arrived in state read_in, it was sent as
11
--                      data.
12
--                Correction: Assert ip_full_out => ip stops write and fifo
13
--                              does not accept addr
14
-- 31.01.2006   ES Divided into two state machines, reading values in can now
15
--                 happen in parallel with writing out =>  better performance
16
-- 23.08.2007   AR new generics and support for LUT
17
-- 2007/08/03   ES Header conficuration possible: place of pkt-len and send/dont_
18
--                 send orig_addr
19
-- 2009-05-05   JN Ver 06 gets tx length from sender in advance to start the
20
--                 transfer more quickly. It can also use a status block.
21
-------------------------------------------------------------------------------
22
 
23
-------------------------------------------------------------------------------
24
-- Funbase IP library Copyright (C) 2011 TUT Department of Computer Systems
25
--
26
-- This source file may be used and distributed without
27
-- restriction provided that this copyright statement is not
28
-- removed from the file and that any derivative work contains
29
-- the original copyright notice and the associated disclaimer.
30
--
31
-- This source file is free software; you can redistribute it
32
-- and/or modify it under the terms of the GNU Lesser General
33
-- Public License as published by the Free Software Foundation;
34
-- either version 2.1 of the License, or (at your option) any
35
-- later version.
36
--
37
-- This source is distributed in the hope that it will be
38
-- useful, but WITHOUT ANY WARRANTY; without even the implied
39
-- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
40
-- PURPOSE.  See the GNU Lesser General Public License for more
41
-- details.
42
--
43
-- You should have received a copy of the GNU Lesser General
44
-- Public License along with this source; if not, download it
45
-- from http://www.opencores.org/lgpl.shtml
46
-------------------------------------------------------------------------------
47
 
48
 
49
library ieee;
50
use ieee.std_logic_1164.all;
51
use ieee.std_logic_arith.all;
52
use ieee.std_logic_unsigned.all;
53
 
54
entity packet_encoder_ctrl is
55
 
56
  generic (
57
    wait_empty_fifo_g : integer := 0;
58
    data_width_g      : integer := 36;
59
    addr_width_g      : integer := 32;  -- lsb part of data_width_g
60
    tx_len_width_g   : integer := 8;   -- how many bits we need for packet length
61
    packet_length_g   : integer := 0;   -- payload_len_g ja hdr_len_g
62
    timeout_g         : integer := 0;
63
    fill_packet_g     : integer := 0;
64
    lut_en_g          : integer := 1;
65
    net_type_g        : integer;
66
    len_flit_en_g     : integer := 1;   -- 2007/08/03 where to place a pkt_len
67
    oaddr_flit_en_g   : integer := 1;   -- 2007/08/03 whether to send the orig address
68
    dbg_en_g          : integer := 0;
69
    dbg_width_g       : integer := 1;
70
    status_en_g       : integer := 0    -- 2009-05-05, JN: Status information or not
71
    );
72
 
73
  port (
74
    clk   : in std_logic;
75
    rst_n : in std_logic;
76
 
77
    ip_av_in      : in std_logic;
78
    ip_data_in    : in std_logic_vector (data_width_g-1 downto 0);
79
    ip_we_in      : in std_logic;
80
    ip_tx_len_in  : in std_logic_vector (tx_len_width_g-1 downto 0);
81
 
82
    fifo_av_in    : in  std_logic;
83
    fifo_data_in  : in  std_logic_vector (data_width_g-1 downto 0);
84
    fifo_full_in  : in  std_logic;
85
    fifo_empty_in : in  std_logic;
86
    fifo_re_out   : out std_logic;
87
 
88
    net_full_in  : in std_logic;
89
    net_empty_in : in std_logic;
90
 
91
    ip_stall_out  : out std_logic;
92
    net_av_out   : out std_logic;
93
    net_data_out : out std_logic_vector (data_width_g-1 downto 0);
94
    net_we_out   : out std_logic;
95
    dbg_out      : out std_logic_vector(dbg_width_g - 1 downto 0)
96
    );
97
 
98
end packet_encoder_ctrl;
99
 
100
 
101
architecture rtl of packet_encoder_ctrl is
102
 
103
  type wr_state_type is (start, wait_req, wait_empty, write_out_addr,
104
                         write_out_in_addr, write_out_amount, write_out_data);
105
  signal wr_state_r : wr_state_type;
106
 
107
 
108
  constant hdr_words_c : integer := 1 + len_flit_en_g + oaddr_flit_en_g;  -- 2007/08/03
109
  -- constant hdr_words_c     : integer := 3;  -- 25.01.2006
110
 
111
  constant payload_words_c : integer := packet_length_g - hdr_words_c;
112
  signal   amount_r        : integer range 1 to payload_words_c+1;
113
  -- amount denoted payload and possibly orig_addr
114
 
115
 
116
  signal timeout_counter_r : integer range 0 to timeout_g;
117
  signal write_counter_r   : integer range 0 to packet_length_g;
118
 
119
 
120
 
121
 
122
  -- 30.01.2006
123
  type   rd_state_type is (wait_trans, read_in, wait_ack);
124
  signal rd_state_r           : rd_state_type;
125
  signal amount_rd_r          : integer range 0 to payload_words_c;
126
  signal prev_addr_r          : std_logic_vector(data_width_g-1 downto 0);
127
  signal timeout_counter_rd_r : integer range 0 to timeout_g;
128
 
129
  -- amount to writing FSM's amount_r, either from amount_rd_r or ip_tx_len_in
130
  signal amount_to_wr_r : integer range 0 to payload_words_c+1;
131
  -- length as integer
132
  signal len_from_ip : integer range 0 to 2**tx_len_width_g;
133
  signal len_r : integer range 0 to 2**tx_len_width_g;
134
  signal len_valid_r : std_logic;
135
  signal next_len_valid_r : std_logic;
136
 
137
  -- 26.03.2006
138
  signal next_addr_r       : std_logic_vector(data_width_g-1 downto 0);
139
  signal next_addr_valid_r : std_logic;
140
 
141
 
142
  signal ack_wr_rd : std_logic;
143
  signal ack_tmp_r : std_logic;
144
  signal ack_from_wr_r : std_logic;
145
  signal req_rd_wr : std_logic;
146
  signal req_writing_r : std_logic;
147
 
148
  signal data_in_fifo_r : std_logic;
149
 
150
  component addr_lut
151
    generic (
152
      in_addr_w_g  : integer;
153
      out_addr_w_g : integer;
154
      cmp_high_g   : integer;
155
      cmp_low_g    : integer;
156
      lut_en_g     : integer;
157
      net_type_g   : integer);
158
    port (
159
      addr_in  : in  std_logic_vector(in_addr_w_g-1 downto 0);
160
      addr_out : out std_logic_vector(out_addr_w_g-1 downto 0));
161
  end component;
162
 
163
 
164
  component pkt_counter
165
    generic (
166
      tx_len_width_g : integer);
167
    port (
168
      clk        : in std_logic;
169
      rst_n      : in std_logic;
170
      len_in     : in std_logic_vector(tx_len_width_g-1 downto 0);
171
      new_tx_in  : in std_logic;
172
      new_pkt_in : in std_logic;
173
      idle_in    : in std_logic);
174
  end component;
175
 
176
 
177
  -- Signals to and from LUT
178
  signal addr_to_lut   : std_logic_vector(addr_width_g-1 downto 0);
179
  signal addr_from_lut : std_logic_vector(data_width_g-1 downto 0);
180
 
181
  signal in_addr_r : std_logic_vector(data_width_g-1 downto 0);
182
 
183
  signal ip_stall : std_logic;
184
 
185
 
186
  signal len_to_status : std_logic_vector( tx_len_width_g-1 downto 0 );
187
 
188
  -- 2007/08/03
189
  signal hdr_len_dbg     : integer;
190
  signal payload_len_dbg : integer;
191
 
192
  constant len_width_c : integer := 8;  -- bits needed for pkt_len, will be generic someday?
193
 
194
begin
195
 
196
  -- convert length to integer
197
  len_from_ip <= conv_integer(ip_tx_len_in);
198
 
199
  len_to_status <= conv_std_logic_vector( amount_to_wr_r, tx_len_width_g );
200
 
201
  -- status counter instantiation
202
  status: if status_en_g = 1 generate
203
 
204
    pkt_counter_1: pkt_counter
205
      generic map (
206
        tx_len_width_g => tx_len_width_g
207
        )
208
      port map (
209
        clk        => clk,
210
        rst_n      => rst_n,
211
        len_in     => len_to_status,
212
        new_tx_in  => ip_av_in,
213
        new_pkt_in => req_rd_wr,
214
        idle_in    => fifo_empty_in
215
        );
216
 
217
  end generate status;
218
 
219
 
220
  -- LUT INSTANTIATION
221
  lut_or_not: if lut_en_g = 1 generate
222
    addr_lut_1 : addr_lut
223
      generic map (
224
        in_addr_w_g  => addr_width_g,
225
        out_addr_w_g => data_width_g,
226
        cmp_high_g   => addr_width_g-1,
227
        cmp_low_g    => 0,
228
        lut_en_g     => lut_en_g,
229
        net_type_g   => net_type_g)
230
      port map (
231
        addr_in  => addr_to_lut,
232
        addr_out => addr_from_lut);
233
  end generate lut_or_not;
234
 
235
  -- without lut signals are simply connected
236
  no_lut: if lut_en_g = 0 generate
237
    addr_from_lut <= addr_to_lut;
238
  end generate no_lut;
239
 
240
 
241
  read_data : process (clk, rst_n)
242
  begin  -- process read_data
243
    if rst_n = '0' then                 -- asynchronous reset (active low)
244
      amount_rd_r          <= 0;
245
      rd_state_r           <= wait_trans;
246
      prev_addr_r          <= (others => '0');
247
      timeout_counter_rd_r <= 0;
248
      ack_from_wr_r        <= '0';
249
      amount_to_wr_r       <= 0;
250
      len_valid_r          <= '0';
251
      next_len_valid_r     <= '0';
252
      req_writing_r        <= '0';
253
      len_r                <= 0;
254
 
255
      next_addr_r       <= (others => '0');
256
      next_addr_valid_r <= '0';
257
      data_in_fifo_r    <= '0';         -- AK 12.06.2007
258
 
259
      hdr_len_dbg     <= hdr_words_c;
260
      payload_len_dbg <= payload_words_c;
261
 
262
    elsif clk'event and clk = '1' then  -- rising clock edge
263
 
264
      -- store the ack
265
      -- ack_wr_rd is '1' on the start state, so we have to make sure that the
266
      -- ack_from_wr_r doesn't rise right after reset (rd_state_r /= wait_trans)
267
      if ack_wr_rd = '1' and rd_state_r /= wait_trans then
268
        ack_from_wr_r <= '1';
269
      end if;
270
 
271
 
272
      case rd_state_r is
273
 
274
        when wait_trans =>
275
          timeout_counter_rd_r <= 0;
276
 
277
          if (ip_we_in = '1' and fifo_full_in = '0' ) then
278
 
279
            -- no actual data is in the fifo, although av is.
280
            if (ip_av_in = '1') then
281
              -- Uusi osoite
282
              amount_rd_r <= 0;
283
              rd_state_r  <= read_in;
284
              prev_addr_r <= ip_data_in;
285
              --assert false report "uus os" severity note;
286
              data_in_fifo_r <= '0';
287
 
288
              -- if the IP offers us the packet length, we start
289
              -- writing right away
290
              if len_from_ip /= 0 then
291
 
292
                -- if length from ip is longer than max pkt length
293
                if len_from_ip > payload_words_c then
294
 
295
                  amount_to_wr_r <= payload_words_c;
296
                  next_len_valid_r <= '1';
297
                  len_valid_r <= '0';
298
                else
299
                  amount_to_wr_r <= len_from_ip;
300
                  next_len_valid_r <= '0';
301
                  len_valid_r <= '1';
302
                end if;
303
 
304
                len_r <= len_from_ip;
305
 
306
                req_writing_r <= '1';
307
              else
308
                len_valid_r <= '0';
309
              end if;
310
 
311
            else
312
              -- dataa (vanha osoite)
313
              amount_rd_r <= 1;
314
              rd_state_r  <= read_in;
315
              prev_addr_r <= prev_addr_r;
316
              --assert false report "vanh os" severity note;
317
              data_in_fifo_r <= '1';
318
 
319
              -- old packet continues with old length information
320
              if next_len_valid_r = '1' then
321
                if len_r > payload_words_c then
322
 
323
                  amount_to_wr_r <= payload_words_c;
324
                  next_len_valid_r <= '1';
325
                  len_valid_r <= '0';
326
                else
327
                  amount_to_wr_r <= len_r;
328
                  next_len_valid_r <= '0';
329
                  len_valid_r <= '1';
330
                end if;
331
 
332
                req_writing_r <= '1';
333
 
334
              end if;
335
            end if;
336
 
337
          else
338
            -- ei dataa eikä osoitetta
339
            amount_rd_r <= 0;
340
            rd_state_r  <= wait_trans;
341
            prev_addr_r <= prev_addr_r;
342
 
343
          end if;
344
 
345
          -- 26.03.2006
346
          if next_addr_valid_r = '1' then
347
            prev_addr_r       <= next_addr_r;
348
            next_addr_valid_r <= '0';
349
            next_addr_r       <= (others => '0'); -- was 'Z' 01.06.2007 AK
350
          end if;
351
 
352
 
353
        when read_in =>
354
          prev_addr_r <= prev_addr_r;
355
 
356
          -- and ip_stall = '0' added 11.9.2006 HP
357
          if ip_we_in = '1' and fifo_full_in = '0' and ip_stall = '0' then
358
            timeout_counter_rd_r <= 0;
359
 
360
            if (ip_av_in = '1') then
361
              -- New address
362
              amount_to_wr_r <= amount_rd_r;
363
              req_writing_r <= '1';
364
              rd_state_r  <= wait_ack;
365
 
366
              -- addr is lost unless stored in reg
367
              next_addr_r       <= ip_data_in;
368
              next_addr_valid_r <= '1';
369
 
370
 
371
            else
372
 
373
              data_in_fifo_r <= '1';
374
 
375
              if (amount_rd_r = payload_words_c) or
376
                (len_valid_r = '1' and amount_rd_r = len_r) or
377
                (req_writing_r = '1' and amount_rd_r = amount_to_wr_r)
378
              then
379
                -- Pkt full
380
                -- if we are already requesting writing, don't change the amount
381
                if req_writing_r = '0' then
382
                  amount_to_wr_r <= amount_rd_r;
383
                end if;
384
 
385
                req_writing_r <= '1';
386
                rd_state_r  <= wait_ack;
387
              else
388
                amount_rd_r <= amount_rd_r + 1;
389
                rd_state_r  <= read_in;
390
              end if;
391
            end if;  -- ip_av_in
392
 
393
          else
394
 
395
            if data_in_fifo_r = '1' then
396
 
397
              -- new if added 17.03.2006
398
              if (amount_rd_r = payload_words_c) or
399
                (len_valid_r = '1' and amount_rd_r = len_r) or
400
                (req_writing_r = '1' and amount_rd_r = amount_to_wr_r)
401
              then
402
 
403
                -- don't change the amount if we're already requesting writing
404
                if req_writing_r = '0' then
405
                  amount_to_wr_r <= amount_rd_r;
406
                end if;
407
 
408
                req_writing_r <= '1';
409
                rd_state_r  <= wait_ack;
410
 
411
              elsif (timeout_counter_rd_r = timeout_g) then
412
                -- oli ennen: IF (timeout_counter_rd_r = timeout_g)            
413
 
414
                timeout_counter_rd_r <= timeout_counter_rd_r;
415
                req_writing_r        <= '1';
416
                rd_state_r           <= wait_ack;
417
 
418
                --assert false report "time_out" severity note;
419
                amount_to_wr_r <= amount_rd_r;
420
 
421
              else
422
                -- timeout_counter_rd_r <= timeout_counter_rd_r + 1;
423
                -- Ei kasvateta ajastinlaskuria, jos verkkoon ei kuitenkaan voi
424
                -- tuupata dataa
425
                if net_full_in = '0' then
426
                  timeout_counter_rd_r <= timeout_counter_rd_r + 1;
427
                else
428
                  timeout_counter_rd_r <= timeout_counter_rd_r;
429
                end if;
430
 
431
                rd_state_r  <= read_in;
432
                amount_rd_r <= amount_rd_r;
433
              end if;
434
 
435
            end if;
436
 
437
          end if;
438
 
439
 
440
        when others =>
441
          -- wait_ack
442
          if (ack_from_wr_r = '1') then
443
            rd_state_r <= wait_trans;
444
            ack_from_wr_r <= '0';
445
            req_writing_r <= '0';
446
 
447
            -- if len value was bigger than max pkt size
448
            if next_len_valid_r = '1' then
449
              len_r <= len_r - payload_words_c;
450
            end if;
451
 
452
          else
453
            rd_state_r <= wait_ack;
454
          end if;
455
 
456
      end case;
457
 
458
 
459
 
460
    end if;
461
  end process read_data;
462
 
463
 
464
  ip_stall_out <= ip_stall;
465
 
466
  -- Ensure that no data is written to (by the IP) when FSM is not counting them
467
  full_tmp : process (rd_state_r, ip_av_in, amount_rd_r,
468
                      timeout_counter_rd_r, data_in_fifo_r,
469
                      len_valid_r, len_r, req_writing_r,
470
                      amount_to_wr_r)
471
  begin  -- process full_tmp
472
 
473
    -- By default:
474
    ip_stall <= '0';
475
 
476
    if rd_state_r = wait_ack then
477
      ip_stall <= '1';
478
 
479
    elsif rd_state_r = read_in then
480
      if (amount_rd_r = payload_words_c) or
481
        (timeout_counter_rd_r = timeout_g and data_in_fifo_r = '1' ) or
482
        (ip_av_in = '1') or
483
        (len_valid_r = '1' and amount_rd_r = len_r) or
484
        (req_writing_r = '1' and amount_rd_r = amount_to_wr_r)
485
      then
486
        ip_stall <= '1';
487
      end if;
488
    end if;
489
  end process full_tmp;
490
 
491
 
492
  -- Read-FSM sends request to write-FSM
493
  req_rd_wr <= req_writing_r;
494
 
495
 
496
  -- purpose: Clocked process for changing the state
497
  -- type   : sequential
498
  -- inputs : clk, rst_n
499
  -- outputs: wr_state_r, timeout_counter_r, write_counter_r, amount_r
500
 
501
  sync : process (clk, rst_n)
502
 
503
  begin  -- PROCESS sync
504
 
505
    if rst_n = '0' then
506
      wr_state_r        <= start;
507
      timeout_counter_r <= 0;
508
      write_counter_r   <= 0;
509
      amount_r          <= 1;
510
      in_addr_r         <= (others => '0');
511
      ack_tmp_r         <= '0';
512
    elsif clk = '1' and clk'event then
513
 
514
      ack_tmp_r <= '0';
515
 
516
 
517
      case wr_state_r is
518
 
519
        when start =>
520
 
521
          timeout_counter_r <= 0;
522
          write_counter_r   <= 0;
523
          amount_r          <= 1;
524
 
525
          wr_state_r <= wait_req;
526
 
527
        when wait_req =>
528
          if req_rd_wr = '1' and ack_tmp_r = '0' then
529
 
530
            -- amount_r <= amount_rd_r+1;  -- orig
531
            amount_r <= amount_to_wr_r + oaddr_flit_en_g;     -- 2007/08/03
532
 
533
            if (net_empty_in = '0' and wait_empty_fifo_g = 1) then
534
              wr_state_r <= wait_empty;
535
            else
536
              wr_state_r <= write_out_addr;
537
            end if;
538
 
539
          else
540
            amount_r   <= 1;
541
            wr_state_r <= wait_req;
542
          end if;
543
 
544
 
545
        when wait_empty =>
546
          -- Wait until network's fifo is empty
547
          -- This state is reached only if associated genric is set
548
          if net_empty_in = '1' then
549
            wr_state_r <= write_out_addr;
550
          else
551
            wr_state_r <= wait_empty;
552
          end if;
553
 
554
 
555
        when write_out_addr =>
556
          -- Write the target address to network
557
          timeout_counter_r <= 0;
558
          write_counter_r   <= 0;
559
          amount_r          <= amount_r;
560
 
561
          if (net_full_in = '0') then
562
 
563
            -- Branching 2007/08/06
564
            if len_flit_en_g = 1 then
565
              wr_state_r <= write_out_amount;
566
            else
567
              if oaddr_flit_en_g = 1 then
568
                wr_state_r <= write_out_in_addr;
569
              else
570
                wr_state_r <= write_out_data;
571
              end if;
572
            end if;
573
 
574
            --wr_state_r <= write_out_amount;  --old way
575
          else
576
            wr_state_r <= write_out_addr;
577
          end if;
578
 
579
          if fifo_av_in = '1' then
580
            in_addr_r <= fifo_data_in;
581
          else
582
            in_addr_r <= prev_addr_r;
583
          end if;
584
 
585
        when write_out_amount =>
586
          timeout_counter_r <= 0;
587
          write_counter_r   <= 0;
588
          amount_r          <= amount_r;
589
          if (net_full_in = '0') then
590
            -- wr_state_r <= write_out_in_addr;
591
 
592
            -- Branch 2007/08/03
593
            if oaddr_flit_en_g = 1 then
594
              wr_state_r <= write_out_in_addr;
595
            else
596
              wr_state_r <= write_out_data;
597
            end if;
598
 
599
          else
600
            wr_state_r <= write_out_amount;
601
          end if;
602
 
603
 
604
        when write_out_in_addr =>
605
          timeout_counter_r <= 0;
606
          write_counter_r   <= 0;
607
          amount_r          <= amount_r;
608
          if (net_full_in = '0') then
609
            wr_state_r <= write_out_data;
610
          else
611
            wr_state_r <= write_out_in_addr;
612
          end if;
613
 
614
--          ack_tmp_r <= '1';             -- orig, this works
615
 
616
 
617
 
618
        when write_out_data =>          -- write_out_data
619
          timeout_counter_r <= 0;
620
 
621
          ack_tmp_r <= '1';             -- 2007/08/03
622
 
623
          -- added fifo_empty_in, because if we get the packet length
624
          -- in advance, we cannot be sure that all the data has come
625
          -- when we start writing. JN 2009-04-09
626
          if (net_full_in = '0' and (fifo_empty_in = '0' or
627
                                     (write_counter_r > amount_r-1-oaddr_flit_en_g and
628
                                     fill_packet_g = 1)))
629
          then
630
 
631
            if (write_counter_r = packet_length_g) then
632
              write_counter_r <= write_counter_r;
633
            else
634
              write_counter_r <= write_counter_r + 1;
635
            end if;
636
 
637
          else
638
            write_counter_r <= write_counter_r;
639
          end if;
640
          amount_r <= amount_r;
641
 
642
          -- Entäs jos full_in = 1??? => ei tartte välittää, koska
643
          -- write_counter muuttuu vain jos full_in = 0
644
          --                      amount_r-1-in_addr
645
          if net_full_in = '0'
646
            and
647
            ((write_counter_r = (amount_r-1 -oaddr_flit_en_g) and fill_packet_g = 0)
648
             or
649
             (write_counter_r = (payload_words_c-1) and fill_packet_g = 1))
650
          then
651
            wr_state_r <= wait_req;
652
          else
653
            wr_state_r <= write_out_data;
654
          end if;
655
 
656
 
657
      end case;
658
 
659
    end if;
660
 
661
  end process sync;
662
 
663
  -- purpose: Asynchronous process for generating outputs
664
  -- type   : combinational
665
  -- inputs : ip_av_in, ip_we_in, ip_data_in,
666
  -- fifo_data_in, fifo_av_in, wr_state_r, addr_from_lut, in_addr_r, fifo_empty_in
667
  -- outputs: ip_full_tmp, fifo_re_out,
668
  -- net_data_out, net_we_out
669
 
670
  async : process (fifo_data_in, fifo_av_in, fifo_empty_in,
671
                   net_full_in,
672
                   write_counter_r, amount_r,
673
                   prev_addr_r,
674
                   ack_tmp_r,
675
                   wr_state_r,          --, req_rd_wr
676
                   addr_from_lut,
677
                   in_addr_r
678
                   )
679
 
680
  begin  -- PROCESS async
681
 
682
    addr_to_lut <= (others => '0');
683
 
684
    case wr_state_r is
685
 
686
      when start =>
687
 
688
        fifo_re_out  <= '0';
689
        net_data_out <= (others => '0');  --'Z');
690
        net_av_out   <= '0';
691
        net_we_out   <= '0';
692
 
693
        ack_wr_rd <= '1';
694
 
695
 
696
      when wait_req =>
697
        net_we_out   <= '0';
698
        fifo_re_out  <= '0';
699
        net_data_out <= (others => '0');  --'Z');
700
        net_av_out   <= '0';
701
        net_we_out   <= '0';
702
        ack_wr_rd    <= '0';
703
 
704
      when wait_empty =>
705
        net_we_out   <= '0';
706
        fifo_re_out  <= '0';
707
        net_data_out <= (others => '0');  --'Z');
708
        net_av_out   <= '0';
709
        net_we_out   <= '0';
710
        ack_wr_rd    <= '0';
711
 
712
 
713
 
714
 
715
      when write_out_addr =>
716
 
717
        ack_wr_rd <= '0';
718
 
719
        -- Jos kuitataan jo tässä ja net_full_in=1
720
        -- read_fsm saattaa lukea uuden osoitteen
721
        -- ja uutta osoitetta käytetään jo tälle vanhalle lähetykselle
722
 
723
        net_av_out <= '1';
724
 
725
        if (net_full_in = '0') then
726
          net_we_out <= '1';
727
        else
728
          net_we_out <= '0';
729
        end if;
730
 
731
 
732
        if (fifo_av_in = '1') then
733
          fifo_re_out <= '1';
734
          addr_to_lut <= fifo_data_in(addr_width_g-1 downto 0);
735
        else
736
          fifo_re_out <= '0';
737
          addr_to_lut <= prev_addr_r(addr_width_g-1 downto 0);
738
        end if;
739
 
740
        --net_data_out <= addr_from_lut;
741
 
742
        if len_flit_en_g = 1 then
743
          -- just address
744
          net_data_out                                                     <= addr_from_lut;
745
        else
746
          -- Concatenate len+addr together
747
          if fill_packet_g = 0 then
748
            net_data_out (data_width_g -1 downto data_width_g - len_width_c) <= conv_std_logic_vector(amount_r, len_width_c);
749
          else
750
            net_data_out (data_width_g -1 downto data_width_g - len_width_c) <= conv_std_logic_vector(payload_words_c, len_width_c);
751
          end if;
752
 
753
          net_data_out (data_width_g -len_width_c-1 downto 0)              <= addr_from_lut(data_width_g -len_width_c-1 downto 0);
754
        end if;
755
 
756
      when write_out_amount =>
757
        ack_wr_rd <= '0';
758
 
759
        fifo_re_out  <= '0';
760
        if fill_packet_g = 0 then
761
          net_data_out <= conv_std_logic_vector(amount_r, data_width_g);
762
        else
763
          net_data_out <= conv_std_logic_vector(payload_words_c, data_width_g);
764
        end if;
765
 
766
        net_av_out   <= '0';
767
 
768
        if (net_full_in = '0') then
769
          net_we_out <= '1';
770
        else
771
          net_we_out <= '0';
772
        end if;
773
 
774
 
775
      when write_out_in_addr =>
776
 
777
        fifo_re_out  <= '0';
778
        net_data_out <= in_addr_r;
779
        net_av_out   <= '0';
780
 
781
        if (net_full_in = '0') then
782
          net_we_out <= '1';
783
        else
784
          net_we_out <= '0';
785
        end if;
786
 
787
        ack_wr_rd <= '0';
788
 
789
 
790
 
791
      when write_out_data =>            -- write_out_data
792
        net_av_out <= '0';
793
 
794
 
795
        -- Ensure that ack is 1 only for one cycle
796
        -- 2007/08/03
797
        if ack_tmp_r = '0' then
798
          ack_wr_rd <= '1';
799
        else
800
          ack_wr_rd <= '0';
801
        end if;
802
 
803
 
804
        -- added fifo_empty_in to prevent writing from a possibly empty fifo
805
        -- JN 2009-04-09
806
        if (net_full_in = '0' and (fifo_empty_in = '0' or
807
                                   (write_counter_r > amount_r-1-oaddr_flit_en_g
808
                                   and fill_packet_g = 1)))
809
        then
810
          net_we_out <= '1';
811
        else
812
          net_we_out <= '0';
813
        end if;
814
 
815
 
816
        if ((write_counter_r < amount_r- oaddr_flit_en_g) and (net_full_in = '0'))
817
        then
818
          if fifo_empty_in = '0' then
819
            net_data_out <= fifo_data_in;
820
            fifo_re_out  <= '1';
821
          else
822
            net_data_out <= fifo_data_in;
823
            fifo_re_out <= '0';
824
          end if;
825
        else
826
          fifo_re_out  <= '0';
827
          net_data_out <= (others => '0');  -- dummy data
828
          -- net_data_out assignment used to be 'L'
829
 
830
        end if;
831
 
832
 
833
 
834
 
835
    end case;
836
 
837
 
838
  end process async;
839
 
840
 
841
 
842
end rtl;

powered by: WebSVN 2.1.0

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