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/] [ahbtbm.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:      ahbtbm
20
-- File:        ahbtbm.vhd
21
-- Author:      Nils-Johan Wessman - Gaisler Research
22
-- Description: AHB Testbench master 
23
------------------------------------------------------------------------------  
24
 
25
library IEEE;
26
use IEEE.std_logic_1164.all;
27
library grlib;
28
use grlib.amba.all;
29
use grlib.stdlib.all;
30
use grlib.devices.all;
31
library gaisler;
32
use gaisler.misc.all;
33
 
34
use work.ahbtbp.all;
35
 
36
entity ahbtbm is
37
  generic (
38
    hindex  : integer := 0;
39
    hirq    : integer := 0;
40
    venid   : integer := VENDOR_GAISLER;
41
    devid   : integer := 0;
42
    version : integer := 0;
43
    chprot  : integer := 3;
44
    incaddr : integer := 0);
45
  port (
46
    rst   : in  std_ulogic;
47
    clk   : in  std_ulogic;
48
    ctrli : in  ahbtbm_ctrl_in_type;
49
    ctrlo : out ahbtbm_ctrl_out_type;
50
    ahbmi : in  ahb_mst_in_type;
51
    ahbmo : out ahb_mst_out_type
52
    );
53
end;
54
 
55
architecture rtl of ahbtbm is
56
 
57
constant hconfig : ahb_config_type := (
58
 
59
  others => zero32);
60
 
61
type reg_type is record
62
  -- new /*
63
  grant     : std_logic;
64
  grant2    : std_logic;
65
  retry     : std_logic_vector(1 downto 0);
66
  read      : std_logic; -- indicate 
67
 
68
  dbgl      : integer;
69
  ac        : ahbtbm_access_array_type;
70
  retryac   : ahbtbm_access_type;
71
  curac     : ahbtbm_access_type;
72
  haddr     : std_logic_vector(31 downto 0); -- addr current access
73
  hdata     : std_logic_vector(31 downto 0); -- data currnet access
74
  hwrite    : std_logic;                     -- write current access
75
  hrdata    : std_logic_vector(31 downto 0);
76
  status    : ahbtbm_status_type;
77
  dvalid    : std_logic;
78
  oldhtrans : std_logic_vector(1 downto 0);
79
 
80
  -- new */
81
  start   : std_ulogic;
82
  active  : std_ulogic;
83
end record;
84
 
85
 
86
signal dmai : ahb_dma_in_type;
87
signal dmao : ahb_dma_out_type;
88
 
89
signal r, rin : reg_type;
90
 
91
begin
92
 
93
  ctrlo.rst <= rst;
94
  ctrlo.clk <= clk;
95
 
96
  comb : process(ahbmi, ctrli, rst, r)
97
  -- new /*
98
  variable v       : reg_type;
99
  variable update  : std_logic;
100
  variable hbusreq : std_ulogic;   -- bus request
101
  variable kblimit : std_logic; -- 1 kB limit indicator
102
  -- new */
103
  variable ready   : std_ulogic;
104
  variable retry   : std_ulogic;
105
  variable mexc    : std_ulogic;
106
  variable inc     : std_logic_vector(3 downto 0);    -- address increment
107
 
108
  variable haddr   : std_logic_vector(31 downto 0);   -- AHB address
109
  variable hwdata  : std_logic_vector(31 downto 0);   -- AHB write data
110
  variable htrans  : std_logic_vector(1 downto 0);    -- transfer type
111
  variable hwrite  : std_ulogic;                      -- read/write
112
  variable hburst  : std_logic_vector(2 downto 0);    -- burst type
113
  variable newaddr : std_logic_vector(10 downto 0); -- next sequential address
114
  variable hprot   : std_logic_vector(3 downto 0);    -- transfer type
115
  variable xhirq    : std_logic_vector(NAHBIRQ-1 downto 0);
116
  begin
117
 
118
    -- new /*
119
    v := r; update := '0'; hbusreq := '0';--v.retry := '0';
120
    v.dvalid := '0'; xhirq := (others => '0');
121
 
122
    v.hrdata := ahbmi.hrdata;
123
    -- pragma translate_off
124
    if ahbmi.hready = '1' and ahbmi.hresp = HRESP_ERROR then
125
      v.hrdata := (others => 'X');
126
    end if;
127
    -- pragma translate_on
128
 
129
    v.status.err := '0';
130
    --v.oldhtrans := r.ac(1).htrans;
131
    kblimit := '0';
132
 
133
    -- Sample grant when hready
134
    if ahbmi.hready = '1' then
135
      v.grant := ahbmi.hgrant(hindex);
136
      v.grant2 := r.grant;
137
      v.oldhtrans := r.ac(1).htrans;
138
    end if;
139
 
140
    -- 1k limit
141
    if (r.ac(0).htrans = HTRANS_SEQ
142
        and (r.ac(0).haddr(10) xor r.ac(1).haddr(10)) = '1')
143
       or (r.retryac.htrans = HTRANS_SEQ
144
        and (r.retryac.haddr(10) xor r.ac(1).haddr(10)) = '1' and r.retry = "10") then
145
      kblimit := '1';
146
    end if;
147
 
148
    -- Read in new access
149
    --if ((ahbmi.hready = '1' and ahbmi.hresp = HRESP_OKAY and r.grant = '1') 
150
    --  or r.ac(1).htrans = HTRANS_IDLE) and r.retry = '0' then
151
    --if ahbmi.hready = '1' and ((ahbmi.hresp = HRESP_OKAY and r.grant = '1') 
152
    --   or r.ac(1).htrans = HTRANS_IDLE) and r.retry = "00" then
153
    if ahbmi.hready = '1' and (( r.grant = '1' and
154
       (ahbmi.hresp = HRESP_OKAY or ahbmi.hresp = HRESP_ERROR))
155
       or r.ac(1).htrans = HTRANS_IDLE) and r.retry = "00" then
156
        v.ac(1) := r.ac(0); v.ac(0) := ctrli.ac;
157
 
158
        v.curac := r.ac(1);
159
        v.hdata := r.ac(1).hdata; v.haddr := r.ac(1).haddr;
160
        v.hwrite := r.ac(1).hwrite; v.dbgl := r.ac(1).ctrl.dbgl;
161
 
162
        v.read := (not r.ac(1).hwrite) and r.ac(1).htrans(1);
163
        update := '1';
164
 
165
        if kblimit = '1' then v.ac(1).htrans := HTRANS_NONSEQ; end if;
166
 
167
    elsif ahbmi.hready = '0' and ahbmi.hresp = HRESP_RETRY and r.grant2 = '1' then
168
      if r.retry = "00" then
169
        v.retryac := r.ac(1);
170
        v.ac(1) := r.curac;
171
        v.ac(1).htrans := HTRANS_IDLE;
172
        v.ac(1).hburst := "000";
173
        v.retry := "01";
174
      elsif r.retry = "10" then
175
        v.ac(1) := r.retryac;
176
        if kblimit = '1' then v.ac(1).htrans := HTRANS_NONSEQ; end if;
177
      end if;
178
    elsif r.retry = "01" then
179
      v.ac(1).htrans := HTRANS_NONSEQ;
180
      v.ac(1).hburst := r.curac.hburst;
181
      v.read := '0';
182
      v.retry := "10";
183
    elsif ahbmi.hready = '1' and r.grant = '1' and r.retry = "10" then
184
      v.read := (not r.ac(1).hwrite) and r.ac(1).htrans(1);
185
      --if ahbmi.hresp = HRESP_OKAY then
186
      if ahbmi.hresp = HRESP_OKAY or ahbmi.hresp = HRESP_ERROR then
187
        v.ac(1) := r.retryac;
188
        if kblimit = '1' then v.ac(1).htrans := HTRANS_NONSEQ; end if;
189
        v.retry := "00";
190
      end if;
191
    end if;
192
 
193
    -- NONSEQ in retry
194
    --if r.retry = '1' then v.ac(1).htrans := HTRANS_NONSEQ; end if;
195
 
196
    -- NONSEQ if burst is interrupted
197
    if r.grant = '0' and r.ac(1).htrans = HTRANS_SEQ then
198
      v.ac(1).htrans := HTRANS_NONSEQ;
199
    end if;
200
 
201
    --if r.ac(1).htrans /= HTRANS_IDLE or r.ac(0).htrans /= HTRANS_IDLE then
202
    --  hbusreq := '1';
203
    --end if;
204
    if r.ac(1).htrans = HTRANS_NONSEQ
205
      or (r.ac(1).htrans = HTRANS_SEQ
206
          and r.ac(0).htrans /= HTRANS_NONSEQ and kblimit = '0') then
207
      hbusreq := '1';
208
    end if;
209
 
210
    --if r.grant = '0' then -- fix dvalid if grant deasserted *** ???
211
    if r.grant = '0' and ahbmi.hready = '1' then
212
      v.read := '0';
213
    end if;
214
 
215
    -- Check read data
216
    if r.read = '1' and ahbmi.hresp = HRESP_OKAY and ahbmi.hready = '1' then
217
      v.dvalid := '1';
218
      if r.hdata /= ahbmi.hrdata then
219
        v.status.err := '1';
220
      end if;
221
    elsif r.read = '1' and ahbmi.hresp = HRESP_ERROR and ahbmi.hready = '1' then
222
      v.status.err := '1';
223
    end if;
224
 
225
    -- new */
226
 
227
 
228
    if rst = '0' then
229
      v.ac(0).htrans := (others => '0');
230
      v.ac(1).htrans := (others => '0');
231
      v.retry := (others => '0');
232
      v.read := '0';
233
 
234
      v.ac(1).haddr := (others => '0');
235
      v.ac(1).htrans := (others => '0');
236
      v.ac(1).hwrite := '0';
237
      v.ac(1).hsize := (others => '0');
238
      v.ac(1).hburst := (others =>'0');
239
    end if;
240
 
241
    rin <= v;
242
 
243
    ctrlo.update <= update;
244
    ctrlo.status <= r.status;
245
    ctrlo.hrdata <= r.hrdata;
246
    ctrlo.dvalid <= r.dvalid;
247
 
248
    ahbmo.haddr   <= r.ac(1).haddr;
249
    ahbmo.htrans  <= r.ac(1).htrans;
250
    ahbmo.hbusreq <= hbusreq;
251
    ahbmo.hwdata  <= r.hdata;
252
    ahbmo.hconfig <= hconfig;
253
    ahbmo.hlock   <= '0';
254
    ahbmo.hwrite  <= r.ac(1).hwrite;
255
    ahbmo.hsize   <= r.ac(1).hsize;
256
    ahbmo.hburst  <= r.ac(1).hburst;
257
    ahbmo.hprot   <= hprot;
258
    ahbmo.hirq    <= xhirq;
259
    ahbmo.hindex  <= hindex;
260
 
261
  end process;
262
 
263
  regs : process(clk)
264
  begin
265
    if rising_edge(clk) then
266
      r <= rin;
267
 
268
-- pragma translate_off
269
    if r.read = '1' and ahbmi.hready = '1' then --and r.oldhtrans /= HTRANS_IDLE then
270
      if ahbmi.hresp = HRESP_OKAY then
271
        if rin.status.err = '0' then
272
          if r.dbgl >= 2 then
273
            print(ptime & "Read[" & tost(r.haddr) & "]: " & tost(ahbmi.hrdata));
274
          end if;
275
        else
276
          if r.dbgl >= 1 then
277
            print(ptime & "Read[" & tost(r.haddr) & "]: " & tost(ahbmi.hrdata)
278
                  & " != " & tost(r.hdata));
279
          end if;
280
        end if;
281
      elsif ahbmi.hresp = HRESP_RETRY then
282
          if r.dbgl >= 3 then
283
            print(ptime & "Read[" & tost(r.haddr) & "]: [RETRY]");
284
          end if;
285
      elsif ahbmi.hresp = HRESP_ERROR then
286
          if r.dbgl >= 1 then
287
            print(ptime & "Read[" & tost(r.haddr) & "]: [ERROR]");
288
          end if;
289
      end if;
290
    end if;
291
    if r.hwrite = '1' and ahbmi.hready = '1' and r.oldhtrans /= HTRANS_IDLE then
292
      if ahbmi.hresp = HRESP_OKAY then
293
        if r.dbgl >= 2 then
294
          print(ptime & "Write[" & tost(r.haddr) & "]: " & tost(r.hdata));
295
        end if;
296
      elsif ahbmi.hresp = HRESP_RETRY then
297
        if r.dbgl >= 3 then
298
          print(ptime & "Write[" & tost(r.haddr) & "]: " & tost(r.hdata)
299
                & " [RETRY]");
300
        end if;
301
      elsif ahbmi.hresp = HRESP_ERROR then
302
        if r.dbgl >= 1 then
303
          print(ptime & "Write[" & tost(r.haddr) & "]: " & tost(r.hdata)
304
                & " [ERROR]");
305
        end if;
306
      end if;
307
    end if;
308
-- pragma translate_on
309
 
310
    end if;
311
  end process;
312
 
313
end;

powered by: WebSVN 2.1.0

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