1 |
35 |
arniml |
-------------------------------------------------------------------------------
|
2 |
|
|
--
|
3 |
|
|
-- The timer unit.
|
4 |
|
|
--
|
5 |
179 |
arniml |
-- $Id: t400_timer.vhd 179 2009-04-01 19:48:38Z arniml $
|
6 |
35 |
arniml |
--
|
7 |
|
|
-- Copyright (c) 2006 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/t400/
|
43 |
|
|
--
|
44 |
|
|
-------------------------------------------------------------------------------
|
45 |
|
|
|
46 |
|
|
library ieee;
|
47 |
|
|
use ieee.std_logic_1164.all;
|
48 |
|
|
|
49 |
|
|
use work.t400_pack.all;
|
50 |
|
|
|
51 |
|
|
entity t400_timer is
|
52 |
|
|
|
53 |
|
|
port (
|
54 |
|
|
-- System Interface -------------------------------------------------------
|
55 |
|
|
ck_i : in std_logic;
|
56 |
|
|
ck_en_i : in boolean;
|
57 |
|
|
por_i : in boolean;
|
58 |
|
|
icyc_en_i : in boolean;
|
59 |
|
|
-- Skip Interface ---------------------------------------------------------
|
60 |
|
|
op_i : in skip_op_t;
|
61 |
|
|
c_o : out boolean
|
62 |
|
|
);
|
63 |
|
|
|
64 |
|
|
end t400_timer;
|
65 |
|
|
|
66 |
|
|
|
67 |
|
|
library ieee;
|
68 |
|
|
use ieee.numeric_std.all;
|
69 |
|
|
|
70 |
|
|
architecture rtl of t400_timer is
|
71 |
|
|
|
72 |
|
|
signal cnt_q : unsigned(9 downto 0);
|
73 |
|
|
signal c_q : boolean;
|
74 |
|
|
|
75 |
|
|
begin
|
76 |
|
|
|
77 |
|
|
-----------------------------------------------------------------------------
|
78 |
|
|
-- Process seq
|
79 |
|
|
--
|
80 |
|
|
-- Purpose:
|
81 |
|
|
-- Implements the sequential elements:
|
82 |
|
|
-- * timer counter
|
83 |
|
|
-- * carry (underflow) marker flag
|
84 |
|
|
--
|
85 |
|
|
seq: process (ck_i, por_i)
|
86 |
|
|
begin
|
87 |
|
|
if por_i then
|
88 |
|
|
cnt_q <= (others => '1');
|
89 |
|
|
c_q <= false;
|
90 |
|
|
|
91 |
|
|
elsif ck_i'event and ck_i = '1' then
|
92 |
|
|
if icyc_en_i then
|
93 |
|
|
if cnt_q = 0 then
|
94 |
|
|
-- counter underflow:
|
95 |
|
|
-- * reload counter
|
96 |
|
|
-- * set marker flag
|
97 |
|
|
cnt_q <= (others => '1');
|
98 |
|
|
c_q <= true;
|
99 |
|
|
else
|
100 |
|
|
cnt_q <= cnt_q - 1;
|
101 |
|
|
end if;
|
102 |
|
|
end if;
|
103 |
|
|
|
104 |
|
|
if ck_en_i and op_i = SKIP_TIMER then
|
105 |
|
|
c_q <= false;
|
106 |
|
|
end if;
|
107 |
|
|
end if;
|
108 |
|
|
end process seq;
|
109 |
|
|
--
|
110 |
|
|
-----------------------------------------------------------------------------
|
111 |
|
|
|
112 |
|
|
|
113 |
|
|
c_o <= c_q;
|
114 |
|
|
|
115 |
|
|
end rtl;
|