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

Subversion Repositories open8_urisc

[/] [open8_urisc/] [trunk/] [VHDL/] [o8_sys_timer_ii.vhd] - Blame information for rev 334

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

Line No. Rev Author Line
1 229 jshamlet
-- Copyright (c)2006, 2016, 2019, 2020 Jeremy Seth Henry
2
-- All rights reserved.
3
--
4
-- Redistribution and use in source and binary forms, with or without
5
-- modification, are permitted provided that the following conditions are met:
6
--     * Redistributions of source code must retain the above copyright
7
--       notice, this list of conditions and the following disclaimer.
8
--     * Redistributions in binary form must reproduce the above copyright
9
--       notice, this list of conditions and the following disclaimer in the
10
--       documentation and/or other materials provided with the distribution,
11
--       where applicable (as part of a user interface, debugging port, etc.)
12
--
13
-- THIS SOFTWARE IS PROVIDED BY JEREMY SETH HENRY ``AS IS'' AND ANY
14
-- EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15
-- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16
-- DISCLAIMED. IN NO EVENT SHALL JEREMY SETH HENRY BE LIABLE FOR ANY
17
-- DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18
-- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19
-- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
20
-- ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22
-- THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23
--
24
-- VHDL Units :  o8_sys_timer
25 308 jshamlet
-- Description:  Provides an 24-bit microsecond resolution timer for generating
26 229 jshamlet
--            :   periodic interrupts for the Open8 CPU.
27
--
28
-- Register Map:
29
-- Offset  Bitfield Description                        Read/Write
30
--   0x00  AAAAAAAA Req Interval Byte 0                   (RW)
31
--   0x01  AAAAAAAA Req Interval Byte 1                   (RW)
32
--   0x02  AAAAAAAA Req Interval Byte 2                   (RW)
33
--   0x03  BA------ Control/Status Register               (RW)
34 240 jshamlet
--                   A: Update timer (WR) or pending (RD) (RW)
35 229 jshamlet
--                   B: Output Enable
36
--
37
-- Notes      :  Setting the output to 0x000000 will disable the timer
38
--            :  Update pending is true if bit A is 1, otherwise false
39
--
40
-- Revision History
41
-- Author          Date     Change
42
------------------ -------- ---------------------------------------------------
43
-- Seth Henry      07/28/11 Design Start
44
-- Seth Henry      12/19/19 Renamed Tmr_Out to Interrupt
45
-- Seth Henry      04/09/20 Modified timer update logic to reset the timer on
46
--                           interval write.
47
-- Seth Henry      04/16/20 Modified to use Open8 bus record
48
-- Seth Henry      04/17/20 Altered interval to be a 24-bit counter
49 244 jshamlet
-- Seth Henry      05/18/20 Added write qualification input
50 308 jshamlet
-- Seth Henry      01/18/23 Added microsecond/millisecond generic
51 229 jshamlet
 
52 308 jshamlet
 
53 229 jshamlet
library ieee;
54
use ieee.std_logic_1164.all;
55
  use ieee.std_logic_unsigned.all;
56
  use ieee.std_logic_arith.all;
57
  use ieee.std_logic_misc.all;
58
 
59
library work;
60
  use work.open8_pkg.all;
61
 
62
entity o8_sys_timer_ii is
63
generic(
64 308 jshamlet
  mSec_Resolution            : boolean := FALSE;
65 229 jshamlet
  Address                    : ADDRESS_TYPE
66
);
67
port(
68
  Open8_Bus                  : in  OPEN8_BUS_TYPE;
69 244 jshamlet
  Write_Qual                 : in  std_logic := '1';
70 229 jshamlet
  Rd_Data                    : out DATA_TYPE;
71
  Interrupt                  : out std_logic
72
);
73
end entity;
74
 
75
architecture behave of o8_sys_timer_ii is
76
 
77
  alias Clock                is Open8_Bus.Clock;
78
  alias Reset                is Open8_Bus.Reset;
79
  alias uSec_Tick            is Open8_Bus.uSec_Tick;
80 333 jshamlet
  alias CPU_Wr_En            is Open8_Bus.Wr_En;
81
  alias CPU_Rd_En            is Open8_Bus.Rd_En;
82 229 jshamlet
 
83
  constant User_Addr         : std_logic_vector(15 downto 2) :=
84
                                Address(15 downto 2);
85
  alias  Comp_Addr           is Open8_Bus.Address(15 downto 2);
86 244 jshamlet
  signal Addr_Match          : std_logic := '0';
87 229 jshamlet
 
88 244 jshamlet
  alias  Reg_Sel_d           is Open8_Bus.Address(1 downto 0);
89
  signal Reg_Sel_q           : std_logic_vector(1 downto 0) := "00";
90
  signal Wr_En_d             : std_logic;
91
  signal Wr_En_q             : std_logic := '0';
92
  alias  Wr_Data_d           is Open8_Bus.Wr_Data;
93 229 jshamlet
  signal Wr_Data_q           : DATA_TYPE := x"00";
94 244 jshamlet
  signal Rd_En_d             : std_logic := '0';
95 229 jshamlet
  signal Rd_En_q             : std_logic := '0';
96
 
97
  signal Req_Interval        : std_logic_vector(23 downto 0) := x"000000";
98
  alias  Req_Interval_B0     is Req_Interval( 7 downto  0);
99
  alias  Req_Interval_B1     is Req_Interval(15 downto  8);
100
  alias  Req_Interval_B2     is Req_Interval(23 downto 16);
