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

Subversion Repositories open8_urisc

[/] [open8_urisc/] [trunk/] [VHDL/] [o8_elapsed_usec.vhd] - Blame information for rev 242

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

Line No. Rev Author Line
1 231 jshamlet
-- Copyright (c)2006, 2016, 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_elapsed_usec
25
-- Description:  Provides an 24-bit microsecond resolution counter for
26
--            :   measuring events
27
--
28
-- Register Map:
29
-- Offset  Bitfield Description                        Read/Write
30
--   0x00  AAAAAAAA Req Interval Byte 0                   (RW)
31
--   0x01  AAAAAAAA Req Interval Byte 1                   (RW)
32
--   0x02  AAAAAAAA Req Interval Byte 2                   (RW)
33
--   0x03  BA------ Control/Status Register               (RW)
34
--                   A: Reset (1)                         (WR)
35
--                   B: Start (1) / Stop (0)
36
--
37
-- Notes      :  Writing to 0x0 - 0x02 will latch the current value
38
--            :  Writing a 1 to bit A of 0x03 will cause an
39
--                immediate timer reset. This bit is a one-shot.
40
--
41
-- Revision History
42
-- Author          Date     Change
43
------------------ -------- ---------------------------------------------------
44
-- Seth Henry      04/20/20 Design Start
45
 
46
library ieee;
47
use ieee.std_logic_1164.all;
48
  use ieee.std_logic_unsigned.all;
49
  use ieee.std_logic_arith.all;
50
  use ieee.std_logic_misc.all;
51
 
52
library work;
53
  use work.open8_pkg.all;
54
 
55
entity o8_elapsed_usec is
56
generic(
57
  Address                    : ADDRESS_TYPE
58
);
59
port(
60
  Open8_Bus                  : in  OPEN8_BUS_TYPE;
61
  Rd_Data                    : out DATA_TYPE
62
);
63
end entity;
64
 
65
architecture behave of o8_elapsed_usec is
66
 
67
  alias Clock                is Open8_Bus.Clock;
68
  alias Reset                is Open8_Bus.Reset;
69
  alias uSec_Tick            is Open8_Bus.uSec_Tick;
70
 
71
  constant User_Addr         : std_logic_vector(15 downto 2) :=
72
                                Address(15 downto 2);
73
  alias  Comp_Addr           is Open8_Bus.Address(15 downto 2);
74
  alias  Reg_Addr            is Open8_Bus.Address(1 downto 0);
75
 
76
  signal Addr_Match          : std_logic := '0';
77
  signal Reg_Sel             : std_logic_vector(1 downto 0) := "00";
78
  signal Wr_En               : std_logic := '0';
79
  signal Wr_Data_q           : DATA_TYPE := x"00";
80
  signal Rd_En               : std_logic := '0';
81
  signal Rd_En_q             : std_logic := '0';
82
 
83
  signal Shadow_Time         : std_logic_vector(23 downto 0) := x"000000";
84
  alias  Shadow_Time_B0      is Shadow_Time( 7 downto  0);
85
  alias  Shadow_Time_B1      is Shadow_Time(15 downto  8);
86
  alias  Shadow_Time_B2      is Shadow_Time(23 downto 16);
87
 
88
  signal Update_Shadow       : std_logic := '0';
89
  signal Timer_Reset         : std_logic := '0';
90
  signal Timer_En_Req        : std_logic := '0';
91
  signal Timer_Enable        : std_logic := '0';
92
  signal Timer_Cnt           : std_logic_vector(23 downto 0) := x"000000";
93
 
94
begin
95
 
96
  Addr_Match                 <= '1' when Comp_Addr = User_Addr else '0';
97
 
98
  io_reg: process( Clock, Reset )
99
  begin
100
    if( Reset = Reset_Level )then
101
      Reg_Sel                <= "00";
102
      Wr_En                  <= '0';
103
      Wr_Data_q              <= x"00";
104
      Rd_En                  <= '0';
105
      Rd_Data                <= OPEN8_NULLBUS;
106
      Update_Shadow          <= '0';
107
      Timer_Reset            <= '0';
108
      Timer_En_Req           <= '0';
109
    elsif( rising_edge( Clock ) )then
110
      Reg_Sel                <= Reg_Addr;
111
 
112
      Wr_En                  <= Addr_Match and Open8_Bus.Wr_En;
113
      Wr_Data_q              <= Open8_Bus.Wr_Data;
114
 
115
      Update_Shadow          <= '0';
116
      Timer_Reset            <= '0';
117
      if( Wr_En = '1' )then
118
        case( Reg_Sel )is
119
          when "00" =>
120
            Update_Shadow    <= '1';
121
          when "01" =>
122
            Update_Shadow    <= '1';
123
          when "10" =>
124
            Update_Shadow    <= '1';
125
          when "11" =>
126
            Timer_Reset      <= Wr_Data_q(6);
127
            Timer_En_Req     <= Wr_Data_q(7);
128
          when others => null;
129
        end case;
130
      end if;
131
 
132
      Rd_Data                <= OPEN8_NULLBUS;
133
      Rd_En                  <= Addr_Match and Open8_Bus.Rd_En;
134
      if( Rd_En = '1' )then
135
        case( Reg_Sel )is
136
          when "00" =>
137
            Rd_Data          <= Shadow_Time_B0;
138
          when "01" =>
139
            Rd_Data          <= Shadow_Time_B1;
140
          when "10" =>
141
            Rd_Data          <= Shadow_Time_B2;
142
          when "11" =>
143
            Rd_Data          <= Timer_En_Req & "0000000";
144
          when others => null;
145
        end case;
146
      end if;
147
    end if;
148
  end process;
149
 
150
  Timer_proc: process( Clock, Reset )
151
  begin
152
    if( Reset = Reset_Level )then
153
      Shadow_Time            <= x"000000";
154
      Timer_Cnt              <= x"000000";
155
    elsif( rising_edge(Clock) )then
156
      if( Timer_Reset = '1' )then
157
        Timer_Cnt              <= x"000000";
158
      elsif( Timer_Enable = '1' )then
159
        Timer_Cnt            <= Timer_Cnt + uSec_Tick;
160
      end if;
161
 
162
      if( uSec_Tick = '1' )then
163
        Timer_Enable         <= Timer_En_Req;
164
      end if;
165
 
166
      if( Update_Shadow = '1' )then
167
        Shadow_Time          <= Timer_Cnt;
168
      end if;
169
    end if;
170
  end process;
171
 
172
end architecture;

powered by: WebSVN 2.1.0

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