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

Subversion Repositories ax4lbr

[/] [ax4lbr/] [trunk/] [rtl/] [axil2wb.vhd] - Blame information for rev 2

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

Line No. Rev Author Line
1 2 wzab
-------------------------------------------------------------------------------
2
-- Title      : axil2wb
3
-- Project    : 
4
-------------------------------------------------------------------------------
5
-- File       : axil2ipb.vhd
6
-- Author     : Wojciech M. Zabolotny  <wzab@ise.pw.edu.pl>
7
-- Company    : Institute of Electronic Systems, Warsaw University of Technology
8
-- Created    : 2016-04-24
9
-- Last update: 2016-05-14
10
-- License    : This is a PUBLIC DOMAIN code, published under
11
--              Creative Commons CC0 license
12
-- Platform   : 
13
-- Standard   : VHDL'93/02
14
-------------------------------------------------------------------------------
15
-- Description: AXI Lite -> WB bridge
16
-------------------------------------------------------------------------------
17
-- Copyright (c) 2016 
18
-------------------------------------------------------------------------------
19
-- Revisions  :
20
-- Date        Version  Author  Description
21
-- 2016-05-13  1.0      WZab    Created
22
-------------------------------------------------------------------------------
23
 
24
-- The AXI implementation is based on the description of AXI provided by
25
-- Rich Griffin in "Designing a Custom AXI-lite Slave Peripheral"
26
-- available at:
27
-- silica.com/wcsstore/Silica/Silica+Content+Library/Silica+Home/resources/71b10b18-9c9c-44c6-b62d-9a031b8f3df8/SILICA_Xilinx_Designing_a_custom_axi_slave_rev1.pdf
28
--
29
-------------------------------------------------------------------------------
30
-- Implementation details
31
-------------------------------------------------------------------------------
32
-- In the AXI bus the read and write accesses may be handled independently
33
-- In the IPbus they can't therefore we must provide an arbitration scheme.
34
-- We assume "Write before read"
35
-- 
36
-- We must avoid duplicated writes and reads (which may corruppt e.g.
37
-- FIFO slaves at IPbus!)
38
--
39
-- Additionally the IPbus uses the word adressing, while AXI uses the byte
40
-- addressing. That is handled by the function a_axi2ipb, which additionally
41
-- zeroes bits not used by the IPbus segment...
42
 
43
 
44
 
45
library IEEE;
46
use IEEE.STD_LOGIC_1164.all;
47
library work;
48
 
49
entity axil2wb is
50
 
51
  generic (
52
    ADRWIDTH  : integer := 15;
53
    DATAWIDTH : integer := 32);
54
 
55
  port (
56
    ---------------------------------------------------------------------------
57
    -- AXI Interface
58
    ---------------------------------------------------------------------------
59
    -- Clock and Reset
60
    S_AXI_ACLK    : in  std_logic;
61
    S_AXI_ARESETN : in  std_logic;
62
    -- Write Address Channel
63
    S_AXI_AWADDR  : in  std_logic_vector(ADRWIDTH-1 downto 0);
64
    S_AXI_AWVALID : in  std_logic;
65
    S_AXI_AWREADY : out std_logic;
66
    -- Write Data Channel
67
    S_AXI_WDATA   : in  std_logic_vector(31 downto 0);
68
    S_AXI_WSTRB   : in  std_logic_vector(3 downto 0);
69
    S_AXI_WVALID  : in  std_logic;
70
    S_AXI_WREADY  : out std_logic;
71
    -- Read Address Channel
72
    S_AXI_ARADDR  : in  std_logic_vector(ADRWIDTH-1 downto 0);
73
    S_AXI_ARVALID : in  std_logic;
74
    S_AXI_ARREADY : out std_logic;
75
    -- Read Data Channel
76
    S_AXI_RDATA   : out std_logic_vector(31 downto 0);
77
    S_AXI_RRESP   : out std_logic_vector(1 downto 0);
78
    S_AXI_RVALID  : out std_logic;
79
    S_AXI_RREADY  : in  std_logic;
80
    -- Write Response Channel
81
    S_AXI_BRESP   : out std_logic_vector(1 downto 0);
82
    S_AXI_BVALID  : out std_logic;
83
    S_AXI_BREADY  : in  std_logic;
84
    -- Here we have the WB ports
85
    -- The clock and reset are comming from AXI!
86
    wb_clk_o      : out std_logic;
87
    wb_rst_o      : out std_logic;
88
    -- master_ipb_out - flattened due to Vivado inability to handle user types
89
    -- in BD
90
    wb_addr_o     : out std_logic_vector(31 downto 0);
91
    wb_dat_o      : out std_logic_vector(31 downto 0);
92
    wb_we_o       : out std_logic;
93
    wb_sel_o      : out std_logic_vector(3 downto 0);
94
    wb_stb_o      : out std_logic;
95
    wb_cyc_o      : out std_logic;
96
    -- master_ipb_in -  flattened due to Vivado inability to handle user types
97
    -- in BD
98
    wb_dat_i      : in  std_logic_vector(31 downto 0);
99
    wb_err_i      : in  std_logic;  -- Not used in figure 1-2 in specification!
100
    wb_ack_i      : in  std_logic
101
    );
