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 301

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 276 jshamlet
--   0x00  AAAAAAAA Time Accumulator Byte 0               (RW*)
31
--   0x01  AAAAAAAA Time Accumulator Byte 1               (RW*)
32
--   0x02  AAAAAAAA Time Accumulator Byte 2               (RW*)
33 231 jshamlet
--   0x03  BA------ Control/Status Register               (RW)
34 276 jshamlet
--                   A: Reset (1)
35
--                   B: Start (1) / Stop (0) (status on RD)
36 231 jshamlet
--
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 296 jshamlet
          when "00" | "01" | "10" =>
127 231 jshamlet
            Update_Shadow    <= '1';
128
          when "11" =>
129
            Timer_Reset      <= Wr_Data_q(6);
130
            Timer_En_Req     <= Wr_Data_q(7);
131
          when others => null;
132
        end case;
133
      end if;
134
 
135
      Rd_Data                <= OPEN8_NULLBUS;
136 244 jshamlet
      Rd_En_q                <= Rd_En_d;
137
      if( Rd_En_q = '1' )then
138
        case( Reg_Sel_q )is
139 231 jshamlet
          when "00" =>
140
            Rd_Data          <= Shadow_Time_B0;
141
          when "01" =>
142
            Rd_Data          <= Shadow_Time_B1;
143
          when "10" =>
144
            Rd_Data          <= Shadow_Time_B2;
145
          when "11" =>
146
            Rd_Data          <= Timer_En_Req & "0000000";
147
          when others => null;
148
        end case;
149
      end if;
150
    end if;
151
  end process;
152
 
153
  Timer_proc: process( Clock, Reset )
154
  begin
155
    if( Reset = Reset_Level )then
156
      Shadow_Time            <= x"000000";
157
      Timer_Cnt              <= x"000000";
158
    elsif( rising_edge(Clock) )then
159
      if( Timer_Reset = '1' )then
160
        Timer_Cnt              <= x"000000";
161
      elsif( Timer_Enable = '1' )then
162
        Timer_Cnt            <= Timer_Cnt + uSec_Tick;
163
      end if;
164
 
165
      if( uSec_Tick = '1' )then
166
        Timer_Enable         <= Timer_En_Req;
167
      end if;
168
 
169
      if( Update_Shadow = '1' )then
170
        Shadow_Time          <= Timer_Cnt;
171
      end if;
172
    end if;
173
  end process;
174
 
175
end architecture;

powered by: WebSVN 2.1.0

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