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

Subversion Repositories open8_urisc

[/] [open8_urisc/] [trunk/] [VHDL/] [o8_epoch_timer.vhd] - Blame information for rev 236

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

Line No. Rev Author Line
1 212 jshamlet
-- Copyright (c)2011, 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_epoch_timer
25
-- Description:  Provides a 24-bit, 4uS resolution elapsed timer with
26
--            :   alarm and interrupt for the Open8 CPU.
27
--
28
-- Notes      :  Requires an externally provided uSec tick input - one clock
29
--            :   per microsecond.
30
--
31
-- Register Map:
32
-- Offset  Bitfield Description                        Read/Write
33
--   0x0   AAAAAAAA B0 of Buffered Setpoint (W) or Current Setpoint(R)
34
--   0x1   AAAAAAAA B1 of Buffered Setpoint (W) or Current Setpoint(R)
35 222 jshamlet
--   0x2   AAAAAAAA B2 of Buffered Setpoint (W) or Current Setpoint(R)
36 212 jshamlet
--   0x3   BA------ Status of buffer/alarm (1 = pending, 0 = current)
37 222 jshamlet
--                  A = Pending status (R)
38
--                  B = Alarm status (R)
39
--                  Note that any write will update the internal set point
40
--                  and clear the alarm
41
--   0x4   AAAAAAAA B0 of Current Epoch Time(RO)
42
--   0x5   AAAAAAAA B1 of Current Epoch Time(RO)
43
--   0x6   AAAAAAAA B2 of Current Epoch Time(RO)
44
--                  Note that any write to 0x04,0x05, or 0x06 will copy the
45
--                  current epoch time to a readable output buffer
46
--   0x7   -------- Epoch Time Latch/Clear Control Register
47
--                  Any write to 0x7 will clear/reset the all timer regs
48 212 jshamlet
--
49
-- Revision History
50
-- Author          Date     Change
51
------------------ -------- ---------------------------------------------------
52
-- Seth Henry      07/28/11 Design Start
53
-- Seth Henry      12/19/19 Renamed to "o8_epoch_timer" to fit "theme"
54 213 jshamlet
-- Seth Henry      04/10/20 Overhauled the register interface of the timer to
55
--                           make the interface more sensible to software.
56 224 jshamlet
-- Seth Henry      04/160/20 Modified to make use of Open8 bus record
57 212 jshamlet
 
58
library ieee;
59
use ieee.std_logic_1164.all;
60
  use ieee.std_logic_unsigned.all;
61
  use ieee.std_logic_arith.all;
62
  use ieee.std_logic_misc.all;
63
 
64
library work;
65
  use work.open8_pkg.all;
66
 
67
entity o8_epoch_timer is
68
generic(
69 217 jshamlet
  Address                    : ADDRESS_TYPE
70 212 jshamlet
);
71
port(
72 223 jshamlet
  Open8_Bus                  : in  OPEN8_BUS_TYPE;
73 217 jshamlet
  Rd_Data                    : out DATA_TYPE;
74
  Interrupt                  : out std_logic
75 212 jshamlet
);
76
end entity;
77
 
78
architecture behave of o8_epoch_timer is
79
 
80 224 jshamlet
  alias Clock                is Open8_Bus.Clock;
81
  alias Reset                is Open8_Bus.Reset;
82
  alias uSec_Tick            is Open8_Bus.uSec_Tick;
83
 
84 212 jshamlet
  constant User_Addr         : std_logic_vector(15 downto 3)
85
                               := Address(15 downto 3);
86 222 jshamlet
 
87 223 jshamlet
  alias  Comp_Addr           is Open8_Bus.Address(15 downto 3);
88 212 jshamlet
  signal Addr_Match          : std_logic := '0';
89
 
90 223 jshamlet
  alias  Reg_Addr            is Open8_Bus.Address(2 downto 0);
91 222 jshamlet
  signal Reg_Addr_q          : std_logic_vector(2 downto 0) :=
92
                                (others => '0');
93 212 jshamlet
 
94
  signal Wr_En               : std_logic := '0';
95
  signal Wr_Data_q           : DATA_TYPE := x"00";
96
  signal Rd_En               : std_logic := '0';
97
 
98 222 jshamlet
  signal setpt_buffer        : std_logic_vector(23 downto 0) :=
99
                                (others => '0');
100
 
101
  alias  setpt_buffer_b0     is setpt_buffer(7 downto 0);
102
  alias  setpt_buffer_b1     is setpt_buffer(15 downto 8);
103
  alias  setpt_buffer_b2     is setpt_buffer(23 downto 16);
104
 
105
  signal buffer_pending      : std_logic := '0';
106
  signal buffer_update       : std_logic := '0';
107
 
108
  signal epoch_buffer        : std_logic_vector(23 downto 0) :=
109
                                (others => '0');
110 212 jshamlet
  alias  epoch_buffer_b0     is epoch_buffer(7 downto 0);
111
  alias  epoch_buffer_b1     is epoch_buffer(15 downto 8);
112
  alias  epoch_buffer_b2     is epoch_buffer(23 downto 16);
113 222 jshamlet
 
114
  signal capture_epoch       : std_logic;
115 212 jshamlet
  signal timer_clear         : std_logic := '0';
116
 
117 222 jshamlet
  signal epoch_tmr           : std_logic_vector(25 downto 0) :=
118
                                (others => '0');
119
 
120
  alias  epoch_tmrcmp        is epoch_tmr(25 downto 2);
121
 
122
  signal epoch_setpt         : std_logic_vector(25 downto 0) :=
123
                                (others => '0');
124
 
125
  alias  epoch_setpt_b0      is epoch_setpt(7 downto 0);
126
  alias  epoch_setpt_b1      is epoch_setpt(15 downto 8);
