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

Subversion Repositories riscv_vhdl

[/] [riscv_vhdl/] [trunk/] [rtl/] [rocketlib/] [tilelink/] [axibridge.vhd] - Blame information for rev 5

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 5 sergeykhbr
-----------------------------------------------------------------------------
2
--! @file
3
--! @copyright Copyright 2015 GNSS Sensor Ltd. All right reserved.
4
--! @author    Sergey Khabarov - sergeykhbr@gmail.com
5
--! @brief     TileLink-to-AXI4 bridge implementation.
6
------------------------------------------------------------------------------
7
 
8
library ieee;
9
use ieee.std_logic_1164.all;
10
library commonlib;
11
use commonlib.types_common.all;
12
--! AMBA system bus specific library.
13
library ambalib;
14
--! AXI4 configuration constants.
15
use ambalib.types_amba4.all;
16
library rocketlib;
17
use rocketlib.types_rocket.all;
18
 
19
entity AxiBridge is
20
  port (
21
    clk   : in  std_logic;
22
    nrst  : in  std_logic;
23
 
24
    --! Tile-to-AXI direction
25
    tloi : in tile_out_type;
26
    msto : out nasti_master_out_type;
27
    --! AXI-to-Tile direction
28
    msti : in nasti_master_in_type;
29
    tlio : out tile_in_type
30
  );
31
end;
32
 
33
architecture arch_AxiBridge of AxiBridge is
34
 
35
  type tile_rstatetype is (rwait_acq, reading);
36
  type tile_wstatetype is (wwait_acq, writting);
37
 
38
  type registers is record
39
    rstate : tile_rstatetype;
40
    rd_addr : std_logic_vector(CFG_NASTI_ADDR_BITS-1 downto 0);
41
    rd_addr_incr : integer;
42
    rd_beat_cnt : integer;
43
    rd_xsize : std_logic_vector(2 downto 0); -- encoded AXI4 bytes size
44
    rd_xact_id : std_logic_vector(2 downto 0);
45
    rd_g_type : std_logic_vector(3 downto 0);
46
 
47
    wstate : tile_wstatetype;
48
    wr_addr : std_logic_vector(CFG_NASTI_ADDR_BITS-1 downto 0);
49
    wr_addr_incr : integer;
50
    wr_beat_cnt : integer;
51
    wr_xsize : std_logic_vector(2 downto 0); -- encoded AXI4 bytes size
52
    wr_xact_id : std_logic_vector(2 downto 0);
53
    wr_g_type : std_logic_vector(3 downto 0);
54
    wmask : std_logic_vector(CFG_NASTI_DATA_BYTES-1 downto 0);
55
    wdata : std_logic_vector(CFG_NASTI_DATA_BITS-1 downto 0);
56
  end record;
57
 
58
 
59
signal r, rin : registers;
60
 
61
 
62
  function functionAxi4MetaData(
63
    a   : std_logic_vector(CFG_NASTI_ADDR_BITS-1 downto 0);
64
    len : integer;
65
    sz  : std_logic_vector(2 downto 0)
66
  ) return nasti_metadata_type is
67
    variable        ret : nasti_metadata_type;
68
  begin
69
        ret.addr    := a;
70
        ret.len     := conv_std_logic_vector(len,8);
71
        ret.size    := sz;
72
        ret.burst   := NASTI_BURST_INCR;
73
        ret.lock    := '0';
74
        ret.cache   := (others => '0');
75
        ret.prot    := (others => '0');
76
        ret.qos     := (others => '0');
77
        ret.region  := (others => '0');
78
        return (ret);
79
  end function;
80
 
81
begin
82
 
83
  comblogic : process(tloi, msti, r)
84
    variable v : registers;
85
    variable vmsto : nasti_master_out_type;
86
    variable vtlio  : tile_in_type;
87
 
88
 
89
    variable addr : std_logic_vector(CFG_NASTI_ADDR_BITS-1 downto 0);
90
    variable write : std_logic;
91
    variable next_ena : std_logic;
92
 
93
    variable wWrite     : std_logic;
94
    variable wb_xsize : std_logic_vector(2 downto 0);
95
    variable wbByteAddr : std_logic_vector(2 downto 0);
96
 
97
  begin
98
 
99
    v := r;
100
    addr := (others => '0');
101
    write := '0';
102
 
103
    vmsto.aw_valid        := '0';
104
    vmsto.aw_bits         := META_NONE;
105
    vmsto.aw_id           := (others => '0');
106
    vmsto.w_valid         := '0';
107
    vmsto.w_data          := (others => '0');
108
    vmsto.w_last          := '0';
109
    vmsto.w_strb          := (others => '0');
110
    vmsto.ar_valid        := '0';
111
    vmsto.ar_bits         := META_NONE;
112
    vmsto.ar_id           := (others => '0');
113
    vmsto.r_ready         := '0';
114
    vmsto.ar_user         := '0';
115
    vmsto.aw_user         := '0';
116
    vmsto.w_user          := '0';
117
    vmsto.b_ready         := '1';
118
 
119
    vtlio.a_ready := '0';
120
    vtlio.b_valid := '0';
121
    vtlio.b_opcode := "000";
122
    vtlio.b_param := "00";
123
    vtlio.b_size := "0000";
124
    vtlio.b_source := "000";
125
    vtlio.b_address := (others => '0');
126
    vtlio.b_mask := (others => '0');
127
    vtlio.b_data := (others => '0');
128
    vtlio.c_ready := '0';
129
    vtlio.d_valid := '0';
130
    vtlio.d_opcode := "001";
131
    vtlio.d_param := "00";
132
    vtlio.d_size := "0000";
133
    vtlio.d_source := "000";
