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 212

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
--   0x2   AAAAAAAA B2 of Buffered Setpoint (W) or Current Setpoint(R)
36
--   0x3   BA------ Status of buffer/alarm (1 = pending, 0 = current)
37
--                  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 timer and compare val
48
--
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
 
55
library ieee;
56
use ieee.std_logic_1164.all;
57
  use ieee.std_logic_unsigned.all;
58
  use ieee.std_logic_arith.all;
59
  use ieee.std_logic_misc.all;
60
 
61
library work;
62
  use work.open8_pkg.all;
63
 
64
entity o8_epoch_timer is
65
generic(
66
  Reset_Level           : std_logic;
67
  Address               : ADDRESS_TYPE
68
);
69
port(
70
  Clock                 : in  std_logic;
71
  Reset                 : in  std_logic;
72
  uSec_Tick             : in  std_logic;
73
  --
74
  Bus_Address           : in  ADDRESS_TYPE;
75
  Wr_Enable             : in  std_logic;
76
  Wr_Data               : in  DATA_TYPE;
77
  Rd_Enable             : in  std_logic;
78
  Rd_Data               : out DATA_TYPE;
79
  Interrupt             : out std_logic
80
);
81
end entity;
82
 
83
architecture behave of o8_epoch_timer is
84
 
85
  constant User_Addr         : std_logic_vector(15 downto 3)
86
                               := Address(15 downto 3);
87
  alias  Comp_Addr           is Bus_Address(15 downto 3);
88
  signal Addr_Match          : std_logic := '0';
89
 
90
  alias  Reg_Addr            is Bus_Address(2 downto 0);
91
  signal Reg_Addr_q          : std_logic_vector(2 downto 0) := (others => '0');
92
 
93
  signal Wr_En               : std_logic := '0';
94
  signal Wr_Data_q           : DATA_TYPE := x"00";
95
  signal Rd_En               : std_logic := '0';
96 170 jshamlet
 
97 212 jshamlet
  signal setpt_buffer        : std_logic_vector(23 downto 0) := (others => '0');
98
  alias  setpt_buffer_b0     is setpt_buffer(7 downto 0);
99
  alias  setpt_buffer_b1     is setpt_buffer(15 downto 8);
100
  alias  setpt_buffer_b2     is setpt_buffer(23 downto 16);
101
 
102
  signal epoch_buffer        : std_logic_vector(23 downto 0) := (others => '0');
103
  alias  epoch_buffer_b0     is epoch_buffer(7 downto 0);
104
  alias  epoch_buffer_b1     is epoch_buffer(15 downto 8);
105
  alias  epoch_buffer_b2     is epoch_buffer(23 downto 16);
106
  signal buffer_pending      : std_logic := '0';
107
  signal buffer_update       : std_logic := '0';
108
  signal timer_clear         : std_logic := '0';
109
 
110
  signal epoch_tmr           : std_logic_vector(25 downto 0) := (others => '0');
111
  alias  epoch_tmrcmp        is epoch_tmr(25 downto 2);
112
  signal epoch_setpt         : std_logic_vector(25 downto 0) := (others => '0');
113
  alias  epoch_setpt_b0      is epoch_setpt(7 downto 0);
114
  alias  epoch_setpt_b1      is epoch_setpt(15 downto 8);
115
  alias  epoch_setpt_b2      is epoch_setpt(23 downto 16);
116
  alias  epoch_setpt_u       is epoch_setpt(25 downto 2);
117
  alias  epoch_setpt_l       is epoch_setpt(1 downto 0);
118
  signal epoch_alarm         : std_logic := '0';
119
  signal epoch_alarm_q       : std_logic := '0';
120
 
121
begin
122
 
123
  Addr_Match                 <= '1' when Comp_Addr = User_Addr else '0';
124
 
125
  io_reg: process( Clock, Reset )
126
  begin
127
    if( Reset = Reset_Level )then
128
      Wr_Data_q              <= (others => '0');
129
      Reg_Addr_q             <= (others => '0');
130
      Wr_En                  <= '0';
131
      Rd_En                  <= '0';
132
      Rd_Data                <= OPEN8_NULLBUS;
133
      setpt_buffer           <= (others => '0');
