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 223

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 173 jshamlet
 
33
library ieee;
34
use ieee.std_logic_1164.all;
35
use ieee.std_logic_unsigned.all;
36
use ieee.std_logic_arith.all;
37
use ieee.std_logic_misc.all;
38
 
39
library work;
40
  use work.open8_pkg.all;
41
 
42
entity o8_clk_detect is
43
generic(
44 191 jshamlet
  Threshold_Count            : integer;
45
  Address                    : ADDRESS_TYPE;
46
  Reset_Level                : std_logic
47 173 jshamlet
);
48
port(
49 191 jshamlet
  Clock                      : in  std_logic;
50
  Reset                      : in  std_logic;
51 173 jshamlet
  --
52 191 jshamlet
  Ref_Clk_In                 : in  std_logic;
53 173 jshamlet
  --
54 223 jshamlet
  Open8_Bus                  : in  OPEN8_BUS_TYPE;
55 191 jshamlet
  Rd_Data                    : out DATA_TYPE;
56
  Interrupt                  : out std_logic
57 173 jshamlet
);
58
end entity;
59
 
60
architecture behave of o8_clk_detect is
61
 
62 191 jshamlet
  constant User_Addr         : std_logic_vector(15 downto 0) := Address;
63 223 jshamlet
  alias  Comp_Addr           is Open8_Bus.Address(15 downto 0);
64 191 jshamlet
  signal Addr_Match          : std_logic := '0';
65 173 jshamlet
 
66 191 jshamlet
  signal Rd_En               : std_logic := '0';
67 173 jshamlet
 
68
  constant Threshold_bits    : integer := ceil_log2(Threshold_Count);
69
  constant THRESHOLD         : std_logic_vector(Threshold_bits - 1 downto 0) :=
70
                        conv_std_logic_vector(Threshold_Count,Threshold_bits);
71
 
72 191 jshamlet
  signal RE_Threshold_Ctr    : std_logic_vector(Threshold_Bits - 1 downto 0) :=
73
                                (others => '0');
74
  signal FE_Threshold_Ctr    : std_logic_vector(Threshold_Bits - 1 downto 0) :=
75
                                (others => '0');
76 173 jshamlet
 
77 191 jshamlet
  signal Ref_In_SR           : std_logic_vector(3 downto 0) := (others => '0');
78 173 jshamlet
  alias  Ref_In_q1           is Ref_In_SR(2);
79
  alias  Ref_In_q2           is Ref_In_SR(3);
80 191 jshamlet
  signal Ref_In_RE           : std_logic := '0';
81
  signal Ref_In_FE           : std_logic := '0';
82 173 jshamlet
 
83 191 jshamlet
  signal Ref_Detect          : std_logic := '0';
84
  signal Ref_Detect_q1       : std_logic := '0';
85
  signal Ref_Detect_CoS      : std_logic := '0';
86 173 jshamlet
 
87
begin
88
 
89 223 jshamlet
  Addr_Match                 <= Open8_Bus.Rd_En when Comp_Addr = User_Addr else '0';
90 173 jshamlet
 
91
  io_reg: process( Clock, Reset )
92
  begin
93
    if( Reset = Reset_Level )then
94 217 jshamlet
      Rd_En                  <= '0';
95
      Rd_Data                <= OPEN8_NULLBUS;
96 173 jshamlet
    elsif( rising_edge( Clock ) )then
97 217 jshamlet
      Rd_En                  <= Addr_Match;
98 173 jshamlet
 
99 217 jshamlet
      Rd_Data                <= OPEN8_NULLBUS;
100 173 jshamlet
      if( Rd_En = '1' )then
101 217 jshamlet
        Rd_Data(6)           <= Ref_In_q2;
102
        Rd_Data(7)           <= Ref_Detect;
103 173 jshamlet
      end if;
104
 
105
    end if;
106
  end process;
107
 
108
  Detect_proc: process( Clock, Reset )
109
  begin
110
    if( Reset = Reset_Level )then
111
      Ref_In_SR              <= (others => '0');
112
      Ref_In_RE              <= '0';
113
      Ref_In_FE              <= '0';
114
      RE_Threshold_Ctr       <= (others => '0');
115
      FE_Threshold_Ctr       <= (others => '0');
116
      Ref_Detect             <= '0';
117
      Interrupt              <= '0';
118
    elsif( rising_edge(Clock) )then
119
      Ref_In_SR              <= Ref_In_SR(2 downto 0) & Ref_Clk_In;
120
      Ref_In_RE              <= Ref_In_q1 and (not Ref_In_q2);
121
      Ref_In_FE              <= (not Ref_In_q1) and Ref_In_q2;
122
 
123
      RE_Threshold_Ctr       <= RE_Threshold_Ctr - 1;
124
      if( Ref_In_RE = '1' )then
125
        RE_Threshold_Ctr     <= THRESHOLD;
126
      elsif( or_reduce(RE_Threshold_Ctr) = '0' )then
127
        RE_Threshold_Ctr     <= (others => '0');
128
      end if;
129
 
130
      FE_Threshold_Ctr       <= FE_Threshold_Ctr - 1;
131
      if( Ref_In_FE = '1' )then
132
        FE_Threshold_Ctr     <= THRESHOLD;
133
      elsif( or_reduce(FE_Threshold_Ctr) = '0' )then
134
        FE_Threshold_Ctr     <= (others => '0');
135
      end if;
136
 
137
 
138
      Ref_Detect             <= or_reduce(RE_Threshold_Ctr) and
139
                                or_reduce(FE_Threshold_Ctr);
140
      Ref_Detect_q1          <= Ref_Detect;
141
      Ref_Detect_CoS         <= Ref_Detect xor Ref_Detect_q1;
142
 
143 191 jshamlet
      Interrupt              <= Ref_Detect_CoS;
144 173 jshamlet
    end if;
145
  end process;
146
 
147
end architecture;

powered by: WebSVN 2.1.0

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