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

Subversion Repositories open8_urisc

[/] [open8_urisc/] [trunk/] [VHDL/] [o8_timer24.vhd] - Blame information for rev 312

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 312 jshamlet
-- VHDL Units :  o8_timer24
2
-- Description:  Provides an 24-bit microsecond resolution timer for generating
3
--            :   periodic interrupts for the Open8 CPU. This timer has a
4
--            :   programmable timebase selector that allows the resolution to
5
--            :   be set at run-time.
6
--
7
-- Register Map:
8
-- Offset  Bitfield Description                        Read/Write
9
--   0x00  AAAAAAAA Req Interval Byte 0                   (RW)
10
--   0x01  AAAAAAAA Req Interval Byte 1                   (RW)
11
--   0x02  AAAAAAAA Req Interval Byte 2                   (RW)
12
--   0x03  CBA----- Control/Status Register               (RW)
13
--                   A: Update timer (WR) or pending (RD)
14
--                   B: Timebase (0 = uS / 1 = mS)
15
--                   C: Output Enable
16
--
17
-- Notes      :  Setting the output to 0x000000 OR clearing bit C will disable
18
--            :   the timer.
19
--            :  Update pending is true if bit A is 1, otherwise false
20
--
21
-- Revision History
22
-- Author          Date     Change
23
------------------ -------- ---------------------------------------------------
24
-- Seth Henry      05/17/23 Initial upload (based on sys_timer_ii)
25
 
26
library ieee;
27
use ieee.std_logic_1164.all;
28
  use ieee.std_logic_unsigned.all;
29
  use ieee.std_logic_arith.all;
30
  use ieee.std_logic_misc.all;
31
 
32
library work;
33
  use work.open8_pkg.all;
34
 
35
entity o8_timer24 is
36
generic(
37
  Address                    : ADDRESS_TYPE
38
);
39
port(
40
  Open8_Bus                  : in  OPEN8_BUS_TYPE;
41
  Write_Qual                 : in  std_logic := '1';
42
  Rd_Data                    : out DATA_TYPE;
43
  Interrupt                  : out std_logic
44
);
45
end entity;
46
 
47
architecture behave of o8_timer24 is
48
 
49
  alias Clock                is Open8_Bus.Clock;
50
  alias Reset                is Open8_Bus.Reset;
51
  alias uSec_Tick            is Open8_Bus.uSec_Tick;
52
 
53
  constant User_Addr         : std_logic_vector(15 downto 2) :=
54
                                Address(15 downto 2);
55
  alias  Comp_Addr           is Open8_Bus.Address(15 downto 2);
56
  signal Addr_Match          : std_logic := '0';
57
 
58
  alias  Reg_Sel_d           is Open8_Bus.Address(1 downto 0);
59
  signal Reg_Sel_q           : std_logic_vector(1 downto 0) := "00";
60
  signal Wr_En_d             : std_logic;
61
  signal Wr_En_q             : std_logic := '0';
62
  alias  Wr_Data_d           is Open8_Bus.Wr_Data;
63
  signal Wr_Data_q           : DATA_TYPE := x"00";
64
  signal Rd_En_d             : std_logic := '0';
65
  signal Rd_En_q             : std_logic := '0';
66
 
67
  signal Req_Interval        : std_logic_vector(23 downto 0) := x"000000";
68
  alias  Req_Interval_B0     is Req_Interval( 7 downto  0);
69
  alias  Req_Interval_B1     is Req_Interval(15 downto  8);
70
  alias  Req_Interval_B2     is Req_Interval(23 downto 16);
71
 
72
  signal Int_Interval        : std_logic_vector(23 downto 0) := x"000000";
73
 
74
  signal Timebase            : std_logic := '0';
75
  signal Update_Interval     : std_logic := '0';
76
  signal Update_Pending      : std_logic := '0';
77
  signal Output_Enable       : std_logic := '0';
78
  signal Output_Qual         : std_logic := '0';
79
 
80
 
81
  signal Timer_Cnt           : std_logic_vector(23 downto 0) := x"000000";
82
 
83
  constant MSEC_DELAY        : std_logic_vector(9 downto 0) :=
84
                                conv_std_logic_vector(1000,10);
85
 
86
  signal mSec_Timer          : std_logic_vector(9 downto 0) := (others => '0');
87
  signal mSec_Tick           : std_logic := '0';
88
 
89
  signal Timer_Tick          : std_logic := '0';
90
 
