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/] [pkt_codec_mk2/] [1.0/] [vhd/] [addr_gen.vhd] - Blame information for rev 145

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

Line No. Rev Author Line
1 145 lanttu
-------------------------------------------------------------------------------
2
-- Title      : Address generator for pkt_codec
3
-- Project    : 
4
-------------------------------------------------------------------------------
5
-- File       : addr_gen.vhd
6
-- Author     : Lasse Lehtonen
7
-- Company    : 
8
-- Created    : 2011-10-12
9
-- Last update: 2011-10-25
10
-- Platform   : 
11
-- Standard   : VHDL'87
12
-------------------------------------------------------------------------------
13
-- Description:
14
--  Handles address flit repeating when data comes slowly from IP and
15
--  prevents sending only address flits without at least on data flit.
16
--
17
-------------------------------------------------------------------------------
18
-- Copyright (c) 2011 
19
-------------------------------------------------------------------------------
20
-- Revisions  :
21
-- Date        Version  Author  Description
22
-- 2011-10-12  1.0      lehton87        Created
23
-------------------------------------------------------------------------------
24
 
25
library ieee;
26
use ieee.std_logic_1164.all;
27
 
28
 
29
entity addr_gen is
30
 
31
  generic (
32
    cmd_width_g    : positive;
33
    data_width_g   : positive;
34
    addr_flit_en_g : natural);
35
 
36
  port (
37
    clk          : in  std_logic;
38
    rst_n        : in  std_logic;
39
    -- from IP side
40
    ip_cmd_in    : in  std_logic_vector(cmd_width_g-1 downto 0);
41
    ip_data_in   : in  std_logic_vector(data_width_g-1 downto 0);
42
    ip_stall_out : out std_logic;
43
    orig_addr_in : in  std_logic_vector(data_width_g-1 downto 0);
44
    -- to NET
45
    net_cmd_out  : out std_logic_vector(cmd_width_g-1 downto 0);
46
    net_data_out : out std_logic_vector(data_width_g-1 downto 0);
47
    net_stall_in : in  std_logic);
48
 
49
end addr_gen;
50
 
51
architecture rtl of addr_gen is
52
 
53
  signal cmd_r        : std_logic_vector(cmd_width_g-1 downto 0);
54
  signal data_r       : std_logic_vector(data_width_g-1 downto 0);
55
  signal addr_r       : std_logic_vector(data_width_g-1 downto 0);
56
  signal stall_r      : std_logic;
57
  signal first_data_r : std_logic;
58
 
59
  type   state_type is (idle, addr, orig, data);
60
  signal state_r : state_type;
61
 
62
begin  -- rtl
63
 
64
  ip_stall_out <= net_stall_in or stall_r;
65
 
66
  fsm_p : process (clk, rst_n)
67
  begin  -- process fsm_p
68
    if rst_n = '0' then                 -- asynchronous reset (active low)
69
      state_r      <= idle;
70
      cmd_r        <= (others => '0');
71
      data_r       <= (others => '0');
72
      addr_r       <= (others => '0');
73
      stall_r      <= '0';
74
      first_data_r <= '0';
75
      net_cmd_out  <= (others => '0');
76
      net_data_out <= (others => '0');
77
    elsif clk'event and clk = '1' then  -- rising clock edge
78
 
79
      -- default
80
      if net_stall_in = '0' then
81
        stall_r <= '0';
82
      end if;
83
 
84
      case state_r is
85
        -----------------------------------------------------------------------
86
        -- IDLE
87
        -----------------------------------------------------------------------
88
        when idle =>
89
          if net_stall_in = '0' then
90
            if ip_cmd_in = "00" then
91
              net_cmd_out  <= "00";
92
              first_data_r <= '0';
93
            elsif ip_cmd_in = "01" then
94
              net_cmd_out  <= "00";
95
              first_data_r <= '1';
96
              addr_r       <= ip_data_in;
97
              state_r      <= addr;
98
            else
99
              first_data_r <= '1';
100
              data_r       <= ip_data_in;
101
              net_cmd_out  <= "01";
102
              net_data_out <= addr_r;
103
              state_r      <= data;
104
            end if;
105
          end if;
106
 
107
          ---------------------------------------------------------------------
108
          -- ADDR
109
          ---------------------------------------------------------------------
110
        when addr =>
111
          if net_stall_in = '0' then
112
            if ip_cmd_in = "00" then
113
              state_r      <= idle;
114
              net_cmd_out  <= "00";
115
              first_data_r <= '0';
116
            elsif ip_cmd_in = "01" then
117
              addr_r       <= ip_data_in;
118
              state_r      <= addr;
119
              net_cmd_out  <= "00";
120
              first_data_r <= '1';
121
            else
122
              net_cmd_out  <= "01";
123
              net_data_out <= addr_r;
124
              data_r       <= ip_data_in;
125
              state_r      <= data;
126
            end if;
127
          end if;
128
 
129
          ---------------------------------------------------------------------
130
          -- DATA
131
          ---------------------------------------------------------------------
132
        when data =>
133
          if net_stall_in = '0' then
134
            if ip_cmd_in = "00" then
135
              if first_data_r = '1' and addr_flit_en_g = 1 then
136
                stall_r      <= '1';
137
                net_cmd_out  <= "10";
138
                net_data_out <= orig_addr_in;
139
                first_data_r <= '0';
140
              else
141
                net_data_out <= data_r;
142
                net_cmd_out  <= "10";
143
                state_r      <= idle;
144
              end if;
145
            elsif ip_cmd_in = "01" then
146
              if first_data_r = '1' and addr_flit_en_g = 1 then
147
                stall_r      <= '1';
148
                net_cmd_out  <= "10";
149
                net_data_out <= orig_addr_in;
150
                first_data_r <= '0';
151
              else
152
                net_data_out <= data_r;
153
                net_cmd_out  <= "10";
154
                addr_r       <= ip_data_in;
155
                state_r      <= addr;
156
                first_data_r <= '1';    -- ase 25-10-2011
157
              end if;
158
            else
159
              if first_data_r = '1' and addr_flit_en_g = 1 then
160
                stall_r      <= '1';
161
                net_cmd_out  <= "10";
162
                net_data_out <= orig_addr_in;
163
                first_data_r <= '0';
164
              else
165
                net_data_out <= data_r;
166
                net_cmd_out  <= "10";
167
                data_r       <= ip_data_in;
168
              end if;
169
            end if;
170
          end if;
171
 
172
        when others => null;
173
      end case;
174
 
175
 
176
    end if;
177
  end process fsm_p;
178
 
179
end rtl;

powered by: WebSVN 2.1.0

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