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

Subversion Repositories t48

[/] [t48/] [tags/] [rel_1_0/] [rtl/] [vhdl/] [clock_ctrl.vhd] - Blame information for rev 77

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

Line No. Rev Author Line
1 4 arniml
-------------------------------------------------------------------------------
2
--
3
-- The Clock Control unit.
4
-- Clock States and Machine Cycles are generated here.
5
--
6 77 arniml
-- $Id: clock_ctrl.vhd,v 1.4 2004-04-24 23:44:25 arniml Exp $
7 4 arniml
--
8
-- Copyright (c) 2004, Arnim Laeuger (arniml@opencores.org)
9
--
10
-- All rights reserved
11
--
12
-- Redistribution and use in source and synthezised forms, with or without
13
-- modification, are permitted provided that the following conditions are met:
14
--
15
-- Redistributions of source code must retain the above copyright notice,
16
-- this list of conditions and the following disclaimer.
17
--
18
-- Redistributions in synthesized form must reproduce the above copyright
19
-- notice, this list of conditions and the following disclaimer in the
20
-- documentation and/or other materials provided with the distribution.
21
--
22
-- Neither the name of the author nor the names of other contributors may
23
-- be used to endorse or promote products derived from this software without
24
-- specific prior written permission.
25
--
26
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27
-- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
28
-- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29
-- PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE
30
-- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31
-- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32
-- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33
-- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34
-- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35
-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36
-- POSSIBILITY OF SUCH DAMAGE.
37
--
38
-- Please report bugs to the author, but before you do so, please
39
-- make sure that this is not a derivative work and that
40
-- you have the latest version of this file.
41
--
42
-- The latest version of this file can be found at:
43
--      http://www.opencores.org/cvsweb.shtml/t48/
44
--
45
-------------------------------------------------------------------------------
46
 
47
library ieee;
48
use ieee.std_logic_1164.all;
49
 
50
use work.t48_pack.all;
51
 
52
entity clock_ctrl is
53
 
54
  generic (
55
    -- divide XTAL1 by 3 to derive Clock States
56
    xtal_div_3_g : integer := 1
57
  );
58
 
59
  port (
60
    clk_i          : in  std_logic;
61
    xtal_i         : in  std_logic;
62
    res_i          : in  std_logic;
63
    en_clk_i       : in  boolean;
64
    xtal3_o        : out boolean;
65
    multi_cycle_i  : in  boolean;
66
    assert_psen_i  : in  boolean;
67
    assert_prog_i  : in  boolean;
68
    assert_rd_i    : in  boolean;
69
    assert_wr_i    : in  boolean;
70
    mstate_o       : out mstate_t;
71
    second_cycle_o : out boolean;
72
    ale_o          : out boolean;
73
    psen_o         : out boolean;
74
    prog_o         : out boolean;
75
    rd_o           : out boolean;
76
    wr_o           : out boolean
77
  );
78
 
79
end clock_ctrl;
80
 
81
 
82
library ieee;
83 77 arniml
use ieee.numeric_std.all;
84 4 arniml
 
85
architecture rtl of clock_ctrl is
86
 
87
  -- The three XTAL1 cycles.
88
  signal xtal_q  : unsigned(1 downto 0);
89
  signal xtal1_s,
90
         xtal2_s,
91
         xtal3_s : boolean;
92
  signal x1_s,
93
         x2_s,
94
         x3_s    : std_logic;
95
 
96
 
97
  -- The five clock states.
98
  signal mstate_q  : mstate_t;
99
 
100
  signal ale_q     : boolean;
101
  signal psen_q    : boolean;
102
  signal prog_q    : boolean;
103
  signal rd_q      : boolean;
104
  signal wr_q      : boolean;
105
 
106
 
107
  -- The Machine Cycle marker.
108
  signal second_cycle_q : boolean;
109
  signal multi_cycle_q  : boolean;
110
 
111
begin
112
 
113
  -----------------------------------------------------------------------------
114
  -- Verify the generics
115
  -----------------------------------------------------------------------------
116
 
117
  -- pragma translate_off
118
 
119
  -- XTAL1 divide by 3 --------------------------------------------------------
120
  assert (xtal_div_3_g = 1) or (xtal_div_3_g = 0)
121
    report "xtal_div_3_g must be either 1 or 0!"
122
    severity failure;
123
 
124
  -- pragma translate_on
125
 
126
 
127
  -----------------------------------------------------------------------------
