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 162

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 162 arniml
-- $Id: clock_ctrl.vhd,v 1.7 2005-05-04 20:12:36 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
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 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
end clock_ctrl;
81
 
82
 
83
library ieee;
84 77 arniml
use ieee.numeric_std.all;
85 4 arniml
 
86
architecture rtl of clock_ctrl is
87
 
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
    x3_s <= '1';
179 162 arniml
    t0_o <= xtal_i;
180 4 arniml
 
181
  end generate;
182
 
183
  -- And finally the boolean flags --------------------------------------------
184
  xtal1_s <= to_boolean(x1_s);
185
  xtal2_s <= to_boolean(x2_s);
186
  xtal3_s <= to_boolean(x3_s);
187
 
188
 
189
  -----------------------------------------------------------------------------
190
  -- Process external_signal
191
  --
192
  -- Purpose:
193
  --   Control signals ALE, PSEN, PROG and RD/WR are generated here.
194
  --
195
  external_signals: process (res_i, xtal_i)
196
  begin
197
    if res_i = res_active_c then
198
      ale_q    <= false;
199
      psen_q   <= false;
200
      prog_q   <= false;
201
      rd_q     <= false;
202
      wr_q     <= false;
203
 
204
    elsif xtal_i'event and xtal_i = clk_active_c then
205
 
206
      case mstate_q is
207
        when MSTATE5 =>
208
          -- RD, WR are set at the end of XTAL2 of first machine cycle
209
          if xtal2_s and not second_cycle_q then
210
            if assert_rd_i then
211
              rd_q <= true;
212
            end if;
213
            if assert_wr_i then
214
              wr_q <= true;
215
            end if;
216
          end if;
217
 
218
        when MSTATE1 =>
219
          if xtal3_s then
220
             psen_q   <= false;
221
           end if;
222
 
223 145 arniml
        when MSTATE2 =>
224
          if xtal2_s then
225
            -- PROG is removed at the end of XTAL2 of second machine cycle
226
            -- according to the user manual, PROG should be removed at the
227
            -- end of XTAL3 but this would raise the need to change P2 at
228
            -- XTAL1 or XTAL2 -> introduction of inter-xtal timing in
229
            -- the rest of the core.
230
            prog_q   <= false;
231
          end if;
232 142 arniml
          if xtal3_s then
233 4 arniml
            -- RD, WR are removed at the end of XTAL3 of second machine cycle
234
            rd_q     <= false;
235
            wr_q     <= false;
236
          end if;
237
 
238
        when MSTATE3 =>
239
          -- ALE is set at the end of XTAL2 of every machine cycle
240
          if xtal2_s then
241
            ale_q    <= true;
242
          end if;
243
 
244
        when MSTATE4 =>
245
          if xtal3_s then
246
            -- PSEN is set at the end of XTAL3
247
            if assert_psen_i then
248
              psen_q <= true;
249
            end if;
250
 
251 20 arniml
          end if;
252 4 arniml
 
253 20 arniml
          -- PROG is set at the and of XTAL2
254
          if xtal2_s and multi_cycle_q and not second_cycle_q and
255
            assert_prog_i then
256
            prog_q <= true;
257 4 arniml
          end if;
258
 
259
          -- ALE is removed at the end of XTAL2 of every machine cycle
260
          if xtal2_s then
261
            ale_q    <= false;
262
          end if;
263
 
264
      when others =>
265
        -- recover when states are out of sync
266
        ale_q    <= false;
267
        psen_q   <= false;
268
        prog_q   <= false;
269
        rd_q     <= false;
270
        wr_q     <= false;
271
 
272
      end case;
273
 
274
    end if;
275
 
276
  end process external_signals;
277
  --
278
  -----------------------------------------------------------------------------
279
 
280
 
281
  -----------------------------------------------------------------------------
282
  -- Process states
283
  --
284
  -- Purpose:
285
  --   The Clock State controller.
286
  --
287
  states: process (res_i, clk_i)
288
  begin
289
    if res_i = res_active_c then
290 63 arniml
      -- Reset machine state to MSTATE3
291
      -- This allows a proper instruction fetch for the first real instruction
292
      -- after reset.
293
      -- The MSTATE3 is part of a virtual NOP that has no MSTATE1 and MSTATE2.
294
      mstate_q <= MSTATE3;
