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

Subversion Repositories mblite

[/] [mblite/] [trunk/] [hw/] [core/] [core_address_decoder.vhd] - Blame information for rev 2

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

Line No. Rev Author Line
1 2 takar
----------------------------------------------------------------------------------------------
2
--
3
--      Input file         : core_address_decoder.vhd
4
--      Design name        : core_address_decoder
5
--      Author             : Tamar Kranenburg
6
--      Company            : Delft University of Technology
7
--                         : Faculty EEMCS, Department ME&CE
8
--                         : Systems and Circuits group
9
--
10
--      Description        : Wishbone adapter for the MB-Lite microprocessor
11
--
12
----------------------------------------------------------------------------------------------
13
 
14
LIBRARY ieee;
15
USE ieee.std_logic_1164.ALL;
16
USE ieee.std_logic_unsigned.ALL;
17
 
18
LIBRARY mblite;
19
USE mblite.config_Pkg.ALL;
20
USE mblite.core_Pkg.ALL;
21
USE mblite.std_Pkg.ALL;
22
 
23
ENTITY core_address_decoder IS GENERIC
24
(
25
    G_NUM_SLAVES : positive := CFG_NUM_SLAVES;
26
    G_MEMORY_MAP : memory_map_type := CFG_MEMORY_MAP
27
);
28
PORT
29
(
30
    m_dmem_i : OUT dmem_in_type;
31
    s_dmem_o : OUT dmem_out_array_type(G_NUM_SLAVES - 1 DOWNTO 0);
32
    m_dmem_o : IN dmem_out_type;
33
    s_dmem_i : IN dmem_in_array_type(G_NUM_SLAVES - 1 DOWNTO 0);
34
    clk_i : std_ulogic
35
);
36
END core_address_decoder;
37
 
38
ARCHITECTURE arch OF core_address_decoder IS
39
 
40
    -- Decodes the address based on the memory map. Returns "1" if 0 or 1 slave is attached.
41
    FUNCTION decode(adr : std_ulogic_vector) RETURN std_ulogic_vector IS
42
        VARIABLE result : std_ulogic_vector(G_NUM_SLAVES - 1 DOWNTO 0);
43
    BEGIN
44
        result := (OTHERS => '1');
45
        IF G_NUM_SLAVES > 1 AND notx(adr) THEN
46
            FOR i IN G_NUM_SLAVES - 1 DOWNTO 0 LOOP
47
                IF (adr >= G_MEMORY_MAP(i) AND adr < G_MEMORY_MAP(i+1)) THEN
48
                    result(i) := '1';
49
                ELSE
50
                    result(i) := '0';
51
                END IF;
52
            END LOOP;
53
        END IF;
54
        RETURN result;
55
    END FUNCTION;
56
 
57
    FUNCTION demux(dmem_i : dmem_in_array_type; ce, r_ce : std_ulogic_vector) RETURN dmem_in_type IS
58
        VARIABLE dmem : dmem_in_type;
59
    BEGIN
60
        dmem := dmem_i(0);
61
        IF notx(ce) THEN
62
            FOR i IN G_NUM_SLAVES - 1 DOWNTO 0 LOOP
63
                IF ce(i) = '1' THEN
64
                    dmem.ena_i := dmem_i(i).ena_i;
65
                END IF;
66
                IF r_ce(i) = '1' THEN
67
                    dmem.dat_i := dmem_i(i).dat_i;
68
                END IF;
69
            END LOOP;
70
        END IF;
71
        RETURN dmem;
72
    END FUNCTION;
73
 
74
    SIGNAL r_ce, ce : std_ulogic_vector(G_NUM_SLAVES - 1 DOWNTO 0) := (OTHERS => '1');
75
 
76
BEGIN
77
 
78
    ce <= decode(m_dmem_o.adr_o);
79
    m_dmem_i <= demux(s_dmem_i, ce, r_ce);
80
 
81
    CON: FOR i IN G_NUM_SLAVES-1 DOWNTO 0 GENERATE
82
    BEGIN
83
        s_dmem_o(i).dat_o <= m_dmem_o.dat_o;
84
        s_dmem_o(i).adr_o <= m_dmem_o.adr_o;
85
        s_dmem_o(i).sel_o <= m_dmem_o.sel_o;
86
        s_dmem_o(i).we_o  <= m_dmem_o.we_o AND ce(i);
87
        s_dmem_o(i).ena_o <= m_dmem_o.ena_o AND ce(i);
88
    END GENERATE;
89
 
90
    PROCESS(clk_i)
91
    BEGIN
92
        IF rising_edge(clk_i) THEN
93
            r_ce <= ce;
94
        END IF;
95
    END PROCESS;
96
END arch;

powered by: WebSVN 2.1.0

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