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 264

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 244 jshamlet
--                  Note that any write to 0x04,0x05, 0x06, or 0x07 will copy
42
--                   the current epoch time to a readable output buffer
43 222 jshamlet
--   0x8   xxxxxxxx (not used - returns 0x00)
44
--   0x9   xxxxxxxx (not used - returns 0x00)
45
--   0xA   xxxxxxxx (not used - returns 0x00)
46
--   0xB   xxxxxxxx (not used - returns 0x00)
47
--   0xC   xxxxxxxx (not used - returns 0x00)
48
--   0xD   xxxxxxxx (not used - returns 0x00)
49
--   0xE   -------- Epoch Time Latch/Clear Control Register
50
--                  Any write to 0xE will clear/reset the all timer regs
51
--   0xF   BA------ Status of buffer/alarm (1 = pending, 0 = current)
52
--                  A = Pending status (R)
53
--                  B = Alarm status (R)
54
--                  Note that any write will update the internal set point
55
--                  and clear the alarm
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 224 jshamlet
-- Seth Henry      04/16/20 Modifiefd to make use of Open8 bus record
63 244 jshamlet
-- Seth Henry      05/18/20 Added write qualification input
64 222 jshamlet
 
65
library ieee;
66
use ieee.std_logic_1164.all;
67
  use ieee.std_logic_unsigned.all;
68
  use ieee.std_logic_arith.all;
69
  use ieee.std_logic_misc.all;
70
 
71
library work;
72
  use work.open8_pkg.all;
73
 
74
entity o8_epoch_timer_ii is
75
generic(
76
  Address                    : ADDRESS_TYPE
77
);
78
port(
79 223 jshamlet
  Open8_Bus                  : in  OPEN8_BUS_TYPE;
80 244 jshamlet
  Write_Qual                 : in  std_logic := '1';
81 222 jshamlet
  Rd_Data                    : out DATA_TYPE;
82
  Interrupt                  : out std_logic
83
);
84
end entity;
85
 
86
architecture behave of o8_epoch_timer_ii is
87
 
88 224 jshamlet
  alias Clock                is Open8_Bus.Clock;
89
  alias Reset                is Open8_Bus.Reset;
90
  alias uSec_Tick            is Open8_Bus.uSec_Tick;
91
 
92 222 jshamlet
  constant User_Addr         : std_logic_vector(15 downto 4)
93
                               := Address(15 downto 4);
94
 
95 223 jshamlet
  alias  Comp_Addr           is Open8_Bus.Address(15 downto 4);
96 222 jshamlet
  signal Addr_Match          : std_logic := '0';
97
 
98 244 jshamlet
  alias  Reg_Sel_d           is Open8_Bus.Address(3 downto 0);
99
  signal Reg_Sel_q           : std_logic_vector(3 downto 0) := "0000";
100
  signal Wr_En_d             : std_logic := '0';
101
  signal Wr_En_q             : std_logic := '0';
102
  alias  Wr_Data_d           is Open8_Bus.Wr_Data;
103 222 jshamlet
  signal Wr_Data_q           : DATA_TYPE := x"00";
104 244 jshamlet
  signal Rd_En_d             : std_logic := '0';
105
  signal Rd_En_q             : std_logic := '0';
106 222 jshamlet
 
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 244 jshamlet
  Wr_En_d                    <= Addr_Match and Open8_Bus.Wr_En;
149
  Rd_En_d                    <= Addr_Match and Open8_Bus.Rd_En;
150 222 jshamlet
 
151
  io_reg: process( Clock, Reset )
152
  begin
153
    if( Reset = Reset_Level )then
154 244 jshamlet
      Reg_Sel_q              <= "0000";
155
      Wr_En_q                <= '0';
156
      Wr_Data_q              <= x"00";
157
      Rd_En_q                <= '0';
158 222 jshamlet
      Rd_Data                <= OPEN8_NULLBUS;
159 244 jshamlet
 
160 222 jshamlet
      setpt_buffer           <= (others => '0');
161
      buffer_pending         <= '0';
162
      buffer_update          <= '0';
163
      capture_epoch          <= '0';
164
      timer_clear            <= '0';
165
    elsif( rising_edge( Clock ) )then