102
 
103
end entity axil2wb;
104
 
105
architecture beh of axil2wb is
106
 
107
  function a_axi2wb (
108
    constant axi_addr : std_logic_vector(ADRWIDTH-1 downto 0))
109
    return std_logic_vector is
110
    variable wb_addr : std_logic_vector(31 downto 0);
111
  begin  -- function a_axi2wb
112
    wb_addr                      := (others => '0');
113
    -- Divide the address by 4 (we use word addresses, not the byte addresses)
114
    wb_addr(ADRWIDTH-3 downto 0) := axi_addr(ADRWIDTH-1 downto 2);
115
    return wb_addr;
116
  end function a_axi2wb;
117
 
118
  signal read_wait, read_wait_in, write_wait, write_wait_in : boolean                                := false;
119
  signal rdata, rdata_in, addr, addr_in, wdata, wdata_in    : std_logic_vector(DATAWIDTH-1 downto 0) := (others => '0');
120
  signal bresp, rresp, bresp_in, rresp_in                   : std_logic_vector(1 downto 0)           := "00";
121
  signal del_bresp, del_rresp, del_bresp_in, del_rresp_in   : boolean                                := false;
122
 
123
begin  -- architecture beh
124
 
125
  wb_clk_o <= S_AXI_ACLK;
126
  wb_rst_o <= S_AXI_ARESETN;
127
  wb_sel_o <= (others => '1');          -- We support only whole word accesses
128
 
129
  qq : process (S_AXI_ARADDR, S_AXI_ARVALID, S_AXI_AWADDR, S_AXI_AWVALID,
130
                S_AXI_BREADY, S_AXI_RREADY, S_AXI_WDATA, S_AXI_WSTRB,
131
                S_AXI_WVALID, addr, bresp, del_bresp, del_rresp, rdata,
132
                read_wait, rresp, wb_ack_i, wb_dat_i, wb_err_i, wdata,
133
                write_wait) is
134
    variable is_read, is_write : boolean := false;
135
  begin  -- process qq
136
    -- Defaults
137
    is_read       := false;
138
    is_write      := false;
139
    wb_stb_o      <= '0';
140
    wb_addr_o     <= (others => '0');
141
    wb_dat_o      <= (others => '0');
142
    wb_we_o       <= '0';
143
    wb_cyc_o      <= '0';
144
    -- Flags handling delayed acceptance of results
145
    del_bresp_in  <= del_bresp;
146
    del_rresp_in  <= del_rresp;
147
    -- Registers storing the results
148
    bresp_in      <= bresp;
149
    rresp_in      <= rresp;
150
    rdata_in      <= rdata;
151
    wdata_in      <= wdata;
152
    read_wait_in  <= read_wait;
153
    write_wait_in <= write_wait;
154
    addr_in       <= addr;
155
    S_AXI_BVALID  <= '0';
156
    S_AXI_BRESP   <= (others => '0');
157
    S_AXI_ARREADY <= '0';
158
    S_AXI_RVALID  <= '0';
159
    S_AXI_RDATA   <= (others => '0');
160
    S_AXI_RRESP   <= (others => '0');
161
    S_AXI_AWREADY <= '0';
162
    S_AXI_WREADY  <= '0';
163
 
164
    -- Real processing
165
    -- Handling of delayed responses
166
    if del_bresp then
167
      S_AXI_BRESP  <= bresp;
168
      S_AXI_BVALID <= '1';
169
      if S_AXI_BREADY = '1' then
170
        del_bresp_in <= false;
171
      end if;
172
    elsif del_rresp then
173
      S_AXI_RRESP  <= rresp;
174
      S_AXI_RDATA  <= rdata;
175
      S_AXI_RVALID <= '1';
176
      if S_AXI_RREADY = '1' then
177
        del_rresp_in <= false;
178
      end if;
179
    -- Handling of new transactions
180
    elsif (S_AXI_AWVALID = '1' and S_AXI_WVALID = '1') or write_wait then
181
      is_write := true;
182
    elsif S_AXI_ARVALID = '1' or read_wait then
183
      is_read := true;
184
    end if;
185
    -- Set the IPbus signals
186
    if is_write then
187
      -- Check if this is a new transmission
188
      if S_AXI_AWVALID = '1' and S_AXI_WVALID = '1' and write_wait = false then
189
        -- This is a new transmission
190
        -- Check if this is a correct 32-bit write
191
        if S_AXI_WSTRB /= "1111" then
192
          -- Erroneouos write. If slave is ready to accept status, inform about it
