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

Subversion Repositories neo430

[/] [neo430/] [trunk/] [neo430/] [rtl/] [core/] [neo430_wb_interface.vhd] - Blame information for rev 198

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 198 zero_gravi
-- #################################################################################################
2
-- # << NEO430 - 32-bit Wishbone Bus Interface Adapter >>                                          #
3
-- # ********************************************************************************************* #
4
-- # BSD 3-Clause License                                                                          #
5
-- #                                                                                               #
6
-- # Copyright (c) 2020, Stephan Nolting. All rights reserved.                                     #
7
-- #                                                                                               #
8
-- # Redistribution and use in source and binary forms, with or without modification, are          #
9
-- # permitted provided that the following conditions are met:                                     #
10
-- #                                                                                               #
11
-- # 1. Redistributions of source code must retain the above copyright notice, this list of        #
12
-- #    conditions and the following disclaimer.                                                   #
13
-- #                                                                                               #
14
-- # 2. Redistributions in binary form must reproduce the above copyright notice, this list of     #
15
-- #    conditions and the following disclaimer in the documentation and/or other materials        #
16
-- #    provided with the distribution.                                                            #
17
-- #                                                                                               #
18
-- # 3. Neither the name of the copyright holder nor the names of its contributors may be used to  #
19
-- #    endorse or promote products derived from this software without specific prior written      #
20
-- #    permission.                                                                                #
21
-- #                                                                                               #
22
-- # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS   #
23
-- # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF               #
24
-- # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE    #
25
-- # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,     #
26
-- # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE #
27
-- # GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED    #
28
-- # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING     #
29
-- # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED  #
30
-- # OF THE POSSIBILITY OF SUCH DAMAGE.                                                            #
31
-- # ********************************************************************************************* #
32
-- # The NEO430 Processor - https://github.com/stnolting/neo430                                    #
33
-- #################################################################################################
34
 
35
library ieee;
36
use ieee.std_logic_1164.all;
37
use ieee.numeric_std.all;
38
 
39
library neo430;
40
use neo430.neo430_package.all;
41
 
42
entity neo430_wb_interface is
43
  port (
44
    -- host access --
45
    clk_i    : in  std_ulogic; -- global clock line
46
    rden_i   : in  std_ulogic; -- read enable
47
    wren_i   : in  std_ulogic; -- write enable
48
    addr_i   : in  std_ulogic_vector(15 downto 0); -- address
49
    data_i   : in  std_ulogic_vector(15 downto 0); -- data in
50
    data_o   : out std_ulogic_vector(15 downto 0); -- data out
51
    -- wishbone interface --
52
    wb_adr_o : out std_ulogic_vector(31 downto 0); -- address
53
    wb_dat_i : in  std_ulogic_vector(31 downto 0); -- read data
54
    wb_dat_o : out std_ulogic_vector(31 downto 0); -- write data
55
    wb_we_o  : out std_ulogic; -- read/write
56
    wb_sel_o : out std_ulogic_vector(03 downto 0); -- byte enable
57
    wb_stb_o : out std_ulogic; -- strobe
58
    wb_cyc_o : out std_ulogic; -- valid cycle
59
    wb_ack_i : in  std_ulogic  -- transfer acknowledge
60
  );
61
end neo430_wb_interface;
62
 
63
architecture neo430_wb_interface_rtl of neo430_wb_interface is
64
 
65
  -- IO space: module base address --
66
  constant hi_abb_c : natural := index_size_f(io_size_c)-1; -- high address boundary bit
67
  constant lo_abb_c : natural := index_size_f(wb32_size_c); -- low address boundary bit
68
 
69
  -- control reg bits --
70
  constant ctrl_byte_en0_c : natural :=  0; -- -/w: wishbone data byte enable bit 0
71
  constant ctrl_byte_en1_c : natural :=  1; -- -/w: wishbone data byte enable bit 1
72
  constant ctrl_byte_en2_c : natural :=  2; -- -/w: wishbone data byte enable bit 2
73
  constant ctrl_byte_en3_c : natural :=  3; -- -/w: wishbone data byte enable bit 3
74
  constant ctrl_pending_c  : natural := 15; -- r/-: pending wb transfer
75
 
76
  -- access control --
77
  signal acc_en : std_ulogic; -- module access enable
78
  signal addr   : std_ulogic_vector(15 downto 0); -- access address
79
  signal wr_en  : std_ulogic;
80
 
81
  -- accessible regs --
82
  signal wb_addr   : std_ulogic_vector(31 downto 0);
83
  signal wb_rdata  : std_ulogic_vector(31 downto 0);
84
  signal wb_wdata  : std_ulogic_vector(31 downto 0);
85
  signal pending   : std_ulogic; -- pending transfer?
