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 203

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 203 arniml
-- $Id: clock_ctrl.vhd,v 1.10 2005-11-01 21:24:21 arniml Exp $
7 4 arniml
--
8 162 arniml
-- Copyright (c) 2004, 2005, Arnim Laeuger (arniml@opencores.org)
9 4 arniml
--
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 179 arniml
entity t48_clock_ctrl is
53 4 arniml
 
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 162 arniml
    t0_o           : out std_logic;
66 4 arniml
    multi_cycle_i  : in  boolean;
67
    assert_psen_i  : in  boolean;
68
    assert_prog_i  : in  boolean;
69
    assert_rd_i    : in  boolean;
70
    assert_wr_i    : in  boolean;
71
    mstate_o       : out mstate_t;
72
    second_cycle_o : out boolean;
73
    ale_o          : out boolean;
74
    psen_o         : out boolean;
75
    prog_o         : out boolean;
76
    rd_o           : out boolean;
77
    wr_o           : out boolean
78
  );
79
 
80 179 arniml
end t48_clock_ctrl;
81 4 arniml
 
82
 
83
library ieee;
84 77 arniml
use ieee.numeric_std.all;
85 4 arniml
 
86 179 arniml
architecture rtl of t48_clock_ctrl is
87 4 arniml
 
88
  -- The three XTAL1 cycles.
89
  signal xtal_q  : unsigned(1 downto 0);
90
  signal xtal1_s,
91
         xtal2_s,
92
         xtal3_s : boolean;
93
  signal x1_s,
94
         x2_s,
95
         x3_s    : std_logic;
96
 
97 162 arniml
  signal t0_q    : std_logic;
98 4 arniml
 
99 162 arniml
 
100 4 arniml
  -- The five clock states.
101
  signal mstate_q  : mstate_t;
102
 
103
  signal ale_q     : boolean;
104
  signal psen_q    : boolean;
105
  signal prog_q    : boolean;
106
  signal rd_q      : boolean;
107
  signal wr_q      : boolean;
108
 
109
 
110
  -- The Machine Cycle marker.
111
  signal second_cycle_q : boolean;
112
  signal multi_cycle_q  : boolean;
113
 
114
begin
115
 
116
  -----------------------------------------------------------------------------
117
  -- Verify the generics
118
  -----------------------------------------------------------------------------
119
 
120
  -- pragma translate_off
121
 
122
  -- XTAL1 divide by 3 --------------------------------------------------------
123
  assert (xtal_div_3_g = 1) or (xtal_div_3_g = 0)
124
    report "xtal_div_3_g must be either 1 or 0!"
125
    severity failure;
126
 
127
  -- pragma translate_on
128
 
129
 
130
  -----------------------------------------------------------------------------
131
  -- Divide XTAL1 by 3 to derive Clock States.
132
  -----------------------------------------------------------------------------
133
  use_xtal_div: if xtal_div_3_g = 1 generate
134
    xtal: process (res_i, xtal_i)
135
    begin
136
      if res_i = res_active_c then
137 77 arniml
        xtal_q <= TO_UNSIGNED(0, 2);
138 162 arniml
        t0_q   <= '0';
139 4 arniml
 
140
      elsif xtal_i'event and xtal_i = clk_active_c then
141
        if xtal_q < 2 then
142
          xtal_q <= xtal_q + 1;
143
        else
144 77 arniml
          xtal_q <= TO_UNSIGNED(0, 2);
145 4 arniml
        end if;
146
 
147 162 arniml
        if xtal3_s then
148
          t0_q <= '1';
149
        else
150
          t0_q <= '0';
151
        end if;
152
 
153 4 arniml
      end if;
154
 
155
    end process xtal;
156
 
157
    x1_s <=   '1'
158
            when xtal_q = 0 else
159
              '0';
160
    x2_s <=   '1'
161
            when xtal_q = 1 else
162
              '0';
163
    x3_s <=   '1'
164
            when xtal_q = 2 else
165
              '0';
166 162 arniml
    t0_o <= t0_q;
167 4 arniml
 
168
  end generate;
169
 
170
  -----------------------------------------------------------------------------
171
  -- XTAL1 is used directly for Clock States.
172
  -----------------------------------------------------------------------------
173
  no_xtal_div: if xtal_div_3_g = 0 generate
174 77 arniml
    xtal_q <= TO_UNSIGNED(0, 2);
175 4 arniml
 
176
    x1_s <= '1';
177
    x2_s <= '1';
178 203 arniml
    x3_s <=   '1'