295 4 arniml
 
296
    elsif clk_i'event and clk_i = clk_active_c then
297
      if en_clk_i then
298
 
299
        case mstate_q is
300
          when MSTATE5 =>
301
            mstate_q <= MSTATE1;
302
 
303
          when MSTATE1 =>
304
            mstate_q <= MSTATE2;
305
 
306
          when MSTATE2 =>
307
            mstate_q <= MSTATE3;
308
 
309
          when MSTATE3 =>
310
            mstate_q <= MSTATE4;
311
 
312
          when MSTATE4 =>
313
            mstate_q <= MSTATE5;
314
 
315
          when others =>
316
            -- recover when states are out of sync
317
            mstate_q <= MSTATE1;
318
 
319
            -- pragma translate_off
320
            assert false
321
              report "Encoding of Clock States failed!"
322
              severity error;
323
            -- pragma translate_on
324
 
325
        end case;
326
 
327
      end if;
328
 
329
    end if;
330
 
331
  end process states;
332
  --
333
  -----------------------------------------------------------------------------
334
 
335
 
336
  -----------------------------------------------------------------------------
337
  -- Process machine_cycle
338
  --
339
  -- Purpose:
340
  --   Keep track of machine cycles.
341
  --   Basically, this means to differ between first and second cycle.
342
  --
343
  machine_cycle: process (res_i, clk_i)
344
    variable state2_v, state5_v : boolean;
345
  begin
346
    if res_i = res_active_c then
347
      multi_cycle_q  <= false;
348
      second_cycle_q <= false;
349
 
350
    elsif clk_i'event and clk_i = clk_active_c then
351
      if en_clk_i then
352
 
353
        state2_v := mstate_q = MSTATE2;
354
        state5_v := mstate_q = MSTATE5;
355
 
356
        -- multi cycle information is delivered in State 2 from the decoder
357
        if state2_v and multi_cycle_i then
358
          multi_cycle_q <= true;
359
        end if;
360
 
361
        -- mark second machine cycle
362
        if multi_cycle_q and state5_v then
363
          second_cycle_q <= true;
364
        end if;
365
 
366
        -- reset at end of second machine cycle
367
        if state5_v and
368 63 arniml
           (multi_cycle_q and second_cycle_q) then
369 4 arniml
          multi_cycle_q  <= false;
370
          second_cycle_q <= false;
371
        end if;
372
 
373
      end if;
374
 
375
    end if;
376
 
377
  end process machine_cycle;
378
  --
379
  -----------------------------------------------------------------------------
380
 
381
 
382
  -----------------------------------------------------------------------------
383
  -- Output assignments
384
  -----------------------------------------------------------------------------
385
  xtal3_o        <= xtal3_s;
386
  mstate_o       <= mstate_q;
387
  second_cycle_o <= second_cycle_q;
388
  ale_o          <= ale_q;
389
  psen_o         <= psen_q;
390
  prog_o         <= prog_q;
391
  rd_o           <= rd_q;
392
  wr_o           <= wr_q;
393
 
394
end rtl;
395
 
396
 
397
-------------------------------------------------------------------------------
398
-- File History:
399
--
400
-- $Log: not supported by cvs2svn $
401 162 arniml
-- Revision 1.6  2004/10/25 20:31:12  arniml
402
-- remove PROG and end of XTAL2, see comment for details
403
--
404 145 arniml
-- Revision 1.5  2004/10/25 19:35:41  arniml
405
-- deassert rd_q, wr_q and prog_q at end of XTAL3
406
--
407 142 arniml
-- Revision 1.4  2004/04/24 23:44:25  arniml
408
-- move from std_logic_arith to numeric_std
409
--
410 77 arniml
-- Revision 1.3  2004/04/18 18:56:23  arniml
411
-- reset machine state to MSTATE3 to allow proper instruction fetch
412
-- after reset
413
--
414 63 arniml
-- Revision 1.2  2004/03/28 12:55:06  arniml
415
-- move code for PROG out of if-branch for xtal3_s
416
--
417 20 arniml
-- Revision 1.1  2004/03/23 21:31:52  arniml
418
-- initial check-in
419 4 arniml
--
420 20 arniml
--
421 4 arniml
-------------------------------------------------------------------------------

powered by: WebSVN 2.1.0

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