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 287

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 273 jshamlet
--   0x4   AAAAAAAA B0 of Buffered Current Epoch Time(RO)
38
--   0x5   AAAAAAAA B1 of Buffered Current Epoch Time(RO)
39
--   0x6   AAAAAAAA B2 of Buffered Current Epoch Time(RO)
40
--   0x7   AAAAAAAA B3 of Buffered 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 273 jshamlet
--   0x8   -------- (not used - returns 0x00)
44
--   0x9   -------- (not used - returns 0x00)
45
--   0xA   -------- (not used - returns 0x00)
46
--   0xB   -------- (not used - returns 0x00)
47
--   0xC   -------- (not used - returns 0x00)
48
--   0xD   -------- (not used - returns 0x00)
49 222 jshamlet
--   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 273 jshamlet
--                  B = Buffer status (R)
54 222 jshamlet
--                  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 279 jshamlet
-- Seth Henry      04/16/20 Modified to make use of Open8 bus record
63 244 jshamlet
-- Seth Henry      05/18/20 Added write qualification input
64 273 jshamlet
-- Seth Henry      11/01/20 Updated comments regarding buffered current time
65 222 jshamlet
 
66
library ieee;
67
use ieee.std_logic_1164.all;
68
  use ieee.std_logic_unsigned.all;
69
  use ieee.std_logic_arith.all;
70
  use ieee.std_logic_misc.all;
71
 
72
library work;
73
  use work.open8_pkg.all;
74
 
75
entity o8_epoch_timer_ii is
76
generic(
77
  Address                    : ADDRESS_TYPE
78
);
79
port(
80 223 jshamlet
  Open8_Bus                  : in  OPEN8_BUS_TYPE;
81 244 jshamlet
  Write_Qual                 : in  std_logic := '1';
82 222 jshamlet
  Rd_Data                    : out DATA_TYPE;
83
  Interrupt                  : out std_logic
84
);
85
end entity;
86
 
87
architecture behave of o8_epoch_timer_ii is
88
 
89 224 jshamlet
  alias Clock                is Open8_Bus.Clock;
90
  alias Reset                is Open8_Bus.Reset;
91
  alias uSec_Tick            is Open8_Bus.uSec_Tick;
92
 
93 222 jshamlet
  constant User_Addr         : std_logic_vector(15 downto 4)
94
                               := Address(15 downto 4);
95
 
96 223 jshamlet
  alias  Comp_Addr           is Open8_Bus.Address(15 downto 4);
97 222 jshamlet
  signal Addr_Match          : std_logic := '0';
98
 
99 244 jshamlet
  alias  Reg_Sel_d           is Open8_Bus.Address(3 downto 0);
100
  signal Reg_Sel_q           : std_logic_vector(3 downto 0) := "0000";
101
  signal Wr_En_d             : std_logic := '0';
102
  signal Wr_En_q             : std_logic := '0';
103
  alias  Wr_Data_d           is Open8_Bus.Wr_Data;
104 222 jshamlet
  signal Wr_Data_q           : DATA_TYPE := x"00";
105 244 jshamlet
  signal Rd_En_d             : std_logic := '0';
106
  signal Rd_En_q             : std_logic := '0';
107 222 jshamlet
 
108
  signal setpt_buffer        : std_logic_vector(31 downto 0) :=
109
                                (others => '0');
110
 
111
  alias  setpt_buffer_b0     is setpt_buffer( 7 downto  0);
112
  alias  setpt_buffer_b1     is setpt_buffer(15 downto  8);
113
  alias  setpt_buffer_b2     is setpt_buffer(23 downto 16);
114
  alias  setpt_buffer_b3     is setpt_buffer(31 downto 24);
115
 
116
  signal buffer_pending      : std_logic := '0';
117
  signal buffer_update       : std_logic := '0';
118
 
119
  signal epoch_buffer        : std_logic_vector(31 downto 0) :=
120
                                (others => '0');
121
 
122
  alias  epoch_buffer_b0     is epoch_buffer( 7 downto  0);
123
  alias  epoch_buffer_b1     is epoch_buffer(15 downto  8);
124
  alias  epoch_buffer_b2     is epoch_buffer(23 downto 16);
125
  alias  epoch_buffer_b3     is epoch_buffer(31 downto 24);
126
 
127
  signal capture_epoch       : std_logic := '0';
128
 
129
  signal timer_clear         : std_logic := '0';
130
 
131
  signal epoch_tmr           : std_logic_vector(31 downto 0) :=
132
                                (others => '0');
133
 
134
  alias  epoch_tmrcmp        is epoch_tmr(31 downto 2);
135
  signal epoch_setpt         : std_logic_vector(31 downto 0) :=
136
                                (others => '0');
137
 
138
  alias  epoch_setpt_b0      is epoch_setpt( 7 downto  0);
139
  alias  epoch_setpt_b1      is epoch_setpt(15 downto  8);
140
  alias  epoch_setpt_b2      is epoch_setpt(23 downto 16);
141
  alias  epoch_setpt_b3      is epoch_setpt(31 downto 24);
142
 
143
  signal epoch_alarm         : std_logic := '0';
144
  signal epoch_alarm_q       : std_logic := '0';
145
 
