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

Subversion Repositories System09

[/] [System09/] [trunk/] [rtl/] [VHDL/] [timer.vhd] - Blame information for rev 95

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 19 dilbert57
--===========================================================================----
2
--
3
--  S Y N T H E Z I A B L E    timer - 9 bit timer
4
--
5
--  www.OpenCores.Org - September 2003
6
--  This core adheres to the GNU public license  
7
--
8
-- File name      : timer.vhd
9
--
10 22 dilbert57
-- Purpose        : 8 bit timer module for System 09
11 19 dilbert57
--
12
-- Dependencies   : ieee.Std_Logic_1164
13
--                  ieee.std_logic_unsigned
14
--
15
-- Uses           : None
16
--
17
-- Author         : John E. Kent      
18
--                  dilbert57@opencores.org      
19
--
20
--===========================================================================----
21
--
22
-- Revision History:
23
--===========================================================================--
24
--
25
-- Version 0.1 - 6 Sept 2002 - John Kent
26
-- converted to a single timer 
27
-- made syncronous with system clock
28
--
29
-- Version 1.0 - 6 Sept 2003 - John Kent
30
-- Realeased to open Cores
31
-- changed Clock Edge
32
--
33 22 dilbert57
-- Version 2.0 - 5th February 2008 - John Kent
34
-- removed Timer inputs and outputs
35
-- made into a simple 8 bit interrupt down counter
36
--
37 19 dilbert57
--===========================================================================
38
--
39
-- Register Addressing:
40
-- addr=0 rw=1 down count
41
-- addr=0 rw=0 preset count
42
-- addr=1 rw=1 status
43
-- addr=1 rw=0 control
44
--
45
-- Control register
46
-- b0 = counter enable
47
-- b7 = interrupt enable
48
--
49
-- Status register
50
-- b7 = interrupt flag
51
--
52 22 dilbert57
-- Operation:
53
-- Write count to counter register
54
-- Enable counter by setting bit 0 of the control register
55
-- enable interrupts by setting bit 7 of the control register
56
-- Counter will count down to zero
57
-- when it reaches zero the terminal flag is set
58
-- if the interrupt is enabled an interrupt is generated
59
-- The interrupt may be disabled by writing a 0 to bit 7 of the control register
60
-- or by loading a new down count into the counter register.
61
-- 
62 19 dilbert57
library ieee;
63
use ieee.std_logic_1164.all;
64
use ieee.std_logic_unsigned.all;
65
 
66
entity timer is
67
        port (
68
         clk        : in  std_logic;
69
    rst        : in  std_logic;
70
    cs         : in  std_logic;
71
    rw         : in  std_logic;
72
    addr       : in  std_logic;
73
    data_in    : in  std_logic_vector(7 downto 0);
74
         data_out   : out std_logic_vector(7 downto 0);
75 22 dilbert57
         irq        : out std_logic
76 19 dilbert57
  );
77
end;
78
 
79
architecture rtl of timer is
80
signal timer_ctrl  : std_logic_vector(7 downto 0);
81
signal timer_stat  : std_logic_vector(7 downto 0);
82
signal timer_count : std_logic_vector(7 downto 0);
83
signal timer_term  : std_logic; -- Timer terminal count
84
--
85
-- control/status register bits
86
--
87
constant T_enab   : integer := 0; -- 0=disable, 1=enabled
88
constant T_irq    : integer := 7; -- 0=disabled, 1-enabled
89
 
90
begin
91
 
92
--------------------------------
93
--
94
-- write control registers
95
-- doesn't do anything yet
96
--
97
--------------------------------
98
timer_write : process( clk, rst, cs, rw, addr, data_in,
99 22 dilbert57
                       timer_ctrl, timer_term, timer_count )
100 19 dilbert57
begin
101 22 dilbert57
  if rst = '1' then
102
           timer_count <= "00000000";
103
                timer_ctrl  <= "00000000";
104
                timer_term  <= '0';
105
  elsif clk'event and clk = '0' then
106
    if cs = '1' and rw = '0' then
107 19 dilbert57
           if addr='0' then
108 22 dilbert57
                  timer_count <= data_in;
109
                  timer_term  <= '0';
110 19 dilbert57
           else
111
                  timer_ctrl <= data_in;
112
                end if;
113
         else
114
           if (timer_ctrl(T_enab) = '1') then
115
                  if (timer_count = "00000000" ) then
116
                    timer_term <= '1';
117 22 dilbert57
        else
118
          timer_count <= timer_count - 1;
119 19 dilbert57
                  end if;
120
                end if;
121
    end if;
122
  end if;
123
end process;
124
 
125
--
126
-- timer data output mux
127
--
128
timer_read : process( addr, timer_count, timer_stat )
129
begin
130
  if addr='0' then
131
    data_out <= timer_count;
132
  else
133
    data_out <= timer_stat;
134
  end if;
135
end process;
136
 
137
--
138 22 dilbert57
-- read timer strobe to reset interrupts
139 19 dilbert57
--
140 22 dilbert57
timer_interrupt : process( timer_term, timer_ctrl )
141 19 dilbert57
begin
142 22 dilbert57
         irq <= timer_term and timer_ctrl( T_irq );
143 19 dilbert57
end process;
144
 
145
  --
146
  -- timer status register
147
  --
148 22 dilbert57
  timer_status : process( timer_ctrl, timer_term )
149 19 dilbert57
  begin
150 22 dilbert57
    timer_stat(6 downto 0) <= timer_ctrl(6 downto 0);
151
    timer_stat(T_irq) <= timer_term;
152 19 dilbert57
  end process;
153
 
154
end rtl;
155
 

powered by: WebSVN 2.1.0

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