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/] [hibi/] [3.0/] [vhd/] [addr_data_mux_write.vhd] - Blame information for rev 145

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 145 lanttu
-------------------------------------------------------------------------------
2
-- File        : addr_data_mux_write.vhd
3
-- Description : Converts separated addr+data signalling into multiplexed
4
--               addr/data.
5
--               Input : separate addr + data ports
6
--               Out   : addr + data muxed into one port
7
--               Write_Mux checks the incoming addr+comm. Same addr+comm is not
8
--               written to fifo more than once!
9
--               
10
-- Author      : Erno Salminen
11
-- Date        : 15.01.2003
12
-- Modified    : 
13
-- 15.12.04     ES names changed
14
-------------------------------------------------------------------------------
15
-- Funbase IP library Copyright (C) 2011 TUT Department of Computer Systems
16
--
17
-- This file is part of HIBI
18
--
19
-- This source file may be used and distributed without
20
-- restriction provided that this copyright statement is not
21
-- removed from the file and that any derivative work contains
22
-- the original copyright notice and the associated disclaimer.
23
--
24
-- This source file is free software; you can redistribute it
25
-- and/or modify it under the terms of the GNU Lesser General
26
-- Public License as published by the Free Software Foundation;
27
-- either version 2.1 of the License, or (at your option) any
28
-- later version.
29
--
30
-- This source is distributed in the hope that it will be
31
-- useful, but WITHOUT ANY WARRANTY; without even the implied
32
-- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
33
-- PURPOSE.  See the GNU Lesser General Public License for more
34
-- details.
35
--
36
-- You should have received a copy of the GNU Lesser General
37
-- Public License along with this source; if not, download it
38
-- from http://www.opencores.org/lgpl.shtml
39
-------------------------------------------------------------------------------
40
library ieee;
41
use ieee.std_logic_1164.all;
42
use ieee.std_logic_arith.all;
43
use ieee.std_logic_unsigned.all;
44
 
45
 
46
entity addr_data_mux_write is
47
 
48
  generic (
49
    data_width_g : integer := 0;
50
    addr_width_g : integer := 0;
51
    comm_width_g : integer := 0
52
    );
53
  port (
54
    clk   : in std_logic;
55
    rst_n : in std_logic;
56
 
57
    data_in   : in  std_logic_vector (data_width_g-1 downto 0);
58
    addr_in   : in  std_logic_vector (addr_width_g-1 downto 0);
59
    comm_in   : in  std_logic_vector (comm_width_g-1 downto 0);
60
    we_in     : in  std_logic;
61
    full_out  : out std_logic;
62
    one_p_out : out std_logic;          -- unused ??
63
 
64
    data_out : out std_logic_vector (data_width_g-1 downto 0);
65
    comm_out : out std_logic_vector (comm_width_g-1 downto 0);
66
    av_out   : out std_logic;
67
    we_out   : out std_logic;
68
    one_p_in : in  std_logic;           -- ununsed ??
69
    full_in  : in  std_logic
70
    );
71
 
72
end addr_data_mux_write;
73
 
74
 
75
 
76
architecture rtl of addr_data_mux_write is
77
 
78
  -- rekisterit
79
  signal   state_r    : integer range 0 to 4;
80
  signal   next_state : integer range 0 to 4;
81
  -- State encoding
82
  --  0 idle
83
  --  1 write addr, keep output, write d_r when leaving
84
  --  2 write data
85
  --  3 write data full, keep output, write d_r when leaving
86
  --  4 write data full 2, keep output, write a_r when leaving
87
  constant idle_c     : integer := 0;
88
  constant wr_a_c     : integer := 1;
89
  constant wr_d_c     : integer := 2;
90
  constant wr_d_f1_c  : integer := 3;
91
  constant wr_d_f2_c  : integer := 4;
92
 
93
 
94
  signal addr_r     : std_logic_vector (addr_width_g-1 downto 0);
95
  signal comm_r     : std_logic_vector (comm_width_g-1 downto 0);
96
  signal comm_out_r : std_logic_vector (comm_width_g-1 downto 0);
97
  signal data_r     : std_logic_vector (data_width_g-1 downto 0);
98
  signal data_out_r : std_logic_vector (data_width_g-1 downto 0);
99
  signal full_out_r : std_logic;
