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

Subversion Repositories copyblaze

[/] [copyblaze/] [trunk/] [copyblaze/] [rtl/] [vhdl/] [ip/] [wb_timer/] [wb_timer_8.vhd] - Blame information for rev 59

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 34 ameziti
-----------------------------------------------------------------------------
2
-- Wishbone TIMER 8bit ------------------------------------------------------
3
library ieee;
4
use ieee.std_logic_1164.all;
5
use ieee.numeric_std.all;
6
 
7
entity wb_timer_8 is
8
   port (
9
      clk      : in  std_ulogic;
10
      reset    : in  std_ulogic;
11
      -- Wishbone bus
12
      wb_adr_i : in  std_ulogic_vector(7 downto 0);
13
      wb_dat_i : in  std_ulogic_vector(7 downto 0);
14
      wb_dat_o : out std_ulogic_vector(7 downto 0);
15
      wb_cyc_i : in  std_ulogic;
16
      wb_stb_i : in  std_ulogic;
17
      wb_ack_o : out std_ulogic;
18
      wb_we_i  : in  std_ulogic;
19
      wb_irq0_o: out std_ulogic;
20
      wb_irq1_o: out std_ulogic );
21
end wb_timer_8;
22
 
23
-----------------------------------------------------------------------------
24
-- 0x00: TCR0          Timer Control and Status Register
25
-- 0x04: COMPARE0
26
-- 0x08: COUNTER0
27
-- 0x0C: TCR1
28
-- 0x10: COMPARE1
29
-- 0x14: COUNTER1
30
--
31
-- TCRx:
32
-- 
33
--   +-----------------------------------+-----+-----+--------+-------+
34
--   |     ZEROs ( 7 downto 4)           | en0 | ar0 | irq0en | trig0 |
35
--   +-----------------------------------+-----+-----+--------+-------+
36
--
37
 
38
-----------------------------------------------------------------------------
39
-- Implementation -----------------------------------------------------------
40
architecture rtl of wb_timer_8 is
41
        constant        ADDR_TRC0               : std_ulogic_vector(7 downto 0) := x"00";
42
        constant        ADDR_COMPARE0   : std_ulogic_vector(7 downto 0) := x"04";
43
        constant        ADDR_COUNTER0   : std_ulogic_vector(7 downto 0) := x"08";
44
        constant        ADDR_TRC1               : std_ulogic_vector(7 downto 0) := x"0C";
45
        constant        ADDR_COMPARE1   : std_ulogic_vector(7 downto 0) := x"10";
46
        constant        ADDR_COUNTER1   : std_ulogic_vector(7 downto 0) := x"14";
47
 
48
signal wbactive      : std_ulogic;
49
 
50
signal counter0      : unsigned(7 downto 0);
51
signal counter1      : unsigned(7 downto 0);
52
 
53
signal compare0      : unsigned(7 downto 0);
54
signal compare1      : unsigned(7 downto 0);
55
 
56
signal en0, en1      : std_ulogic;     -- Enable counter
57
signal ar0, ar1      : std_ulogic;     -- Auto Reload
58
signal trig0, trig1  : std_ulogic;     -- Triggered
59
 
60
signal irq0en, irq1en: std_ulogic;     -- Enable Interrupt
61
 
62
signal tcr0, tcr1    : std_ulogic_vector(7 downto 0);
63
 
64
 
65
begin
66
 
67
-----------------------------------------------------------------------------
68
-- Wishbone handling --------------------------------------------------------
69
wbactive <= wb_stb_i and wb_cyc_i;
70
 
71
wb_ack_o <= wbactive;
72
 
73
wb_dat_o <= tcr0                        when wbactive='1' and wb_adr_i=ADDR_TRC0                else
74
            std_ulogic_vector(compare0)  when wbactive='1' and wb_adr_i=ADDR_COMPARE0   else
75
            std_ulogic_vector(counter0)  when wbactive='1' and wb_adr_i=ADDR_COUNTER0   else