101
 
102
  signal Int_Interval        : std_logic_vector(23 downto 0) := x"000000";
103
 
104
  signal Update_Interval     : std_logic := '0';
105
  signal Update_Pending      : std_logic := '0';
106
  signal Output_Enable       : std_logic := '0';
107
  signal Timer_Cnt           : std_logic_vector(23 downto 0) := x"000000";
108
 
109 308 jshamlet
  constant MSEC_DELAY        : std_logic_vector(9 downto 0) :=
110
                                conv_std_logic_vector(1000,10);
111
 
112
  signal mSec_Timer          : std_logic_vector(9 downto 0) := (others => '0');
113
 
114
  signal Timer_Tick          : std_logic := '0';
115
 
116 229 jshamlet
begin
117
 
118
  Addr_Match                 <= '1' when Comp_Addr = User_Addr else '0';
119 331 jshamlet
  Wr_En_d                    <= Addr_Match and Write_Qual and CPU_Wr_En;
120
  Rd_En_d                    <= Addr_Match and CPU_Rd_En;
121 229 jshamlet
 
122 308 jshamlet
mSec_Resolution_enabled : if( mSec_Resolution )generate
123
 
124
  mSec_Tick_proc: process( Clock, Reset )
125
  begin
126
    if( Reset = Reset_Level )then
127
      mSec_Timer             <= (others => '0');
128
      Timer_Tick             <= '0';
129
    elsif( rising_edge(Clock) )then
130
      mSec_Timer             <= mSec_Timer - uSec_Tick;
131
      Timer_Tick             <= '0';
132
      if( mSec_Timer = 0 )then
133
        mSec_Timer           <= MSEC_DELAY;
134
        Timer_Tick           <= '1';
135
      end if;
136
    end if;
137
  end process;
138
 
139
end generate;
140
 
141
uSec_Resolution_enabled : if( not mSec_Resolution )generate
142
 
143
  Timer_Tick                 <= uSec_Tick;
144
 
145
end generate;
146
 
147 229 jshamlet
  io_reg: process( Clock, Reset )
148
  begin
149
    if( Reset = Reset_Level )then
150 244 jshamlet
      Reg_Sel_q              <= "00";
151
      Wr_En_q                <= '0';
152 229 jshamlet
      Wr_Data_q              <= x"00";
153 244 jshamlet
      Rd_En_q                <= '0';
154 229 jshamlet
      Rd_Data                <= OPEN8_NULLBUS;
155
      Req_Interval           <= x"000000";
156
      Update_Interval        <= '0';
157
      Update_Pending         <= '0';
158
      Output_Enable          <= '0';
159
    elsif( rising_edge( Clock ) )then
160 244 jshamlet
      Reg_Sel_q              <= Reg_Sel_d;
161 229 jshamlet
 
162 244 jshamlet
      Wr_En_q                <= Wr_En_d;
163
      Wr_Data_q              <= Wr_Data_d;
164 229 jshamlet
      Update_Interval        <= '0';
165 331 jshamlet
      if( Wr_En_q = '1' )then
166 244 jshamlet
        case( Reg_Sel_q )is
167 229 jshamlet
          when "00" =>
168
            Req_Interval_B0  <= Wr_Data_q;
169
            Update_Pending   <= '1';
170
          when "01" =>
171
            Req_Interval_B1  <= Wr_Data_q;
172
            Update_Pending   <= '1';
173
          when "10" =>
174
            Req_Interval_B2  <= Wr_Data_q;
175
            Update_Pending   <= '1';
176
          when "11" =>
177
            Output_Enable    <= Wr_Data_q(7);
178
            Update_Interval  <= Wr_Data_q(6);
179
          when others => null;
180
        end case;
181
      end if;
182
 
183
      if( Update_Interval = '1' )then
184
        Update_Pending       <= '0';
185
      end if;
186
 
187
      Rd_Data                <= OPEN8_NULLBUS;
188 244 jshamlet
      Rd_En_q                <= Rd_En_d;
189
      if( Rd_En_q = '1' )then
190
        case( Reg_Sel_q )is
191 229 jshamlet
          when "00" =>
192
            Rd_Data          <= Req_Interval_B0;
193
          when "01" =>
194
            Rd_Data          <= Req_Interval_B1;
195
          when "10" =>
196
            Rd_Data          <= Req_Interval_B2;
197
          when "11" =>
198
            Rd_Data          <= Output_Enable & Update_Pending & "000000";
199
          when others => null;
200
        end case;
201
      end if;
202
    end if;
203
  end process;
204
 
205
  Interval_proc: process( Clock, Reset )
206
  begin
207
    if( Reset = Reset_Level )then
208
      Int_Interval           <= x"000000";
209
      Timer_Cnt              <= x"000000";
210
      Interrupt              <= '0';
211
    elsif( rising_edge(Clock) )then
212
      Interrupt              <= '0';
213 308 jshamlet
      Timer_Cnt              <= Timer_Cnt - Timer_Tick;
214 229 jshamlet
      if( Update_Interval = '1' )then
215
        Int_Interval         <= Req_Interval;
216
        Timer_Cnt            <= Req_Interval;
217
      elsif( or_reduce(Timer_Cnt) = '0' )then
218
        Timer_Cnt            <= Int_Interval;
219
        Interrupt            <= Output_Enable;
220
      end if;
221
    end if;
222
  end process;
223
 
224
end architecture;

powered by: WebSVN 2.1.0

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