134
      epoch_buffer           <= (others => '0');
135
      buffer_pending         <= '0';
136
      buffer_update          <= '0';
137
      timer_clear            <= '0';
138
    elsif( rising_edge( Clock ) )then
139
 
140
      Reg_Addr_q             <= Reg_Addr;
141
      Wr_En                  <= Addr_Match and Wr_Enable;
142
      Wr_Data_q              <= Wr_Data;
143
 
144
      buffer_update          <= '0';
145
      timer_clear            <= '0';
146
      if( Wr_En = '1' )then
147
        case( Reg_Addr_q )is
148
          when "000" =>
149
            setpt_buffer_b0  <= Wr_Data_q;
150
            buffer_pending   <= '1';
151
 
152
          when "001" =>
153
            setpt_buffer_b1  <= Wr_Data_q;
154
            buffer_pending   <= '1';
155
 
156
          when "010" =>
157
            setpt_buffer_b2  <= Wr_Data_q;
158
            buffer_pending   <= '1';
159 170 jshamlet
 
160 212 jshamlet
          when "011" =>
161
            buffer_update    <= '1';
162
            buffer_pending   <= '0';
163 170 jshamlet
 
164 212 jshamlet
          when "100" | "101" | "110" =>
165
            epoch_buffer     <= epoch_tmrcmp;
166
 
167
          when "111" =>
168
            timer_clear      <= '1';
169
          when others => null;
170
        end case;
171
      end if;
172
 
173
      Rd_Data                <= OPEN8_NULLBUS;
174
      Rd_En                  <= Addr_Match and Rd_Enable;
175
      if( Rd_En = '1' )then
176
        case( Reg_Addr_q )is
177
          when "000" =>
178
            Rd_Data          <= epoch_setpt_b0;
179
          when "001" =>
180
            Rd_Data          <= epoch_setpt_b1;
181
          when "010" =>
182
            Rd_Data          <= epoch_setpt_b2;
183
          when "011" =>
184
            Rd_Data          <= epoch_alarm & buffer_pending & "000000";
185
          when "100" =>
186
            Rd_Data          <= epoch_buffer_b0(7 downto 0);
187
          when "101" =>
188
            Rd_Data          <= epoch_buffer_b1(15 downto 8);
189
          when "110" =>
190
            Rd_Data          <= epoch_buffer_b2(23 downto 16);
191
          when others => null;
192
        end case;
193
      end if;
194
    end if;
195
  end process;
196
 
197
  timer_proc: process( Clock, Reset )
198
  begin
199
    if( Reset = Reset_Level )then
200
      epoch_setpt            <= (others => '0');
201
      epoch_tmr              <= (others => '0');
202
      epoch_alarm            <= '0';
203
      epoch_alarm_q          <= '0';
204
      Interrupt              <= '0';
205
 
206
    elsif( rising_edge(Clock) )then
207
 
208
      epoch_tmr              <= epoch_tmr + uSec_Tick;
209
 
210
      -- Set and hold on alarm condition
211
      if( epoch_tmr > epoch_setpt and epoch_setpt > 0 )then
212
        epoch_alarm          <= '1';
213
      end if;
214
 
215
      if( buffer_update = '1' )then
216
        epoch_setpt_u        <= setpt_buffer;
217
                  -- Force the lower bits of the setpoint to "11" so that the offset is
218
              --  reduced to 1uS (reproducing the original behavior). Software should
219
                    --  always subtract 4uS (-1) from the desired time to compensate
220
        epoch_setpt_l        <= (others => or_reduce(setpt_buffer));
221
        epoch_alarm          <= '0';
222
      end if;
223
 
224
      if( timer_clear = '1' )then
225
        epoch_setpt          <= (others => '0');
226
        epoch_tmr            <= (others => '0');
227
        epoch_alarm          <= '0';
228 209 jshamlet
      end if;
229 212 jshamlet
 
230
      epoch_alarm_q          <= epoch_alarm;
231
      -- Fire on rising edge of epoch_alarm
232
      Interrupt              <= epoch_alarm and not epoch_alarm_q;
233
 
234
    end if;
235
  end process;
236
 
237
end architecture;

powered by: WebSVN 2.1.0

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