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

Subversion Repositories wb_fifo

[/] [wb_fifo/] [trunk/] [model/] [vhdl/] [fifo.vhdl] - Blame information for rev 4

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

Line No. Rev Author Line
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 4 daniel.kho
        /* FIFO control signalling. */
56
        signal fifoCtrl:t_fifo;
57
 
58 3 daniel.kho
        /*
59
                writeRequest and readRequest are inputs. This indicate that a block is requesting to write to or
60
                        read from the FIFO.
61
                        For write requests, the external block requests to write some data into the FIFO. The data
62
                        is attached as part of the write request (writeRequest.message).
63
                        For read requests, the external block requests to read some data from the FIFO. The data will
64
                        later be attached in the read response (readResponse.message).
65
 
66
                There is no such concept as messages attached to a write response (no writeResponse.message) or
67
                        read request (no readRequest.message).
68
 
69
                To generate a write response, the FIFO can assert an acknowledge signal, which could be part of
70
                        the response (writeResponse.trigger). The acknowledge is generated only when the FIFO is not
71
                        full. The requester can check this flag so that it will not continue requesting a write when
72
                        the FIFO is full.
73
                        When generating a read response, the FIFO can assert an acknowledge signal as part of the
74
                        response (readResponse.trigger), while at the same time, sending data back to the external
75
                        requester (readResponse.message). The acknowledge signal is generated only when the FIFO is
76
                        not empty. The requester can check this flag so that it will not continue requesting a read
77
                        when the FIFO is empty.
78
                        Currently, response acknowledge signals (writeResponse.trigger and readResponse.trigger) are
79
                        not yet implemented.
80
        */
81 2 daniel.kho
        signal i_writeRequest,i_readRequest:i_transactor.t_bfm;
82 3 daniel.kho
        signal i_full,i_empty:boolean;
83 2 daniel.kho
        signal write,read:boolean;
84
begin
85
        controller: process(reset,clk) is begin
86 3 daniel.kho
                if reset then
87
                        fifoInterface.readResponse.message<=(others=>'Z');
88
                        fifoInterface.readResponse.trigger<=false;
89 2 daniel.kho
                elsif falling_edge(clk) then
90 3 daniel.kho
                        /* Default assignments. */
91
                        fifoInterface.readResponse.trigger<=false;
92
                        fifoInterface.writeResponse.trigger<=false;
93
 
94
                        /* Write request.
95
                                Safety control: allow writing only when FIFO is not full.
96
                        */
97
                        --if i_pctFilled<d"100" and (fifoInterface.writeRequest.trigger xor i_writeRequest.trigger) then
98
                        if not i_full and (fifoInterface.writeRequest.trigger xor i_writeRequest.trigger) then
99
                                fifoInterface.writeResponse.trigger<=true;
100 2 daniel.kho
                                memory(ptr)<=fifoInterface.writeRequest.message;
101
                        end if;
102
 
103 3 daniel.kho
                        /* Read request.
104
                                Safety control: allow reading only when FIFO is not empty.
105
                        */
106
                        if not i_empty and (fifoInterface.readRequest.trigger xor i_readRequest.trigger) then
107
                                fifoInterface.readResponse.trigger<=true;
108 2 daniel.kho
                                fifoInterface.readResponse.message<=memory(ptr);
109
                        end if;
110
                end if;
111
        end process controller;
112
 
113
        write<=fifoInterface.writeRequest.trigger xor i_writeRequest.trigger;
114
        read<=fifoInterface.readRequest.trigger xor i_readRequest.trigger;
115
 
116
        addrPointer: process(reset,clk) is begin
117
                if reset then ptr<=0;
118
                elsif falling_edge(clk) then
119
                        /* Increment or decrement the address pointer only when write or read is HIGH;
120
                                do nothing when both are HIGH or when both are LOW.
121
                        */
122
                        if write xor read then
123
                                if write then
124
                                        if ptr<memoryDepth-1 then ptr<=ptr+1; end if;
125
                                end if;
126
                                if read then
127
                                        if ptr>0 then ptr<=ptr-1; end if;
128
                                end if;
129
                        end if;
130
                end if;
131
        end process addrPointer;
132
 
133
        /* Registers and pipelines. */
134 3 daniel.kho
        /* TODO recheck pipelining. */
135 2 daniel.kho
        process(clk) is begin
136 3 daniel.kho
                if falling_edge(clk) then
137
                        i_writeRequest <= fifoInterface.writeRequest;
138
                        i_readRequest <= fifoInterface.readRequest;
139 4 daniel.kho
                        i_full <= fifoCtrl.full;
140
                        i_empty <= fifoCtrl.empty;
141 3 daniel.kho
                end if;
142 2 daniel.kho
        end process;
143
 
144 4 daniel.kho
        fifoCtrl.pctFilled<=to_unsigned(ptr*100/(memoryDepth-1), fifoCtrl.pctFilled'length);
145 2 daniel.kho
 
146
        process(clk) is begin
147
                if rising_edge(clk) then
148 4 daniel.kho
                        fifoCtrl.nearFull<=true when fifoCtrl.pctFilled>=d"75" and fifoCtrl.pctFilled<d"100" else false;
149
                        fifoCtrl.full<=true when fifoCtrl.pctFilled=d"100" else false;
150
                        fifoCtrl.nearEmpty<=true when fifoCtrl.pctFilled<=d"25" and fifoCtrl.pctFilled>d"0" else false;
151
                        fifoCtrl.empty<=true when fifoCtrl.pctFilled=d"0" else false;
152 2 daniel.kho
                end if;
153
        end process;
154
 
155
        process(clk) is begin
156
                if falling_edge(clk) then
157 4 daniel.kho
                        fifoCtrl.overflow<=fifoCtrl.full and write;
158
                        fifoCtrl.underflow<=fifoCtrl.empty and read;
159 2 daniel.kho
                end if;
160
        end process;
161
end architecture rtl;

powered by: WebSVN 2.1.0

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