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

Subversion Repositories ahb_system_generator

[/] [ahb_system_generator/] [trunk/] [src/] [mst_wrap.vhd] - Blame information for rev 2

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

Line No. Rev Author Line
1 2 federico.a
library ieee;
2
use ieee.std_logic_1164.all;
3
use ieee.std_logic_unsigned.all;
4
use ieee.std_logic_misc.all;
5
use ieee.std_logic_arith.all;
6
 
7
use std.textio.all;
8
 
9
use work.ahb_package.all;
10
 
11
entity mst_wrap is
12
generic (
13
--synopsys translate_off
14
dump_file: in string:= "mst_wrap.log";
15
dump_type: in integer:= dump_no;
16
--synopsys translate_on
17
ahb_max_addr: in integer:= 4;
18
--***************************************************************
19
--parameters for master access
20
--***************************************************************
21
m_const_lat_write: in integer:= 0;--0 latency states in write
22
m_const_lat_read: in integer:= 2;--2 cycles to get first data
23
m_write_burst: in integer := burst_support;--master accepts bursts in write!!!
24
m_read_burst: in integer := burst_support--master accepts bursts in read!!!
25
);
26
port (
27
  hresetn: in std_logic;
28
  clk: in std_logic;
29
  conf: in conf_type_t;
30
  dma_start: out start_type_t;
31
  m_wrap_in: in wrap_out_t;
32
  m_wrap_out: out wrap_in_t);
33
end mst_wrap;
34
 
35
architecture rtl of mst_wrap is
36
 
37
 
38
--synopsys translate_off
39
--***************************************************************
40
--**** DUMP OF MEMORY *******************************************
41
--***************************************************************
42
file file_descriptor : TEXT open WRITE_MODE is dump_file;
43
 
44
constant msg1: string(1 to 4):= "MEM ";
45
constant msg3: string(1 to 5):= "DATA ";
46
 
47
procedure Write_Message(msg1:string; addr:in integer; msg2:string; value:in integer) is
48
variable STR : line;
49
  begin
50
    write(STR,now);
