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

Subversion Repositories t48

[/] [t48/] [tags/] [rel_1_0/] [rtl/] [vhdl/] [system/] [wb_master.vhd] - Blame information for rev 292

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 164 arniml
-------------------------------------------------------------------------------
2
--
3
-- The Wishbone master module.
4
--
5 180 arniml
-- $Id: wb_master.vhd,v 1.5 2005-06-11 10:16:05 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 180 arniml
entity t48_wb_master is
73 164 arniml
 
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 180 arniml
end t48_wb_master;
96 164 arniml
 
97
 
98 180 arniml
architecture rtl of t48_wb_master is
99 164 arniml
 
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 172 arniml
  signal adr_q    : std_logic_vector(23 downto 0);
118
  signal wb_dat_q : std_logic_vector( 7 downto 0);
119 164 arniml
 
120
begin
121
 
122
  -----------------------------------------------------------------------------
123
  -- Select signal generation
124
  -----------------------------------------------------------------------------
125 167 arniml
  sel_adr1_s <= adr_i = '1' and adr_q(word_t'range) = "00000000";
126
  sel_adr2_s <= adr_i = '1' and adr_q(word_t'range) = "00000001";
127
  sel_wb_s   <= adr_i = '0';
128 164 arniml
 
129 167 arniml
  wr_s      <= wr_n_i = '0';
130
  rd_s      <= rd_n_i = '0';
131 164 arniml
 
132
 
133
  -----------------------------------------------------------------------------
134
  -- Process seq
135
  --
136
  -- Purpose:
137
  --   Implements the sequential elements.
138
  --
139
  seq: process (res_i, xtal_i)
140
  begin
141
    if res_i = res_active_c then
142 172 arniml
      adr_q    <= (others => '0');
143
      wb_dat_q <= (others => '0');
144
      state_q  <= IDLE;
145 164 arniml
 
146
    elsif xtal_i'event and xtal_i = clk_active_c then
147
      -- Address register -----------------------------------------------------
148
      -- update lowest address byte
149
      if ale_i = '1' then
150
        adr_q(word_t'range) <= db_bus_i;
151
      end if;
152
      -- set adr1 part
153
      if wr_s and sel_adr1_s then
154
        adr_q(word_t'length*2 - 1 downto word_t'length) <= db_bus_i;
155
      end if;
156
      -- set adr2 part
157
      if wr_s and sel_adr2_s then
158
        adr_q(word_t'length*3 - 1 downto word_t'length*2) <= db_bus_i;
159
      end if;
160
 
161 172 arniml
      -- Data from peripheral has to be saved ---------------------------------
162
      if wb_ack_i = '1' then
163
        wb_dat_q <= wb_dat_i;
164
      end if;
165
 
166 164 arniml
      -- FSM state ------------------------------------------------------------
167
      state_q <= state_s;
168
 
169
    end if;
170
  end process seq;
171
  --
172
  -----------------------------------------------------------------------------
173
 
174
 
175
  -----------------------------------------------------------------------------
176
  -- Process fsm
177
  --
178
  -- Purpose:
179
  --   Implements the state transitions of the controller FSM.
180
  --
181
  fsm: process (state_q,
182
                wr_s,
183
                rd_s,
184
                sel_wb_s,
185
                wb_ack_i)
186
  begin
187
    -- default assignments
188
    wb_cyc_o <= '0';
189
    wb_stb_o <= '0';
190
    en_clk_o <= '1';
191 166 arniml
    state_s  <= IDLE;
192 164 arniml
 
193
    case state_q is
194 167 arniml
      -- Idle State: Wait for read or write access ----------------------------
195 164 arniml
      when IDLE =>
196
        if sel_wb_s and (wr_s or rd_s) then
197
          state_s <= CYC;
198
        end if;
199
 
200 167 arniml
      -- WB Cycle State: Start Wishbone cycle and wait for ack ----------------
201 164 arniml
      when CYC =>
202
        wb_cyc_o <= '1';
203
        wb_stb_o <= '1';
204
        en_clk_o <= '0';
205
 
206
        if wb_ack_i = '1' then
207
          state_s <= WAIT_INACT;
208
        else
209
          state_s <= CYC;
210
        end if;
211
 
212 167 arniml
      -- Wait inact State: Wait for end of T48 access -------------------------
213 164 arniml
      when WAIT_INACT =>
214
        if not wr_s and not rd_s then
215
          state_s <= IDLE;
216
        else
217
          state_s <= WAIT_INACT;
218
        end if;
219
 
220
      when others =>
221
        null;
222
 
223
    end case;
224
 
225
  end process fsm;
226
  --
227
  -----------------------------------------------------------------------------
228
 
229
 
230
  -----------------------------------------------------------------------------
231
  --  Output multiplexer
232
  -----------------------------------------------------------------------------
233
  db_bus_o <=   adr_q(word_t'length*2 - 1 downto word_t'length)
234
              when sel_adr1_s else
235
                adr_q(word_t'length*3 - 1 downto word_t'length*2)
236 167 arniml
              when sel_adr2_s else
237 172 arniml
                wb_dat_q;
238 164 arniml
 
239
 
240
  -----------------------------------------------------------------------------
241
  -- Output mapping
242
  -----------------------------------------------------------------------------
243
  wb_adr_o <= adr_q;
244
  wb_dat_o <= db_bus_i;
245
  wb_we_o  <=   '1'
246 172 arniml
              when wr_s and sel_wb_s else
247 164 arniml
                '0';
248
 
249
end rtl;
250
 
251
 
252
-------------------------------------------------------------------------------
253
-- File History:
254
--
255
-- $Log: not supported by cvs2svn $
256 180 arniml
-- Revision 1.4  2005/05/10 22:36:23  arniml
257
-- save data from wishbone bus in register bank with wb_ack
258
-- necessary to hold data from peripheral/memory until it is read by T48
259
--
260 172 arniml
-- Revision 1.3  2005/05/08 10:36:07  arniml
261
-- simplify address range:
262
-- - configuration range
263
-- - Wishbone range
264
--
265 167 arniml
-- Revision 1.2  2005/05/06 18:54:03  arniml
266
-- assign default for state_s
267
--
268 166 arniml
-- Revision 1.1  2005/05/05 19:49:03  arniml
269
-- initial check-in
270
--
271 164 arniml
-------------------------------------------------------------------------------

powered by: WebSVN 2.1.0

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