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/] [ambatest/] [ahbtbs.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:      ahbtbs
20
-- File:        ahbtbs.vhd
21
-- Author:      Nils-Johan Wessman - Gaisler Research
22
-- Description: AMBA testbench slave
23
------------------------------------------------------------------------------  
24
library ieee;
25
use ieee.std_logic_1164.all;
26
library grlib;
27
use grlib.amba.all;
28
use grlib.stdlib.all;
29
use grlib.devices.all;
30
library techmap;
31
use techmap.gencomp.all;
32
 
33
library gaisler;
34
use gaisler.misc.all;
35
 
36
use work.ahbtbp.all;
37
 
38
entity ahbtbs is
39
  generic (
40
    hindex  : integer := 0;
41
    haddr   : integer := 0;
42
    hmask   : integer := 16#fff#;
43
    tech    : integer := DEFMEMTECH;
44
    kbytes  : integer := 1);
45
  port (
46
    rst     : in  std_ulogic;
47
    clk     : in  std_ulogic;
48
    ahbsi   : in  ahb_slv_in_type;
49
    ahbso   : out ahb_slv_out_type
50
  );
51
end;
52
 
53
architecture rtl of ahbtbs is
54
 
55
constant abits : integer := log2(kbytes) + 8;
56
constant ws : std_logic_vector(7 downto 0) :="00000000";
57
constant retry : integer := 0;
58
 
59
constant hconfig : ahb_config_type := (
60
 
61
  4 => ahb_membar(haddr, '1', '1', hmask),
62
  others => zero32);
63
 
64
 
65
type reg_type is record
66
  hwrite : std_ulogic;
67
  hready : std_ulogic;
68
  hsel   : std_ulogic;
69
  addr   : std_logic_vector(abits+1 downto 0);
70
  size   : std_logic_vector(1 downto 0);
71
  hresp  : std_logic_vector(1 downto 0);
72
  ws     : std_logic_vector(7 downto 0);
73
  rty    : std_logic_vector(3 downto 0);
74
  retry  : std_logic;
75
end record;
76
 
77
signal r, c : reg_type;
78
signal ramsel : std_ulogic;
79
signal write : std_logic_vector(3 downto 0);
80
signal ramaddr  : std_logic_vector(abits-1 downto 0);
81
signal ramdata  : std_logic_vector(31 downto 0);
82
begin
83
 
84
  comb : process (ahbsi, r, rst, ramdata)
85
  variable bs : std_logic_vector(3 downto 0);
86
  variable v : reg_type;
87
  variable haddr  : std_logic_vector(abits-1 downto 0);
88
  begin
89
    v := r; v.hready := '1'; bs := (others => '0');
90
    v.hresp := HRESP_OKAY;
91
 
92
    if ahbsi.hready = '1' then
93
      v.hsel := ahbsi.hsel(hindex) and ahbsi.htrans(1);
94
      v.hwrite := ahbsi.hwrite and v.hsel;
95
      v.addr := ahbsi.haddr(abits+1 downto 0);
96
      v.size := ahbsi.hsize(1 downto 0);
97
      v.ws := ws;
98
      --v.retry := retry;
99
      if retry = 1 then
100
        if v.hsel = '1' then
101
          v.rty := r.rty - 1;
102
          if r.rty = "0000" then
103
            v.retry := '0';
104
            v.rty := "0010";
105
          else
106
            v.retry := '1';
107
          end if;
108
        end if;
109
      else
110
          v.retry := '0';
111
      end if;
112
    end if;
113
 
114
    if r.ws /= "00000000" and r.hsel = '1' then
115
      v.ws := r.ws - 1;
116
    end if;
117
 
118
    if v.ws /= "00000000" and v.hsel = '1' then
119
      v.hready := '0';
120
    elsif v.hsel = '1' and v.retry = '1' then
121
      if r.hresp = HRESP_OKAY then
122
        v.hready := '0';
123
        v.hresp := HRESP_RETRY;
124
      else
125
        v.hready := '1';
126
        v.hresp := HRESP_RETRY;
127
        v.retry := '0';
128
      end if;
129
    end if;
130
 
131
    if (r.hwrite or not r.hready) = '1' then
132
      haddr := r.addr(abits+1 downto 2);
133
    else
134
      haddr := ahbsi.haddr(abits+1 downto 2); bs := (others => '0');
135
    end if;
136
 
137
 
138
    if r.hwrite = '1' and r.hready = '1' then
139
      case r.size(1 downto 0) is
140
      when "00" => bs (conv_integer(r.addr(1 downto 0))) := '1';
141
      when "01" => bs := r.addr(1) & r.addr(1) & not (r.addr(1) & r.addr(1));
142
      when others => bs := (others => '1');
143
      end case;
144
      --v.hready := not (v.hsel and not ahbsi.hwrite);
145
      --v.hwrite := v.hwrite and v.hready;
146
    end if;
147
 
148
    if rst = '0' then
149
      v.hwrite := '0'; v.hready := '1'; v.ws := ws;
150
      v.rty := "0010";
151
    end if;
152
    write <= bs; ramsel <= v.hsel or r.hwrite; ahbso.hready <= r.hready;
153
    ramaddr <= haddr; c <= v; ahbso.hrdata <= ramdata;
154
 
155
  end process;
156
 
157
  ahbso.hresp   <= r.hresp; --"00"; 
158
  ahbso.hsplit  <= (others => '0');
159
  ahbso.hirq    <= (others => '0');
160
  ahbso.hcache  <= '1';
161
  ahbso.hconfig <= hconfig;
162
  ahbso.hindex  <= hindex;
163
 
164
  ra : for i in 0 to 3 generate
165
    aram :  syncram generic map (tech, abits, 8) port map (
166
        clk, ramaddr, ahbsi.hwdata(i*8+7 downto i*8),
167
        ramdata(i*8+7 downto i*8), ramsel, write(3-i));
168
  end generate;
169
 
170
  reg : process (clk)
171
  begin
172
    if rising_edge(clk ) then r <= c; end if;
173
  end process;
174
 
175
-- pragma translate_off
176
    bootmsg : report_version
177
    generic map ("ahbram" & tost(hindex) &
178
    ": AHB SRAM Module rev 1, " & tost(kbytes) & " kbytes");
179
-- pragma translate_on
180
end;

powered by: WebSVN 2.1.0

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