1 |
164 |
arniml |
-------------------------------------------------------------------------------
|
2 |
|
|
--
|
3 |
|
|
-- The Wishbone master module.
|
4 |
|
|
--
|
5 |
166 |
arniml |
-- $Id: wb_master.vhd,v 1.2 2005-05-06 18:54:03 arniml Exp $
|
6 |
164 |
arniml |
--
|
7 |
|
|
-- Copyright (c) 2005, Arnim Laeuger (arniml@opencores.org)
|
8 |
|
|
--
|
9 |
|
|
-- All rights reserved
|
10 |
|
|
--
|
11 |
|
|
-- Redistribution and use in source and synthezised forms, with or without
|
12 |
|
|
-- modification, are permitted provided that the following conditions are met:
|
13 |
|
|
--
|
14 |
|
|
-- Redistributions of source code must retain the above copyright notice,
|
15 |
|
|
-- this list of conditions and the following disclaimer.
|
16 |
|
|
--
|
17 |
|
|
-- Redistributions in synthesized form must reproduce the above copyright
|
18 |
|
|
-- notice, this list of conditions and the following disclaimer in the
|
19 |
|
|
-- documentation and/or other materials provided with the distribution.
|
20 |
|
|
--
|
21 |
|
|
-- Neither the name of the author nor the names of other contributors may
|
22 |
|
|
-- be used to endorse or promote products derived from this software without
|
23 |
|
|
-- specific prior written permission.
|
24 |
|
|
--
|
25 |
|
|
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
26 |
|
|
-- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
27 |
|
|
-- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
28 |
|
|
-- PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE
|
29 |
|
|
-- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
30 |
|
|
-- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
31 |
|
|
-- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
32 |
|
|
-- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
33 |
|
|
-- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
34 |
|
|
-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
35 |
|
|
-- POSSIBILITY OF SUCH DAMAGE.
|
36 |
|
|
--
|
37 |
|
|
-- Please report bugs to the author, but before you do so, please
|
38 |
|
|
-- make sure that this is not a derivative work and that
|
39 |
|
|
-- you have the latest version of this file.
|
40 |
|
|
--
|
41 |
|
|
-- The latest version of this file can be found at:
|
42 |
|
|
-- http://www.opencores.org/cvsweb.shtml/t48/
|
43 |
|
|
--
|
44 |
|
|
-------------------------------------------------------------------------------
|
45 |
|
|
|
46 |
|
|
library ieee;
|
47 |
|
|
use ieee.std_logic_1164.all;
|
48 |
|
|
|
49 |
|
|
use work.t48_pack.all;
|
50 |
|
|
|
51 |
|
|
entity wb_master is
|
52 |
|
|
|
53 |
|
|
port (
|
54 |
|
|
xtal_i : in std_logic;
|
55 |
|
|
res_i : in std_logic;
|
56 |
|
|
en_clk_o : out std_logic;
|
57 |
|
|
-- T48 Interface ----------------------------------------------------------
|
58 |
|
|
ale_i : in std_logic;
|
59 |
|
|
rd_n_i : in std_logic;
|
60 |
|
|
wr_n_i : in std_logic;
|
61 |
|
|
sel_range_i : in std_logic_vector( 1 downto 0);
|
62 |
|
|
db_bus_i : in std_logic_vector( 7 downto 0);
|
63 |
|
|
db_bus_o : out std_logic_vector( 7 downto 0);
|
64 |
|
|
-- Wishbone Interface -----------------------------------------------------
|
65 |
|
|
wb_cyc_o : out std_logic;
|
66 |
|
|
wb_stb_o : out std_logic;
|
67 |
|
|
wb_we_o : out std_logic;
|
68 |
|
|
wb_adr_o : out std_logic_vector(23 downto 0);
|
69 |
|
|
wb_ack_i : in std_logic;
|
70 |
|
|
wb_dat_i : in std_logic_vector( 7 downto 0);
|
71 |
|
|
wb_dat_o : out std_logic_vector( 7 downto 0)
|
72 |
|
|
);
|
73 |
|
|
|
74 |
|
|
end wb_master;
|
75 |
|
|
|
76 |
|
|
|
77 |
|
|
architecture rtl of wb_master is
|
78 |
|
|
|
79 |
|
|
-----------------------------------------------------------------------------
|
80 |
|
|
-- Controller FSM
|
81 |
|
|
-----------------------------------------------------------------------------
|
82 |
|
|
type state_t is (IDLE, CYC, WAIT_INACT);
|
83 |
|
|
signal state_s,
|
84 |
|
|
state_q : state_t;
|
85 |
|
|
|
86 |
|
|
-----------------------------------------------------------------------------
|
87 |
|
|
-- Select signals for each range
|
88 |
|
|
-----------------------------------------------------------------------------
|
89 |
|
|
signal sel_adr1_s,
|
90 |
|
|
sel_adr2_s,
|
91 |
|
|
sel_wb_s : boolean;
|
92 |
|
|
|
93 |
|
|
signal wr_s,
|
94 |
|
|
rd_s : boolean;
|
95 |
|
|
|
96 |
|
|
signal adr_q : std_logic_vector(23 downto 0);
|
97 |
|
|
|
98 |
|
|
begin
|
99 |
|
|
|
100 |
|
|
-----------------------------------------------------------------------------
|
101 |
|
|
-- Select signal generation
|
102 |
|
|
-----------------------------------------------------------------------------
|
103 |
|
|
sel_adr1_s <= sel_range_i = "01";
|
104 |
|
|
sel_adr2_s <= sel_range_i = "10";
|
105 |
|
|
sel_wb_s <= sel_range_i = "00";
|
106 |
|
|
|
107 |
|
|
wr_s <= wr_n_i = '0';
|
108 |
|
|
rd_s <= rd_n_i = '0';
|
109 |
|
|
|
110 |
|
|
|
111 |
|
|
-----------------------------------------------------------------------------
|
112 |
|
|
-- Process seq
|
113 |
|
|
--
|
114 |
|
|
-- Purpose:
|
115 |
|
|
-- Implements the sequential elements.
|
116 |
|
|
--
|
117 |
|
|
seq: process (res_i, xtal_i)
|
118 |
|
|
begin
|
119 |
|
|
if res_i = res_active_c then
|
120 |
|
|
adr_q <= (others => '0');
|
121 |
|
|
state_q <= IDLE;
|
122 |
|
|
|
123 |
|
|
elsif xtal_i'event and xtal_i = clk_active_c then
|
124 |
|
|
-- Address register -----------------------------------------------------
|
125 |
|
|
-- update lowest address byte
|
126 |
|
|
if ale_i = '1' then
|
127 |
|
|
adr_q(word_t'range) <= db_bus_i;
|
128 |
|
|
end if;
|
129 |
|
|
-- set adr1 part
|
130 |
|
|
if wr_s and sel_adr1_s then
|
131 |
|
|
adr_q(word_t'length*2 - 1 downto word_t'length) <= db_bus_i;
|
132 |
|
|
end if;
|
133 |
|
|
-- set adr2 part
|
134 |
|
|
if wr_s and sel_adr2_s then
|
135 |
|
|
adr_q(word_t'length*3 - 1 downto word_t'length*2) <= db_bus_i;
|
136 |
|
|
end if;
|
137 |
|
|
|
138 |
|
|
-- FSM state ------------------------------------------------------------
|
139 |
|
|
state_q <= state_s;
|
140 |
|
|
|
141 |
|
|
end if;
|
142 |
|
|
end process seq;
|
143 |
|
|
--
|
144 |
|
|
-----------------------------------------------------------------------------
|
145 |
|
|
|
146 |
|
|
|
147 |
|
|
-----------------------------------------------------------------------------
|
148 |
|
|
-- Process fsm
|
149 |
|
|
--
|
150 |
|
|
-- Purpose:
|
151 |
|
|
-- Implements the state transitions of the controller FSM.
|
152 |
|
|
--
|
153 |
|
|
fsm: process (state_q,
|
154 |
|
|
wr_s,
|
155 |
|
|
rd_s,
|
156 |
|
|
sel_wb_s,
|
157 |
|
|
wb_ack_i)
|
158 |
|
|
begin
|
159 |
|
|
-- default assignments
|
160 |
|
|
wb_cyc_o <= '0';
|
161 |
|
|
wb_stb_o <= '0';
|
162 |
|
|
en_clk_o <= '1';
|
163 |
166 |
arniml |
state_s <= IDLE;
|
164 |
164 |
arniml |
|
165 |
|
|
case state_q is
|
166 |
|
|
when IDLE =>
|
167 |
|
|
if sel_wb_s and (wr_s or rd_s) then
|
168 |
|
|
state_s <= CYC;
|
169 |
|
|
end if;
|
170 |
|
|
|
171 |
|
|
when CYC =>
|
172 |
|
|
wb_cyc_o <= '1';
|
173 |
|
|
wb_stb_o <= '1';
|
174 |
|
|
en_clk_o <= '0';
|
175 |
|
|
|
176 |
|
|
if wb_ack_i = '1' then
|
177 |
|
|
state_s <= WAIT_INACT;
|
178 |
|
|
else
|
179 |
|
|
state_s <= CYC;
|
180 |
|
|
end if;
|
181 |
|
|
|
182 |
|
|
when WAIT_INACT =>
|
183 |
|
|
if not wr_s and not rd_s then
|
184 |
|
|
state_s <= IDLE;
|
185 |
|
|
else
|
186 |
|
|
state_s <= WAIT_INACT;
|
187 |
|
|
end if;
|
188 |
|
|
|
189 |
|
|
when others =>
|
190 |
|
|
null;
|
191 |
|
|
|
192 |
|
|
end case;
|
193 |
|
|
|
194 |
|
|
end process fsm;
|
195 |
|
|
--
|
196 |
|
|
-----------------------------------------------------------------------------
|
197 |
|
|
|
198 |
|
|
|
199 |
|
|
-----------------------------------------------------------------------------
|
200 |
|
|
-- Output multiplexer
|
201 |
|
|
-----------------------------------------------------------------------------
|
202 |
|
|
db_bus_o <= adr_q(word_t'length*2 - 1 downto word_t'length)
|
203 |
|
|
when sel_adr1_s else
|
204 |
|
|
adr_q(word_t'length*3 - 1 downto word_t'length*2)
|
205 |
|
|
when sel_adr1_s else
|
206 |
|
|
wb_dat_i;
|
207 |
|
|
|
208 |
|
|
|
209 |
|
|
-----------------------------------------------------------------------------
|
210 |
|
|
-- Output mapping
|
211 |
|
|
-----------------------------------------------------------------------------
|
212 |
|
|
wb_adr_o <= adr_q;
|
213 |
|
|
wb_dat_o <= db_bus_i;
|
214 |
|
|
wb_we_o <= '1'
|
215 |
|
|
when wr_s else
|
216 |
|
|
'0';
|
217 |
|
|
|
218 |
|
|
end rtl;
|
219 |
|
|
|
220 |
|
|
|
221 |
|
|
-------------------------------------------------------------------------------
|
222 |
|
|
-- File History:
|
223 |
|
|
--
|
224 |
|
|
-- $Log: not supported by cvs2svn $
|
225 |
166 |
arniml |
-- Revision 1.1 2005/05/05 19:49:03 arniml
|
226 |
|
|
-- initial check-in
|
227 |
|
|
--
|
228 |
164 |
arniml |
-------------------------------------------------------------------------------
|