76
            tcr1                        when wbactive='1' and wb_adr_i=ADDR_TRC1                else
77
            std_ulogic_vector(compare1)  when wbactive='1' and wb_adr_i=ADDR_COMPARE1   else
78
            std_ulogic_vector(counter1)  when wbactive='1' and wb_adr_i=ADDR_COUNTER1   else
79
            (others => '-');
80
 
81
wb_irq0_o <= trig0 and irq0en;
82
wb_irq1_o <= trig1 and irq1en;
83
 
84
tcr0 <= "0000" & en0 & ar0 & irq0en & trig0;
85
tcr1 <= "0000" & en1 & ar1 & irq1en & trig1;
86
 
87
timerproc: process (reset, clk) is
88
variable val : std_ulogic_vector(7 downto 0);
89
begin
90
        if reset='1' then
91
                en0       <= '0';      -- enable
92
                en1       <= '0';
93
                ar0       <= '0';      -- auto reload
94
                ar1       <= '0';
95
                trig0     <= '0';      -- triggered
96
                trig1     <= '0';
97
                irq0en    <= '0';      -- IRQ enable
98
                irq1en    <= '0';
99
                compare0  <= TO_UNSIGNED(0, 8);        -- compare
100
                compare1  <= TO_UNSIGNED(0, 8);
101
                counter0  <= TO_UNSIGNED(0, 8);        -- actual counter
102
                counter1  <= TO_UNSIGNED(0, 8);
103
        elsif clk'event and clk='1' then
104
 
105
                -- Reset trigX on TCR access --------------------------------
106
                if wbactive='1' and wb_adr_i=x"00" then
107
                        trig0 <= '0';
108
                end if;
109
                if wbactive='1' and wb_adr_i=x"0C" then
110
                        trig1 <= '0';
111
                end if;
112
 
113
                -- WB write register ----------------------------------------
114
                if wbactive='1' and wb_we_i='1' then
115
 
116
                        val := wb_dat_i;
117
 
118
                        -- decode WB_ADR_I --
119
                        if wb_adr_i=ADDR_TRC0 then
120
                                en0    <= val(3);
121
                                ar0    <= val(2);
122
                                irq0en <= val(1);
123
                        elsif wb_adr_i=ADDR_COMPARE0 then
124
                                compare0 <= unsigned(val);
125
                        elsif wb_adr_i=ADDR_COUNTER0 then
126
                                counter0 <= unsigned(val);
127
                        elsif wb_adr_i=ADDR_TRC1 then
128
                                en1    <= val(3);
129
                                ar1    <= val(2);
130
                                irq1en <= val(1);
131
                        elsif wb_adr_i=ADDR_COMPARE1 then
132
                                compare1 <= unsigned(val);
133
                        elsif wb_adr_i=ADDR_COUNTER1 then
134
                                counter1 <= unsigned(val);
135
                        end if;
136
                end if;
137
 
138
 
139
                -- timer0 ---------------------------------------------------
140
                if en0='1' then
141
                        if counter0 = compare0 then
142
                                trig0 <= '1';
143
                                if ar0='1' then
144
                                        counter0 <= to_unsigned(1, 8);
145
                                else
146
                                        en0 <= '0';
147
                                end if;
148
                        else
149
                                counter0 <= counter0 + 1;
150
                        end if;
151
                end if;
152
 
153
                -- timer1 ---------------------------------------------------
154
                if en1='1' then
155
                        if counter1 = compare1 then
156
                                trig1 <= '1';
157
                                if ar1='1' then
158
                                        counter1 <= to_unsigned(1, 8);
159
                                else
160
                                        en1 <= '0';
161
                                end if;
162
                        else
163
                                counter1 <= counter1 + 1;
164
                        end if;
165
                end if;
166
 
167
        end if;
168
end process;
169
 
170
end rtl;

powered by: WebSVN 2.1.0

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