179
            when en_clk_i else
180
              '0';
181 162 arniml
    t0_o <= xtal_i;
182 4 arniml
 
183
  end generate;
184
 
185
  -- And finally the boolean flags --------------------------------------------
186
  xtal1_s <= to_boolean(x1_s);
187
  xtal2_s <= to_boolean(x2_s);
188
  xtal3_s <= to_boolean(x3_s);
189
 
190
 
191
  -----------------------------------------------------------------------------
192
  -- Process external_signal
193
  --
194
  -- Purpose:
195
  --   Control signals ALE, PSEN, PROG and RD/WR are generated here.
196
  --
197
  external_signals: process (res_i, xtal_i)
198
  begin
199
    if res_i = res_active_c then
200
      ale_q    <= false;
201
      psen_q   <= false;
202
      prog_q   <= false;
203
      rd_q     <= false;
204
      wr_q     <= false;
205
 
206
    elsif xtal_i'event and xtal_i = clk_active_c then
207
 
208
      case mstate_q is
209
        when MSTATE5 =>
210
          -- RD, WR are set at the end of XTAL2 of first machine cycle
211
          if xtal2_s and not second_cycle_q then
212
            if assert_rd_i then
213
              rd_q <= true;
214
            end if;
215
            if assert_wr_i then
216
              wr_q <= true;
217
            end if;
218
          end if;
219
 
220
        when MSTATE1 =>
221 203 arniml
          if xtal3_s then
222 4 arniml
             psen_q   <= false;
223
           end if;
224
 
225 145 arniml
        when MSTATE2 =>
226
          if xtal2_s then
227
            -- PROG is removed at the end of XTAL2 of second machine cycle
228
            -- according to the user manual, PROG should be removed at the
229
            -- end of XTAL3 but this would raise the need to change P2 at
230
            -- XTAL1 or XTAL2 -> introduction of inter-xtal timing in
231
            -- the rest of the core.
232
            prog_q   <= false;
233
          end if;
234 203 arniml
          if xtal3_s then
235 4 arniml
            -- RD, WR are removed at the end of XTAL3 of second machine cycle
236
            rd_q     <= false;
237
            wr_q     <= false;
238
          end if;
239
 
240
        when MSTATE3 =>
241 203 arniml
          -- ALE is set at the end of XTAL3 of every machine cycle
242
          if xtal3_s then
243 4 arniml
            ale_q    <= true;
244
          end if;
245
 
246
        when MSTATE4 =>
247 203 arniml
          if xtal3_s then
248 4 arniml
            -- PSEN is set at the end of XTAL3
249
            if assert_psen_i then
250
              psen_q <= true;
251
            end if;
252
 
253 20 arniml
          end if;
254 4 arniml
 
255 203 arniml
          -- PROG is set at the end of XTAL3
256
          if xtal3_s and
257
             multi_cycle_q and not second_cycle_q and assert_prog_i then
258 20 arniml
            prog_q <= true;
259 4 arniml
          end if;
260
 
261
          -- ALE is removed at the end of XTAL2 of every machine cycle
262
          if xtal2_s then
263
            ale_q    <= false;
264
          end if;
265
 
266
      when others =>
267
        -- recover when states are out of sync
268
        ale_q    <= false;
269
        psen_q   <= false;
270
        prog_q   <= false;
271
        rd_q     <= false;
272
        wr_q     <= false;
273
 
274
      end case;
275
 
276
    end if;
277
 
278
  end process external_signals;
279
  --
280
  -----------------------------------------------------------------------------
281
 
282
 
283
  -----------------------------------------------------------------------------
284
  -- Process states
285
  --
286
  -- Purpose:
287
  --   The Clock State controller.
288
  --
289
  states: process (res_i, clk_i)
290
  begin
291
    if res_i = res_active_c then
292 63 arniml
      -- Reset machine state to MSTATE3
293
      -- This allows a proper instruction fetch for the first real instruction
294
      -- after reset.
295
      -- The MSTATE3 is part of a virtual NOP that has no MSTATE1 and MSTATE2.
296
      mstate_q <= MSTATE3;
297 4 arniml
 
298
    elsif clk_i'event and clk_i = clk_active_c then
299
      if en_clk_i then
300
 
301
        case mstate_q is
302
          when MSTATE5 =>
303
            mstate_q <= MSTATE1;
304
 
305
          when MSTATE1 =>
306
            mstate_q <= MSTATE2;
307
 
308
          when MSTATE2 =>
309
            mstate_q <= MSTATE3;
310
 
311
          when MSTATE3 =>