51
    write(STR,STRING'(" "));
52
    write (STR, msg1);
53
    write (STR, addr);
54
    write(STR,STRING'(" "));
55
    write (STR, msg2);
56
    write (STR, value);
57
    writeLine(file_descriptor, STR);
58
    writeLine(OUTPUT, STR);
59
  end Write_Message;
60
--***************************************************************
61
--***************************************************************
62
--synopsys translate_on
63
 
64
 
65
--***************************************************************
66
--configuration registers 
67
--***************************************************************
68
signal hsize_reg: std_logic_Vector(2 downto 0);
69
signal priority_reg: std_logic;
70
signal hburst_reg: std_logic_Vector(2 downto 0);
71
signal hprot_reg: std_logic_Vector(3 downto 0);
72
signal trx_dir_reg: std_logic;
73
signal hlock_reg: std_logic;
74
signal extaddr: std_logic_Vector(31 downto 0);
75
signal intaddr: std_logic_Vector(15 downto 0);
76
signal intmod: std_logic_Vector(15 downto 0);
77
signal count_reg: std_logic_Vector(15 downto 0);
78
signal dma_go: std_logic;
79
--***************************************************************
80
--***************************************************************
81
 
82
type vect_32 is array (2**ahb_max_addr-1 downto 0) of std_logic_vector (31 downto 0);
83
signal mem : vect_32;
84
 
85
 
86
signal m_lat_write_ok, m_lat_read_ok: std_logic;
87
signal m_lat_write: integer range 0 to m_const_lat_write;
88
signal m_lat_read: integer range 0 to m_const_lat_read;
89
--***************************************************************
90
--***************************************************************
91
 
92
 
93
begin
94
 
95
 
96
--***************************************************************
97
--***************************************************************
98
--***************** master part *********************************
99
--***************************************************************
100
process(clk, hresetn)
101
begin
102
  if hresetn='0' then
103
    m_lat_write <= m_const_lat_write;
104
  elsif clk'event and clk='1' then
105
    if (m_wrap_in.take='1') then
106
      if (m_lat_write_ok='0') then
107
        m_lat_write <= m_lat_write-1 after 1 ns;
108
      elsif (m_write_burst=1) then--accepts bursts .....
109
        m_lat_write <= 0 after 1 ns;
110
      else
111
        m_lat_write <= m_const_lat_write after 1 ns;
112
      end if;
113
    else
114
      m_lat_write <= m_const_lat_write after 1 ns;
115
    end if;
116
  end if;
117
end process;
118
 
119
m_lat_write_ok <= '1' when (m_lat_write=0) else '0';
120
m_wrap_out.take_ok <= '1' when (m_wrap_in.take='1' and m_lat_write_ok='1') else '0';
121
 
122
process(clk, hresetn)
123
begin
124
  if hresetn='0' then
125
    for i in 0 to 2**ahb_max_addr-1 loop
126
      mem(i) <= conv_std_logic_vector(i, 32);
127
    end loop;--i
128
  elsif clk'event and clk='1' then
129
    if (m_wrap_in.take='1' and m_lat_write_ok='1') then
130
      mem(conv_integer(m_wrap_in.addr(2+ahb_max_addr-1 downto 2))) <= m_wrap_in.wdata after 1 ns;
131
--synopsys translate_off
132
if dump_type/=dump_no then Write_Message(msg1, conv_integer(m_wrap_in.addr(2+ahb_max_addr-1 downto 2)), msg3, conv_integer(m_wrap_in.wdata)); end if;
133
--synopsys translate_on
134
    end if;
135
  end if;
136
end process;
137
 
138
m_wrap_out.rdata <= mem(conv_integer(m_wrap_in.addr(2+ahb_max_addr-1 downto 2))) when (m_wrap_in.ask='1' and m_lat_read_ok='1') else (others => '-');
139
 
140
 
141
process(clk, hresetn)
142
begin
143
  if hresetn='0' then
144
    m_lat_read <= m_const_lat_read;
145
  elsif clk'event and clk='1' then
146
    if (m_wrap_in.ask='1') then
147
      if (m_lat_read_ok='0') then
148
            m_lat_read <= m_lat_read-1  after 1 ns;
149
      elsif (m_read_burst=1) then--accepts bursts .....
150
            m_lat_read <= 0  after 1 ns;
151
      else
152
            m_lat_read <= m_const_lat_read  after 1 ns;
153
      end if;
154
    else
155
      m_lat_read <= m_const_lat_read after 1 ns;
156
    end if;
157
  end if;
158
end process;
159
 
160
m_lat_read_ok <= '1' when (m_lat_read=0) else '0';
161
m_wrap_out.ask_ok <= '1' when (m_wrap_in.ask='1' and m_lat_read_ok='1') else '0';
162
 
163
 
164
 
165
 
166
--**************************************************************************
167
-- configuration registers write
168
--**************************************************************************
169
 
170
 
171
conf_reg_pr:process(hresetn, clk)
172
variable addr: std_logic_Vector(3 downto 0);
173
begin
174
if hresetn='0' then
175
  hsize_reg <= bits32;
176
  priority_reg <= slave;
177
  hburst_reg <= incr;
178
  hprot_reg <= "0011";
179
  trx_dir_reg <= '0';
180
  hlock_reg <= locked;
181
  extaddr <= zeroes;
182
  intaddr <= zeroes(15 downto 0);
183
  intmod <= conv_std_logic_vector(4, intmod'length);--mod=+4(+1 word32)
184
  count_reg <= zeroes(15 downto 0);
185
  dma_go <= '0';
186
elsif clk'event and clk='1' then
187
  if (conf.write='1') then
188
    case conf.addr is
189
      when dma_extadd_addr =>
190
        extaddr <= conf.wdata;
191
      when dma_intadd_addr =>
192
        intaddr <= conf.wdata(15 downto 0);
193
      when dma_intmod_addr =>
194
        intmod <= conf.wdata(15 downto 0);
195
      when dma_type_addr =>
196
        priority_reg <= conf.wdata(12);
197
        hsize_reg <= conf.wdata(11 downto 9);
198
        hburst_reg <= conf.wdata(8 downto 6);
199
        hprot_reg <= conf.wdata(5 downto 2);
200
        trx_dir_reg <= conf.wdata(1);
201
        hlock_reg <= conf.wdata(0);
202
      when dma_count_addr =>
203
        count_reg <= conf.wdata(15 downto 0);
204
      when others => null;
205
    end case;
206
  end if;
207
  if (conf.write='1' and conf.addr=dma_count_addr) then
208
    dma_go <= '1';
209
  else
210
    dma_go <= '0';
211
  end if;
212
 end if;
213
end process;
214
--**************************************************************************
215
--**************************************************************************
216
 
217
 
218
--**************************************************************************
219
--**************************************************************************
220
  dma_start.extaddr <= extaddr;
221
  dma_start.intaddr <= intaddr;
222
  dma_start.intmod <= intmod;
223
  dma_start.hparams <= "000"&priority_reg&hsize_reg&hburst_reg&hprot_reg&trx_dir_reg&hlock_reg;
224
  dma_start.count <= count_reg;
225
  dma_start.start <= dma_go;
226
 
227
end rtl;

powered by: WebSVN 2.1.0

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