146
begin
147
 
148
  Addr_Match                 <= '1' when Comp_Addr = User_Addr else '0';
149 244 jshamlet
  Wr_En_d                    <= Addr_Match and Open8_Bus.Wr_En;
150
  Rd_En_d                    <= Addr_Match and Open8_Bus.Rd_En;
151 222 jshamlet
 
152
  io_reg: process( Clock, Reset )
153
  begin
154
    if( Reset = Reset_Level )then
155 244 jshamlet
      Reg_Sel_q              <= "0000";
156
      Wr_En_q                <= '0';
157
      Wr_Data_q              <= x"00";
158
      Rd_En_q                <= '0';
159 222 jshamlet
      Rd_Data                <= OPEN8_NULLBUS;
160 244 jshamlet
 
161 222 jshamlet
      setpt_buffer           <= (others => '0');
162
      buffer_pending         <= '0';
163
      buffer_update          <= '0';
164
      capture_epoch          <= '0';
165
      timer_clear            <= '0';
166
    elsif( rising_edge( Clock ) )then
167
 
168 244 jshamlet
      Reg_Sel_q              <= Reg_Sel_d;
169 222 jshamlet
 
170 244 jshamlet
      Wr_En_q                <= Wr_En_d;
171
      Wr_Data_q              <= Wr_Data_d;
172
 
173 222 jshamlet
      buffer_update          <= '0';
174
      timer_clear            <= '0';
175
      capture_epoch          <= '0';
176
 
177 244 jshamlet
      if( Wr_En_q = '1' and Write_Qual = '1' )then
178
        case( Reg_Sel_q )is
179 222 jshamlet
          when x"0" =>
180
            setpt_buffer_b0  <= Wr_Data_q;
181
            buffer_pending   <= '1';
182
 
183
          when x"1" =>
184
            setpt_buffer_b1  <= Wr_Data_q;
185
            buffer_pending   <= '1';
186
 
187
          when x"2" =>
188
            setpt_buffer_b2  <= Wr_Data_q;
189
            buffer_pending   <= '1';
190
 
191
          when x"3" =>
192
            setpt_buffer_b3  <= Wr_Data_q;
193
            buffer_pending   <= '1';
194
 
195
          when x"4" | x"5" | x"6" | x"7" =>
196
            capture_epoch    <= '1';
197
 
198
          when x"E" =>
199
            timer_clear      <= '1';
200
 
201
          when x"F" =>
202
            buffer_update    <= '1';
203
            buffer_pending   <= '0';
204
 
205
          when others => null;
206
        end case;
207
      end if;
208
 
209
      Rd_Data                <= OPEN8_NULLBUS;
210 244 jshamlet
      Rd_En_q                <= Rd_En_d;
211
      if( Rd_En_q = '1' )then
212
        case( Reg_Sel_q )is
213 222 jshamlet
          when x"0" =>
214
            Rd_Data          <= epoch_setpt_b0;
215
          when x"1" =>
216
            Rd_Data          <= epoch_setpt_b1;
217
          when x"2" =>
218
            Rd_Data          <= epoch_setpt_b2;
219
          when x"3" =>
220
            Rd_Data          <= epoch_setpt_b3;
221
          when x"4" =>
222
            Rd_Data          <= epoch_buffer_b0;
223
          when x"5" =>
224
            Rd_Data          <= epoch_buffer_b1;
225
          when x"6" =>
226
            Rd_Data          <= epoch_buffer_b2;
227
          when x"7" =>
228
            Rd_Data          <= epoch_buffer_b3;
229
          when x"F" =>
230
            Rd_Data          <= epoch_alarm & buffer_pending & "000000";
231
          when others => null;
232
        end case;
233
      end if;
234
    end if;
235
  end process;
236
 
237
  timer_proc: process( Clock, Reset )
238
  begin
239
    if( Reset = Reset_Level )then
240
      epoch_setpt            <= (others => '0');
241
      epoch_buffer           <= (others => '0');
242
      epoch_tmr              <= (others => '0');
243
      epoch_alarm            <= '0';
244
      epoch_alarm_q          <= '0';
245
      Interrupt              <= '0';
246
 
247
    elsif( rising_edge(Clock) )then
248
 
249
      epoch_tmr              <= epoch_tmr + uSec_Tick;
250
 
251
      if( epoch_tmr > epoch_setpt )then
252
        epoch_alarm          <= or_reduce(epoch_setpt);
253
      end if;
254
 
255
      if( buffer_update = '1' )then
256
        epoch_setpt          <= setpt_buffer;
257
        epoch_alarm          <= '0';
258
      end if;
259
 
260
      if( timer_clear = '1' )then
261
        epoch_setpt          <= (others => '0');
262
        epoch_tmr            <= (others => '0');
263
        epoch_alarm          <= '0';
264
      end if;
265
 
266
      epoch_alarm_q          <= epoch_alarm;
267
      Interrupt              <= epoch_alarm and not epoch_alarm_q;
268
 
269
      if( capture_epoch = '1' )then
270
        epoch_buffer         <= epoch_tmr;
271
      end if;
272
 
273
    end if;
274
  end process;
275
 
276
end architecture;

powered by: WebSVN 2.1.0

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