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

Subversion Repositories wb_vga

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

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

Line No. Rev Author Line
1 7 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
library synopsys;
27
use synopsys.std_logic_arith.all;
28
 
29
entity wb_bus_dnsize is
30
        generic (
31
                m_bus_width: positive := 32; -- master bus width
32
                m_addr_width: positive := 20; -- master bus width
33
                s_bus_width: positive := 16; -- slave bus width
34
                s_addr_width: positive := 21; -- master bus width
35
                little_endien: boolean := true -- if set to false, big endien
36
        );
37
        port (
38
--              clk_i: in std_logic;
39
--              rst_i: in std_logic := '0';
40
 
41
                -- Master bus interface
42
                m_adr_i: in std_logic_vector (m_addr_width-1 downto 0);
43
                m_sel_i: in std_logic_vector ((m_bus_width/8)-1 downto 0) := (others => '1');
44
                m_dat_i: in std_logic_vector (m_bus_width-1 downto 0);
45
                m_dat_oi: in std_logic_vector (m_bus_width-1 downto 0) := (others => '-');
46
                m_dat_o: out std_logic_vector (m_bus_width-1 downto 0);
47
                m_cyc_i: in std_logic;
48
                m_ack_o: out std_logic;
49
                m_ack_oi: in std_logic := '-';
50
                m_err_o: out std_logic;
51
                m_err_oi: in std_logic := '-';
52
                m_rty_o: out std_logic;
53
                m_rty_oi: in std_logic := '-';
54
                m_we_i: in std_logic;
55
                m_stb_i: in std_logic;
56
 
57
                -- Slave bus interface
58
                s_adr_o: out std_logic_vector (s_addr_width-1 downto 0);
59
                s_sel_o: out std_logic_vector ((s_bus_width/8)-1 downto 0);
60
                s_dat_i: in std_logic_vector (s_bus_width-1 downto 0);
61
                s_dat_o: out std_logic_vector (s_bus_width-1 downto 0);
62
                s_cyc_o: out std_logic;
63
                s_ack_i: in std_logic;
64
                s_err_i: in std_logic := '-';
65
                s_rty_i: in std_logic := '-';
66
                s_we_o: out std_logic;
67
                s_stb_o: out std_logic
68
        );
69
end wb_bus_dnsize;
70
 
71
architecture wb_bus_dnsize of wb_bus_dnsize is
72
        constant addr_diff: integer := log2(m_bus_width/s_bus_width);
73
        constant mux_mask: integer := ((m_bus_width / 8)-1) - ((s_bus_width/8)-1);
74
        signal i_m_dat_o: std_logic_vector(m_bus_width-1 downto 0);
75
        signal mux_sel: std_logic_vector(log2(m_sel_i'HIGH+1)-1 downto 0);
76
        signal i_mux_sel: integer := 0;
77
 
78
        function prior_decode(inp: std_logic_vector) return integer is
79
        begin
80
--          variable ret: std_logic_vector(log2(inp'HIGH)-1 downto 0) := (others = '1');
81
            for i in inp'HIGH downto 0 loop
82
                if (inp(i) = '1') then
83
                    return i;
84
                end if;
85
            end loop;
86
            return inp'HIGH;
87
        end;
88
begin
89
        assert (s_addr_width = m_addr_width+addr_diff) report "Address widths are not consistent" severity FAILURE;
90
 
91
    -- Reconstructing address bits (mux_sel)    
92
        compute_mux_sel: process is
93
                variable i: integer;
94
        begin
95
            wait on m_sel_i;
96
            i := prior_decode(m_sel_i);
97
                mux_sel <= CONV_STD_LOGIC_VECTOR(i,log2(m_sel_i'HIGH+1)) and CONV_STD_LOGIC_VECTOR(mux_mask,log2(m_sel_i'HIGH+1));
98
        end process;
99
    i_mux_sel <= CONV_INTEGER(mux_sel);
100
 
101
 
102
    -- create slave address bus
103
        s_adr_o(s_addr_width-1 downto addr_diff) <= m_adr_i;
104
        s_adr_o_gen: process is
105
                variable all_ones: std_logic_vector(addr_diff-1 downto 0) := (others => '1');
106
        begin
107
                wait on mux_sel(mux_sel'HIGH downto mux_sel'HIGH-addr_diff+1);
108
                if (little_endien) then
109
                s_adr_o(addr_diff-1 downto 0) <= mux_sel(mux_sel'HIGH downto mux_sel'HIGH-addr_diff+1);
110
        else
111
                s_adr_o(addr_diff-1 downto 0) <= all_ones-mux_sel(mux_sel'HIGH downto mux_sel'HIGH-addr_diff+1);
112
        end if;
113
    end process;
114
 
115
        -- create output byte select signals
116
    s_sel_o <= m_sel_i(i_mux_sel+(s_bus_width/8)-1 downto i_mux_sel);
117
 
118
 
119
        s_we_o <= m_we_i;
120
        m_ack_o <= (m_stb_i and s_ack_i) or (not m_stb_i and m_ack_oi);
121
        m_err_o <= (m_stb_i and s_err_i) or (not m_stb_i and m_err_oi);
122
        m_rty_o <= (m_stb_i and s_rty_i) or (not m_stb_i and m_rty_oi);
123
        s_stb_o <= m_stb_i;
124
        s_cyc_o <= m_cyc_i;
125
 
126
    -- Multiplex data-bus down to the slave width
127
    s_dat_o <= m_dat_i((i_mux_sel)*8-1+s_bus_width downto (i_mux_sel)*8);
128
 
129
        m_dat_o_mux: process is
130
        begin
131
                wait on m_dat_oi, s_dat_i, i_mux_sel, m_stb_i, m_we_i;
132
                m_dat_o <= m_dat_oi;
133
                if (m_stb_i = '1' and m_we_i = '0') then
134
                m_dat_o((i_mux_sel)*8-1+s_bus_width downto (i_mux_sel)*8) <= s_dat_i;
135
                end if;
136
        end process;
137
end wb_bus_dnsize;
138
 

powered by: WebSVN 2.1.0

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