1 |
164 |
arniml |
-------------------------------------------------------------------------------
|
2 |
|
|
--
|
3 |
|
|
-- The Wishbone master module.
|
4 |
|
|
--
|
5 |
167 |
arniml |
-- $Id: wb_master.vhd,v 1.3 2005-05-08 10:36:07 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 |
167 |
arniml |
--
|
45 |
|
|
-- Short description:
|
46 |
|
|
-- This design implements a simple Wishbone bus master. It connects to the
|
47 |
|
|
-- BUS interface of the T48 uController core.
|
48 |
|
|
--
|
49 |
|
|
-- The CPU clock is suppressed with en_clk_o to stall the CPU until the
|
50 |
|
|
-- acknowledge signal from the peripheral is detected.
|
51 |
|
|
--
|
52 |
|
|
-- The adr_i input selects between configuration and Wishbone address range:
|
53 |
|
|
-- 1 - configuration range
|
54 |
|
|
-- 0 - Wishbone range
|
55 |
|
|
--
|
56 |
|
|
-- When configuration range is selected, two address register are accessible.
|
57 |
|
|
-- 000h -> adr1
|
58 |
|
|
-- 001h -> adr2
|
59 |
|
|
-- These registers can be read and written with movx to their addresses.
|
60 |
|
|
--
|
61 |
|
|
-- When Wishbone range is selected, all movx generate Wishbone bus cycles
|
62 |
|
|
-- (either read or write) at following address:
|
63 |
|
|
-- Wishbone address = adr2 & adr1 & address of movx
|
64 |
|
|
--
|
65 |
164 |
arniml |
-------------------------------------------------------------------------------
|
66 |
|
|
|
67 |
|
|
library ieee;
|
68 |
|
|
use ieee.std_logic_1164.all;
|
69 |
|
|
|
70 |
|
|
use work.t48_pack.all;
|
71 |
|
|
|
72 |
|
|
entity wb_master is
|
73 |
|
|
|
74 |
|
|
port (
|
75 |
167 |
arniml |
xtal_i : in std_logic;
|
76 |
|
|
res_i : in std_logic;
|
77 |
|
|
en_clk_o : out std_logic;
|
78 |
164 |
arniml |
-- T48 Interface ----------------------------------------------------------
|
79 |
167 |
arniml |
ale_i : in std_logic;
|
80 |
|
|
rd_n_i : in std_logic;
|
81 |
|
|
wr_n_i : in std_logic;
|
82 |
|
|
adr_i : in std_logic;
|
83 |
|
|
db_bus_i : in std_logic_vector( 7 downto 0);
|
84 |
|
|
db_bus_o : out std_logic_vector( 7 downto 0);
|
85 |
164 |
arniml |
-- Wishbone Interface -----------------------------------------------------
|
86 |
167 |
arniml |
wb_cyc_o : out std_logic;
|
87 |
|
|
wb_stb_o : out std_logic;
|
88 |
|
|
wb_we_o : out std_logic;
|
89 |
|
|
wb_adr_o : out std_logic_vector(23 downto 0);
|
90 |
|
|
wb_ack_i : in std_logic;
|
91 |
|
|
wb_dat_i : in std_logic_vector( 7 downto 0);
|
92 |
|
|
wb_dat_o : out std_logic_vector( 7 downto 0)
|
93 |
164 |
arniml |
);
|
94 |
|
|
|
95 |
|
|
end wb_master;
|
96 |
|
|
|
97 |
|
|
|
98 |
|
|
architecture rtl of wb_master is
|
99 |
|
|
|
100 |
|
|
-----------------------------------------------------------------------------
|
101 |
|
|
-- Controller FSM
|
102 |
|
|
-----------------------------------------------------------------------------
|
103 |
|
|
type state_t is (IDLE, CYC, WAIT_INACT);
|
104 |
|
|
signal state_s,
|
105 |
|
|
state_q : state_t;
|
106 |
|
|
|
107 |
|
|
-----------------------------------------------------------------------------
|
108 |
|
|
-- Select signals for each range
|
109 |
|
|
-----------------------------------------------------------------------------
|
110 |
|
|
signal sel_adr1_s,
|
111 |
|
|
sel_adr2_s,
|
112 |
167 |
arniml |
sel_wb_s : boolean;
|
113 |
164 |
arniml |
|
114 |
|
|
signal wr_s,
|
115 |
167 |
arniml |
rd_s : boolean;
|
116 |
164 |
arniml |
|
117 |
|
|
signal adr_q : std_logic_vector(23 downto 0);
|
118 |
|
|
|
119 |
|
|
begin
|
120 |
|
|
|
121 |
|
|
-----------------------------------------------------------------------------
|
122 |
|
|
-- Select signal generation
|
123 |
|
|
-----------------------------------------------------------------------------
|
124 |
167 |
arniml |
sel_adr1_s <= adr_i = '1' and adr_q(word_t'range) = "00000000";
|
125 |
|
|
sel_adr2_s <= adr_i = '1' and adr_q(word_t'range) = "00000001";
|
126 |
|
|
sel_wb_s <= adr_i = '0';
|
127 |
164 |
arniml |
|
128 |
167 |
arniml |
wr_s <= wr_n_i = '0';
|
129 |
|
|
rd_s <= rd_n_i = '0';
|
130 |
164 |
arniml |
|
131 |
|
|
|
132 |
|
|
-----------------------------------------------------------------------------
|
133 |
|
|
-- Process seq
|
134 |
|
|
--
|
135 |
|
|
-- Purpose:
|
136 |
|
|
-- Implements the sequential elements.
|
137 |
|
|
--
|
138 |
|
|
seq: process (res_i, xtal_i)
|
139 |
|
|
begin
|
140 |
|
|
if res_i = res_active_c then
|
141 |
|
|
adr_q <= (others => '0');
|
142 |
|
|
state_q <= IDLE;
|
143 |
|
|
|
144 |
|
|
elsif xtal_i'event and xtal_i = clk_active_c then
|
145 |
|
|
-- Address register -----------------------------------------------------
|
146 |
|
|
-- update lowest address byte
|
147 |
|
|
if ale_i = '1' then
|
148 |
|
|
adr_q(word_t'range) <= db_bus_i;
|
149 |
|
|
end if;
|
150 |
|
|
-- set adr1 part
|
151 |
|
|
if wr_s and sel_adr1_s then
|
152 |
|
|
adr_q(word_t'length*2 - 1 downto word_t'length) <= db_bus_i;
|
153 |
|
|
end if;
|
154 |
|
|
-- set adr2 part
|
155 |
|
|
if wr_s and sel_adr2_s then
|
156 |
|
|
adr_q(word_t'length*3 - 1 downto word_t'length*2) <= db_bus_i;
|
157 |
|
|
end if;
|
158 |
|
|
|
159 |
|
|
-- FSM state ------------------------------------------------------------
|
160 |
|
|
state_q <= state_s;
|
161 |
|
|
|
162 |
|
|
end if;
|
163 |
|
|
end process seq;
|
164 |
|
|
--
|
165 |
|
|
-----------------------------------------------------------------------------
|
166 |
|
|
|
167 |
|
|
|
168 |
|
|
-----------------------------------------------------------------------------
|
169 |
|
|
-- Process fsm
|
170 |
|
|
--
|
171 |
|
|
-- Purpose:
|
172 |
|
|
-- Implements the state transitions of the controller FSM.
|
173 |
|
|
--
|
174 |
|
|
fsm: process (state_q,
|
175 |
|
|
wr_s,
|
176 |
|
|
rd_s,
|
177 |
|
|
sel_wb_s,
|
178 |
|
|
wb_ack_i)
|
179 |
|
|
begin
|
180 |
|
|
-- default assignments
|
181 |
|
|
wb_cyc_o <= '0';
|
182 |
|
|
wb_stb_o <= '0';
|
183 |
|
|
en_clk_o <= '1';
|
184 |
166 |
arniml |
state_s <= IDLE;
|
185 |
164 |
arniml |
|
186 |
|
|
case state_q is
|
187 |
167 |
arniml |
-- Idle State: Wait for read or write access ----------------------------
|
188 |
164 |
arniml |
when IDLE =>
|
189 |
|
|
if sel_wb_s and (wr_s or rd_s) then
|
190 |
|
|
state_s <= CYC;
|
191 |
|
|
end if;
|
192 |
|
|
|
193 |
167 |
arniml |
-- WB Cycle State: Start Wishbone cycle and wait for ack ----------------
|
194 |
164 |
arniml |
when CYC =>
|
195 |
|
|
wb_cyc_o <= '1';
|
196 |
|
|
wb_stb_o <= '1';
|
197 |
|
|
en_clk_o <= '0';
|
198 |
|
|
|
199 |
|
|
if wb_ack_i = '1' then
|
200 |
|
|
state_s <= WAIT_INACT;
|
201 |
|
|
else
|
202 |
|
|
state_s <= CYC;
|
203 |
|
|
end if;
|
204 |
|
|
|
205 |
167 |
arniml |
-- Wait inact State: Wait for end of T48 access -------------------------
|
206 |
164 |
arniml |
when WAIT_INACT =>
|
207 |
|
|
if not wr_s and not rd_s then
|
208 |
|
|
state_s <= IDLE;
|
209 |
|
|
else
|
210 |
|
|
state_s <= WAIT_INACT;
|
211 |
|
|
end if;
|
212 |
|
|
|
213 |
|
|
when others =>
|
214 |
|
|
null;
|
215 |
|
|
|
216 |
|
|
end case;
|
217 |
|
|
|
218 |
|
|
end process fsm;
|
219 |
|
|
--
|
220 |
|
|
-----------------------------------------------------------------------------
|
221 |
|
|
|
222 |
|
|
|
223 |
|
|
-----------------------------------------------------------------------------
|
224 |
|
|
-- Output multiplexer
|
225 |
|
|
-----------------------------------------------------------------------------
|
226 |
|
|
db_bus_o <= adr_q(word_t'length*2 - 1 downto word_t'length)
|
227 |
|
|
when sel_adr1_s else
|
228 |
|
|
adr_q(word_t'length*3 - 1 downto word_t'length*2)
|
229 |
167 |
arniml |
when sel_adr2_s else
|
230 |
164 |
arniml |
wb_dat_i;
|
231 |
|
|
|
232 |
|
|
|
233 |
|
|
-----------------------------------------------------------------------------
|
234 |
|
|
-- Output mapping
|
235 |
|
|
-----------------------------------------------------------------------------
|
236 |
|
|
wb_adr_o <= adr_q;
|
237 |
|
|
wb_dat_o <= db_bus_i;
|
238 |
|
|
wb_we_o <= '1'
|
239 |
|
|
when wr_s else
|
240 |
|
|
'0';
|
241 |
|
|
|
242 |
|
|
end rtl;
|
243 |
|
|
|
244 |
|
|
|
245 |
|
|
-------------------------------------------------------------------------------
|
246 |
|
|
-- File History:
|
247 |
|
|
--
|
248 |
|
|
-- $Log: not supported by cvs2svn $
|
249 |
167 |
arniml |
-- Revision 1.2 2005/05/06 18:54:03 arniml
|
250 |
|
|
-- assign default for state_s
|
251 |
|
|
--
|
252 |
166 |
arniml |
-- Revision 1.1 2005/05/05 19:49:03 arniml
|
253 |
|
|
-- initial check-in
|
254 |
|
|
--
|
255 |
164 |
arniml |
-------------------------------------------------------------------------------
|