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

Subversion Repositories tinyvliw8

[/] [tinyvliw8/] [trunk/] [src/] [vhdl/] [timer.vhd] - Blame information for rev 9

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 steckol
-----------------------------------------------------------------
2 9 steckol
--
3
-- Design:  tinyVLIW8 soft-core processor
4 2 steckol
-- Author:  Oliver Stecklina <stecklina@ihp-microelectronics.com>
5
-- Date:    27.05.2015 
6
-- File:    timer.vhd
7 9 steckol
--
8 2 steckol
-----------------------------------------------------------------
9 9 steckol
--
10
-- Description : 16-bit timer module. The timer provides two
11 2 steckol
--      internal timer modules.
12 9 steckol
--
13 2 steckol
-----------------------------------------------------------------
14 9 steckol
--
15 2 steckol
--    Copyright (C) 2015 IHP GmbH, Frankfurt (Oder), Germany
16
--
17
-- This code is free software. It is licensed under the EUPL, Version 1.1
18
-- or - as soon they will be approved by the European Commission - subsequent
19
-- versions of the EUPL (the "License").
20
-- You may redistribute this code and/or modify it under the terms of this
21
-- License.
22
-- You may not use this work except in compliance with the License.
23
-- You may obtain a copy of the License at:
24
--
25
-- http://joinup.ec.europa.eu/software/page/eupl/licence-eupl
26
--
27
-- Unless required by applicable law or agreed to in writing, software
28
-- distributed under the License is distributed on an "AS IS" basis,
29
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
30
-- See the License for the specific language governing permissions and
31
-- limitations under the License.
32 9 steckol
--
33
-----------------------------------------------------------------
34 2 steckol
 
35 9 steckol
LIBRARY IEEE;
36 2 steckol
 
37
USE IEEE.STD_LOGIC_1164.ALL;
38
use ieee.std_logic_arith.all;
39
 
40
ENTITY timer IS
41
        PORT (
42
                clk       : in std_logic;
43
 
44
                addr      : in std_logic_vector(2 downto 0);      -- register address
45
 
46
                writeEn_n : in  STD_LOGIC;                         -- write enable, low active
47
                readEn_n  : in  STD_LOGIC;                    -- read enable, low active
48
 
49
                dataOut   : OUT std_logic_vector(7 downto 0); -- data bus for writing register
50
                dataIn    : IN std_logic_vector(7 downto 0);  -- data bus for reading register
51
 
52
                irq       : out std_logic;
53
                irq_ack   : in  std_logic;
54
 
55
                rst_n     : IN  STD_LOGIC                -- asynchr. reset, low active
56
        );
57
END timer;
58
 
59
ARCHITECTURE behav OF timer IS
60 9 steckol
 
61
component clock_divider
62 2 steckol
        generic (n: integer := 2);
63
        PORT (
64 9 steckol
                inclk     : in  std_logic;
65
                outclk    : out std_logic;
66
 
67
                div       : in std_logic_vector((n - 1) downto 0);
68
                en        : IN std_logic
69 2 steckol
        );
70
END component;
71 9 steckol
 
72 2 steckol
component gendelay
73
        generic (n: integer := 1);
74
        port (
75
                a_in    : in    std_logic;
76
                a_out   : out   std_logic
77
        );
78
end component;
79 9 steckol
 
80
--      signal clk_s      : std_logic;
81
        signal rst_n_s    : std_logic;
82
 
83 2 steckol
        signal cnt_reg    : std_logic_vector(15 downto 0);       -- state counter
84
        signal ifg_reg    : std_logic_vector(1 downto 0);
85 9 steckol
 
86
        signal ccr0       : std_logic_vector(15 downto 0);
87
        signal ccr1       : std_logic_vector(15 downto 0);
88
 
89
        -- | clr(7) | mode(6) | ie1(5) | ie0(4) | .. | div(2 .. 1) | en(0) |
90
        signal ctl_reg    : std_logic_vector(6 downto 0);
91
 
92
        signal irq_s      : std_logic;
93
        signal ifgEn_s    : std_logic;
94
        signal divclk_s   : std_logic;
95
 
96
        signal clrBit_s      : std_logic;
97
        signal clr_s      : std_logic;
98
 
99
  signal rst_tar_cnt : std_logic;
100
 
101 2 steckol
BEGIN
102 9 steckol
 
103
--      delay_i: gendelay
104
--              generic map (n => 2)
105
--              port map (
106
--                      a_in    => clrBit_s,
107
--                      a_out   => clr_s
108
--              );
109
  clr_s <= clrBit_s;
110
        rst_n_s <= rst_n;
111
--      clk_s <= clk;
112
 
113
        clk_div_i : clock_divider
114
        generic map (n => 2)
115
        port map (
116
                inclk  => clk,
117
                outclk => divclk_s,
118
 
119
                div    => ctl_reg(2 downto 1),
120
                en     => ctl_reg(0)
121
        );
122
 
123
        clrBit_s <= '1' when dataIn(7) = '1' and readEn_n = '0' and addr = "000" and writeEn_n = '0' else
124
                    '0';
125
 
126
  rst_tar_cnt <='0' when rst_n_s='0' else
127
                '0' when clrBit_s='1' else
128
                '1';
