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

Subversion Repositories mod_sim_exp

[/] [mod_sim_exp/] [tags/] [Release_1.4/] [rtl/] [vhdl/] [core/] [fifo_generic.vhd] - Blame information for rev 89

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

Line No. Rev Author Line
1 54 JonasDC
----------------------------------------------------------------------  
2
----  fifo_generic                                                ---- 
3
----                                                              ---- 
4
----  This file is part of the                                    ----
5
----    Modular Simultaneous Exponentiation Core project          ---- 
6
----    http://www.opencores.org/cores/mod_sim_exp/               ---- 
7
----                                                              ---- 
8
----  Description                                                 ---- 
9 55 JonasDC
----    behavorial description of a FIFO, correctly inferred by   ----
10
----    altera and xilinx.                                        ----
11
----                                                              ----
12
----  Resources needed (xilinx):                                  ----
13
----    - RAM: (depth+1 * 32) bits                                ----
14
----    - 2 adders/substractors                                   ----
15
----    - 2 comparators                                           ----
16
----    - 2 registers: aw bits  (for the address pointers)        ----
17
----    - 3 registers:  1 bit (for the flags)                     ----
18
----                                                              ----
19 54 JonasDC
----  Authors:                                                    ----
20
----      - Geoffrey Ottoy, DraMCo research group                 ----
21
----      - Jonas De Craene, JonasDC@opencores.org                ---- 
22
----                                                              ---- 
23
---------------------------------------------------------------------- 
24
----                                                              ---- 
25
---- Copyright (C) 2011 DraMCo research group and OPENCORES.ORG   ---- 
26
----                                                              ---- 
27
---- This source file may be used and distributed without         ---- 
28
---- restriction provided that this copyright statement is not    ---- 
29
---- removed from the file and that any derivative work contains  ---- 
30
---- the original copyright notice and the associated disclaimer. ---- 
31
----                                                              ---- 
32
---- This source file is free software; you can redistribute it   ---- 
33
---- and/or modify it under the terms of the GNU Lesser General   ---- 
34
---- Public License as published by the Free Software Foundation; ---- 
35
---- either version 2.1 of the License, or (at your option) any   ---- 
36
---- later version.                                               ---- 
37
----                                                              ---- 
38
---- This source is distributed in the hope that it will be       ---- 
39
---- useful, but WITHOUT ANY WARRANTY; without even the implied   ---- 
40
---- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ---- 
41
---- PURPOSE.  See the GNU Lesser General Public License for more ---- 
42
---- details.                                                     ---- 
43
----                                                              ---- 
44
---- You should have received a copy of the GNU Lesser General    ---- 
45
---- Public License along with this source; if not, download it   ---- 
46
---- from http://www.opencores.org/lgpl.shtml                     ---- 
47
----                                                              ---- 
48
----------------------------------------------------------------------
49
 
50
library ieee;
51
use ieee.std_logic_1164.all;
52
use ieee.std_logic_unsigned.all;
53
use ieee.std_logic_arith.all;
54
 
55 69 JonasDC
library mod_sim_exp;
56
use mod_sim_exp.mod_sim_exp_pkg.all;
57 60 JonasDC
use mod_sim_exp.std_functions.all;
58 54 JonasDC
 
59
entity fifo_generic is
60
  generic (
61
    depth : integer := 32
62
  );
63 60 JonasDC
  port  (
64
    clk    : in  std_logic; -- clock input
65 54 JonasDC
    din    : in  std_logic_vector (31 downto 0); -- 32 bit input data for push
66
    dout   : out  std_logic_vector (31 downto 0); -- 32 bit output data for pop
67
    empty  : out  std_logic; -- empty flag, 1 when FIFO is empty
68
    full   : out  std_logic; -- full flag, 1 when FIFO is full
69
    push   : in  std_logic;
70
    pop    : in  std_logic;
71
    reset  : in std_logic;
72
    nopop  : out std_logic;
73
    nopush : out std_logic
74 60 JonasDC
  );
75 54 JonasDC
end fifo_generic;
76
 
77
architecture arch of fifo_generic is
78 60 JonasDC
  -- calculate the width for the address-pointers
79
  constant aw : integer := log2(depth+1);
80
 
81 54 JonasDC
  -- read and write pointer
82
  signal rd_addr : std_logic_vector(aw-1 downto 0);
83
  signal wr_addr : std_logic_vector(aw-1 downto 0);
84
 
85
  -- control signals
86
  signal empty_i  : std_logic;
87
  signal full_i   : std_logic;
88
  signal push_i   : std_logic;
89
  signal push_i_d : std_logic;
90
  signal pop_i    : std_logic;
91
begin
92
 
93
  empty <= empty_i;
94
  full <= full_i;
95
  -- full flag is 1 when read address is one below write address
96
  full_i <= '1' when (wr_addr+'1'=rd_addr) or
97
                      (wr_addr=conv_std_logic_vector(depth, aw) and (rd_addr=conv_std_logic_vector(0, aw)))
98
                else '0';
99
  -- empty flag is 1 when read and write address are the same
100
  empty_i <= '1' when (wr_addr=rd_addr) else '0';
101
 
102
  fifo_addr_proc : process (clk)
103
  begin
104
    if rising_edge(clk) then
105
      if reset='1' then -- if reset, both read and write address point to the maximum address (depth)
106
        wr_addr <= conv_std_logic_vector(depth, aw);
107
        rd_addr <= conv_std_logic_vector(depth, aw);
108
      else
109
        if push_i='1' then -- push
110
          if (wr_addr=conv_std_logic_vector(depth, aw)) then
111
            wr_addr <= (others=>'0'); -- if overflow, set to zero
112
          else
113
            wr_addr <= wr_addr+'1'; -- else, increase address
114
          end if;
115
        end if;
116
 
117
        if pop_i='1' then -- pop
118
          if (rd_addr=conv_std_logic_vector(depth, aw)) then
119
            rd_addr <= (others=>'0'); -- if overflow, set to zero
120
          else
121
            rd_addr <= rd_addr+'1'; -- else, increase address
122
          end if;
123
        end if;
124
      end if;
125
      push_i_d <= push_i; -- delayed version of push signal
126
 
127
      nopop <= (pop and empty_i) or (pop and reset);
128
      nopush <= (push and full_i) or (push and reset);
129
    end if;
130
  end process;
131
 
132
  push_i <= push and not full_i;
133
  pop_i <= pop and not empty_i;
134
 
135
  -- Block RAM
136 69 JonasDC
  ramblock: dpram_generic
137 60 JonasDC
    generic map(
138
      depth => depth+1
139
    )
140
    port map(
141
      -- write port
142 89 JonasDC
      clkA   => clk,
143
      waddrA => wr_addr,
144
      weA    => push_i_d,
145
      dinA   => din,
146 60 JonasDC
      -- read port
147 89 JonasDC
      clkB  => clk,
148
      raddrB => rd_addr,
149
      doutB  => dout
150 60 JonasDC
    );
151 54 JonasDC
 
152
end arch;

powered by: WebSVN 2.1.0

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