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

Subversion Repositories ax4lbr

[/] [ax4lbr/] [trunk/] [rtl/] [axil2ipb.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      : axil2ipb
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 -> IPbus bridge
16
-------------------------------------------------------------------------------
17
-- Copyright (c) 2016 
18
-------------------------------------------------------------------------------
19
-- Revisions  :
20
-- Date        Version  Author  Description
21
-- 2016-04-24  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
-- The IPbus implementation is based on the description provided in
30
-- "Notes on Firmware Implementation of an IPbus SoC Bus"
31
-- available at:
32
-- https://svnweb.cern.ch/trac/cactus/export/32752/trunk/doc/IPbus_firmware_notes.pdf
33
 
34
-------------------------------------------------------------------------------
35
-- Implementation details
36
-------------------------------------------------------------------------------
37
-- In the AXI bus the read and write accesses may be handled independently
38
-- In the IPbus they can't therefore we must provide an arbitration scheme.
39
-- We assume "Write before read"
40
-- 
41
-- We must avoid duplicated writes and reads (which may corruppt e.g.
42
-- FIFO slaves at IPbus!)
43
--
44
-- Additionally the IPbus uses the word adressing, while AXI uses the byte
45
-- addressing. That is handled by the function a_axi2ipb, which additionally
46
-- zeroes bits not used by the IPbus segment...
47
 
48
 
49
 
50
library IEEE;
51
use IEEE.STD_LOGIC_1164.all;
52
library work;
53
use work.ipbus.all;
54
 
55
entity axil2ipb is
56
 
57
  generic (
58
    ADRWIDTH : integer := 15);
59
 
60
  port (
61
    ---------------------------------------------------------------------------
62
    -- AXI Interface
63
    ---------------------------------------------------------------------------
64
    -- Clock and Reset
65
    S_AXI_ACLK    : in  std_logic;
66
    S_AXI_ARESETN : in  std_logic;
67
    -- Write Address Channel
68
    S_AXI_AWADDR  : in  std_logic_vector(ADRWIDTH-1 downto 0);
69
    S_AXI_AWVALID : in  std_logic;
70
    S_AXI_AWREADY : out std_logic;
71
    -- Write Data Channel
72
    S_AXI_WDATA   : in  std_logic_vector(31 downto 0);
73
    S_AXI_WSTRB   : in  std_logic_vector(3 downto 0);
74
    S_AXI_WVALID  : in  std_logic;
75
    S_AXI_WREADY  : out std_logic;
76
    -- Read Address Channel
77
    S_AXI_ARADDR  : in  std_logic_vector(ADRWIDTH-1 downto 0);
78
    S_AXI_ARVALID : in  std_logic;
79
    S_AXI_ARREADY : out std_logic;
80
    -- Read Data Channel
81
    S_AXI_RDATA   : out std_logic_vector(31 downto 0);
82
    S_AXI_RRESP   : out std_logic_vector(1 downto 0);
83
    S_AXI_RVALID  : out std_logic;
84
    S_AXI_RREADY  : in  std_logic;
85
    -- Write Response Channel
86
    S_AXI_BRESP   : out std_logic_vector(1 downto 0);
87
    S_AXI_BVALID  : out std_logic;
88
    S_AXI_BREADY  : in  std_logic;
89
    -- Here we have the IPbus ports
90
    ipb_clk       : out std_logic;
91
    ipb_rst       : out std_logic;
92
    -- master_ipb_out - flattened due to Vivado inability to handle user types
93
    -- in BD
94
    ipb_addr      : out std_logic_vector(31 downto 0);
95
    ipb_wdata     : out std_logic_vector(31 downto 0);
96
    ipb_strobe    : out std_logic;
97
    ipb_write     : out std_logic;
98
    -- master_ipb_in -  flattened due to Vivado inability to handle user types
99
    -- in BD
100
    ipb_rdata     : in  std_logic_vector(31 downto 0);
101
    ipb_ack       : in  std_logic;
102
    ipb_err       :     std_logic
103
    );
104
 
105
end entity axil2ipb;
106
 
107
architecture beh of axil2ipb is
108
 
109
  function a_axi2ipb (
110
    constant axi_addr : std_logic_vector(ADRWIDTH-1 downto 0))
111
    return std_logic_vector is
112
    variable ipb_addr : std_logic_vector(31 downto 0);
113
  begin  -- function a_axi2ipb
114
    ipb_addr                      := (others => '0');
115
    -- Divide the address by 4 (we use word addresses, not the byte addresses)
116
    ipb_addr(ADRWIDTH-3 downto 0) := axi_addr(ADRWIDTH-1 downto 2);
117
    return ipb_addr;
118
  end function a_axi2ipb;
119
 
120
  signal master_ipb_out                                     : ipb_wbus;
121
  signal master_ipb_in                                      : ipb_rbus;
122
  signal read_wait, read_wait_in, write_wait, write_wait_in : boolean                       := false;
123
  signal rdata, rdata_in, addr, addr_in, wdata, wdata_in    : std_logic_vector(31 downto 0) := (others => '0');
124
  signal bresp, rresp, bresp_in, rresp_in                   : std_logic_vector(1 downto 0)  := "00";
125
  signal del_bresp, del_rresp, del_bresp_in, del_rresp_in   : boolean                       := false;
126
 
127
begin  -- architecture beh
128
 
129
  ipb_clk    <= S_AXI_ACLK;
130
  ipb_rst    <= not S_AXI_ARESETN;
131
  -- We keep the master_ipb... signals internally in hope, that one day
132
  -- Xilinx/Vivado will be able to handle user defined records in ports of BD blocks...
133
  ipb_addr   <= master_ipb_out.ipb_addr;
134
  ipb_wdata  <= master_ipb_out.ipb_wdata;
135
  ipb_strobe <= master_ipb_out.ipb_strobe;
136
  ipb_write  <= master_ipb_out.ipb_write;
137
 
138
  master_ipb_in.ipb_rdata <= ipb_rdata;
139
  master_ipb_in.ipb_ack   <= ipb_ack;
140
  master_ipb_in.ipb_err   <= ipb_err;
141
 
142
  qq : process (S_AXI_ARADDR, S_AXI_ARVALID, S_AXI_AWADDR, S_AXI_AWVALID,
143
                S_AXI_BREADY, S_AXI_RREADY, S_AXI_WDATA, S_AXI_WSTRB,
144
                S_AXI_WVALID, addr, bresp, del_bresp, del_rresp, master_ipb_in,
145
                rdata, read_wait, rresp, wdata, write_wait) is
146
    variable is_read, is_write : boolean := false;
147
  begin  -- process qq
148
    -- Defaults
149
    is_read                   := false;
150
    is_write                  := false;
151
    master_ipb_out.ipb_strobe <= '0';
152
    master_ipb_out.ipb_addr   <= (others => '0');
153
    master_ipb_out.ipb_wdata  <= (others => '0');
154
    master_ipb_out.ipb_write  <= '0';
155
    -- Flags handling delayed acceptance of results
156
    del_bresp_in              <= del_bresp;
157
    del_rresp_in              <= del_rresp;
158
    -- Registers storing the results
159
    bresp_in                  <= bresp;
160
    rresp_in                  <= rresp;
161
    rdata_in                  <= rdata;
162
    wdata_in                  <= wdata;
163
    read_wait_in              <= read_wait;
164
    write_wait_in             <= write_wait;
165
    addr_in                   <= addr;
166
    S_AXI_BVALID              <= '0';
167
    S_AXI_BRESP               <= (others => '0');
168
    S_AXI_ARREADY             <= '0';
169
    S_AXI_RVALID              <= '0';
170
    S_AXI_RDATA               <= (others => '0');
171
    S_AXI_RRESP               <= (others => '0');
172
    S_AXI_AWREADY             <= '0';
173
    S_AXI_WREADY              <= '0';
174
 
175
    -- Real processing
176
    -- Handling of delayed responses
177
    if del_bresp then
178
      S_AXI_BRESP  <= bresp;
179
      S_AXI_BVALID <= '1';
180
      if S_AXI_BREADY = '1' then
181
        del_bresp_in <= false;
182
      end if;
183
    elsif del_rresp then
184
      S_AXI_RRESP  <= rresp;
185
      S_AXI_RDATA  <= rdata;
186
      S_AXI_RVALID <= '1';
187
      if S_AXI_RREADY = '1' then
188
        del_rresp_in <= false;
189
      end if;
190
    -- Handling of new transactions
191
    elsif (S_AXI_AWVALID = '1' and S_AXI_WVALID = '1') or write_wait then
192
      is_write := true;
193
    elsif S_AXI_ARVALID = '1' or read_wait then
194
      is_read := true;
195
    end if;
196
    -- Set the IPbus signals
197
    if is_write then
198
      -- Check if this is a new transmission
199
      if S_AXI_AWVALID = '1' and S_AXI_WVALID = '1' and write_wait = false then
200
        -- This is a new transmission
201
        -- Check if this is a correct 32-bit write
202
        if S_AXI_WSTRB /= "1111" then
203
          -- Erroneouos write. If slave is ready to accept status, inform about it
204
          S_AXI_AWREADY <= '1';
205
          S_AXI_WREADY  <= '1';
206
          S_AXI_BRESP   <= "10";
207
          S_AXI_BVALID  <= '1';
208
          if S_AXI_BREADY = '0' then
209
            -- Prepare delayed response
210
            bresp_in     <= "10";
211
            del_bresp_in <= true;
212
          end if;
213
        else
214
          -- Correct write
215
          -- Write transaction on IPbus
216
          master_ipb_out.ipb_addr   <= a_axi2ipb(S_AXI_AWADDR);
217
          master_ipb_out.ipb_wdata  <= S_AXI_WDATA;
218
          master_ipb_out.ipb_strobe <= '1';
219
          master_ipb_out.ipb_write  <= '1';
220
          -- Store data for the next cycles
221
          addr_in                   <= a_axi2ipb(S_AXI_AWADDR);
222
          wdata_in                  <= S_AXI_WDATA;
223
          S_AXI_AWREADY             <= '1';
224
          S_AXI_WREADY              <= '1';
225
          write_wait_in             <= true;
226
        end if;
227
      else
228
        -- This the next cycle of the write transmission
229
        master_ipb_out.ipb_addr   <= addr;
230
        master_ipb_out.ipb_wdata  <= wdata;
231
        master_ipb_out.ipb_strobe <= '1';
232
        master_ipb_out.ipb_write  <= '1';
233
      end if;
234
      -- Check the slave response
235
      if master_ipb_in.ipb_err = '1' then
236
        write_wait_in <= false;
237
        S_AXI_BRESP   <= "10";
238
        S_AXI_BVALID  <= '1';
239
        if S_AXI_BREADY = '0' then
240
          -- Prepare delayed response
241
          bresp_in     <= "10";
242
          del_bresp_in <= true;
243
        end if;
244
      elsif master_ipb_in.ipb_ack = '1' then
245
        write_wait_in <= false;
246
        S_AXI_BRESP   <= "00";
247
        S_AXI_BVALID  <= '1';
248
        if S_AXI_BREADY = '0' then
249
          -- Prepare delayed response
250
          bresp_in     <= "00";
251
          del_bresp_in <= true;
252
        end if;
253
      end if;
254
    elsif is_read then
255
      -- Read transaction on IPbus
256
      if S_AXI_ARVALID = '1' and read_wait = false then
257
        addr_in                 <= a_axi2ipb(S_AXI_ARADDR);
258
        master_ipb_out.ipb_addr <= a_axi2ipb(S_AXI_ARADDR);
259
        S_AXI_ARREADY           <= '1';
260
        -- Remember that we are in read
261
        read_wait_in            <= true;
262
      else
263
        master_ipb_out.ipb_addr <= addr;
264
      end if;
265
      master_ipb_out.ipb_strobe <= '1';
266
      master_ipb_out.ipb_write  <= '0';
267
      -- Check the slave response
268
      if master_ipb_in.ipb_err = '1' then
269
        S_AXI_RRESP  <= "10";
270
        S_AXI_RDATA  <= master_ipb_in.ipb_rdata;
271
        S_AXI_RVALID <= '1';
272
        read_wait_in <= false;
273
        if S_AXI_RREADY = '0' then
274
          -- Prepare delayed response
275
          rresp_in     <= "10";
276
          rdata_in     <= master_ipb_in.ipb_rdata;
277
          del_rresp_in <= true;
278
        end if;
279
      elsif master_ipb_in.ipb_ack = '1' then
280
        S_AXI_RRESP  <= "00";
281
        S_AXI_RDATA  <= master_ipb_in.ipb_rdata;
282
        S_AXI_RVALID <= '1';
283
        read_wait_in <= false;
284
        if S_AXI_RREADY = '0' then
285
          -- Prepare delayed response
286
          rresp_in     <= "00";
287
          rdata_in     <= master_ipb_in.ipb_rdata;
288
          del_rresp_in <= true;
289
        end if;
290
      end if;
291
    end if;
292
  end process qq;
293
 
294
  process (S_AXI_ACLK) is
295
  begin  -- process
296
    if S_AXI_ACLK'event and S_AXI_ACLK = '1' then  -- rising clock edge
297
      if S_AXI_ARESETN = '0' then       -- synchronous reset (active low)
298
        del_rresp  <= false;
299
        del_bresp  <= false;
300
        rdata      <= (others => '0');
301
        wdata      <= (others => '0');
302
        rresp      <= (others => '0');
303
        bresp      <= (others => '0');
304
        addr       <= (others => '0');
305
        read_wait  <= false;
306
        write_wait <= false;
307
      else
308
        del_rresp  <= del_rresp_in;
309
        del_bresp  <= del_bresp_in;
310
        addr       <= addr_in;
311
        rdata      <= rdata_in;
312
        wdata      <= wdata_in;
313
        rresp      <= rresp_in;
314
        bresp      <= bresp_in;
315
        read_wait  <= read_wait_in;
316
        write_wait <= write_wait_in;
317
      end if;
318
    end if;
319
  end process;
320
 
321
 
322
end architecture beh;

powered by: WebSVN 2.1.0

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