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

Subversion Repositories simpcon

[/] [simpcon/] [trunk/] [vhdl/] [sc2avalon.vhd] - Blame information for rev 29

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 18 martin
--
2 29 martin
--
3
--  This file is a part of JOP, the Java Optimized Processor
4
--
5
--  Copyright (C) 2001-2008, Martin Schoeberl (martin@jopdesign.com)
6
--
7
--  This program is free software: you can redistribute it and/or modify
8
--  it under the terms of the GNU General Public License as published by
9
--  the Free Software Foundation, either version 3 of the License, or
10
--  (at your option) any later version.
11
--
12
--  This program is distributed in the hope that it will be useful,
13
--  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
--  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
--  GNU General Public License for more details.
16
--
17
--  You should have received a copy of the GNU General Public License
18
--  along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
--
20
 
21
 
22
--
23 18 martin
--      sc2avalon.vhd
24
--
25
--      SimpCon to Avalon bridge
26
--
27
--      Author: Martin Schoeberl        martin@jopdesign.com
28
--
29
--      2006-08-10      first version
30
--
31
 
32
Library IEEE;
33
use IEEE.std_logic_1164.all;
34
use ieee.numeric_std.all;
35
 
36
entity sc2avalon is
37
generic (addr_bits : integer);
38
 
39
port (
40
 
41
        clk, reset      : in std_logic;
42
 
43
-- SimpCon interface
44
 
45
        sc_address              : in std_logic_vector(addr_bits-1 downto 0);
46
        sc_wr_data              : in std_logic_vector(31 downto 0);
47
        sc_rd, sc_wr    : in std_logic;
48
        sc_rd_data              : out std_logic_vector(31 downto 0);
49
        sc_rdy_cnt              : out unsigned(1 downto 0);
50
 
51
-- Avalon interface
52
 
53
        av_address              : out std_logic_vector(addr_bits-1+2 downto 0);
54
        av_writedata    : out std_logic_vector(31 downto 0);
55
        av_byteenable   : out std_logic_vector(3 downto 0);
56
        av_readdata             : in std_logic_vector(31 downto 0);
57
        av_read                 : out std_logic;
58
        av_write                : out std_logic;
59
        av_waitrequest  : in std_logic
60
 
61
);
62
end sc2avalon;
63
 
64
architecture rtl of sc2avalon is
65
 
66
        type state_type         is (idl, rd, rdw, wr, wrw);
67
        signal state            : state_type;
68
        signal next_state       : state_type;
69
 
70
        signal reg_addr         : std_logic_vector(addr_bits-1 downto 0);
71
        signal reg_wr_data      : std_logic_vector(31 downto 0);
72
        signal reg_rd_data      : std_logic_vector(31 downto 0);
73
 
74
        signal reg_rd           : std_logic;
75
        signal reg_wr           : std_logic;
76
 
77
begin
78
 
79
        av_byteenable <= "1111";                        -- we use only 32 bit transfers
80
        av_address(1 downto 0) <= "00";
81
 
82
        sc_rd_data <= reg_rd_data;
83
 
84
 
85
--
86
--      Register memory address, write data and read data
87
--
88
process(clk, reset)
89
begin
90
        if reset='1' then
91
 
92
                reg_addr <= (others => '0');
93
                reg_wr_data <= (others => '0');
94
 
95
        elsif rising_edge(clk) then
96
 
97
                if sc_rd='1' or sc_wr='1' then
98
                        reg_addr <= sc_address;
99
                end if;
100
                if sc_wr='1' then
101
                        reg_wr_data <= sc_wr_data;
102
                end if;
103
 
104
        end if;
105
end process;
106
 
107
 
108
--
109
--      The address MUX slightly violates the Avalon
110
--      specification. The address changes from the sc_address
111
--      to the registerd address in the second cycle. However,
112
--      as both registers contain the same value there should be
113
--      no real glitch. For synchronous peripherals this is not
114
--      an issue. For asynchronous peripherals (SRAM) the possible
115
--      glitch should be short enough to be not seen on the output
116
--      pins.
117
--
118
process(sc_rd, sc_wr, sc_address, reg_addr)
119
begin
120
        if sc_rd='1' or sc_wr='1' then
121
                av_address(addr_bits-1+2 downto 2) <= sc_address;
122
        else
123
                av_address(addr_bits-1+2 downto 2) <= reg_addr;
124
        end if;
125
end process;
126
 
127
--      Same game for the write data and write/read control
128
process(sc_wr, sc_wr_data, reg_wr_data)
129
begin
130
        if sc_wr='1' then
131
                av_writedata <= sc_wr_data;
132
        else
133
                av_writedata <= reg_wr_data;
134
        end if;
135
end process;
136
 
137
        av_write <= sc_wr or reg_wr;
138
        av_read <= sc_rd or reg_rd;
139
 
140
 
141
 
142
--
143
--      next state logic
144
--
145
--      At the moment we do not support back to back read
146
--      or write. We don't need it for JOP, right?
147
--      If needed just copy the idl code to rd and wr.
148
--
149
process(state, sc_rd, sc_wr, av_waitrequest)
150
 
151
begin
152
 
153
        next_state <= state;
154
 
155
        case state is
156
 
157
                when idl =>
158
                        if sc_rd='1' then
159
                                if av_waitrequest='0' then
160
                                        next_state <= rd;
161
                                else
162
                                        next_state <= rdw;
163
                                end if;
164
                        elsif sc_wr='1' then
165
                                if av_waitrequest='0' then
166
                                        next_state <= wr;
167
                                else
168
                                        next_state <= wrw;
169
                                end if;
170
                        end if;
171
 
172
                when rdw =>
173
                        if av_waitrequest='0' then
174
                                next_state <= rd;
175
                        end if;
176
 
177
                when rd =>
178
                        next_state <= idl;
179
 
180
                when wrw =>
181
                        if av_waitrequest='0' then
182
                                next_state <= wr;
183
                        end if;
184
 
185
                when wr =>
186
                        next_state <= idl;
187
 
188
 
189
        end case;
190
 
191
end process;
192
 
193
--
194
--      state machine register
195
--      and output register
196
--
197
process(clk, reset)
198
 
199
begin
200
        if (reset='1') then
201
                state <= idl;
202
                reg_rd_data <= (others => '0');
203
                sc_rdy_cnt <= "00";
204
                reg_rd <= '0';
205
                reg_wr <= '0';
206
 
207
        elsif rising_edge(clk) then
208
 
209
                state <= next_state;
210
                sc_rdy_cnt <= "00";
211
                reg_rd <= '0';
212
                reg_wr <= '0';
213
 
214
                case next_state is
215
 
216
                        when idl =>
217
 
218
                        when rdw =>
219
                                sc_rdy_cnt <= "11";
220
                                reg_rd <= '1';
221
 
222
                        when rd =>
223
                                reg_rd_data <= av_readdata;
224
 
225
                        when wrw =>
226
                                sc_rdy_cnt <= "11";
227
                                reg_wr <= '1';
228
 
229
                        when wr =>
230
 
231
                end case;
232
 
233
        end if;
234
end process;
235
 
236
end rtl;

powered by: WebSVN 2.1.0

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