134
    vtlio.d_sink := "0000";
135
    vtlio.d_addr_lo := "000";
136
    vtlio.d_data := (others => '0');
137
    vtlio.d_error := '0';
138
    vtlio.e_ready := '1';
139
 
140
    wWrite := not tloi.a_opcode(2);
141
 
142
    if tloi.a_size(3 downto 2) /= "00" then
143
       wb_xsize     := "011";
144
    else
145
       wb_xsize     := '0' & tloi.a_size(1 downto 0);
146
    end if;
147
 
148
    vmsto.aw_valid        := tloi.a_valid and wWrite;
149
    vmsto.ar_valid        := tloi.a_valid and not wWrite;
150
 
151
    case r.wstate is
152
    when wwait_acq =>
153
        if vmsto.aw_valid = '1' and r.rstate = rwait_acq then
154
 
155
          v.wr_xsize     := wb_xsize;
156
          v.wr_addr      := tloi.a_address;
157
          v.wr_addr_incr := XSizeToBytes(conv_integer(wb_xsize));
158
          v.wr_beat_cnt  := conv_integer(tloi.a_size(3 downto 2));
159
          v.wr_xact_id   := tloi.a_source;
160
          v.wmask        := tloi.a_mask;
161
 
162
          if msti.aw_ready = '1' then
163
             v.wstate := writting;
164
             v.wdata := tloi.a_data;
165
          end if;
166
          vmsto.aw_bits         := functionAxi4MetaData(tloi.a_address, v.wr_beat_cnt, wb_xsize);
167
          vmsto.aw_id(2 downto 0) := tloi.a_source;
168
          vmsto.aw_id(CFG_ROCKET_ID_BITS-1 downto 3) := (others => '0');
169
 
170
          vtlio.a_ready := tloi.a_valid and msti.aw_ready;
171
        end if;
172
 
173
    when writting =>
174
          if r.wr_beat_cnt = 0 and msti.w_ready = '1' then
175
              vmsto.w_last := '1';
176
              v.wstate := wwait_acq;
177
          elsif msti.w_ready = '1' and tloi.a_valid = '1' then
178
             v.wr_beat_cnt := r.wr_beat_cnt - 1;
179
             v.wr_addr := r.wr_addr + r.wr_addr_incr;
180
             v.wdata := tloi.a_data;
181
          end if;
182
          vmsto.w_valid         := '1';
183
          vmsto.w_data          := r.wdata;
184
          vmsto.w_strb          := r.wmask;
185
    when others =>
186
    end case;
187
 
188
 
189
    case r.rstate is
190
    when rwait_acq =>
191
        if vmsto.ar_valid = '1' and r.wstate = wwait_acq then
192
 
193
          v.rd_addr := tloi.a_address;
194
          v.rd_addr_incr := XSizeToBytes(conv_integer(wb_xsize));
195
          v.rd_beat_cnt := conv_integer(tloi.a_size(3 downto 2));
196
          v.rd_xsize := wb_xsize;
197
          v.rd_xact_id := tloi.a_source;
198
 
199
          if msti.ar_ready = '1' then
200
            v.rstate := reading;
201
          end if;
202
          vmsto.ar_bits         := functionAxi4MetaData(tloi.a_address, v.rd_beat_cnt, wb_xsize);
203
          vmsto.ar_id(2 downto 0) := tloi.a_source;
204
          vmsto.ar_id(CFG_ROCKET_ID_BITS-1 downto 3) := (others => '0');
205
 
206
          vtlio.a_ready := tloi.a_valid and msti.ar_ready;
207
        end if;
208
 
209
    when reading =>
210
          next_ena := tloi.d_ready and msti.r_valid;
211
          if next_ena = '1' and r.rd_xact_id = msti.r_id(2 downto 0) then
212
              v.rd_beat_cnt := r.rd_beat_cnt - 1;
213
              v.rd_addr := r.rd_addr + r.rd_addr_incr;
214
              if r.rd_beat_cnt = 0 then
215
                 v.rstate := rwait_acq;
216
              end if;
217
          end if;
218
          vmsto.r_ready         := tloi.d_ready;
219
    when others =>
220
    end case;
221
 
222
    if r.rstate = reading then
223
        if r.rd_xact_id = msti.r_id(2 downto 0) then
224
          vtlio.d_valid                := msti.r_valid;
225
        else
226
          vtlio.d_valid                := '0';
227
        end if;
228
        vtlio.d_size := "0110";
229
        vtlio.d_addr_lo       := r.rd_addr(5 downto 3);--!!  depends on AXI_DATA_WIDTH
230
        vtlio.d_source  := r.rd_xact_id;
231
        --vtlio.grant_bits_g_type          := r.rd_g_type;
232
        vtlio.d_data            := msti.r_data;
233
    elsif r.wstate = writting then
234
        vtlio.d_valid               := msti.w_ready;
235
        vtlio.d_addr_lo      := r.wr_addr(5 downto 3);--!!  depends on AXI_DATA_WIDTH
236
        vtlio.d_source := r.wr_xact_id;
237
        --vtlio.grant_bits_g_type         := r.wr_g_type;
238
        --vtlio.grant_bits_data           := (others => '0');
239
    end if;
240
 
241
    rin <= v;
242
    tlio <= vtlio;
243
    msto  <= vmsto;
244
 
245
  end process;
246
 
247
 
248
  -- registers:
249
  regs : process(clk, nrst)
250
  begin
251
     if nrst = '0' then
252
        r.rstate <= rwait_acq;
253
        r.wstate <= wwait_acq;
254
     elsif rising_edge(clk) then
255
        r <= rin;
256
     end if;
257
  end process;
258
 
259
end;

powered by: WebSVN 2.1.0

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