128
  -- Divide XTAL1 by 3 to derive Clock States.
129
  -----------------------------------------------------------------------------
130
  use_xtal_div: if xtal_div_3_g = 1 generate
131
    xtal: process (res_i, xtal_i)
132
    begin
133
      if res_i = res_active_c then
134 77 arniml
        xtal_q <= TO_UNSIGNED(0, 2);
135 4 arniml
 
136
      elsif xtal_i'event and xtal_i = clk_active_c then
137
        if xtal_q < 2 then
138
          xtal_q <= xtal_q + 1;
139
        else
140 77 arniml
          xtal_q <= TO_UNSIGNED(0, 2);
141 4 arniml
        end if;
142
 
143
      end if;
144
 
145
    end process xtal;
146
 
147
    x1_s <=   '1'
148
            when xtal_q = 0 else
149
              '0';
150
    x2_s <=   '1'
151
            when xtal_q = 1 else
152
              '0';
153
    x3_s <=   '1'
154
            when xtal_q = 2 else
155
              '0';
156
 
157
  end generate;
158
 
159
  -----------------------------------------------------------------------------
160
  -- XTAL1 is used directly for Clock States.
161
  -----------------------------------------------------------------------------
162
  no_xtal_div: if xtal_div_3_g = 0 generate
163 77 arniml
    xtal_q <= TO_UNSIGNED(0, 2);
164 4 arniml
 
165
    x1_s <= '1';
166
    x2_s <= '1';
167
    x3_s <= '1';
168
 
169
  end generate;
170
 
171
  -- And finally the boolean flags --------------------------------------------
172
  xtal1_s <= to_boolean(x1_s);
173
  xtal2_s <= to_boolean(x2_s);
174
  xtal3_s <= to_boolean(x3_s);
175
 
176
 
177
  -----------------------------------------------------------------------------
178
  -- Process external_signal
179
  --
180
  -- Purpose:
181
  --   Control signals ALE, PSEN, PROG and RD/WR are generated here.
182
  --
183
  external_signals: process (res_i, xtal_i)
184
  begin
185
    if res_i = res_active_c then
186
      ale_q    <= false;
187
      psen_q   <= false;
188
      prog_q   <= false;
189
      rd_q     <= false;
190
      wr_q     <= false;
191
 
192
    elsif xtal_i'event and xtal_i = clk_active_c then
193
 
194
      case mstate_q is
195
        when MSTATE5 =>
196
          -- RD, WR are set at the end of XTAL2 of first machine cycle
197
          if xtal2_s and not second_cycle_q then
198
            if assert_rd_i then
199
              rd_q <= true;
200
            end if;
201
            if assert_wr_i then
202
              wr_q <= true;
203
            end if;
204
          end if;
205
 
206
        when MSTATE1 =>
207
          if xtal3_s then
208
             psen_q   <= false;
209
           end if;
210
 
211
        when MSTATE2 =>
212
          if xtal2_s then
213
            -- RD, WR are removed at the end of XTAL3 of second machine cycle
214
            rd_q     <= false;
215
            wr_q     <= false;
216
            -- PROG is removed at the and of XTAL3 of second machine cycle
217
            prog_q   <= false;
218
          end if;
219
 
220
        when MSTATE3 =>
221
          -- ALE is set at the end of XTAL2 of every machine cycle
222
          if xtal2_s then
223
            ale_q    <= true;
224
          end if;
225
 
226
        when MSTATE4 =>
227
          if xtal3_s then
228
            -- PSEN is set at the end of XTAL3
229
            if assert_psen_i then
230
              psen_q <= true;
231
            end if;
232
 
233 20 arniml
          end if;
234 4 arniml
 
235 20 arniml
          -- PROG is set at the and of XTAL2
236
          if xtal2_s and multi_cycle_q and not second_cycle_q and
237
            assert_prog_i then
238
            prog_q <= true;
239 4 arniml
          end if;
240
 
241
          -- ALE is removed at the end of XTAL2 of every machine cycle
242
          if xtal2_s then
243
            ale_q    <= false;
244
          end if;
245
 
246
      when others =>
247
        -- recover when states are out of sync
248
        ale_q    <= false;
249
        psen_q   <= false;
250
        prog_q   <= false;
251
        rd_q     <= false;
252
        wr_q     <= false;
253
 
254
      end case;
255
 
256
    end if;
257
 
258
  end process external_signals;
259
  --