86
  signal byte_en   : std_ulogic_vector(03 downto 0);
87
 
88
  -- misc --
89
  signal enable : std_ulogic;
90
 
91
begin
92
 
93
  -- Access control -----------------------------------------------------------
94
  -- -----------------------------------------------------------------------------
95
  acc_en <= '1' when (addr_i(hi_abb_c downto lo_abb_c) = wb32_base_c(hi_abb_c downto lo_abb_c)) else '0';
96
  addr   <= wb32_base_c(15 downto lo_abb_c) & addr_i(lo_abb_c-1 downto 1) & '0'; -- word aligned
97
  wr_en  <= acc_en and wren_i;
98
 
99
 
100
  -- Write access -------------------------------------------------------------
101
  -- -----------------------------------------------------------------------------
102
  wr_access: process(clk_i)
103
  begin
104
    if rising_edge(clk_i) then
105
      if (wr_en = '1') then -- valid word write
106
        if (addr = wb32_rd_adr_lo_addr_c) then
107
          wb_addr(15 downto 0) <= data_i;
108
          wb_we_o <= '0';
109
        end if;
110
        if (addr = wb32_rd_adr_hi_addr_c) then
111
          wb_addr(31 downto 16) <= data_i;
112
          wb_we_o <= '0';
113
        end if;
114
        if (addr = wb32_wr_adr_lo_addr_c) then
115
          wb_addr(15 downto 0) <= data_i;
116
          wb_we_o <= '1';
117
        end if;
118
        if (addr = wb32_wr_adr_hi_addr_c) then
119
          wb_addr(31 downto 16) <= data_i;
120
          wb_we_o <= '1';
121
        end if;
122
        if (addr = wb32_data_lo_addr_c) then
123
          wb_wdata(15 downto 0) <= data_i;
124
        end if;
125
        if (addr = wb32_data_hi_addr_c) then
126
          wb_wdata(31 downto 16) <= data_i;
127
        end if;
128
        if (addr = wb32_ctrl_addr_c) then
129
          byte_en(0) <= data_i(ctrl_byte_en0_c);
130
          byte_en(1) <= data_i(ctrl_byte_en1_c);
131
          byte_en(2) <= data_i(ctrl_byte_en2_c);
132
          byte_en(3) <= data_i(ctrl_byte_en3_c);
133
        end if;
134
      end if;
135
    end if;
136
  end process wr_access;
137
 
138
  -- direct output --
139
  wb_adr_o <= wb_addr; -- address
140
  wb_dat_o <= wb_wdata; -- write data
141
  wb_sel_o <= byte_en; -- byte enable
142
 
143
 
144
  -- Access arbiter -------------------------------------------------------------
145
  -- -----------------------------------------------------------------------------
146
  arbiter: process(clk_i)
147
  begin
148
    if rising_edge(clk_i) then
149
      -- trigger transfer --
150
      if (pending = '0') or (enable = '0') then
151
        wb_stb_o <= '0';
152
        pending  <= '0';
153
        if (wr_en = '1') and (enable = '1') and ((addr_i = wb32_rd_adr_hi_addr_c) or (addr_i = wb32_wr_adr_hi_addr_c)) then
154
          wb_stb_o <= '1';
155
          pending  <= '1';
156
        end if;
157
      else -- transfer in progress
158
        wb_stb_o <= '0'; -- use ONLY standard/classic cycle with single-cycle STB assertion!!
159
        -- waiting for ACK
160
        if (wb_ack_i = '1') then
161
          wb_rdata <= wb_dat_i; -- sample input data
162
          wb_stb_o <= '0';
163
          pending  <= '0';
164
        end if;
165
      end if;
166
    end if;
167
  end process arbiter;
168
 
169
  -- device actually in use? --
170
  enable <= or_all_f(byte_en);
171
 
172
  -- valid cycle signal --
173
  wb_cyc_o <= pending;
174
 
175
 
176
  -- Read access --------------------------------------------------------------
177
  -- -----------------------------------------------------------------------------
178
  rd_access: process(clk_i)
179
  begin
180
    if rising_edge(clk_i) then
181
      data_o <= (others => '0');
182
      if (rden_i = '1') and (acc_en = '1') then
183
        if (addr = wb32_data_lo_addr_c) then
184
          data_o <= wb_rdata(15 downto 00);
185
        elsif (addr = wb32_data_hi_addr_c) then
186
          data_o <= wb_rdata(31 downto 16);
187
        else -- when wb32_ctrl_addr_c =>
188
          data_o(ctrl_pending_c) <= pending;
189
        end if;
190
      end if;
191
    end if;
192
  end process rd_access;
193
 
194
 
195
end neo430_wb_interface_rtl;

powered by: WebSVN 2.1.0

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