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

Subversion Repositories open8_urisc

[/] [open8_urisc/] [trunk/] [VHDL/] [o8_epoch_timer_ii.vhd] - Blame information for rev 222

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

Line No. Rev Author Line
1 222 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_ii
25
-- Description:  Provides a 32-bit, 1uS 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   AAAAAAAA B3 of Buffered Setpoint (W) or Current Setpoint(R)
37
--   0x4   AAAAAAAA B0 of Current Epoch Time(RO)
38
--   0x5   AAAAAAAA B1 of Current Epoch Time(RO)
39
--   0x6   AAAAAAAA B2 of Current Epoch Time(RO)
40
--   0x7   AAAAAAAA B3 of Current Epoch Time(RO)
41
--   0x8   xxxxxxxx (not used - returns 0x00)
42
--   0x9   xxxxxxxx (not used - returns 0x00)
43
--   0xA   xxxxxxxx (not used - returns 0x00)
44
--   0xB   xxxxxxxx (not used - returns 0x00)
45
--   0xC   xxxxxxxx (not used - returns 0x00)
46
--   0xD   xxxxxxxx (not used - returns 0x00)
47
--   0xE   -------- Epoch Time Latch/Clear Control Register
48
--                  Any write to 0xE will clear/reset the all timer regs
49
--   0xF   BA------ Status of buffer/alarm (1 = pending, 0 = current)
50
--                  A = Pending status (R)
51
--                  B = Alarm status (R)
52
--                  Note that any write will update the internal set point
53
--                  and clear the alarm
54
--                  Note that any write to 0x04,0x05, or 0x06 will copy the
55
--                  current epoch time to a readable output buffer
56
--
57
-- Revision History
58
-- Author          Date     Change
59
------------------ -------- ---------------------------------------------------
60
-- Seth Henry      04/15/20 Created from o8_epoch_timer due to requirement
61
--                           change.
62
 
63
library ieee;
64
use ieee.std_logic_1164.all;
65
  use ieee.std_logic_unsigned.all;
66
  use ieee.std_logic_arith.all;
67
  use ieee.std_logic_misc.all;
68
 
69
library work;
70
  use work.open8_pkg.all;
71
 
72
entity o8_epoch_timer_ii is
73
generic(
74
  Reset_Level                : std_logic;
75
  Address                    : ADDRESS_TYPE
76
);
77
port(
78
  Clock                      : in  std_logic;
79
  Reset                      : in  std_logic;
80
  uSec_Tick                  : in  std_logic;
81
  --
82
  Bus_Address                : in  ADDRESS_TYPE;
83
  Wr_Enable                  : in  std_logic;
84
  Wr_Data                    : in  DATA_TYPE;
85
  Rd_Enable                  : in  std_logic;
86
  Rd_Data                    : out DATA_TYPE;
87
  Interrupt                  : out std_logic
88
);
89
end entity;
90
 
91
architecture behave of o8_epoch_timer_ii is
92
 
93
  constant User_Addr         : std_logic_vector(15 downto 4)
94
                               := Address(15 downto 4);
95
 
96
  alias  Comp_Addr           is Bus_Address(15 downto 4);
97
  signal Addr_Match          : std_logic := '0';
98
 
99
  alias  Reg_Addr            is Bus_Address(3 downto 0);
100
  signal Reg_Addr_q          : std_logic_vector(3 downto 0) :=
101
                                (others => '0');
102
 
103
  signal Wr_En               : std_logic := '0';
104
  signal Wr_Data_q           : DATA_TYPE := x"00";
105
  signal Rd_En               : std_logic := '0';
106
 
107
  signal setpt_buffer        : std_logic_vector(31 downto 0) :=
108
                                (others => '0');
109
 
110
  alias  setpt_buffer_b0     is setpt_buffer( 7 downto  0);
111
  alias  setpt_buffer_b1     is setpt_buffer(15 downto  8);
112
  alias  setpt_buffer_b2     is setpt_buffer(23 downto 16);
113
  alias  setpt_buffer_b3     is setpt_buffer(31 downto 24);
114
 
115
  signal buffer_pending      : std_logic := '0';
116
  signal buffer_update       : std_logic := '0';
117
 
118
  signal epoch_buffer        : std_logic_vector(31 downto 0) :=
119
                                (others => '0');
120
 
121
  alias  epoch_buffer_b0     is epoch_buffer( 7 downto  0);
122
  alias  epoch_buffer_b1     is epoch_buffer(15 downto  8);
123
  alias  epoch_buffer_b2     is epoch_buffer(23 downto 16);
124
  alias  epoch_buffer_b3     is epoch_buffer(31 downto 24);
125
 
126
  signal capture_epoch       : std_logic := '0';
127
 
128
  signal timer_clear         : std_logic := '0';
129
 
130
  signal epoch_tmr           : std_logic_vector(31 downto 0) :=
131
                                (others => '0');
132
 
133
  alias  epoch_tmrcmp        is epoch_tmr(31 downto 2);
134
  signal epoch_setpt         : std_logic_vector(31 downto 0) :=
135
                                (others => '0');
136
 
137
  alias  epoch_setpt_b0      is epoch_setpt( 7 downto  0);