260
  -----------------------------------------------------------------------------
261
 
262
 
263
  -----------------------------------------------------------------------------
264
  -- Process states
265
  --
266
  -- Purpose:
267
  --   The Clock State controller.
268
  --
269
  states: process (res_i, clk_i)
270
  begin
271
    if res_i = res_active_c then
272 63 arniml
      -- Reset machine state to MSTATE3
273
      -- This allows a proper instruction fetch for the first real instruction
274
      -- after reset.
275
      -- The MSTATE3 is part of a virtual NOP that has no MSTATE1 and MSTATE2.
276
      mstate_q <= MSTATE3;
277 4 arniml
 
278
    elsif clk_i'event and clk_i = clk_active_c then
279
      if en_clk_i then
280
 
281
        case mstate_q is
282
          when MSTATE5 =>
283
            mstate_q <= MSTATE1;
284
 
285
          when MSTATE1 =>
286
            mstate_q <= MSTATE2;
287
 
288
          when MSTATE2 =>
289
            mstate_q <= MSTATE3;
290
 
291
          when MSTATE3 =>
292
            mstate_q <= MSTATE4;
293
 
294
          when MSTATE4 =>
295
            mstate_q <= MSTATE5;
296
 
297
          when others =>
298
            -- recover when states are out of sync
299
            mstate_q <= MSTATE1;
300
 
301
            -- pragma translate_off
302
            assert false
303
              report "Encoding of Clock States failed!"
304
              severity error;
305
            -- pragma translate_on
306
 
307
        end case;
308
 
309
      end if;
310
 
311
    end if;
312
 
313
  end process states;
314
  --
315
  -----------------------------------------------------------------------------
316
 
317
 
318
  -----------------------------------------------------------------------------
319
  -- Process machine_cycle
320
  --
321
  -- Purpose:
322
  --   Keep track of machine cycles.
323
  --   Basically, this means to differ between first and second cycle.
324
  --
325
  machine_cycle: process (res_i, clk_i)
326
    variable state2_v, state5_v : boolean;
327
  begin
328
    if res_i = res_active_c then
329
      multi_cycle_q  <= false;
330
      second_cycle_q <= false;
331
 
332
    elsif clk_i'event and clk_i = clk_active_c then
333
      if en_clk_i then
334
 
335
        state2_v := mstate_q = MSTATE2;
336
        state5_v := mstate_q = MSTATE5;
337
 
338
        -- multi cycle information is delivered in State 2 from the decoder
339
        if state2_v and multi_cycle_i then
340
          multi_cycle_q <= true;
341
        end if;
342
 
343
        -- mark second machine cycle
344
        if multi_cycle_q and state5_v then
345
          second_cycle_q <= true;
346
        end if;
347
 
348
        -- reset at end of second machine cycle
349
        if state5_v and
350 63 arniml
           (multi_cycle_q and second_cycle_q) then
351 4 arniml
          multi_cycle_q  <= false;
352
          second_cycle_q <= false;
353
        end if;
354
 
355
      end if;
356
 
357
    end if;
358
 
359
  end process machine_cycle;
360
  --
361
  -----------------------------------------------------------------------------
362
 
363
 
364
  -----------------------------------------------------------------------------
365
  -- Output assignments
366
  -----------------------------------------------------------------------------
367
  xtal3_o        <= xtal3_s;
368
  mstate_o       <= mstate_q;
369
  second_cycle_o <= second_cycle_q;
370
  ale_o          <= ale_q;
371
  psen_o         <= psen_q;
372
  prog_o         <= prog_q;
373
  rd_o           <= rd_q;
374
  wr_o           <= wr_q;
375
 
376
end rtl;
377
 
378
 
379
-------------------------------------------------------------------------------
380
-- File History:
381
--
382
-- $Log: not supported by cvs2svn $
383 77 arniml
-- Revision 1.3  2004/04/18 18:56:23  arniml
384
-- reset machine state to MSTATE3 to allow proper instruction fetch
385
-- after reset
386
--
387 63 arniml
-- Revision 1.2  2004/03/28 12:55:06  arniml
388
-- move code for PROG out of if-branch for xtal3_s
389
--
390 20 arniml
-- Revision 1.1  2004/03/23 21:31:52  arniml
391
-- initial check-in
392 4 arniml
--
393 20 arniml
--
394 4 arniml
-------------------------------------------------------------------------------

powered by: WebSVN 2.1.0

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