127
  alias  epoch_setpt_b2      is epoch_setpt(23 downto 16);
128 212 jshamlet
  alias  epoch_setpt_u       is epoch_setpt(25 downto 2);
129
  alias  epoch_setpt_l       is epoch_setpt(1 downto 0);
130 222 jshamlet
 
131 212 jshamlet
  signal epoch_alarm         : std_logic := '0';
132
  signal epoch_alarm_q       : std_logic := '0';
133
 
134
begin
135
 
136
  Addr_Match                 <= '1' when Comp_Addr = User_Addr else '0';
137
 
138
  io_reg: process( Clock, Reset )
139
  begin
140
    if( Reset = Reset_Level )then
141
      Wr_Data_q              <= (others => '0');
142
      Reg_Addr_q             <= (others => '0');
143
      Wr_En                  <= '0';
144
      Rd_En                  <= '0';
145
      Rd_Data                <= OPEN8_NULLBUS;
146
      setpt_buffer           <= (others => '0');
147
      buffer_pending         <= '0';
148
      buffer_update          <= '0';
149 222 jshamlet
      capture_epoch          <= '0';
150 212 jshamlet
      timer_clear            <= '0';
151
    elsif( rising_edge( Clock ) )then
152
 
153
      Reg_Addr_q             <= Reg_Addr;
154 223 jshamlet
      Wr_En                  <= Addr_Match and Open8_Bus.Wr_En;
155
      Wr_Data_q              <= Open8_Bus.Wr_Data;
156 212 jshamlet
 
157
      buffer_update          <= '0';
158 222 jshamlet
      capture_epoch          <= '0';
159 212 jshamlet
      timer_clear            <= '0';
160 222 jshamlet
 
161 212 jshamlet
      if( Wr_En = '1' )then
162
        case( Reg_Addr_q )is
163
          when "000" =>
164
            setpt_buffer_b0  <= Wr_Data_q;
165 222 jshamlet
            buffer_pending   <= '1';
166 212 jshamlet
 
167
          when "001" =>
168
            setpt_buffer_b1  <= Wr_Data_q;
169 222 jshamlet
            buffer_pending   <= '1';
170 212 jshamlet
 
171
          when "010" =>
172
            setpt_buffer_b2  <= Wr_Data_q;
173 222 jshamlet
            buffer_pending   <= '1';
174 212 jshamlet
 
175 222 jshamlet
          when "011" =>
176
            buffer_update    <= '1';
177
            buffer_pending   <= '0';
178
 
179
          when "100" | "101" | "110" =>
180
            capture_epoch    <= '1';
181
 
182 212 jshamlet
          when "111" =>
183
            timer_clear      <= '1';
184
          when others => null;
185
        end case;
186
      end if;
187
 
188
      Rd_Data                <= OPEN8_NULLBUS;
189 223 jshamlet
      Rd_En                  <= Addr_Match and Open8_Bus.Rd_En;
190 212 jshamlet
      if( Rd_En = '1' )then
191
        case( Reg_Addr_q )is
192
          when "000" =>
193
            Rd_Data          <= epoch_setpt_b0;
194
          when "001" =>
195
            Rd_Data          <= epoch_setpt_b1;
196
          when "010" =>
197
            Rd_Data          <= epoch_setpt_b2;
198
          when "011" =>
199
            Rd_Data          <= epoch_alarm & buffer_pending & "000000";
200 222 jshamlet
          when "100" =>
201
            Rd_Data          <= epoch_buffer_b0(7 downto 0);
202
          when "101" =>
203
            Rd_Data          <= epoch_buffer_b1(15 downto 8);
204
          when "110" =>
205
            Rd_Data          <= epoch_buffer_b2(23 downto 16);
206 212 jshamlet
          when others => null;
207
        end case;
208
      end if;
209
    end if;
210
  end process;
211
 
212
  timer_proc: process( Clock, Reset )
213
  begin
214
    if( Reset = Reset_Level )then
215
      epoch_setpt            <= (others => '0');
216 222 jshamlet
      epoch_buffer           <= (others => '0');
217 212 jshamlet
      epoch_tmr              <= (others => '0');
218
      epoch_alarm            <= '0';
219
      epoch_alarm_q          <= '0';
220
      Interrupt              <= '0';
221
 
222
    elsif( rising_edge(Clock) )then
223
 
224
      epoch_tmr              <= epoch_tmr + uSec_Tick;
225
 
226 222 jshamlet
      if( epoch_tmr > epoch_setpt )then
227
        epoch_alarm          <= or_reduce(epoch_setpt);
228 212 jshamlet
      end if;
229
 
230
      if( buffer_update = '1' )then
231
        epoch_setpt_u        <= setpt_buffer;
232
                  -- Force the lower bits of the setpoint to "11" so that the offset is
233 222 jshamlet
              -- reduced to 1uS (reproducing the original behavior). Software
234
                    -- should always subtract 4uS (-1) from the desired time to compensate
235 212 jshamlet
        epoch_setpt_l        <= (others => or_reduce(setpt_buffer));
236
        epoch_alarm          <= '0';
237
      end if;
238
 
239 222 jshamlet
      if( timer_clear = '1' )then
240
        epoch_setpt          <= (others => '0');
241
        epoch_tmr            <= (others => '0');
242
        epoch_alarm          <= '0';
243
      end if;
244 212 jshamlet
 
245
      epoch_alarm_q          <= epoch_alarm;
246
      Interrupt              <= epoch_alarm and not epoch_alarm_q;
247
 
248 222 jshamlet
      if( capture_epoch = '1' )then
249
        epoch_buffer         <= epoch_tmrcmp;
250
      end if;
251
 
252 212 jshamlet
    end if;
253
  end process;
254
 
255
end architecture;

powered by: WebSVN 2.1.0

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