1 |
2 |
daniel.kho |
/*
|
2 |
|
|
This file is part of the Memories project:
|
3 |
|
|
http://opencores.org/project,wb_fifo
|
4 |
|
|
|
5 |
|
|
Description
|
6 |
|
|
FIFO memory model.
|
7 |
|
|
|
8 |
|
|
To Do:
|
9 |
|
|
|
10 |
|
|
Author(s):
|
11 |
|
|
- Daniel C.K. Kho, daniel.kho@opencores.org | daniel.kho@tauhop.com
|
12 |
|
|
|
13 |
|
|
Copyright (C) 2012-2013 Authors and OPENCORES.ORG.
|
14 |
|
|
|
15 |
|
|
This source file may be used and distributed without
|
16 |
|
|
restriction provided that this copyright statement is not
|
17 |
|
|
removed from the file and that any derivative work contains
|
18 |
|
|
the original copyright notice and the associated disclaimer.
|
19 |
|
|
|
20 |
|
|
This source file is free software; you can redistribute it
|
21 |
|
|
and/or modify it under the terms of the GNU Lesser General
|
22 |
|
|
Public License as published by the Free Software Foundation;
|
23 |
|
|
either version 2.1 of the License, or (at your option) any
|
24 |
|
|
later version.
|
25 |
|
|
|
26 |
|
|
This source is distributed in the hope that it will be
|
27 |
|
|
useful, but WITHOUT ANY WARRANTY; without even the implied
|
28 |
|
|
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
29 |
|
|
PURPOSE. See the GNU Lesser General Public License for more
|
30 |
|
|
details.
|
31 |
|
|
|
32 |
|
|
You should have received a copy of the GNU Lesser General
|
33 |
|
|
Public License along with this source; if not, download it
|
34 |
|
|
from http://www.opencores.org/lgpl.shtml.
|
35 |
|
|
*/
|
36 |
|
|
library ieee; use ieee.std_logic_1164.all, ieee.numeric_std.all;
|
37 |
|
|
library tauhop;
|
38 |
|
|
--package fifoTypes is new tauhop.types generic map(t_data=>unsigned(31 downto 0));
|
39 |
|
|
use tauhop.fifoTransactor.all;
|
40 |
|
|
|
41 |
|
|
--library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all;
|
42 |
|
|
--library tauhop; use tauhop.fifoTypes.all;
|
43 |
|
|
entity fifo is
|
44 |
|
|
generic(memoryDepth:positive);
|
45 |
|
|
port(clk,reset:in std_ulogic;
|
46 |
|
|
fifoInterface:inout t_fifoTransactor
|
47 |
|
|
);
|
48 |
|
|
end entity fifo;
|
49 |
|
|
|
50 |
|
|
architecture rtl of fifo is
|
51 |
|
|
type t_memory is array(memoryDepth-1 downto 0) of i_transactor.t_msg;
|
52 |
|
|
signal memory:t_memory;
|
53 |
|
|
signal ptr:natural range 0 to memoryDepth-1;
|
54 |
|
|
|
55 |
|
|
signal i_writeRequest,i_readRequest:i_transactor.t_bfm;
|
56 |
|
|
signal write,read:boolean;
|
57 |
|
|
begin
|
58 |
|
|
controller: process(reset,clk) is begin
|
59 |
|
|
if reset then fifoInterface.readResponse.message<=(others=>'Z');
|
60 |
|
|
elsif falling_edge(clk) then
|
61 |
|
|
if fifoInterface.writeRequest.trigger xor i_writeRequest.trigger then
|
62 |
|
|
memory(ptr)<=fifoInterface.writeRequest.message;
|
63 |
|
|
end if;
|
64 |
|
|
|
65 |
|
|
if fifoInterface.readRequest.trigger xor i_readRequest.trigger then
|
66 |
|
|
fifoInterface.readResponse.message<=memory(ptr);
|
67 |
|
|
end if;
|
68 |
|
|
|
69 |
|
|
end if;
|
70 |
|
|
end process controller;
|
71 |
|
|
|
72 |
|
|
write<=fifoInterface.writeRequest.trigger xor i_writeRequest.trigger;
|
73 |
|
|
read<=fifoInterface.readRequest.trigger xor i_readRequest.trigger;
|
74 |
|
|
|
75 |
|
|
addrPointer: process(reset,clk) is begin
|
76 |
|
|
if reset then ptr<=0;
|
77 |
|
|
elsif falling_edge(clk) then
|
78 |
|
|
/* Increment or decrement the address pointer only when write or read is HIGH;
|
79 |
|
|
do nothing when both are HIGH or when both are LOW.
|
80 |
|
|
*/
|
81 |
|
|
if write xor read then
|
82 |
|
|
if write then
|
83 |
|
|
if ptr<memoryDepth-1 then ptr<=ptr+1; end if;
|
84 |
|
|
end if;
|
85 |
|
|
if read then
|
86 |
|
|
if ptr>0 then ptr<=ptr-1; end if;
|
87 |
|
|
end if;
|
88 |
|
|
end if;
|
89 |
|
|
end if;
|
90 |
|
|
end process addrPointer;
|
91 |
|
|
|
92 |
|
|
/* Registers and pipelines. */
|
93 |
|
|
process(clk) is begin
|
94 |
|
|
i_writeRequest<=fifoInterface.writeRequest;
|
95 |
|
|
i_readRequest<=fifoInterface.readRequest;
|
96 |
|
|
end process;
|
97 |
|
|
|
98 |
|
|
fifoInterface.pctFilled<=to_unsigned(ptr*100/(memoryDepth-1), fifoInterface.pctFilled'length);
|
99 |
|
|
|
100 |
|
|
process(clk) is begin
|
101 |
|
|
if rising_edge(clk) then
|
102 |
|
|
fifoInterface.nearFull<=true when fifoInterface.pctFilled>=d"75" and fifoInterface.pctFilled<d"100" else false;
|
103 |
|
|
fifoInterface.full<=true when fifoInterface.pctFilled=d"100" else false;
|
104 |
|
|
fifoInterface.nearEmpty<=true when fifoInterface.pctFilled<=d"25" and fifoInterface.pctFilled>d"0" else false;
|
105 |
|
|
fifoInterface.empty<=true when fifoInterface.pctFilled=d"0" else false;
|
106 |
|
|
end if;
|
107 |
|
|
end process;
|
108 |
|
|
|
109 |
|
|
process(clk) is begin
|
110 |
|
|
if falling_edge(clk) then
|
111 |
|
|
fifoInterface.overflow<=fifoInterface.full and write;
|
112 |
|
|
fifoInterface.underflow<=fifoInterface.empty and read;
|
113 |
|
|
end if;
|
114 |
|
|
end process;
|
115 |
|
|
end architecture rtl;
|