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

Subversion Repositories lxp32

[/] [lxp32/] [trunk/] [verify/] [lxp32/] [src/] [platform/] [timer.vhd] - Blame information for rev 9

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 9 ring0_mipt
---------------------------------------------------------------------
2
-- Timer
3
--
4
-- Part of the LXP32 test platform
5
--
6
-- Copyright (c) 2016 by Alex I. Kuznetsov
7
--
8
-- A simple programmable interval timer.
9
--
10
-- Note: regardless of whether this description is synthesizable,
11
-- it was designed exclusively for simulation purposes.
12
---------------------------------------------------------------------
13
 
14
library ieee;
15
use ieee.std_logic_1164.all;
16
use ieee.numeric_std.all;
17
 
18
entity timer is
19
        port(
20
                clk_i: in std_logic;
21
                rst_i: in std_logic;
22
 
23
                wbs_cyc_i: in std_logic;
24
                wbs_stb_i: in std_logic;
25
                wbs_we_i: in std_logic;
26
                wbs_sel_i: in std_logic_vector(3 downto 0);
27
                wbs_ack_o: out std_logic;
28
                wbs_adr_i: in std_logic_vector(27 downto 2);
29
                wbs_dat_i: in std_logic_vector(31 downto 0);
30
                wbs_dat_o: out std_logic_vector(31 downto 0);
31
 
32
                elapsed_o: out std_logic
33
        );
34
end entity;
35
 
36
architecture rtl of timer is
37
 
38
signal pulses: unsigned(31 downto 0):=(others=>'0');
39
signal interval: unsigned(31 downto 0):=(others=>'0');
40
signal cnt: unsigned(31 downto 0):=(others=>'0');
41
signal elapsed: std_logic:='0';
42
 
43
begin
44
 
45
process (clk_i) is
46
begin
47
        if rising_edge(clk_i) then
48
                if rst_i='1' then
49
                        pulses<=(others=>'0');
50
                        interval<=(others=>'0');
51
                        cnt<=(others=>'0');
52
                        elapsed<='0';
53
                else
54
                        elapsed<='0';
55
                        if pulses/=X"00000000" or cnt/=X"00000000" then
56
                                if cnt=X"00000000" then
57
                                        if pulses/=X"FFFFFFFF" then
58
                                                pulses<=pulses-1;
59
                                        end if;
60
                                        if pulses/=X"00000000" then
61
                                                cnt<=interval;
62
                                        end if;
63
                                else
64
                                        cnt<=cnt-1;
65
                                end if;
66
                                if cnt=X"00000001" then
67
                                        elapsed<='1';
68
                                end if;
69
                        end if;
70
 
71
                        if wbs_cyc_i='1' and wbs_stb_i='1' and wbs_we_i='1' then
72
                                for i in wbs_sel_i'range loop
73
                                        if wbs_sel_i(i)='1' then
74
                                                if wbs_adr_i="00"&X"000000" then
75
                                                        pulses(i*8+7 downto i*8)<=
76
                                                                unsigned(wbs_dat_i(i*8+7 downto i*8));
77
                                                        cnt<=(others=>'0');
78
                                                end if;
79
                                                if wbs_adr_i="00"&X"000001" then
80
                                                        interval(i*8+7 downto i*8)<=
81
                                                                unsigned(wbs_dat_i(i*8+7 downto i*8));
82
                                                        cnt<=(others=>'0');
83
                                                end if;
84
                                        end if;
85
                                end loop;
86
                        end if;
87
                end if;
88
        end if;
89
end process;
90
 
91
wbs_ack_o<=wbs_cyc_i and wbs_stb_i;
92
wbs_dat_o<=std_logic_vector(pulses) when wbs_adr_i="00"&X"000000" else
93
        std_logic_vector(interval) when wbs_adr_i="00"&X"000001" else
94
        (others=>'-');
95
 
96
elapsed_o<=elapsed;
97
 
98
end architecture;

powered by: WebSVN 2.1.0

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