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

Subversion Repositories common_components

[/] [common_components/] [trunk/] [common_switch.vhd] - Blame information for rev 3

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

Line No. Rev Author Line
1 2 danv
-------------------------------------------------------------------------------
2
--
3
-- Copyright (C) 2009
4
-- ASTRON (Netherlands Institute for Radio Astronomy) <http://www.astron.nl/>
5
-- P.O.Box 2, 7990 AA Dwingeloo, The Netherlands
6
--
7
-- This program is free software: you can redistribute it and/or modify
8
-- it under the terms of the GNU General Public License as published by
9
-- the Free Software Foundation, either version 3 of the License, or
10
-- (at your option) any later version.
11
--
12
-- This program is distributed in the hope that it will be useful,
13
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
14
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
-- GNU General Public License for more details.
16
--
17
-- You should have received a copy of the GNU General Public License
18
-- along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
--
20
-------------------------------------------------------------------------------
21
 
22
-- Purpose : Switch output high or low
23
-- Description:
24
-- . The output goes high when switch_high='1' and low when switch_low='1'.
25
-- . If g_or_high is true then the output follows the switch_high immediately,
26
--   else it goes high in the next clk cycle.
27
-- . If g_and_low is true then the output follows the switch_low immediately,
28
--   else it goes low in the next clk cycle.
29
--   The g_priority_lo defines which input has priority when switch_high and
30
--   switch_low are active simultaneously.
31
 
32
LIBRARY ieee;
33
USE ieee.std_logic_1164.ALL;
34
 
35
ENTITY common_switch IS
36
  GENERIC (
37
    g_rst_level    : STD_LOGIC := '0';  -- Defines the output level at reset.
38
    g_priority_lo  : BOOLEAN := TRUE;   -- When TRUE then input switch_low has priority, else switch_high. Don't care when switch_high and switch_low are pulses that do not occur simultaneously.
39
    g_or_high      : BOOLEAN := FALSE;  -- When TRUE and priority hi then the registered switch_level is OR-ed with the input switch_high to get out_level, else out_level is the registered switch_level
40
    g_and_low      : BOOLEAN := FALSE   -- When TRUE and priority lo then the registered switch_level is AND-ed with the input switch_low to get out_level, else out_level is the registered switch_level
41
  );
42
  PORT (
43
    rst         : IN  STD_LOGIC;
44
    clk         : IN  STD_LOGIC;
45
    clken       : IN  STD_LOGIC := '1';
46
    switch_high : IN  STD_LOGIC;    -- A pulse on switch_high makes the out_level go high
47
    switch_low  : IN  STD_LOGIC;    -- A pulse on switch_low makes the out_level go low
48
    out_level   : OUT STD_LOGIC
49
  );
50
END;
51
 
52
ARCHITECTURE rtl OF common_switch IS
53
 
54
  SIGNAL switch_level         : STD_LOGIC := g_rst_level;
55
  SIGNAL nxt_switch_level     : STD_LOGIC;
56
 
57
BEGIN
58
 
59
  gen_wire : IF g_or_high=FALSE AND g_and_low=FALSE GENERATE
60
    out_level <= switch_level;
61
  END GENERATE;
62
 
63
  gen_or : IF g_or_high=TRUE AND g_and_low=FALSE GENERATE
64
    out_level <= switch_level OR switch_high;
65
  END GENERATE;
66
 
67
  gen_and : IF g_or_high=FALSE AND g_and_low=TRUE GENERATE
68
    out_level <= switch_level AND (NOT switch_low);
69
  END GENERATE;
70
 
71
  gen_or_and : IF g_or_high=TRUE AND g_and_low=TRUE GENERATE
72
    out_level <= (switch_level OR switch_high) AND (NOT switch_low);
73
  END GENERATE;
74
 
75
  p_reg : PROCESS(rst, clk)
76
  BEGIN
77
    IF rst='1' THEN
78
      switch_level <= g_rst_level;
79
    ELSIF rising_edge(clk) THEN
80
      IF clken='1' THEN
81
        switch_level <= nxt_switch_level;
82
      END IF;
83
    END IF;
84
  END PROCESS;
85
 
86
  p_switch_level : PROCESS(switch_level, switch_low, switch_high)
87
  BEGIN
88
    nxt_switch_level <= switch_level;
89
    IF g_priority_lo=TRUE THEN
90
      IF switch_low='1' THEN
91
        nxt_switch_level <= '0';
92
      ELSIF switch_high='1' THEN
93
        nxt_switch_level <= '1';
94
      END IF;
95
    ELSE
96
      IF switch_high='1' THEN
97
        nxt_switch_level <= '1';
98
      ELSIF switch_low='1' THEN
99
        nxt_switch_level <= '0';
100
      END IF;
101
    END IF;
102
  END PROCESS;
103
END rtl;

powered by: WebSVN 2.1.0

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