91
begin
92
 
93
  Addr_Match                 <= '1' when Comp_Addr = User_Addr else '0';
94
  Wr_En_d                    <= Addr_Match and Open8_Bus.Wr_En;
95
  Rd_En_d                    <= Addr_Match and Open8_Bus.Rd_En;
96
 
97
  mSec_Tick_proc: process( Clock, Reset )
98
  begin
99
    if( Reset = Reset_Level )then
100
      mSec_Timer            <= (others => '0');
101
      mSec_Tick             <= '0';
102
    elsif( rising_edge(Clock) )then
103
      mSec_Timer            <= mSec_Timer - uSec_Tick;
104
      mSec_Tick             <= '0';
105
      if( mSec_Timer = 0 )then
106
        mSec_Timer          <= MSEC_DELAY;
107
        mSec_Tick           <= '1';
108
      end if;
109
    end if;
110
  end process;
111
 
112
  Timer_Tick                 <= mSec_Tick when Timebase = '1' else uSec_Tick;
113
 
114
  io_reg: process( Clock, Reset )
115
  begin
116
    if( Reset = Reset_Level )then
117
      Reg_Sel_q              <= "00";
118
      Wr_En_q                <= '0';
119
      Wr_Data_q              <= x"00";
120
      Rd_En_q                <= '0';
121
      Rd_Data                <= OPEN8_NULLBUS;
122
      Req_Interval           <= x"000000";
123
      Update_Interval        <= '0';
124
      Update_Pending         <= '0';
125
      Timebase               <= '0';
126
      Output_Enable          <= '0';
127
    elsif( rising_edge( Clock ) )then
128
      Reg_Sel_q              <= Reg_Sel_d;
129
 
130
      Wr_En_q                <= Wr_En_d;
131
      Wr_Data_q              <= Wr_Data_d;
132
      Update_Interval        <= '0';
133
      if( Wr_En_q = '1' and Write_Qual = '1' )then
134
        case( Reg_Sel_q )is
135
          when "00" =>
136
            Req_Interval_B0  <= Wr_Data_q;
137
            Update_Pending   <= '1';
138
          when "01" =>
139
            Req_Interval_B1  <= Wr_Data_q;
140
            Update_Pending   <= '1';
141
          when "10" =>
142
            Req_Interval_B2  <= Wr_Data_q;
143
            Update_Pending   <= '1';
144
          when "11" =>
145
            Output_Enable    <= Wr_Data_q(7);
146
            Timebase         <= Wr_Data_q(6);
147
            Update_Interval  <= Wr_Data_q(5);
148
          when others => null;
149
        end case;
150
      end if;
151
 
152
      if( Update_Interval = '1' )then
153
        Update_Pending       <= '0';
154
      end if;
155
 
156
      Rd_Data                <= OPEN8_NULLBUS;
157
      Rd_En_q                <= Rd_En_d;
158
      if( Rd_En_q = '1' )then
159
        case( Reg_Sel_q )is
160
          when "00" =>
161
            Rd_Data          <= Req_Interval_B0;
162
          when "01" =>
163
            Rd_Data          <= Req_Interval_B1;
164
          when "10" =>
165
            Rd_Data          <= Req_Interval_B2;
166
          when "11" =>
167
            Rd_Data          <= Output_Enable & Timebase &
168
                                Update_Pending & "00000";
169
          when others => null;
170
        end case;
171
      end if;
172
    end if;
173
  end process;
174
 
175
  Interval_proc: process( Clock, Reset )
176
  begin
177
    if( Reset = Reset_Level )then
178
      Output_Qual            <= '0';
179
      Int_Interval           <= x"000000";
180
      Timer_Cnt              <= x"000000";
181
      Interrupt              <= '0';
182
    elsif( rising_edge(Clock) )then
183
      Output_Qual            <= Output_Enable and or_reduce(Int_Interval);
184
      Interrupt              <= '0';
185
      Timer_Cnt              <= Timer_Cnt - Timer_Tick;
186
      if( Update_Interval = '1' )then
187
        Int_Interval         <= Req_Interval;
188
        Timer_Cnt            <= Req_Interval;
189
      elsif( or_reduce(Timer_Cnt) = '0' )then
190
        Timer_Cnt            <= Int_Interval;
191
        Interrupt            <= Output_Qual;
192
      end if;
193
    end if;
194
  end process;
195
 
196
end architecture;

powered by: WebSVN 2.1.0

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