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/] [ahbmst_em.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:      ahbmst_em
20
-- File:        ahbmst_em.vhd
21
-- Author:      Alf Vaerneus, Gaisler Research
22
-- Description: AMBA AHB Master emulator for simulation purposes only
23
------------------------------------------------------------------------------
24
 
25
-- pragma translate_off
26
library IEEE;
27
use IEEE.std_logic_1164.all;
28
library grlib;
29
use grlib.amba.all;
30
use grlib.stdlib.all;
31
library gaisler;
32
use grlib.devices.all;
33
use gaisler.ambatest.all;
34
library std;
35
use std.textio.all;
36
 
37
 
38
entity ahbmst_em is
39
  generic(
40
    hindex    : integer := 0;
41
    timeoutc   : integer := 100;
42
    dbglevel  : integer := 2
43
  );
44
  port(
45
    rst       : in std_logic;
46
    clk       : in std_logic;
47
    -- AMBA signals
48
    ahbmi     : in  ahb_mst_in_type;
49
    ahbmo     : out ahb_mst_out_type;
50
    -- TB signals
51
    tbi       : in  tb_in_type;
52
    tbo       : out  tb_out_type
53
 
54
  );
55
end;
56
 
57
architecture tb of ahbmst_em is
58
 
59
constant VERSION : integer := 1;
60
constant hconfig : ahb_config_type := (
61
 
62
  others => zero32);
63
 
64
constant T_O : integer := timeoutc;
65
 
66
type state_type is(idle,active,done);
67
type reg_type is record
68
  state : state_type;
69
  current_word : integer;
70
  address : std_logic_vector(31 downto 0);
71
  data : std_logic_vector(31 downto 0);
72
  tocnt : integer;
73
  running : std_logic;
74
  longfile : std_logic;
75
  active : std_logic;
76
  grant : std_logic;
77
  ahbmo : ahb_mst_out_type;
78
end record;
79
 
80
signal r,rin : reg_type;
81
signal fileahbmo : ahb_mst_out_type;
82
 
83
begin
84
 
85
tb : process(tbi,ahbmi,r,rst)
86
variable v : reg_type;
87
variable status : status_type;
88
variable ready : std_logic;
89
variable ahbm : ahb_mst_out_type;
90
variable newaddress : std_logic_vector(31 downto 0);
91
variable inc : std_logic_vector(3 downto 0);
92
begin
93
  v := r; ahbm := AHB_IDLE; newaddress := r.address;
94
  v.tocnt := 0; ready := '0'; inc := (others => '0');
95
  ahbm.hconfig := hconfig;
96
 
97
  if tbi.start = '1' then
98
    if (r.running = '0' and r.state = idle) then
99
      v.address := tbi.address;
100
      status := OK;
101
      v.running := '1';
102
    end if;
103
    case tbi.command is
104
    when RD_SINGLE => ahbm := READ_SINGLE;
105
    when RD_INCR => ahbm := READ_INCR;
106
    when WR_SINGLE => ahbm := WRITE_SINGLE;
107
    when WR_INCR => ahbm := WRITE_INCR;
108
    when others =>
109
    end case;
110
    ahbm.hwdata := tbi.data;
111
  end if;
112
 
113
  inc(conv_integer(ahbm.hsize)) := '1';
114
 
115
  if ((r.active and not ahbmi.hresp(1)) = '1') then
116
    if ahbm.htrans = HTRANS_NONSEQ then
117
      ahbm.htrans := HTRANS_SEQ; newaddress := newaddress+inc;
118
    end if;
119
    if ahbmi.hready = '1' then
120
      v.address := r.address + inc; v.current_word := r.current_word+1;
121
    end if;
122
    if newaddress(9 downto 0) = "0000000000" then ahbm.htrans := HTRANS_NONSEQ; end if;
123
  end if;
124
 
125
  if v.current_word >= tbi.no_words then ahbm.htrans := HTRANS_IDLE; end if;
126
 
127
  ahbm.haddr := newaddress;
128
 
129
  if tbi.userfile then
130
    if ahbmi.hresp(1) = '0' then
131
      v.ahbmo := fileahbmo;
132
      v.ahbmo.hwrite := ahbm.hwrite;
133
      ahbm.haddr := fileahbmo.haddr;
134
      if ahbmi.hready = '1' then v.data := fileahbmo.hwdata; end if;
135
      ahbm.hwdata := r.data;
136
      if r.longfile = '1' then
137
        ahbm.htrans := fileahbmo.htrans;
138
        ahbm.hburst := fileahbmo.hburst;
139
        ahbm.hsize := fileahbmo.hsize;
140
        ahbm.hprot := fileahbmo.hprot;
141
      end if;
142
    else ahbm := r.ahbmo; end if;
143
  end if;
144
 
145
  if ahbmi.hresp = HRESP_ERROR then status := ERR;
146
  elsif r.tocnt = T_O then status := TIMEOUT; end if;
147
 
148
  case r.state is
149
  when idle =>
150
    if r.running = '1' then
151
      v.state := active;
152
    end if;
153
  when active =>
154
    v.tocnt := r.tocnt + 1;
155
    ahbm.hbusreq := r.running;
156
    if (r.grant and ahbmi.hready) = '1' then v.tocnt := 0; end if;
157
    if (v.current_word >= tbi.no_words and r.grant = '1' and tbi.userfile = false) then v.running := '0'; ahbm.hbusreq := '0'; end if;
158
    if (status /= OK or ((ahbmi.hready and not r.running) = '1' and ahbmi.hresp = HRESP_OKAY)) then
159
      v.state := done; ahbm.htrans := HTRANS_IDLE;
160
    end if;
161
  when done =>
162
    v.running := '0'; ready := '1';
163
    if tbi.start = '0' then
164
      v.state := idle; v.longfile := '0';
165
      v.current_word := 0;
166
    end if;
167
  when others =>
168
  end case;
169
 
170
  if ahbmi.hready = '1' then
171
    v.grant := ahbmi.hgrant(hindex);
172
    if ahbm.htrans /= HTRANS_IDLE then v.active := r.grant;
173
    else v.active := '0'; end if;
174
  end if;
175
 
176
  ahbm.hindex := hindex;
177
 
178
  if rst = '0' then
179
    v.address := (others => '0');
180
    v.state := idle;
181
    v.running := '0';
182
    v.current_word := 0;
183
    v.tocnt := 0;
184
    v.longfile := '0';
185
    v.ahbmo := AHB_IDLE;
186
  end if;
187
 
188
  tbo.ready <= ready;
189
  tbo.status <= status;
190
  rin <= v;
191
  ahbmo <= ahbm;
192
 
193
end process;
194
 
195
tbo.data <= ahbmi.hrdata when (ahbmi.hready and r.running) = '1';
196
 
197
cpur : process (clk)
198
file datafile_write,datafile_read :text;
199
variable L : line;
200
variable dataint : integer;
201
variable datahex : string(1 to 8);
202
variable count : integer;
203
begin
204
 
205
  if rising_edge (clk) then
206
    r <= rin;
207
    if tbi.usewfile then
208
      case r.state is
209
      when idle =>
210
        if r.running = '1' then
211
          file_open(datafile_write,external_name => tbi.wfile(18 downto trimlen(tbi.wfile)), open_kind => write_mode);
212
          count := 0;
213
        end if;
214
      when active =>
215
        if ((r.active and ahbmi.hready) = '1' and ahbmi.hresp = HRESP_OKAY) then
216
          if (tbi.userfile = false or count > 0) then
217
            write(L,printhex(ahbmi.hrdata,32));
218
            writeline(datafile_write,L);
219
          end if;
220
          count := count+1;
221
        end if;
222
        if rin.state = done then file_close(datafile_write); end if;
223
      when done =>
224
      when others =>
225
      end case;
226
    end if;
227
    if tbi.userfile then
228
      case r.state is
229
      when idle =>
230
        if r.running = '1' then
231
          fileahbmo <= AHB_IDLE; fileahbmo.hwrite <= rin.ahbmo.hwrite;
232
          file_open(datafile_read,external_name => tbi.rfile(18 downto trimlen(tbi.rfile)), open_kind => read_mode);
233
          readline(datafile_read,L); read(L,dataint);
234
          if dataint = 1 then r.longfile <= '1';
235
          else r.longfile <= '0'; end if;
236
        end if;
237
      when active =>
238
        if ((ahbmi.hgrant(hindex) and ahbmi.hready) = '1' and ahbmi.hresp = HRESP_OKAY) then
239
          if not endfile(datafile_read) then
240
            if r.longfile = '1' then
241
              readline(datafile_read,L); -- Dummy read for header
242
              readline(datafile_read,L); read(L,dataint);
243
              fileahbmo.htrans <= conv_std_logic_vector(dataint,2);
244
              readline(datafile_read,L); read(L,dataint);
245
              fileahbmo.hburst <= conv_std_logic_vector(dataint,3);
246
              readline(datafile_read,L); read(L,dataint);
247
              fileahbmo.hsize <= conv_std_logic_vector(dataint,3);
248
              readline(datafile_read,L); read(L,dataint);
249
              fileahbmo.hprot <= conv_std_logic_vector(dataint,4);
250
              readline(datafile_read,L); read(L,datahex);
251
              fileahbmo.haddr <= conv_std_logic_vector(datahex,32);
252
              readline(datafile_read,L); read(L,datahex);
253
              fileahbmo.hwdata <= conv_std_logic_vector(datahex,32);
254
            else
255
              readline(datafile_read,L); -- Dummy read for header
256
              readline(datafile_read,L); read(L,datahex);
257
              fileahbmo.haddr <= conv_std_logic_vector(datahex,32);
258
              readline(datafile_read,L); read(L,datahex);
259
              fileahbmo.hwdata <= conv_std_logic_vector(datahex,32);
260
            end if;
261
          else r.running <= '0'; end if;
262
        end if;
263
      when done =>
264
          if tbi.start = '0' then
265
            file_close(datafile_read);
266
          end if;
267
      when others =>
268
      end case;
269
    end if;
270
  end if;
271
 
272
end process;
273
 
274
bootmsg : report_version
275
generic map ("pcimst_em" & tost(hindex) &
276
": PCI Master Emulator rev " & tost(VERSION) &
277
" for simulation purpose only." &
278
" NOT syntheziseable.");
279
 
280
end;
281
-- pragma translate_on

powered by: WebSVN 2.1.0

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