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 191

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

Line No. Rev Author Line
1 189 jshamlet
-- Copyright (c)2011, 2019 Jeremy Seth Henry
2 170 jshamlet
-- 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 THIS
22
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23
--
24 184 jshamlet
-- VHDL Units :  o8_epoch_timer
25 170 jshamlet
-- Description:  Provides a 24-bit, 4uS resolution elapsed timer with
26 172 jshamlet
--            :   alarm and interrupt for the Open8 CPU.
27 170 jshamlet
--
28
-- Notes      :  Requires an externally provided uSec tick input - one clock
29
--            :   per microsecond.
30 172 jshamlet
--
31 170 jshamlet
-- Register Map:
32
-- Offset  Bitfield Description                        Read/Write
33 184 jshamlet
--   0x0   AAAAAAAA B0 of Setpoint (W) or Buffered Time(R)
34
--   0x1   AAAAAAAA B1 of Setpoint (W) or Buffered Time(R)
35
--   0x2   AAAAAAAA B2 of Setpoint (W) or Buffered Time(R)
36 189 jshamlet
--   0x3   C-----BA Control/Status register (RW)
37 170 jshamlet
--                  A = Update Buffered Time from internal timer (W)
38
--                  B = Reset Internal Epoch Time (W)
39 189 jshamlet
--                  C = Alarm State Flag (RW) (write a 1 to clear)
40
--
41
-- Revision History
42
-- Author          Date     Change
43
------------------ -------- ---------------------------------------------------
44
-- Seth Henry      07/28/11 Design Start
45
-- Seth Henry      12/19/19 Renamed to "o8_epoch_timer" to fit "theme"
46 170 jshamlet
 
47
library ieee;
48
use ieee.std_logic_1164.all;
49
  use ieee.std_logic_unsigned.all;
50
  use ieee.std_logic_arith.all;
51
  use ieee.std_logic_misc.all;
52
 
53
library work;
54
  use work.open8_pkg.all;
55
 
56 184 jshamlet
entity o8_epoch_timer is
57 170 jshamlet
generic(
58
  Reset_Level           : std_logic;
59
  Address               : ADDRESS_TYPE
60
);
61
port(
62
  Clock                 : in  std_logic;
63
  Reset                 : in  std_logic;
64
  uSec_Tick             : in  std_logic;
65
  --
66
  Bus_Address           : in  ADDRESS_TYPE;
67
  Wr_Enable             : in  std_logic;
68
  Wr_Data               : in  DATA_TYPE;
69
  Rd_Enable             : in  std_logic;
70
  Rd_Data               : out DATA_TYPE;
71
  Interrupt             : out std_logic
72
);
73
end entity;
74
 
75 184 jshamlet
architecture behave of o8_epoch_timer is
76 170 jshamlet
 
77
  constant User_Addr    : std_logic_vector(15 downto 2)
78
                          := Address(15 downto 2);
79
  alias  Comp_Addr      is Bus_Address(15 downto 2);
80
  signal Addr_Match     : std_logic;
81
 
82
  alias  Reg_Addr       is Bus_Address(1 downto 0);
83
  signal Reg_Addr_q     : std_logic_vector(1 downto 0);
84
 
85
  signal Wr_En          : std_logic;
86
  signal Wr_Data_q      : DATA_TYPE;
87
  signal Rd_En          : std_logic;
88
 
89
  signal epoch_tmr      : std_logic_vector(25 downto 0);
90
  alias  epoch_tmrcmp   is epoch_tmr(25 downto 2);
91
  signal epoch_buffer   : std_logic_vector(23 downto 0);
92
  signal epoch_setpt    : std_logic_vector(25 downto 0);
93
  signal epoch_alarm    : std_logic;
94
  signal epoch_alarm_q  : std_logic;
95
 
96
begin
97
 
98
  Addr_Match            <= '1' when Comp_Addr = User_Addr else '0';
99
 
100
  io_reg: process( Clock, Reset )
101
  begin
102
    if( Reset = Reset_Level )then
103
      epoch_tmr         <= (others => '0');
104
      epoch_buffer      <= (others => '0');
105
      epoch_setpt       <= (others => '0');
106
      epoch_alarm       <= '0';
107
      epoch_alarm_q     <= '0';
108
      Wr_Data_q         <= (others => '0');
109
      Reg_Addr_q        <= (others => '0');
110
      Wr_En             <= '0';
111
      Rd_En             <= '0';
112 191 jshamlet
      Rd_Data           <= OPEN8_NULLBUS;
113 170 jshamlet
      Interrupt         <= '0';
114
    elsif( rising_edge( Clock ) )then
115
      epoch_tmr         <= epoch_tmr + uSec_Tick;
116 189 jshamlet
                -- Force the lower bits of the setpoint to "11" so that the offset is
117
                --  reduced to 1uS (reproducing the original behavior). Software should
118
                --  always subtract 4uS (-1) from the desired time to compensate
119
                epoch_setpt(1 downto 0) <= "11";
120 170 jshamlet
      Reg_Addr_q        <= Reg_Addr;
121
      Wr_Data_q         <= Wr_Data;
122
 
123
      Wr_En             <= Addr_Match and Wr_Enable;
124
      if( Wr_En = '1' and or_reduce(Reg_Addr_q) = '0' )then
125
        epoch_buffer    <= epoch_tmrcmp(25 downto 2);
126
      end if;
127
 
128
      if( Wr_En = '1' )then
129
        case( Reg_Addr_q )is
130
          when "00" =>
131
            epoch_setpt(9 downto 2)   <= Wr_Data_q;
132
          when "01" =>
133
            epoch_setpt(17 downto 10) <= Wr_Data_q;
134
          when "10" =>
135
            epoch_setpt(25 downto 18) <= Wr_Data_q;
136
          when "11" =>
137
            if( Wr_Data_q(0) = '1' )then
138
              epoch_buffer            <= epoch_tmrcmp;
139
            end if;
140
            if( Wr_Data_q(1) = '1' )then
141
              epoch_tmr               <= (others => '0');
142
            end if;
143
            if( Wr_Data_q(7) = '1' )then
144
              epoch_alarm             <= '0';
145
            end if;
146
 
147
          when others => null;
148
        end case;
149
      end if;
150
 
151
      -- Set and hold on alarm condition
152 189 jshamlet
      if( epoch_tmr > epoch_setpt )then
153 172 jshamlet
        epoch_alarm     <= '1';
154 170 jshamlet
      end if;
155
 
156
      epoch_alarm_q     <= epoch_alarm;
157
      -- Fire on rising edge of epoch_alarm
158 189 jshamlet
      Interrupt         <= epoch_alarm and not epoch_alarm_q;
159 170 jshamlet
 
160 191 jshamlet
      Rd_Data           <= OPEN8_NULLBUS;
161 170 jshamlet
      Rd_En             <= Addr_Match and Rd_Enable;
162
      if( Rd_En = '1' )then
163
        case( Reg_Addr_q )is
164
          when "00" =>
165
            Rd_Data     <= epoch_buffer(7 downto 0);
166
          when "01" =>
167
            Rd_Data     <= epoch_buffer(15 downto 8);
168
          when "10" =>
169
            Rd_Data     <= epoch_buffer(23 downto 16);
170
          when "11" =>
171 189 jshamlet
            Rd_Data     <= epoch_alarm & "0000000";
172 170 jshamlet
          when others => null;
173
        end case;
174
      end if;
175
    end if;
176
  end process;
177
 
178
end architecture;

powered by: WebSVN 2.1.0

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