312
            mstate_q <= MSTATE4;
313
 
314
          when MSTATE4 =>
315
            mstate_q <= MSTATE5;
316
 
317
          when others =>
318
            -- recover when states are out of sync
319
            mstate_q <= MSTATE1;
320
 
321
            -- pragma translate_off
322
            assert false
323
              report "Encoding of Clock States failed!"
324
              severity error;
325
            -- pragma translate_on
326
 
327
        end case;
328
 
329
      end if;
330
 
331
    end if;
332
 
333
  end process states;
334
  --
335
  -----------------------------------------------------------------------------
336
 
337
 
338
  -----------------------------------------------------------------------------
339
  -- Process machine_cycle
340
  --
341
  -- Purpose:
342
  --   Keep track of machine cycles.
343
  --   Basically, this means to differ between first and second cycle.
344
  --
345
  machine_cycle: process (res_i, clk_i)
346
    variable state2_v, state5_v : boolean;
347
  begin
348
    if res_i = res_active_c then
349
      multi_cycle_q  <= false;
350
      second_cycle_q <= false;
351
 
352
    elsif clk_i'event and clk_i = clk_active_c then
353
      if en_clk_i then
354
 
355
        state2_v := mstate_q = MSTATE2;
356
        state5_v := mstate_q = MSTATE5;
357
 
358
        -- multi cycle information is delivered in State 2 from the decoder
359
        if state2_v and multi_cycle_i then
360
          multi_cycle_q <= true;
361
        end if;
362
 
363
        -- mark second machine cycle
364
        if multi_cycle_q and state5_v then
365
          second_cycle_q <= true;
366
        end if;
367
 
368
        -- reset at end of second machine cycle
369
        if state5_v and
370 63 arniml
           (multi_cycle_q and second_cycle_q) then
371 4 arniml
          multi_cycle_q  <= false;
372
          second_cycle_q <= false;
373
        end if;
374
 
375
      end if;
376
 
377
    end if;
378
 
379
  end process machine_cycle;
380
  --
381
  -----------------------------------------------------------------------------
382
 
383
 
384
  -----------------------------------------------------------------------------
385
  -- Output assignments
386
  -----------------------------------------------------------------------------
387
  xtal3_o        <= xtal3_s;
388
  mstate_o       <= mstate_q;
389
  second_cycle_o <= second_cycle_q;
390
  ale_o          <= ale_q;
391
  psen_o         <= psen_q;
392
  prog_o         <= prog_q;
393
  rd_o           <= rd_q;
394
  wr_o           <= wr_q;
395
 
396
end rtl;
397
 
398
 
399
-------------------------------------------------------------------------------
400
-- File History:
401
--
402
-- $Log: not supported by cvs2svn $
403 203 arniml
-- Revision 1.9  2005/06/11 10:08:43  arniml
404
-- introduce prefix 't48_' for all packages, entities and configurations
405
--
406 179 arniml
-- Revision 1.8  2005/06/09 22:15:10  arniml
407
-- Use en_clk_i instead of xtal3_s for generation of external signals.
408
-- This is required when the core runs with full xtal clock instead
409
-- of xtal/3 (xtal_div_3_g = 0).
410
--
411 176 arniml
-- Revision 1.7  2005/05/04 20:12:36  arniml
412
-- Fix bug report:
413
-- "Wrong clock applied to T0"
414
-- t0_o is generated inside clock_ctrl with a separate flip-flop running
415
-- with xtal_i
416
--
417 162 arniml
-- Revision 1.6  2004/10/25 20:31:12  arniml
418
-- remove PROG and end of XTAL2, see comment for details
419
--
420 145 arniml
-- Revision 1.5  2004/10/25 19:35:41  arniml
421
-- deassert rd_q, wr_q and prog_q at end of XTAL3
422
--
423 142 arniml
-- Revision 1.4  2004/04/24 23:44:25  arniml
424
-- move from std_logic_arith to numeric_std
425
--
426 77 arniml
-- Revision 1.3  2004/04/18 18:56:23  arniml
427
-- reset machine state to MSTATE3 to allow proper instruction fetch
428
-- after reset
429
--
430 63 arniml
-- Revision 1.2  2004/03/28 12:55:06  arniml
431
-- move code for PROG out of if-branch for xtal3_s
432
--
433 20 arniml
-- Revision 1.1  2004/03/23 21:31:52  arniml
434
-- initial check-in
435 4 arniml
--
436
-------------------------------------------------------------------------------

powered by: WebSVN 2.1.0

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