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 263

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

Line No. Rev Author Line
1 259 jshamlet
-- Copyright (c)2020 Jeremy Seth Henry
2 231 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
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 244 jshamlet
-- Seth Henry      05/18/20 Added write qualification input
46 231 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
entity o8_elapsed_usec is
57
generic(
58
  Address                    : ADDRESS_TYPE
59
);
60
port(
61
  Open8_Bus                  : in  OPEN8_BUS_TYPE;
62 244 jshamlet
  Write_Qual                 : in  std_logic := '1';
63 231 jshamlet
  Rd_Data                    : out DATA_TYPE
64
);
65
end entity;
66
 
67
architecture behave of o8_elapsed_usec is
68
 
69
  alias Clock                is Open8_Bus.Clock;
70
  alias Reset                is Open8_Bus.Reset;
71
  alias uSec_Tick            is Open8_Bus.uSec_Tick;
72
 
73
  constant User_Addr         : std_logic_vector(15 downto 2) :=
74
                                Address(15 downto 2);
75
  alias  Comp_Addr           is Open8_Bus.Address(15 downto 2);
76 244 jshamlet
  signal Addr_Match          : std_logic := '0';
77 231 jshamlet
 
78 244 jshamlet
  alias  Reg_Sel_d           is Open8_Bus.Address(1 downto 0);
79
  signal Reg_Sel_q           : std_logic_vector(1 downto 0) := "00";
80
  signal Wr_En_d             : std_logic := '0';
81
  signal Wr_En_q             : std_logic := '0';
82
  alias  Wr_Data_d           is Open8_Bus.Wr_Data;
83 231 jshamlet
  signal Wr_Data_q           : DATA_TYPE := x"00";
84 244 jshamlet
  signal Rd_En_d             : std_logic := '0';
85 231 jshamlet
  signal Rd_En_q             : std_logic := '0';
86
 
87
  signal Shadow_Time         : std_logic_vector(23 downto 0) := x"000000";
88
  alias  Shadow_Time_B0      is Shadow_Time( 7 downto  0);
89
  alias  Shadow_Time_B1      is Shadow_Time(15 downto  8);
90
  alias  Shadow_Time_B2      is Shadow_Time(23 downto 16);
91
 
92
  signal Update_Shadow       : std_logic := '0';
93
  signal Timer_Reset         : std_logic := '0';
94
  signal Timer_En_Req        : std_logic := '0';
95
  signal Timer_Enable        : std_logic := '0';
96
  signal Timer_Cnt           : std_logic_vector(23 downto 0) := x"000000";
97
 
98
begin
99
 
100
  Addr_Match                 <= '1' when Comp_Addr = User_Addr else '0';
101 244 jshamlet
  Wr_En_d                    <= Addr_Match and Open8_Bus.Wr_En;
102
  Rd_En_d                    <= Addr_Match and Open8_Bus.Rd_En;
103 231 jshamlet
 
104
  io_reg: process( Clock, Reset )
105
  begin
106
    if( Reset = Reset_Level )then
107 244 jshamlet
      Reg_Sel_q              <= "00";
108
      Wr_En_q                <= '0';
109 231 jshamlet
      Wr_Data_q              <= x"00";
110 244 jshamlet
      Rd_En_q                <= '0';
111 231 jshamlet
      Rd_Data                <= OPEN8_NULLBUS;
112 244 jshamlet
 
113 231 jshamlet
      Update_Shadow          <= '0';
114
      Timer_Reset            <= '0';
115
      Timer_En_Req           <= '0';
116
    elsif( rising_edge( Clock ) )then
117 244 jshamlet
      Reg_Sel_q              <= Reg_Sel_d;
118 231 jshamlet
 
119 244 jshamlet
      Wr_En_q                <= Wr_En_d;
120
      Wr_Data_q              <= Wr_Data_d;
121 231 jshamlet
 
122
      Update_Shadow          <= '0';
123
      Timer_Reset            <= '0';
124 244 jshamlet
      if( Wr_En_q = '1' and Write_Qual = '1' )then
125
        case( Reg_Sel_q )is
126 231 jshamlet
          when "00" =>
127
            Update_Shadow    <= '1';
128
          when "01" =>
129
            Update_Shadow    <= '1';
130
          when "10" =>
131
            Update_Shadow    <= '1';
132
          when "11" =>
133
            Timer_Reset      <= Wr_Data_q(6);
134
            Timer_En_Req     <= Wr_Data_q(7);
135
          when others => null;
136
        end case;
137
      end if;
138
 
139
      Rd_Data                <= OPEN8_NULLBUS;
140 244 jshamlet
      Rd_En_q                <= Rd_En_d;
141
      if( Rd_En_q = '1' )then
142
        case( Reg_Sel_q )is
143 231 jshamlet
          when "00" =>
144
            Rd_Data          <= Shadow_Time_B0;
145
          when "01" =>
146
            Rd_Data          <= Shadow_Time_B1;
147
          when "10" =>
148
            Rd_Data          <= Shadow_Time_B2;
149
          when "11" =>
150
            Rd_Data          <= Timer_En_Req & "0000000";
151
          when others => null;
152
        end case;
153
      end if;
154
    end if;
155
  end process;
156
 
157
  Timer_proc: process( Clock, Reset )
158
  begin
159
    if( Reset = Reset_Level )then
160
      Shadow_Time            <= x"000000";
161
      Timer_Cnt              <= x"000000";
162
    elsif( rising_edge(Clock) )then
163
      if( Timer_Reset = '1' )then
164
        Timer_Cnt              <= x"000000";
165
      elsif( Timer_Enable = '1' )then
166
        Timer_Cnt            <= Timer_Cnt + uSec_Tick;
167
      end if;
168
 
169
      if( uSec_Tick = '1' )then
170
        Timer_Enable         <= Timer_En_Req;
171
      end if;
172
 
173
      if( Update_Shadow = '1' )then
174
        Shadow_Time          <= Timer_Cnt;
175
      end if;
176
    end if;
177
  end process;
178
 
179
end architecture;

powered by: WebSVN 2.1.0

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