166
 
167 244 jshamlet
      Reg_Sel_q              <= Reg_Sel_d;
168 222 jshamlet
 
169 244 jshamlet
      Wr_En_q                <= Wr_En_d;
170
      Wr_Data_q              <= Wr_Data_d;
171
 
172 222 jshamlet
      buffer_update          <= '0';
173
      timer_clear            <= '0';
174
      capture_epoch          <= '0';
175
 
176 244 jshamlet
      if( Wr_En_q = '1' and Write_Qual = '1' )then
177
        case( Reg_Sel_q )is
178 222 jshamlet
          when x"0" =>
179
            setpt_buffer_b0  <= Wr_Data_q;
180
            buffer_pending   <= '1';
181
 
182
          when x"1" =>
183
            setpt_buffer_b1  <= Wr_Data_q;
184
            buffer_pending   <= '1';
185
 
186
          when x"2" =>
187
            setpt_buffer_b2  <= Wr_Data_q;
188
            buffer_pending   <= '1';
189
 
190
          when x"3" =>
191
            setpt_buffer_b3  <= Wr_Data_q;
192
            buffer_pending   <= '1';
193
 
194
          when x"4" | x"5" | x"6" | x"7" =>
195
            capture_epoch    <= '1';
196
 
197
          when x"E" =>
198
            timer_clear      <= '1';
199
 
200
          when x"F" =>
201
            buffer_update    <= '1';
202
            buffer_pending   <= '0';
203
 
204
          when others => null;
205
        end case;
206
      end if;
207
 
208
      Rd_Data                <= OPEN8_NULLBUS;
209 244 jshamlet
      Rd_En_q                <= Rd_En_d;
210
      if( Rd_En_q = '1' )then
211
        case( Reg_Sel_q )is
212 222 jshamlet
          when x"0" =>
213
            Rd_Data          <= epoch_setpt_b0;
214
          when x"1" =>
215
            Rd_Data          <= epoch_setpt_b1;
216
          when x"2" =>
217
            Rd_Data          <= epoch_setpt_b2;
218
          when x"3" =>
219
            Rd_Data          <= epoch_setpt_b3;
220
          when x"4" =>
221
            Rd_Data          <= epoch_buffer_b0;
222
          when x"5" =>
223
            Rd_Data          <= epoch_buffer_b1;
224
          when x"6" =>
225
            Rd_Data          <= epoch_buffer_b2;
226
          when x"7" =>
227
            Rd_Data          <= epoch_buffer_b3;
228
          when x"F" =>
229
            Rd_Data          <= epoch_alarm & buffer_pending & "000000";
230
          when others => null;
231
        end case;
232
      end if;
233
    end if;
234
  end process;
235
 
236
  timer_proc: process( Clock, Reset )
237
  begin
238
    if( Reset = Reset_Level )then
239
      epoch_setpt            <= (others => '0');
240
      epoch_buffer           <= (others => '0');
241
      epoch_tmr              <= (others => '0');
242
      epoch_alarm            <= '0';
243
      epoch_alarm_q          <= '0';
244
      Interrupt              <= '0';
245
 
246
    elsif( rising_edge(Clock) )then
247
 
248
      epoch_tmr              <= epoch_tmr + uSec_Tick;
249
 
250
      if( epoch_tmr > epoch_setpt )then
251
        epoch_alarm          <= or_reduce(epoch_setpt);
252
      end if;
253
 
254
      if( buffer_update = '1' )then
255
        epoch_setpt          <= setpt_buffer;
256
        epoch_alarm          <= '0';
257
      end if;
258
 
259
      if( timer_clear = '1' )then
260
        epoch_setpt          <= (others => '0');
261
        epoch_tmr            <= (others => '0');
262
        epoch_alarm          <= '0';
263
      end if;
264
 
265
      epoch_alarm_q          <= epoch_alarm;
266
      Interrupt              <= epoch_alarm and not epoch_alarm_q;
267
 
268
      if( capture_epoch = '1' )then
269
        epoch_buffer         <= epoch_tmr;
270
      end if;
271
 
272
    end if;
273
  end process;
274
 
275
end architecture;

powered by: WebSVN 2.1.0

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