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

Subversion Repositories minimips_superscalar

[/] [minimips_superscalar/] [trunk/] [sources/] [bus_ctrl01.vhd] - Blame information for rev 21

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

Line No. Rev Author Line
1 2 mcafruni
--------------------------------------------------------------------------
2
--                                                                      --
3
--                                                                      --
4
-- miniMIPS Superscalar Processor : bus controler 01                    --
5
-- based on miniMIPS Processor                                          --
6
--                                                                      --
7
--                                                                      --
8
-- Author : Miguel Cafruni                                              --
9
-- miguel_cafruni@hotmail.com                                           --
10
--                                                      December 2018   --
11
--------------------------------------------------------------------------
12
 
13
library ieee;
14
use ieee.std_logic_1164.all;
15
use ieee.numeric_std.all;
16
 
17
library work;
18
use work.pack_mips.all;
19
 
20
entity bus_ctrl01 is
21
port
22
(
23
    clock : std_logic;
24
    reset : std_logic;
25
 
26
    -- Interruption in the pipeline
27
    interrupt      : in std_logic;
28
 
29
    -- Interface for the Instruction Extraction Stage
30
    adr_from_ei    : in bus32;      -- The address of the data to read
31
    instr_to_ei    : out bus32;     -- Instruction from the memory
32
 
33
    -- Interface with the MEMory Stage
34
    req_from_mem   : in std_logic;  -- Request to access the ram
35
    r_w_from_mem   : in std_logic;  -- Read/Write request
36
    adr_from_mem   : in bus32;      -- Address in ram
37
    data_from_mem  : in bus32;      -- Data to write in ram
38
    data_to_mem    : out bus32;     -- Data from the ram to the MEMory stage
39
 
40
    -- RAM interface signals
41
    req_to_ram     : out std_logic;  -- Request to ram
42
    adr_to_ram     : out bus32;     -- Address of the data to read or write
43
    r_w_to_ram     : out std_logic; -- Read/Write request
44
    ack_from_ram   : in std_logic;  -- Acknowledge from the memory
45
    data_inout_ram : inout bus32;   -- Data from/to the memory
46
 
47
    -- Pipeline progress control signal
48
    stop_all       : out std_logic
49
);
50
end bus_ctrl01;
51
 
52
 
53
architecture rtl of bus_ctrl01 is
54
 
55
    type ctrl_state is ( ST1, ST2 );
56
    signal cs, ns : ctrl_state;
57
    signal ei_buffer : bus32;       -- Buffer storing the data for EI
58
 
59
    signal r_w : std_logic;         -- Current utilisation of the tristate bus
60
    signal data_in : bus32;         -- Data read on the tristate bus
61
    signal req_allowed : std_logic;
62
 
63
begin
64
 
65
    -- Read/write on the tristate bus
66
    process (r_w, data_from_mem, data_inout_ram)
67
    begin
68
        r_w_to_ram <= r_w;
69
        if r_w='0' then -- Reads bus
70
            data_inout_ram <= (others => 'Z');
71
            data_in <= data_inout_ram;
72
        else            -- Writing of the data from the MEM stage
73
            data_inout_ram <= data_from_mem;
74
            data_in <= (others => '0');
75
        end if;
76
    end process;
77
 
78
    process (clock)
79
    begin
80
        if rising_edge(clock) then
81
            if reset='1' then
82
                cs <= ST1;
83
                ei_buffer <= (others => '0');
84
            else
85
                if cs=ST1 then
86
                    -- Storing of the data to send to EI stage
87
                    ei_buffer <= data_in;
88
                end if;
89
 
90
                cs <= ns;
91
            end if;
92
        end if;
93
    end process;
94
 
95
    process (clock, ack_from_ram)
96
    begin
97
        if ack_from_ram = '0' then
98
            req_allowed <= '0';
99
        elsif rising_edge(clock) then
100
            if ack_from_ram = '1' then
101
                req_allowed <= '1';
102
            end if;
103
        end if;
104
    end process;
105
 
106
    process (req_allowed, ack_from_ram)
107
    begin
108
        if req_allowed = '1' then
109
            req_to_ram <= '1';
110
        elsif ack_from_ram = '0' then
111
            req_to_ram <= '1';
112
        else
113
            req_to_ram <= '0';
114
        end if;
115
    end process;
116
 
117
    process (cs, interrupt, adr_from_ei, req_from_mem, r_w_from_mem, adr_from_mem, ack_from_ram)
118
    begin
119
        if interrupt = '1' then -- An interruption is detected
120
            ns <= ST1;       -- Get back to the reading request
121
            stop_all <= '0'; -- The pipeline is unlock for taking in account the interruption
122
            adr_to_ram <= adr_from_ei;
123
            r_w <= '0';
124
        else
125
            case cs is
126
 
127
                when ST1 => -- First step the reading for EI
128
                    adr_to_ram <= adr_from_ei;
129
                    r_w <= '0';
130
 
131
                    if ack_from_ram='1' then
132
 
133
                        if req_from_mem='1' then
134
                            -- If request from MEM, then step 2
135
                            ns <= ST2;
136
                            stop_all <= '1';
137
                        else
138
                            -- else next reading for EI
139
                            ns <= ST1;
140
                            stop_all <= '0';
141
                        end if;
142
                    else
143
                        -- Wait the end of the reading
144
                        ns <= ST1;
145
                        stop_all <= '1';
146
                    end if;
147
 
148
                when ST2 => -- Treat the request from the MEM stage
149
                    adr_to_ram <= adr_from_mem;
150
                    r_w <= r_w_from_mem;
151
 
152
                    -- Wait the acknowledge from the RAM
153
                    if ack_from_ram='1' then
154
                        ns <= ST1;
155
                        stop_all <= '0';
156
                    else
157
                        ns <= ST2;
158
                        stop_all <= '1';
159
                    end if;
160
            end case;
161
        end if;
162
    end process;
163
    data_to_mem <= data_in;
164
    instr_to_ei <= ei_buffer when cs=ST2 else data_in;
165
 
166
end rtl;

powered by: WebSVN 2.1.0

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