193
          S_AXI_AWREADY <= '1';
194
          S_AXI_WREADY  <= '1';
195
          S_AXI_BRESP   <= "10";
196
          S_AXI_BVALID  <= '1';
197
          if S_AXI_BREADY = '0' then
198
            -- Prepare delayed response
199
            bresp_in     <= "10";
200
            del_bresp_in <= true;
201
          end if;
202
        else
203
          -- Correct write
204
          -- Write transaction on IPbus
205
          wb_addr_o     <= a_axi2wb(S_AXI_AWADDR);
206
          wb_dat_o      <= S_AXI_WDATA;
207
          wb_stb_o      <= '1';
208
          wb_cyc_o      <= '1';
209
          wb_we_o       <= '1';
210
          -- Store data for the next cycles
211
          addr_in       <= a_axi2wb(S_AXI_AWADDR);
212
          wdata_in      <= S_AXI_WDATA;
213
          S_AXI_AWREADY <= '1';
214
          S_AXI_WREADY  <= '1';
215
          write_wait_in <= true;
216
        end if;
217
      else
218
        -- This the next cycle of the write transmission
219
        wb_addr_o <= addr;
220
        wb_dat_o  <= wdata;
221
        wb_stb_o  <= '1';
222
        wb_cyc_o  <= '1';
223
        wb_we_o   <= '1';
224
      end if;
225
      -- Check the slave response
226
      if wb_err_i = '1' then
227
        write_wait_in <= false;
228
        S_AXI_BRESP   <= "10";
229
        S_AXI_BVALID  <= '1';
230
        if S_AXI_BREADY = '0' then
231
          -- Prepare delayed response
232
          bresp_in     <= "10";
233
          del_bresp_in <= true;
234
        end if;
235
      elsif wb_ack_i = '1' then
236
        write_wait_in <= false;
237
        S_AXI_BRESP   <= "00";
238
        S_AXI_BVALID  <= '1';
239
        if S_AXI_BREADY = '0' then
240
          -- Prepare delayed response
241
          bresp_in     <= "00";
242
          del_bresp_in <= true;
243
        end if;
244
      end if;
245
    elsif is_read then
246
      -- Read transaction on IPbus
247
      if S_AXI_ARVALID = '1' and read_wait = false then
248
        addr_in       <= a_axi2wb(S_AXI_ARADDR);
249
        wb_addr_o     <= a_axi2wb(S_AXI_ARADDR);
250
        S_AXI_ARREADY <= '1';
251
        -- Remember that we are in read
252
        read_wait_in  <= true;
253
      else
254
        wb_addr_o <= addr;
255
      end if;
256
      wb_stb_o <= '1';
257
      wb_cyc_o <= '1';
258
      wb_we_o  <= '0';
259
      -- Check the slave response
260
      if wb_err_i = '1' then
261
        S_AXI_RRESP  <= "10";
262
        S_AXI_RDATA  <= wb_dat_i;
263
        S_AXI_RVALID <= '1';
264
        read_wait_in <= false;
265
        if S_AXI_RREADY = '0' then
266
          -- Prepare delayed response
267
          rresp_in     <= "10";
268
          rdata_in     <= wb_dat_i;
269
          del_rresp_in <= true;
270
        end if;
271
      elsif wb_ack_i = '1' then
272
        S_AXI_RRESP  <= "00";
273
        S_AXI_RDATA  <= wb_dat_i;
274
        S_AXI_RVALID <= '1';
275
        read_wait_in <= false;
276
        if S_AXI_RREADY = '0' then
277
          -- Prepare delayed response
278
          rresp_in     <= "00";
279
          rdata_in     <= wb_dat_i;
280
          del_rresp_in <= true;
281
        end if;
282
      end if;
283
    end if;
284
  end process qq;
285
 
286
  process (S_AXI_ACLK) is
287
  begin  -- process
288
    if S_AXI_ACLK'event and S_AXI_ACLK = '1' then  -- rising clock edge
289
      if S_AXI_ARESETN = '0' then       -- synchronous reset (active low)
290
        del_rresp  <= false;
291
        del_bresp  <= false;
292
        rdata      <= (others => '0');
293
        wdata      <= (others => '0');
294
        rresp      <= (others => '0');
295
        bresp      <= (others => '0');
296
        addr       <= (others => '0');
297
        read_wait  <= false;
298
        write_wait <= false;
299
      else
300
        del_rresp  <= del_rresp_in;
301
        del_bresp  <= del_bresp_in;
302
        addr       <= addr_in;
303
        rdata      <= rdata_in;
304
        wdata      <= wdata_in;
305
        rresp      <= rresp_in;
306
        bresp      <= bresp_in;
307
        read_wait  <= read_wait_in;
308
        write_wait <= write_wait_in;
309
      end if;
310
    end if;
311
  end process;
312
 
313
 
314
end architecture beh;

powered by: WebSVN 2.1.0

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