138
  alias  epoch_setpt_b1      is epoch_setpt(15 downto  8);
139
  alias  epoch_setpt_b2      is epoch_setpt(23 downto 16);
140
  alias  epoch_setpt_b3      is epoch_setpt(31 downto 24);
141
 
142
  signal epoch_alarm         : std_logic := '0';
143
  signal epoch_alarm_q       : std_logic := '0';
144
 
145
begin
146
 
147
  Addr_Match                 <= '1' when Comp_Addr = User_Addr else '0';
148
 
149
  io_reg: process( Clock, Reset )
150
  begin
151
    if( Reset = Reset_Level )then
152
      Wr_Data_q              <= (others => '0');
153
      Reg_Addr_q             <= (others => '0');
154
      Wr_En                  <= '0';
155
      Rd_En                  <= '0';
156
      Rd_Data                <= OPEN8_NULLBUS;
157
      setpt_buffer           <= (others => '0');
158
      buffer_pending         <= '0';
159
      buffer_update          <= '0';
160
      capture_epoch          <= '0';
161
      timer_clear            <= '0';
162
    elsif( rising_edge( Clock ) )then
163
 
164
      Reg_Addr_q             <= Reg_Addr;
165
      Wr_En                  <= Addr_Match and Wr_Enable;
166
      Wr_Data_q              <= Wr_Data;
167
 
168
      buffer_update          <= '0';
169
      timer_clear            <= '0';
170
      capture_epoch          <= '0';
171
 
172
      if( Wr_En = '1' )then
173
        case( Reg_Addr_q )is
174
          when x"0" =>
175
            setpt_buffer_b0  <= Wr_Data_q;
176
            buffer_pending   <= '1';
177
 
178
          when x"1" =>
179
            setpt_buffer_b1  <= Wr_Data_q;
180
            buffer_pending   <= '1';
181
 
182
          when x"2" =>
183
            setpt_buffer_b2  <= Wr_Data_q;
184
            buffer_pending   <= '1';
185
 
186
          when x"3" =>
187
            setpt_buffer_b3  <= Wr_Data_q;
188
            buffer_pending   <= '1';
189
 
190
          when x"4" | x"5" | x"6" | x"7" =>
191
            capture_epoch    <= '1';
192
 
193
          when x"E" =>
194
            timer_clear      <= '1';
195
 
196
          when x"F" =>
197
            buffer_update    <= '1';
198
            buffer_pending   <= '0';
199
 
200
          when others => null;
201
        end case;
202
      end if;
203
 
204
      Rd_Data                <= OPEN8_NULLBUS;
205
      Rd_En                  <= Addr_Match and Rd_Enable;
206
      if( Rd_En = '1' )then
207
        case( Reg_Addr_q )is
208
          when x"0" =>
209
            Rd_Data          <= epoch_setpt_b0;
210
          when x"1" =>
211
            Rd_Data          <= epoch_setpt_b1;
212
          when x"2" =>
213
            Rd_Data          <= epoch_setpt_b2;
214
          when x"3" =>
215
            Rd_Data          <= epoch_setpt_b3;
216
          when x"4" =>
217
            Rd_Data          <= epoch_buffer_b0;
218
          when x"5" =>
219
            Rd_Data          <= epoch_buffer_b1;
220
          when x"6" =>
221
            Rd_Data          <= epoch_buffer_b2;
222
          when x"7" =>
223
            Rd_Data          <= epoch_buffer_b3;
224
          when x"F" =>
225
            Rd_Data          <= epoch_alarm & buffer_pending & "000000";
226
          when others => null;
227
        end case;
228
      end if;
229
    end if;
230
  end process;
231
 
232
  timer_proc: process( Clock, Reset )
233
  begin
234
    if( Reset = Reset_Level )then
235
      epoch_setpt            <= (others => '0');
236
      epoch_buffer           <= (others => '0');
237
      epoch_tmr              <= (others => '0');
238
      epoch_alarm            <= '0';
239
      epoch_alarm_q          <= '0';
240
      Interrupt              <= '0';
241
 
242
    elsif( rising_edge(Clock) )then
243
 
244
      epoch_tmr              <= epoch_tmr + uSec_Tick;
245
 
246
      if( epoch_tmr > epoch_setpt )then
247
        epoch_alarm          <= or_reduce(epoch_setpt);
248
      end if;
249
 
250
      if( buffer_update = '1' )then
251
        epoch_setpt          <= setpt_buffer;
252
        epoch_alarm          <= '0';
253
      end if;
254
 
255
      if( timer_clear = '1' )then
256
        epoch_setpt          <= (others => '0');
257
        epoch_tmr            <= (others => '0');
258
        epoch_alarm          <= '0';
259
      end if;
260
 
261
      epoch_alarm_q          <= epoch_alarm;
262
      Interrupt              <= epoch_alarm and not epoch_alarm_q;
263
 
264
      if( capture_epoch = '1' )then
265
        epoch_buffer         <= epoch_tmr;
266
      end if;
267
 
268
    end if;
269
  end process;
270
 
271
end architecture;

powered by: WebSVN 2.1.0

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