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

Subversion Repositories plb2wbbridge

[/] [plb2wbbridge/] [trunk/] [systems/] [EDK_Libs/] [WishboneIPLib/] [pcores/] [plb2wb_bridge_v1_00_a/] [hdl/] [vhdl/] [plb2wb_fifo.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 feddischso
----------------------------------------------------------------------
2
----                                                              ----
3
----  PLB2WB-Bridge                                               ----
4
----                                                              ----
5
----  This file is part of the PLB-to-WB-Bridge project           ----
6
----  http://opencores.org/project,plb2wbbridge                   ----
7
----                                                              ----
8
----  Description                                                 ----
9
----  Implementation of a PLB-to-WB-Bridge according to           ----
10
----  PLB-to-WB Bridge specification document.                    ----
11
----                                                              ----
12
----  To Do:                                                      ----
13
----   Nothing                                                    ----
14
----                                                              ----
15
----  Author(s):                                                  ----
16
----      - Christian Haettich                                    ----
17
----        feddischson@opencores.org                             ----
18
----                                                              ----
19
----------------------------------------------------------------------
20
----                                                              ----
21
---- Copyright (C) 2010 Authors                                   ----
22
----                                                              ----
23
---- This source file may be used and distributed without         ----
24
---- restriction provided that this copyright statement is not    ----
25
---- removed from the file and that any derivative work contains  ----
26
---- the original copyright notice and the associated disclaimer. ----
27
----                                                              ----
28
---- This source file is free software; you can redistribute it   ----
29
---- and/or modify it under the terms of the GNU Lesser General   ----
30
---- Public License as published by the Free Software Foundation; ----
31
---- either version 2.1 of the License, or (at your option) any   ----
32
---- later version.                                               ----
33
----                                                              ----
34
---- This source is distributed in the hope that it will be       ----
35
---- useful, but WITHOUT ANY WARRANTY; without even the implied   ----
36
---- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ----
37
---- PURPOSE.  See the GNU Lesser General Public License for more ----
38
---- details.                                                     ----
39
----                                                              ----
40
---- You should have received a copy of the GNU Lesser General    ----
41
---- Public License along with this source; if not, download it   ----
42
---- from http://www.opencores.org/lgpl.shtml                     ----
43
----                                                              ----
44
----------------------------------------------------------------------
45
 
46
 
47
library ieee;
48
use ieee.std_logic_1164.all;
49
use ieee.std_logic_unsigned.all;
50
use ieee.numeric_std.ALL;
51
 
52
 
53
 
54
entity plb2wb_fifo is
55
   generic(
56
      DATA_W : natural := 32;
57
      ADDR_W : natural := 4
58
   );
59
   port(
60
      clk            : IN     std_logic;
61
      rst            : IN     std_logic;
62
      rd_en          : IN     std_logic;
63
      wr_en          : IN     std_logic;
64
      din            : IN     std_logic_vector( DATA_W-1 downto 0 );
65
      dout           : OUT    std_logic_vector( DATA_W-1 downto 0 );
66
      empty          : OUT    std_logic;
67
      full           : OUT    std_logic
68
   );
69
end entity plb2wb_fifo;
70
 
71
 
72
architecture IMP of plb2wb_fifo is
73
 
74
 
75
   type fifo_array_type is array( 2**ADDR_W-1 downto 0 )
76
      of std_logic_vector( DATA_W-1 downto 0 );
77
 
78
   type state_type is record
79
      read_pointer   : std_logic_vector( ADDR_W-1 downto 0 );
80
      write_pointer  : std_logic_vector( ADDR_W-1 downto 0 );
81
      full           : std_logic;
82
      empty          : std_logic;
83
   end record;
84
 
85
   signal current_state, next_state : state_type         := -- to avoid modelsim warning at time: 0ps, iteration 0
86
   ( read_pointer => ( others => '0' ), write_pointer => ( others => '0' ), full => '0', empty => '0' );
87
   signal fifo_array                : fifo_array_type;
88
   signal read_write_select         : std_logic_vector( 1 downto 0 );
89
   signal rp_plus_1                 : std_logic_vector( ADDR_W-1 downto 0 );
90
   signal wp_plus_1                 : std_logic_vector( ADDR_W-1 downto 0 );
91
 
92
begin
93
 
94
   n_state : process( clk, rst ) begin
95
 
96
      if rst = '1' then
97
         current_state.read_pointer    <= ( others => '0' );
98
         current_state.write_pointer   <= ( others => '0' );
99
         current_state.full            <= '0';
100
         current_state.empty           <= '1';
101
      elsif clk'event and clk='1' then
102
         current_state <= next_state;
103
      end if;
104
 
105
   end process;
106
 
107
 
108
   wp_plus_1         <= std_logic_vector( unsigned (current_state.write_pointer) +1 );
109
   rp_plus_1         <= std_logic_vector( unsigned (current_state.read_pointer)  +1 );
110
   read_write_select <= wr_en & rd_en  ;
111
 
112
   states : process( current_state, read_write_select, wp_plus_1, rp_plus_1 ) begin
113
 
114
      next_state <= current_state;
115
 
116
      case read_write_select is
117
         when "00" =>   -- nothing to do
118
         when "01" =>   -- read
119
 
120
            if current_state.empty /= '1' then
121
               next_state.read_pointer  <= rp_plus_1;
122
               next_state.full          <= '0';
123
               if rp_plus_1 = current_state.write_pointer then
124
                  next_state.empty <= '1';
125
               end if;
126
            end if;
127
 
128
         when "10" =>   -- write
129
 
130
            if current_state.full /= '1' then
131
               next_state.write_pointer <= wp_plus_1;
132
               next_state.empty         <= '0';
133
               if wp_plus_1 = current_state.read_pointer then
134
                  next_state.full <= '1';
135
               end if;
136
            end if;
137
 
138
         when others =>  -- read and write
139
            next_state.write_pointer <= wp_plus_1;
140
            next_state.read_pointer  <= rp_plus_1;
141
         end case;
142
 
143
 
144
   end process;
145
 
146
 
147
   write_fifo : process( clk, rst ) begin
148
      if rst = '1' then
149
         fifo_array  <= ( others => ( others => '0' ) );
150
      elsif clk'event and clk='1' then
151
         if wr_en = '1' and current_state.full = '0' then
152
            fifo_array( to_integer( unsigned( current_state.write_pointer ))) <= din;
153
         end if;
154
      end if;
155
 
156
   end process;
157
 
158
   dout     <= fifo_array( to_integer( unsigned( current_state.read_pointer ) ) );
159
   full     <= current_state.full;
160
   empty    <= current_state.empty;
161
 
162
 
163
end architecture IMP;
164
 
165
 
166
 

powered by: WebSVN 2.1.0

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