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

Subversion Repositories open8_urisc

[/] [open8_urisc/] [trunk/] [VHDL/] [o8_clk_detect.vhd] - Blame information for rev 224

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

Line No. Rev Author Line
1 194 jshamlet
-- Copyright (c)2013, 2020 Jeremy Seth Henry
2 173 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 194 jshamlet
-- (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 173 jshamlet
--
24
-- VHDL Units :  o8_clk_detect
25
-- Description:  Provides up/down status and interrupt for monitoring a clock
26
--
27
-- Register Map:
28
-- Offset  Bitfield Description                          Read/Write
29 197 jshamlet
--  0x00   BA------ Recieve Clock Status                   (RO)
30
--                    A = Clock Line State (follows input)
31
--                    B = Clock Detect (1 = transition detected)
32 224 jshamlet
--
33
-- Revision History
34
-- Author          Date     Change
35
------------------ -------- ---------------------------------------------------
36
-- Seth Henry      04/16/20 Revision block added
37 173 jshamlet
 
38
library ieee;
39
use ieee.std_logic_1164.all;
40
use ieee.std_logic_unsigned.all;
41
use ieee.std_logic_arith.all;
42
use ieee.std_logic_misc.all;
43
 
44
library work;
45
  use work.open8_pkg.all;
46
 
47
entity o8_clk_detect is
48
generic(
49 191 jshamlet
  Threshold_Count            : integer;
50 224 jshamlet
  Address                    : ADDRESS_TYPE
51 173 jshamlet
);
52
port(
53 191 jshamlet
  Ref_Clk_In                 : in  std_logic;
54 173 jshamlet
  --
55 223 jshamlet
  Open8_Bus                  : in  OPEN8_BUS_TYPE;
56 191 jshamlet
  Rd_Data                    : out DATA_TYPE;
57
  Interrupt                  : out std_logic
58 173 jshamlet
);
59
end entity;
60
 
61
architecture behave of o8_clk_detect is
62
 
63 224 jshamlet
  alias Clock                is Open8_Bus.Clock;
64
  alias Reset                is Open8_Bus.Reset;
65
 
66 191 jshamlet
  constant User_Addr         : std_logic_vector(15 downto 0) := Address;
67 223 jshamlet
  alias  Comp_Addr           is Open8_Bus.Address(15 downto 0);
68 191 jshamlet
  signal Addr_Match          : std_logic := '0';
69 173 jshamlet
 
70 191 jshamlet
  signal Rd_En               : std_logic := '0';
71 173 jshamlet
 
72
  constant Threshold_bits    : integer := ceil_log2(Threshold_Count);
73
  constant THRESHOLD         : std_logic_vector(Threshold_bits - 1 downto 0) :=
74
                        conv_std_logic_vector(Threshold_Count,Threshold_bits);
75
 
76 191 jshamlet
  signal RE_Threshold_Ctr    : std_logic_vector(Threshold_Bits - 1 downto 0) :=
77
                                (others => '0');
78
  signal FE_Threshold_Ctr    : std_logic_vector(Threshold_Bits - 1 downto 0) :=
79
                                (others => '0');
80 173 jshamlet
 
81 191 jshamlet
  signal Ref_In_SR           : std_logic_vector(3 downto 0) := (others => '0');
82 173 jshamlet
  alias  Ref_In_q1           is Ref_In_SR(2);
83
  alias  Ref_In_q2           is Ref_In_SR(3);
84 191 jshamlet
  signal Ref_In_RE           : std_logic := '0';
85
  signal Ref_In_FE           : std_logic := '0';
86 173 jshamlet
 
87 191 jshamlet
  signal Ref_Detect          : std_logic := '0';
88
  signal Ref_Detect_q1       : std_logic := '0';
89
  signal Ref_Detect_CoS      : std_logic := '0';
90 173 jshamlet
 
91
begin
92
 
93 223 jshamlet
  Addr_Match                 <= Open8_Bus.Rd_En when Comp_Addr = User_Addr else '0';
94 173 jshamlet
 
95
  io_reg: process( Clock, Reset )
96
  begin
97
    if( Reset = Reset_Level )then
98 217 jshamlet
      Rd_En                  <= '0';
99
      Rd_Data                <= OPEN8_NULLBUS;
100 173 jshamlet
    elsif( rising_edge( Clock ) )then
101 217 jshamlet
      Rd_En                  <= Addr_Match;
102 173 jshamlet
 
103 217 jshamlet
      Rd_Data                <= OPEN8_NULLBUS;
104 173 jshamlet
      if( Rd_En = '1' )then
105 217 jshamlet
        Rd_Data(6)           <= Ref_In_q2;
106
        Rd_Data(7)           <= Ref_Detect;
107 173 jshamlet
      end if;
108
 
109
    end if;
110
  end process;
111
 
112
  Detect_proc: process( Clock, Reset )
113
  begin
114
    if( Reset = Reset_Level )then
115
      Ref_In_SR              <= (others => '0');
116
      Ref_In_RE              <= '0';
117
      Ref_In_FE              <= '0';
118
      RE_Threshold_Ctr       <= (others => '0');
119
      FE_Threshold_Ctr       <= (others => '0');
120
      Ref_Detect             <= '0';
121
      Interrupt              <= '0';
122
    elsif( rising_edge(Clock) )then
123
      Ref_In_SR              <= Ref_In_SR(2 downto 0) & Ref_Clk_In;
124
      Ref_In_RE              <= Ref_In_q1 and (not Ref_In_q2);
125
      Ref_In_FE              <= (not Ref_In_q1) and Ref_In_q2;
126
 
127
      RE_Threshold_Ctr       <= RE_Threshold_Ctr - 1;
128
      if( Ref_In_RE = '1' )then
129
        RE_Threshold_Ctr     <= THRESHOLD;
130
      elsif( or_reduce(RE_Threshold_Ctr) = '0' )then
131
        RE_Threshold_Ctr     <= (others => '0');
132
      end if;
133
 
134
      FE_Threshold_Ctr       <= FE_Threshold_Ctr - 1;
135
      if( Ref_In_FE = '1' )then
136
        FE_Threshold_Ctr     <= THRESHOLD;
137
      elsif( or_reduce(FE_Threshold_Ctr) = '0' )then
138
        FE_Threshold_Ctr     <= (others => '0');
139
      end if;
140
 
141
 
142
      Ref_Detect             <= or_reduce(RE_Threshold_Ctr) and
143
                                or_reduce(FE_Threshold_Ctr);
144
      Ref_Detect_q1          <= Ref_Detect;
145
      Ref_Detect_CoS         <= Ref_Detect xor Ref_Detect_q1;
146
 
147 191 jshamlet
      Interrupt              <= Ref_Detect_CoS;
148 173 jshamlet
    end if;
149
  end process;
150
 
151
end architecture;

powered by: WebSVN 2.1.0

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