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

Subversion Repositories mips_enhanced

[/] [mips_enhanced/] [trunk/] [grlib-gpl-1.0.19-b3188/] [lib/] [gaisler/] [ata/] [atahost_dma_fifo.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 dimamali
------------------------------------------------------------------------------
2
--  This file is a part of the GRLIB VHDL IP LIBRARY
3
--  Copyright (C) 2003, Gaisler Research
4
--
5
--  This program is free software; you can redistribute it and/or modify
6
--  it under the terms of the GNU General Public License as published by
7
--  the Free Software Foundation; either version 2 of the License, or
8
--  (at your option) any later version.
9
--
10
--  This program is distributed in the hope that it will be useful,
11
--  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
--  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
--  GNU General Public License for more details.
14
--
15
--  You should have received a copy of the GNU General Public License
16
--  along with this program; if not, write to the Free Software
17
--  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
18
-----------------------------------------------------------------------------
19
-- Entity:      atahost_dma_fifo
20
-- File:        atahost_dma_fifo.vhd
21
-- Author:      Erik Jagre - Gaisler Research
22
-- Description: Generic FIFO, based on syncram in grlib
23
-----------------------------------------------------------------------------
24
 
25
library IEEE;
26
use IEEE.std_logic_1164.all;
27
use ieee.std_logic_arith.all;
28
library techmap;
29
use techmap.gencomp.all;
30
 
31
entity atahost_dma_fifo is
32
  generic(tech  : integer:=0;  abits : integer:=3;
33
          dbits : integer:=32; depth : integer:=8);
34
  port( clk          : in std_logic;
35
        reset        : in std_logic;
36
        write_enable : in std_logic;
37
        read_enable  : in std_logic;
38
        data_in      : in std_logic_vector(dbits-1 downto 0);
39
        data_out     : out std_logic_vector(dbits-1 downto 0);
40
        write_error  : out std_logic:='0';
41
        read_error   : out std_logic:='0';
42
        level        : out natural range 0 to depth;
43
        empty        : out std_logic:='1';
44
        full         : out std_logic:='0');
45
end;
46
 
47
architecture rtl of atahost_dma_fifo is
48
type state_type is (full_state, empty_state, idle_state);
49
type reg_type is record
50
  state      : state_type;
51
  level      : integer range 0 to depth;
52
  aw         : integer range 0 to depth;
53
  ar         : integer range 0 to depth;
54
  data_o     : std_logic_vector(dbits-1 downto 0);
55
  rd         : std_logic;
56
  wr         : std_logic;
57
  erd        : std_logic;
58
  ewr        : std_logic;
59
  reset      : std_logic;
60
  adr        : std_logic_vector(abits-1 downto 0);
61
end record;
62
 
63
constant RESET_VECTOR : reg_type := (empty_state,0,0,0,
64
  conv_std_logic_vector(0,dbits),'0','0','0','0','0',(others=>'0'));
65
 
66
signal r,ri : reg_type;
67
signal s_ram_adr : std_logic_vector(abits-1 downto 0);
68
 
69
begin
70
--  comb:process(write_enable, read_enable, data_in,reset, r) Erik 2007-02-08
71
  comb:process(write_enable, read_enable, reset, r)
72
  variable v : reg_type;
73
  variable vfull, vempty : std_logic;
74
 
75
  begin
76
    v:=r;
77
    v.wr:=write_enable; v.rd:=read_enable; v.reset:=reset;
78
 
79
    case r.state is
80
      when full_state=>
81
        if write_enable='1' and read_enable='0' and reset='0' then
82
          v.ewr:='1'; v.state:=full_state;
83
        elsif write_enable='0' and read_enable='1' and reset='0' then
84
          v.adr:=conv_std_logic_vector(r.ar,abits);
85
          if r.ar=depth-1 then v.ar:=0; else v.ar:=r.ar+1; end if;
86
          v.level:=r.level-1;
87
          if r.aw=v.ar then v.state:=empty_state;
88
          else v.state:=idle_state; end if;
89
          v.ewr:='0';
90
        end if;
91
 
92
      when empty_state=>
93
        if write_enable='1' and read_enable='0' and reset='0' then
94
          v.adr:=conv_std_logic_vector(r.aw,abits);
95
          if r.aw=depth-1 then v.aw:=0; else v.aw:=r.aw+1; end if;
96
          v.level:=r.level+1;
97
          if v.aw=r.ar then v.state:=full_state;
98
          else v.state:=idle_state; end if;
99
          v.erd:='0';
100
        elsif write_enable='0' and read_enable='1' and reset='0' then
101
          v.erd:='1'; v.state:=empty_state;
102
        end if;
103
 
104
      when idle_state=>
105
        if write_enable='1' and read_enable='0' and reset='0' then
106
          v.adr:=conv_std_logic_vector(r.aw,abits);
107
          if r.aw=depth-1 then v.aw:=0; else v.aw:=r.aw+1; end if;
108
          v.level:=r.level+1;
109
          if v.level=depth then v.state:=full_state;
110
          else v.state:=idle_state; end if;
111
        elsif write_enable='0' and read_enable='1' and reset='0' then
112
          v.adr:=conv_std_logic_vector(r.ar,abits);
113
          if r.ar=depth-1 then v.ar:=0; else v.ar:=r.ar+1; end if;
114
          v.level:=r.level-1;
115
          if v.level=0 then v.state:=empty_state;
116
          else v.state:=idle_state; end if;
117
        end if;
118
    end case;
119
 
120
    if r.level=0 then vempty:='1'; vfull:='0';
121
    elsif r.level=depth then vempty:='0'; vfull:='1';
122
    else vempty:='0'; vfull:='0'; end if;
123
 
124
    --reset logic
125
    if (reset='1') then v:=RESET_VECTOR; end if;
126
 
127
    ri<=v;
128
    s_ram_adr<=v.adr;
129
 
130
    --assigning outport
131
    write_error<=v.ewr; read_error<=v.erd; level<=v.level;
132
    empty<=vempty; full<=vfull;
133
  end process;
134
 
135
  ram : syncram
136
  generic map(tech=>tech, abits=>abits, dbits=>dbits)
137
  port map (
138
    clk     => clk,
139
    address => s_ram_adr,
140
    datain  => data_in,
141
    dataout => data_out,
142
    enable  => read_enable,
143
    write   => write_enable
144
  );
145
 
146
  sync:process(clk)     --Activate on clock & reset
147
  begin
148
    if clk'event and clk='1' then r<=ri; end if;
149
  end process;
150
end;

powered by: WebSVN 2.1.0

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