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

Subversion Repositories wb_tk

[/] [wb_tk/] [trunk/] [wb_bus_dnsize.vhd] - Blame information for rev 7

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 tantos
--
2
--  Wishbone bus toolkit.
3
--
4
--  (c) Copyright Andras Tantos <andras_tantos@yahoo.com> 2001/03/31
5
--  This code is distributed under the terms and conditions of the GNU General Public Lince.
6
--
7
--
8
-- ELEMENTS:
9
--   wb_bus_dnsize: bus downsizer.
10
--   doesn't split access cycles so granularity on the input bus must not be greater than
11
--   the width of the output bus.
12
 
13
-------------------------------------------------------------------------------
14
--
15
--  wb_bus_upsize
16
--
17
-------------------------------------------------------------------------------
18
 
19
library IEEE;
20
use IEEE.std_logic_1164.all;
21
use IEEE.STD_LOGIC_UNSIGNED.all;
22
 
23
library wb_tk;
24
use wb_tk.technology.all;
25
 
26
entity wb_bus_dnsize is
27
        generic (
28 6 tantos
                m_dat_width: positive := 32; -- master bus width
29
                m_adr_width: positive := 20; -- master bus width
30
                s_dat_width: positive := 16; -- slave bus width
31
                s_adr_width: positive := 21; -- master bus width
32 4 tantos
                little_endien: boolean := true -- if set to false, big endien
33
        );
34
        port (
35
--              clk_i: in std_logic;
36
--              rst_i: in std_logic := '0';
37
 
38
                -- Master bus interface
39 6 tantos
                m_adr_i: in std_logic_vector (m_adr_width-1 downto 0);
40
                m_sel_i: in std_logic_vector ((m_dat_width/8)-1 downto 0) := (others => '1');
41
                m_dat_i: in std_logic_vector (m_dat_width-1 downto 0);
42
                m_dat_oi: in std_logic_vector (m_dat_width-1 downto 0) := (others => '-');
43
                m_dat_o: out std_logic_vector (m_dat_width-1 downto 0);
44 4 tantos
                m_cyc_i: in std_logic;
45
                m_ack_o: out std_logic;
46
                m_ack_oi: in std_logic := '-';
47
                m_err_o: out std_logic;
48
                m_err_oi: in std_logic := '-';
49
                m_rty_o: out std_logic;
50
                m_rty_oi: in std_logic := '-';
51
                m_we_i: in std_logic;
52
                m_stb_i: in std_logic;
53
 
54
                -- Slave bus interface
55 6 tantos
                s_adr_o: out std_logic_vector (s_adr_width-1 downto 0);
56
                s_sel_o: out std_logic_vector ((s_dat_width/8)-1 downto 0);
57
                s_dat_i: in std_logic_vector (s_dat_width-1 downto 0);
58
                s_dat_o: out std_logic_vector (s_dat_width-1 downto 0);
59 4 tantos
                s_cyc_o: out std_logic;
60
                s_ack_i: in std_logic;
61
                s_err_i: in std_logic := '-';
62
                s_rty_i: in std_logic := '-';
63
                s_we_o: out std_logic;
64
                s_stb_o: out std_logic
65
        );
66
end wb_bus_dnsize;
67
 
68
architecture wb_bus_dnsize of wb_bus_dnsize is
69 6 tantos
        constant addr_diff: integer := log2(m_dat_width/s_dat_width);
70
        constant mux_mask: integer := ((m_dat_width / 8)-1) - ((s_dat_width/8)-1);
71
        signal i_m_dat_o: std_logic_vector(m_dat_width-1 downto 0);
72 4 tantos
        signal mux_sel: std_logic_vector(log2(m_sel_i'HIGH+1)-1 downto 0);
73
        signal i_mux_sel: integer := 0;
74 6 tantos
 
75 4 tantos
        function prior_decode(inp: std_logic_vector) return integer is
76
        begin
77
--          variable ret: std_logic_vector(log2(inp'HIGH)-1 downto 0) := (others = '1');
78 6 tantos
                for i in inp'HIGH downto 0 loop
79
                        if (inp(i) = '1') then
80
                                return i;
81
                        end if;
82
                end loop;
83
                return inp'HIGH;
84 4 tantos
        end;
85
begin
86 6 tantos
        assert (s_adr_width = m_adr_width+addr_diff) report "Address widths are not consistent" severity FAILURE;
87 4 tantos
 
88 6 tantos
        -- Reconstructing address bits (mux_sel)
89
        compute_mux_sel: process(m_sel_i)
90 4 tantos
                variable i: integer;
91
        begin
92 6 tantos
--              wait on m_sel_i;
93
                i := prior_decode(m_sel_i);
94
                mux_sel <= to_std_logic_vector(i,log2(m_sel_i'HIGH+1)) and to_std_logic_vector(mux_mask,log2(m_sel_i'HIGH+1));
95 4 tantos
        end process;
96 6 tantos
        i_mux_sel <= to_integer(mux_sel);
97 4 tantos
 
98 6 tantos
 
99
        -- create slave address bus
100
        s_adr_o(s_adr_width-1 downto addr_diff) <= m_adr_i;
101
        s_adr_o_gen: process
102 4 tantos
                variable all_ones: std_logic_vector(addr_diff-1 downto 0) := (others => '1');
103
        begin
104 6 tantos
--:::TA This does not work under webpack. Re-simulate!!!!
105
--              wait on mux_sel(mux_sel'HIGH downto mux_sel'HIGH-addr_diff+1);
106
                wait on mux_sel;
107 4 tantos
                if (little_endien) then
108 6 tantos
                        s_adr_o(addr_diff-1 downto 0) <= mux_sel(mux_sel'HIGH downto mux_sel'HIGH-addr_diff+1);
109
                else
110
                        s_adr_o(addr_diff-1 downto 0) <= all_ones-mux_sel(mux_sel'HIGH downto mux_sel'HIGH-addr_diff+1);
111
                end if;
112
        end process;
113
 
114 4 tantos
        -- create output byte select signals
115 6 tantos
        s_sel_o <= m_sel_i(i_mux_sel+(s_dat_width/8)-1 downto i_mux_sel);
116 4 tantos
 
117 6 tantos
 
118 4 tantos
        s_we_o <= m_we_i;
119
        m_ack_o <= (m_stb_i and s_ack_i) or (not m_stb_i and m_ack_oi);
120
        m_err_o <= (m_stb_i and s_err_i) or (not m_stb_i and m_err_oi);
121
        m_rty_o <= (m_stb_i and s_rty_i) or (not m_stb_i and m_rty_oi);
122
        s_stb_o <= m_stb_i;
123
        s_cyc_o <= m_cyc_i;
124 6 tantos
 
125
        -- Multiplex data-bus down to the slave width
126
        s_dat_o <= m_dat_i((i_mux_sel)*8-1+s_dat_width downto (i_mux_sel)*8);
127
 
128
        m_dat_o_mux: process
129 4 tantos
        begin
130
                wait on m_dat_oi, s_dat_i, i_mux_sel, m_stb_i, m_we_i;
131
                m_dat_o <= m_dat_oi;
132
                if (m_stb_i = '1' and m_we_i = '0') then
133 6 tantos
                        m_dat_o((i_mux_sel)*8-1+s_dat_width downto (i_mux_sel)*8) <= s_dat_i;
134 4 tantos
                end if;
135
        end process;
136
end wb_bus_dnsize;
137
 

powered by: WebSVN 2.1.0

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