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 216

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 191 jshamlet
  Bus_Address                : in  ADDRESS_TYPE;
55
  Rd_Enable                  : in  std_logic;
56
  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 191 jshamlet
  constant User_Addr         : std_logic_vector(15 downto 0) := Address;
64
  alias  Comp_Addr           is Bus_Address(15 downto 0);
65
  signal Addr_Match          : std_logic := '0';
66 173 jshamlet
 
67 191 jshamlet
  signal Rd_En               : std_logic := '0';
68 173 jshamlet
 
69
  constant Threshold_bits    : integer := ceil_log2(Threshold_Count);
70
  constant THRESHOLD         : std_logic_vector(Threshold_bits - 1 downto 0) :=
71
                        conv_std_logic_vector(Threshold_Count,Threshold_bits);
72
 
73 191 jshamlet
  signal RE_Threshold_Ctr    : std_logic_vector(Threshold_Bits - 1 downto 0) :=
74
                                (others => '0');
75
  signal FE_Threshold_Ctr    : std_logic_vector(Threshold_Bits - 1 downto 0) :=
76
                                (others => '0');
77 173 jshamlet
 
78 191 jshamlet
  signal Ref_In_SR           : std_logic_vector(3 downto 0) := (others => '0');
79 173 jshamlet
  alias  Ref_In_q1           is Ref_In_SR(2);
80
  alias  Ref_In_q2           is Ref_In_SR(3);
81 191 jshamlet
  signal Ref_In_RE           : std_logic := '0';
82
  signal Ref_In_FE           : std_logic := '0';
83 173 jshamlet
 
84 191 jshamlet
  signal Ref_Detect          : std_logic := '0';
85
  signal Ref_Detect_q1       : std_logic := '0';
86
  signal Ref_Detect_CoS      : std_logic := '0';
87 173 jshamlet
 
88
begin
89
 
90 191 jshamlet
  Addr_Match            <= Rd_Enable when Comp_Addr = User_Addr else '0';
91 173 jshamlet
 
92
  io_reg: process( Clock, Reset )
93
  begin
94
    if( Reset = Reset_Level )then
95
      Rd_En             <= '0';
96 191 jshamlet
      Rd_Data           <= OPEN8_NULLBUS;
97 173 jshamlet
    elsif( rising_edge( Clock ) )then
98 191 jshamlet
      Rd_En             <= Addr_Match;
99 173 jshamlet
 
100 191 jshamlet
      Rd_Data           <= OPEN8_NULLBUS;
101 173 jshamlet
      if( Rd_En = '1' )then
102
        Rd_Data(6)      <= Ref_In_q2;
103
        Rd_Data(7)      <= Ref_Detect;
104
      end if;
105
 
106
    end if;
107
  end process;
108
 
109
  Detect_proc: process( Clock, Reset )
110
  begin
111
    if( Reset = Reset_Level )then
112
      Ref_In_SR              <= (others => '0');
113
      Ref_In_RE              <= '0';
114
      Ref_In_FE              <= '0';
115
      RE_Threshold_Ctr       <= (others => '0');
116
      FE_Threshold_Ctr       <= (others => '0');
117
      Ref_Detect             <= '0';
118
      Interrupt              <= '0';
119
    elsif( rising_edge(Clock) )then
120
      Ref_In_SR              <= Ref_In_SR(2 downto 0) & Ref_Clk_In;
121
      Ref_In_RE              <= Ref_In_q1 and (not Ref_In_q2);
122
      Ref_In_FE              <= (not Ref_In_q1) and Ref_In_q2;
123
 
124
      RE_Threshold_Ctr       <= RE_Threshold_Ctr - 1;
125
      if( Ref_In_RE = '1' )then
126
        RE_Threshold_Ctr     <= THRESHOLD;
127
      elsif( or_reduce(RE_Threshold_Ctr) = '0' )then
128
        RE_Threshold_Ctr     <= (others => '0');
129
      end if;
130
 
131
      FE_Threshold_Ctr       <= FE_Threshold_Ctr - 1;
132
      if( Ref_In_FE = '1' )then
133
        FE_Threshold_Ctr     <= THRESHOLD;
134
      elsif( or_reduce(FE_Threshold_Ctr) = '0' )then
135
        FE_Threshold_Ctr     <= (others => '0');
136
      end if;
137
 
138
 
139
      Ref_Detect             <= or_reduce(RE_Threshold_Ctr) and
140
                                or_reduce(FE_Threshold_Ctr);
141
      Ref_Detect_q1          <= Ref_Detect;
142
      Ref_Detect_CoS         <= Ref_Detect xor Ref_Detect_q1;
143
 
144 191 jshamlet
      Interrupt              <= Ref_Detect_CoS;
145 173 jshamlet
    end if;
146
  end process;
147
 
148
end architecture;

powered by: WebSVN 2.1.0

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