129
 
130
 
131
        tar_cnt : process (divclk_s, rst_tar_cnt)                       -- state counter
132 2 steckol
                variable cnt: unsigned (15 downto 0);
133
        BEGIN
134 9 steckol
                --IF (rst_n_s = '0' or clr_s = '1') THEN
135
    IF (rst_tar_cnt='0') THEN
136 2 steckol
                         cnt := (others => '0');
137 9 steckol
                ELSE
138
                        if (divclk_s'EVENT AND divclk_s = '1') THEN     -- rising SCKL edge                             
139 2 steckol
                                IF (ctl_reg(6) = '0' and cnt = cnt'high) or (ctl_reg(6) = '1' and cnt = unsigned(ccr0)) THEN
140
                                        cnt := (others => '0');
141
                                ELSE
142
                                        cnt := cnt + 1;
143 9 steckol
                                END IF;
144 2 steckol
                        END if;
145 9 steckol
                END IF;
146
 
147 2 steckol
                cnt_reg <= std_logic_vector(cnt);
148
        END PROCESS;
149 9 steckol
 
150
        irq_en : process(rst_n_s, clk)
151
        begin
152 2 steckol
                IF (rst_n_s = '0') THEN
153
                         irq_s <= '0';
154 9 steckol
                ELSE
155
                        if (clk'EVENT AND clk = '0') THEN        -- falling SCKL edge
156
                                if (irq_ack = '1') then
157
                                        irq_s <= '0';
158
                                else
159
                                        if ((ctl_reg(4) = '1' and cnt_reg = ccr0 and ifg_reg(0) = '0') or (ctl_reg(5) = '1' and cnt_reg = ccr1 and ifg_reg(1) = '0')) then
160
                                                irq_s <= '1';
161
                                        end if;
162
                                end if;
163
                        end if;
164
                end if;
165
        end process;
166
 
167
        ifgEn_s <=  irq_s or not(writeEn_n);
168
 
169
        ifg : process(rst_n_s, ifgEn_s)
170 2 steckol
        BEGIN
171
                IF (rst_n_s = '0') THEN
172
                         ifg_reg <= (others => '0');
173 9 steckol
                ELSE
174
                        if (ifgEn_s'event and ifgEn_s = '1') then
175
                                if (irq_s = '1') then
176
                                        if (ctl_reg(4) = '1' and cnt_reg = ccr0) then
177
                                                ifg_reg(0) <= '1';
178
                                        end if;
179
 
180
                                        if (ctl_reg(5) = '1' and cnt_reg = ccr1) then
181
                                                ifg_reg(1) <= '1';
182
                                        end if;
183
                                else
184
                                        if (readEn_n = '0' and writeEn_n = '0' and addr = "001") then
185
                                                ifg_reg <= ifg_reg and not(dataIn(1 downto 0));
186
                                        end if;
187
                                end if;
188
                        end if;
189
                end if;
190
        end process;
191
 
192
        wr_reg : process(rst_n_s, readEn_n, writeEn_n)                  -- state counter
193 2 steckol
        BEGIN
194
                IF (rst_n_s = '0') THEN
195 9 steckol
                         ctl_reg <= (others => '0');
196
 
197 2 steckol
                         ccr0    <= (others => '0');
198
                         ccr1    <= (others => '0');
199 9 steckol
                ELSE
200
                        if (readEn_n = '0') then
201
                                if (writeEn_n'event and writeEn_n = '0') then
202
                                        CASE addr IS
203
                                                when "000" => ctl_reg           <= dataIn(6 downto 0);
204
                                                when "100" => ccr0(7 downto 0)  <= dataIn;
205
                                                when "101" => ccr0(15 downto 8) <= dataIn;
206
                                                when "110" => ccr1(7 downto 0)  <= dataIn;
207
                                                when "111" => ccr1(15 downto 8) <= dataIn;
208
                                                WHEN others => null;
209
                                        END CASE;
210
                                end if;
211
                        end if;
212
                end if;
213 2 steckol
        END PROCESS;
214 9 steckol
 
215
 
216
        dataOut <= '0' & ctl_reg                   when rst_n_s = '1' and readEn_n = '0' and addr = "000" else
217
                   "000000" & ifg_reg(1 downto 0)  when rst_n_s = '1' and readEn_n = '0' and addr = "001" else
218
                   cnt_reg(7 downto 0)             when rst_n_s = '1' and readEn_n = '0' and addr = "010" else
219
                   cnt_reg(15 downto 8)            when rst_n_s = '1' and readEn_n = '0' and addr = "011" else
220
                   ccr0(7 downto 0)                when rst_n_s = '1' and readEn_n = '0' and addr = "100" else
221
                   ccr0(15 downto 8)               when rst_n_s = '1' and readEn_n = '0' and addr = "101" else
222
                   ccr1(7 downto 0)                when rst_n_s = '1' and readEn_n = '0' and addr = "110" else
223
                   ccr1(15 downto 8)               when rst_n_s = '1' and readEn_n = '0' and addr = "111" else
224
                   (others => '0');
225
 
226
        irq <= irq_s when rst_n_s = '1' else
227
               '0';
228 2 steckol
 
229
END behav;
230
 

powered by: WebSVN 2.1.0

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