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

Subversion Repositories potato

[/] [potato/] [trunk/] [src/] [pp_wb_adapter.vhd] - Blame information for rev 3

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

Line No. Rev Author Line
1 2 skordal
-- The Potato Processor - A simple processor for FPGAs
2
-- (c) Kristian Klomsten Skordal 2014 - 2015 <kristian.skordal@wafflemail.net>
3 3 skordal
-- Report bugs and issues on <http://opencores.org/project,potato,bugtracker>
4 2 skordal
 
5
library ieee;
6
use ieee.std_logic_1164.all;
7
use ieee.numeric_std.all;
8
 
9
--! @brief Wishbone adapter, for connecting the processor to a Wishbone bus when not using caches.
10
entity pp_wb_adapter is
11
        port(
12
                clk   : in std_logic;
13
                reset : in std_logic;
14
 
15
                -- Processor instruction memory signals:
16
                signal imem_address  : in  std_logic_vector(31 downto 0);
17
                signal imem_data_out : out std_logic_vector(31 downto 0);
18
                signal imem_read_req : in  std_logic;
19
                signal imem_read_ack : out std_logic;
20
 
21
                -- Processor data memory signals:
22
                signal dmem_address   : in  std_logic_vector(31 downto 0);
23
                signal dmem_data_in   : in  std_logic_vector(31 downto 0); -- Data in to the bus
24
                signal dmem_data_out  : out std_logic_vector(31 downto 0); -- Data out to the bus
25
                signal dmem_data_size : in  std_logic_vector( 1 downto 0);
26
                signal dmem_read_req  : in  std_logic;
27
                signal dmem_read_ack  : out std_logic;
28
                signal dmem_write_req : in  std_logic;
29
                signal dmem_write_ack : out std_logic;
30
 
31
                -- Wishbone interface:
32
                wb_adr_out : out std_logic_vector(31 downto 0);
33
                wb_dat_out : out std_logic_vector(31 downto 0);
34
                wb_sel_out : out std_logic_vector( 3 downto 0);
35
                wb_cyc_out : out std_logic;
36
                wb_stb_out : out std_logic;
37
                wb_we_out  : out std_logic;
38
                wb_dat_in  : in  std_logic_vector(31 downto 0);
39
                wb_ack_in  : in  std_logic
40
        );
41
end entity pp_wb_adapter;
42
 
43
architecture behaviour of pp_wb_adapter is
44
 
45
        type states is (IDLE, READ_WAIT_ACK, WRITE_WAIT_ACK, IREAD_WAIT_ACK);
46
        signal state : states;
47
 
48
        signal dmem_r_ack : std_logic;
49
 
50
        function get_data_shift(size : in std_logic_vector(1 downto 0); address : in std_logic_vector)
51
                return natural is
52
        begin
53
                case size is
54
                        when b"01" =>
55
                                case address(1 downto 0) is
56
                                        when b"00" =>
57
                                                return 0;
58
                                        when b"01" =>
59
                                                return 8;
60
                                        when b"10" =>
61
                                                return 16;
62
                                        when b"11" =>
63
                                                return 24;
64
                                        when others =>
65
                                                return 0;
66
                                end case;
67
                        when b"10" =>
68
                                if address(1) = '0' then
69
                                        return 0;
70
                                else
71
                                        return 16;
72
                                end if;
73
                        when others =>
74
                                return 0;
75
                end case;
76
        end function get_data_shift;
77
 
78
        function get_data_sel(size : in std_logic_vector(1 downto 0); address : in std_logic_vector)
79
                return std_logic_vector is
80
        begin
81
                case size is
82
                        when b"01" =>
83
                                case address(1 downto 0) is
84
                                        when b"00" =>
85
                                                return b"0001";
86
                                        when b"01" =>
87
                                                return b"0010";
88
                                        when b"10" =>
89
                                                return b"0100";
90
                                        when b"11" =>
91
                                                return b"1000";
92
                                        when others =>
93
                                                return b"0001";
94
                                end case;
95
                        when b"10" =>
96
                                if address(1) = '0' then
97
                                        return b"0011";
98
                                else
99
                                        return b"1100";
100
                                end if;
101
                        when others =>
102
                                return b"1111";
103
                end case;
104
        end function get_data_sel;
105
 
106
begin
107
 
108
        imem_read_ack <= '1' when state = IREAD_WAIT_ACK and wb_ack_in = '1' else '0';
109
        imem_data_out <= wb_dat_in;
110
 
111
        dmem_write_ack <= '1' when state = WRITE_WAIT_ACK and wb_ack_in = '1' else '0';
112
        dmem_read_ack <= dmem_r_ack;
113
 
114
        wishbone: process(clk)
115
        begin
116
                if rising_edge(clk) then
117
                        if reset = '1' then
118
                                state <= IDLE;
119
                                wb_cyc_out <= '0';
120
                                wb_stb_out <= '0';
121
                                dmem_r_ack <= '0';
122
                        else
123
                                case state is
124
                                        when IDLE =>
125
                                                dmem_r_ack <= '0';
126
 
127
                                                -- Prioritize requests from the data memory:
128
                                                if dmem_write_req = '1' then
129
                                                        wb_adr_out <= dmem_address;
130
                                                        wb_dat_out <= std_logic_vector(shift_left(unsigned(dmem_data_in),
131
                                                                get_data_shift(dmem_data_size, dmem_address)));
132
                                                        wb_sel_out <= get_data_sel(dmem_data_size, dmem_address);
133
                                                        wb_cyc_out <= '1';
134
                                                        wb_stb_out <= '1';
135
                                                        wb_we_out <= '1';
136
                                                        state <= WRITE_WAIT_ACK;
137
                                                elsif dmem_read_req = '1' and dmem_r_ack = '0' then
138
                                                        wb_adr_out <= dmem_address;
139
                                                        wb_sel_out <= get_data_sel(dmem_data_size, dmem_address);
140
                                                        wb_cyc_out <= '1';
141
                                                        wb_stb_out <= '1';
142
                                                        wb_we_out <= '0';
143
                                                        state <= READ_WAIT_ACK;
144
                                                elsif imem_read_req = '1' then
145
                                                        wb_adr_out <= imem_address;
146
                                                        wb_sel_out <= (others => '1');
147
                                                        wb_cyc_out <= '1';
148
                                                        wb_stb_out <= '1';
149
                                                        wb_we_out <= '0';
150
                                                        state <= IREAD_WAIT_ACK;
151
                                                end if;
152
                                        when READ_WAIT_ACK =>
153
                                                if wb_ack_in = '1' then
154
                                                        dmem_data_out <= std_logic_vector(shift_right(unsigned(wb_dat_in),
155
                                                                get_data_shift(dmem_data_size, dmem_address)));
156
                                                        wb_cyc_out <= '0';
157
                                                        wb_stb_out <= '0';
158
                                                        dmem_r_ack <= '1';
159
                                                        state <= IDLE;
160
                                                end if;
161
                                        when WRITE_WAIT_ACK | IREAD_WAIT_ACK =>
162
                                                if wb_ack_in = '1' then
163
                                                        wb_cyc_out <= '0';
164
                                                        wb_stb_out <= '0';
165
                                                        wb_we_out <= '0';
166
                                                        state <= IDLE;
167
                                                end if;
168
                                end case;
169
                        end if;
170
                end if;
171
        end process wishbone;
172
 
173
end architecture behaviour;

powered by: WebSVN 2.1.0

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