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

Subversion Repositories t48

[/] [t48/] [tags/] [rel_0_6_beta/] [rtl/] [vhdl/] [clock_ctrl.vhd] - Blame information for rev 145

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

powered by: WebSVN 2.1.0

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