100
  signal av_out_r   : std_logic;
101
  signal we_out_r   : std_logic;
102
 
103
 
104
begin  -- rtl
105
 
106
  -- Concurrent assignments
107
  av_out   <= av_out_r;
108
  full_out <= full_out_r;
109
  comm_out <= comm_out_r;
110
  data_out <= data_out_r;
111
  we_out   <= we_out_r;
112
 
113
  -- Unused?? 08.02.05 
114
  one_p_out <= one_p_in;                -- danger ???
115
 
116
 
117
  -- COMB PROC
118
  -- Define next state
119
  Define_next_state : process (addr_in,
120
                                --data_in,comm_in,
121
                                we_in, full_in,
122
                                addr_r, state_r)
123
  begin  -- process Define_next_state
124
    case state_r is
125
 
126
      when idle_c =>
127
        if we_in = '0' then
128
          next_state <= idle_c;
129
        else
130
          if addr_in = addr_r then
131
            next_state <= wr_d_c;
132
          else
133
            next_state <= wr_a_c;
134
          end if;
135
        end if;
136
 
137
      when wr_a_c =>
138
        if full_in = '0' then
139
          next_state <= wr_d_c;
140
        else
141
          next_state <= wr_a_c;
142
        end if;
143
 
144
      when wr_d_c =>
145
        if full_in = '0' then
146
          if we_in = '0' then
147
            next_state <= idle_c;
148
          else
149
            if addr_in = addr_r then
150
              next_state <= wr_d_c;
151
            else
152
              next_state <= wr_a_c;
153
            end if;
154
          end if;
155
        else
156
          if we_in = '0' then
157
            next_state <= wr_d_c;
158
          else
159
            if addr_in = addr_r then
160
              next_state <= wr_d_f1_c;
161
            else
162
              next_state <= wr_d_f2_c;
163
            end if;
164
          end if;
165
        end if;
166
 
167
 
168
      when wr_d_f1_c =>
169
        if full_in = '0' then
170
          next_state <= wr_d_c;
171
        else
172
          next_state <= wr_d_f1_c;
173
        end if;
174
 
175
      when wr_d_f2_c =>
176
        if full_in = '0' then
177
          next_state <= wr_a_c;
178
        else
179
          next_state <= wr_d_f2_c;
180
        end if;
181
 
182
 
183
      when others =>
184
        next_state <= idle_c;
185
        assert false report "Illegal state in addr_data_mux_write" severity warning;
186
 
187
    end case;  -- state_r
188
 
189
  end process Define_next_state;
190
 
191
 
192
  -- SEQ PROC
193
  -- Change state
194
  change_state : process (clk, rst_n)
195
  begin  -- process change_state
196
    if rst_n = '0' then                 -- asynchronous reset (active low)
197
      state_r <= 0;
198
    elsif clk'event and clk = '1' then  -- rising clock edge
199
      state_r <= next_state;
200
    end if;
201
  end process change_state;
202
 
203
 
204
 
205
  -- SEQ PROC
206
  -- Define output
207
  Define_output : process (clk, rst_n)
208
  begin  -- process Define_output
209
    if rst_n = '0' then                 -- asynchronous reset (active low)
210
      full_out_r <= '0';
211
      av_out_r   <= '0';
212
      data_out_r <= (others => '0');    -- 'Z');
213
      comm_out_r <= (others => '0');
214
      we_out_r   <= '0';
215
 
216
      addr_r <= (others => '1');        -- 'Z');
217
      comm_r <= (others => '0');
218
      data_r <= (others => '0');        -- 'Z');
219
 
220
    elsif clk'event and clk = '1' then  -- rising clock edge
221
 
222
      -- Registers keep their values by default
223
      full_out_r <= full_out_r;
224
      av_out_r   <= av_out_r;
225
      data_out_r <= data_out_r;
226
      comm_out_r <= comm_out_r;
227
      we_out_r   <= we_out_r;
228
 
229
      addr_r <= addr_r;
230
      comm_r <= comm_r;
231
      data_r <= DAta_r;
232
 
233
 
234
      -- Always write when not in IDLE state
235
      if next_state = idle_c then
236
        we_out_r <= '0';
237
      else
238
        we_out_r <= '1';
239
      end if;
240
 
