1 |
2 |
danv |
-------------------------------------------------------------------------------
|
2 |
|
|
--
|
3 |
4 |
danv |
-- Copyright 2020
|
4 |
2 |
danv |
-- ASTRON (Netherlands Institute for Radio Astronomy) <http://www.astron.nl/>
|
5 |
|
|
-- P.O.Box 2, 7990 AA Dwingeloo, The Netherlands
|
6 |
4 |
danv |
--
|
7 |
|
|
-- Licensed under the Apache License, Version 2.0 (the "License");
|
8 |
|
|
-- you may not use this file except in compliance with the License.
|
9 |
|
|
-- You may obtain a copy of the License at
|
10 |
|
|
--
|
11 |
|
|
-- http://www.apache.org/licenses/LICENSE-2.0
|
12 |
|
|
--
|
13 |
|
|
-- Unless required by applicable law or agreed to in writing, software
|
14 |
|
|
-- distributed under the License is distributed on an "AS IS" BASIS,
|
15 |
|
|
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16 |
|
|
-- See the License for the specific language governing permissions and
|
17 |
|
|
-- limitations under the License.
|
18 |
2 |
danv |
--
|
19 |
|
|
-------------------------------------------------------------------------------
|
20 |
|
|
|
21 |
|
|
-- Purpose : Switch output high or low
|
22 |
|
|
-- Description:
|
23 |
|
|
-- . The output goes high when switch_high='1' and low when switch_low='1'.
|
24 |
|
|
-- . If g_or_high is true then the output follows the switch_high immediately,
|
25 |
|
|
-- else it goes high in the next clk cycle.
|
26 |
|
|
-- . If g_and_low is true then the output follows the switch_low immediately,
|
27 |
|
|
-- else it goes low in the next clk cycle.
|
28 |
|
|
-- The g_priority_lo defines which input has priority when switch_high and
|
29 |
|
|
-- switch_low are active simultaneously.
|
30 |
|
|
|
31 |
|
|
LIBRARY ieee;
|
32 |
|
|
USE ieee.std_logic_1164.ALL;
|
33 |
|
|
|
34 |
|
|
ENTITY common_switch IS
|
35 |
|
|
GENERIC (
|
36 |
|
|
g_rst_level : STD_LOGIC := '0'; -- Defines the output level at reset.
|
37 |
|
|
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.
|
38 |
|
|
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
|
39 |
|
|
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
|
40 |
|
|
);
|
41 |
|
|
PORT (
|
42 |
|
|
rst : IN STD_LOGIC;
|
43 |
|
|
clk : IN STD_LOGIC;
|
44 |
|
|
clken : IN STD_LOGIC := '1';
|
45 |
|
|
switch_high : IN STD_LOGIC; -- A pulse on switch_high makes the out_level go high
|
46 |
|
|
switch_low : IN STD_LOGIC; -- A pulse on switch_low makes the out_level go low
|
47 |
|
|
out_level : OUT STD_LOGIC
|
48 |
|
|
);
|
49 |
|
|
END;
|
50 |
|
|
|
51 |
|
|
ARCHITECTURE rtl OF common_switch IS
|
52 |
|
|
|
53 |
|
|
SIGNAL switch_level : STD_LOGIC := g_rst_level;
|
54 |
|
|
SIGNAL nxt_switch_level : STD_LOGIC;
|
55 |
|
|
|
56 |
|
|
BEGIN
|
57 |
|
|
|
58 |
|
|
gen_wire : IF g_or_high=FALSE AND g_and_low=FALSE GENERATE
|
59 |
|
|
out_level <= switch_level;
|
60 |
|
|
END GENERATE;
|
61 |
|
|
|
62 |
|
|
gen_or : IF g_or_high=TRUE AND g_and_low=FALSE GENERATE
|
63 |
|
|
out_level <= switch_level OR switch_high;
|
64 |
|
|
END GENERATE;
|
65 |
|
|
|
66 |
|
|
gen_and : IF g_or_high=FALSE AND g_and_low=TRUE GENERATE
|
67 |
|
|
out_level <= switch_level AND (NOT switch_low);
|
68 |
|
|
END GENERATE;
|
69 |
|
|
|
70 |
|
|
gen_or_and : IF g_or_high=TRUE AND g_and_low=TRUE GENERATE
|
71 |
|
|
out_level <= (switch_level OR switch_high) AND (NOT switch_low);
|
72 |
|
|
END GENERATE;
|
73 |
|
|
|
74 |
|
|
p_reg : PROCESS(rst, clk)
|
75 |
|
|
BEGIN
|
76 |
|
|
IF rst='1' THEN
|
77 |
|
|
switch_level <= g_rst_level;
|
78 |
|
|
ELSIF rising_edge(clk) THEN
|
79 |
|
|
IF clken='1' THEN
|
80 |
|
|
switch_level <= nxt_switch_level;
|
81 |
|
|
END IF;
|
82 |
|
|
END IF;
|
83 |
|
|
END PROCESS;
|
84 |
|
|
|
85 |
|
|
p_switch_level : PROCESS(switch_level, switch_low, switch_high)
|
86 |
|
|
BEGIN
|
87 |
|
|
nxt_switch_level <= switch_level;
|
88 |
|
|
IF g_priority_lo=TRUE THEN
|
89 |
|
|
IF switch_low='1' THEN
|
90 |
|
|
nxt_switch_level <= '0';
|
91 |
|
|
ELSIF switch_high='1' THEN
|
92 |
|
|
nxt_switch_level <= '1';
|
93 |
|
|
END IF;
|
94 |
|
|
ELSE
|
95 |
|
|
IF switch_high='1' THEN
|
96 |
|
|
nxt_switch_level <= '1';
|
97 |
|
|
ELSIF switch_low='1' THEN
|
98 |
|
|
nxt_switch_level <= '0';
|
99 |
|
|
END IF;
|
100 |
|
|
END IF;
|
101 |
|
|
END PROCESS;
|
102 |
|
|
END rtl;
|