241
      -- adrresses are awriten only in state wr_a_c
242
      if next_state = wr_a_c then
243
        av_out_r <= '1';
244
      else
245
        av_out_r <= '0';
246
      end if;
247
 
248
 
249
      -- Define register values
250
      case state_r is
251
        when idle_c =>
252
          if next_state = idle_c then
253
            full_out_r <= '0';
254
            data_out_r <= (others => '0');  -- 'Z');
255
            comm_out_r <= (others => '0');
256
          elsif next_state = wr_d_c then
257
            full_out_r <= '0';
258
            data_out_r <= data_in;
259
            comm_out_r <= comm_in;
260
          else
261
            --next_state <= wr_a_c;
262
            full_out_r <= '1';
263
            data_out_r <= (others => '0');
264
            data_out_r(addr_width_g-1 downto 0) <= addr_in;
265
            comm_out_r <= comm_in;
266
            addr_r     <= addr_in;
267
            data_r     <= data_in;
268
            comm_r     <= comm_in;
269
          end if;
270
 
271
        when wr_a_c =>
272
          if next_state = wr_d_c then
273
            full_out_r <= '0';
274
            data_out_r <= data_r;
275
            comm_out_r <= comm_r;
276
            data_r     <= (others => '0');  -- 'Z');
277
          else
278
            -- next_state <= wr_a_c;
279
            full_out_r <= '1';
280
            data_out_r <= data_out_r;
281
            comm_out_r <= comm_out_r;
282
          end if;
283
 
284
        when wr_d_c =>
285
          if next_state = wr_d_c then
286
            if we_in = '0' then
287
              full_out_r <= '0';
288
              data_out_r <= data_out_r;
289
              comm_out_r <= comm_out_r;
290
            else
291
              full_out_r <= '0';
292
              data_out_r <= data_in;
293
              comm_out_r <= comm_in;
294
            end if;
295
            data_r <= (others => '0');      -- 'Z');
296
          elsif next_state = wr_a_c then
297
            full_out_r <= '1';
298
            data_out_r <= (others => '0');
299
            data_out_r(addr_width_g-1 downto 0) <= addr_in;
300
            comm_out_r <= comm_in;
301
            addr_r     <= addr_in;
302
            data_r     <= data_in;
303
            comm_r     <= comm_in;
304
          elsif next_state = wr_d_f1_c then
305
            full_out_r <= '1';
306
            data_out_r <= data_out_r;
307
            comm_out_r <= comm_out_r;
308
            data_r     <= data_in;
309
            comm_r     <= comm_in;      -- ase
310
          elsif next_state = wr_d_f2_c then
311
            full_out_r <= '1';
312
            data_out_r <= data_out_r;
313
            comm_out_r <= comm_out_r;
314
            addr_r     <= addr_in;
315
            data_r     <= data_in;
316
            comm_r     <= comm_in;
317
          else
318
            -- next_state = idle_c
319
            full_out_r <= '0';
320
            data_out_r <= (others => '0');  -- 'Z');
321
            comm_out_r <= (others => '0');
322
            data_r     <= (others => '0');  -- 'Z');
323
 
324
          end if;
325
 
326
 
327
        when wr_d_f1_c =>
328
          if next_state = wr_d_c then
329
            full_out_r <= '0';
330
            data_out_r <= data_r;
331
            comm_out_r <= comm_r;
332
            data_r     <= (others => '0');  -- 'Z');
333
          else
334
            -- next_state <= wr_d_f1_c;
335
            full_out_r <= '1';
336
            data_out_r <= data_out_r;
337
            comm_out_r <= comm_out_r;
338
          end if;
339
 
340
        when wr_d_f2_c =>
341
          if next_state = wr_a_c then
342
            full_out_r <= '1';
343
            data_out_r <= (others => '0');
344
            data_out_r(addr_width_g-1 downto 0) <= addr_r;
345
            comm_out_r <= comm_r;
346
          else
347
            --next_state <= wr_d_f2_c;
348
            full_out_r <= '1';
349
            data_out_r <= data_out_r;
350
            comm_out_r <= comm_out_r;
351
          end if;
352
      end case;
353
    end if;  -- rst_n/clk
354
  end process Define_output;
355
 
356
 
357
end rtl;

powered by: WebSVN 2.1.0

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