-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
--
|
--
|
-- Copyright (C) 2009
|
-- Copyright 2020
|
-- ASTRON (Netherlands Institute for Radio Astronomy) <http://www.astron.nl/>
|
-- ASTRON (Netherlands Institute for Radio Astronomy) <http://www.astron.nl/>
|
-- P.O.Box 2, 7990 AA Dwingeloo, The Netherlands
|
-- P.O.Box 2, 7990 AA Dwingeloo, The Netherlands
|
--
|
--
|
-- This program is free software: you can redistribute it and/or modify
|
-- Licensed under the Apache License, Version 2.0 (the "License");
|
-- it under the terms of the GNU General Public License as published by
|
-- you may not use this file except in compliance with the License.
|
-- the Free Software Foundation, either version 3 of the License, or
|
-- You may obtain a copy of the License at
|
-- (at your option) any later version.
|
|
--
|
--
|
-- This program is distributed in the hope that it will be useful,
|
-- http://www.apache.org/licenses/LICENSE-2.0
|
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
-- GNU General Public License for more details.
|
|
--
|
--
|
-- You should have received a copy of the GNU General Public License
|
-- Unless required by applicable law or agreed to in writing, software
|
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
|
-- distributed under the License is distributed on an "AS IS" BASIS,
|
|
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
-- See the License for the specific language governing permissions and
|
|
-- limitations under the License.
|
--
|
--
|
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
|
|
-- Purpose : Switch output high or low
|
-- Purpose : Switch output high or low
|
-- Description:
|
-- Description:
|
-- . The output goes high when switch_high='1' and low when switch_low='1'.
|
-- . The output goes high when switch_high='1' and low when switch_low='1'.
|
-- . If g_or_high is true then the output follows the switch_high immediately,
|
-- . If g_or_high is true then the output follows the switch_high immediately,
|
-- else it goes high in the next clk cycle.
|
-- else it goes high in the next clk cycle.
|
-- . If g_and_low is true then the output follows the switch_low immediately,
|
-- . If g_and_low is true then the output follows the switch_low immediately,
|
-- else it goes low in the next clk cycle.
|
-- else it goes low in the next clk cycle.
|
-- The g_priority_lo defines which input has priority when switch_high and
|
-- The g_priority_lo defines which input has priority when switch_high and
|
-- switch_low are active simultaneously.
|
-- switch_low are active simultaneously.
|
|
|
LIBRARY ieee;
|
LIBRARY ieee;
|
USE ieee.std_logic_1164.ALL;
|
USE ieee.std_logic_1164.ALL;
|
|
|
ENTITY common_switch IS
|
ENTITY common_switch IS
|
GENERIC (
|
GENERIC (
|
g_rst_level : STD_LOGIC := '0'; -- Defines the output level at reset.
|
g_rst_level : STD_LOGIC := '0'; -- Defines the output level at reset.
|
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.
|
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.
|
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
|
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
|
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
|
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
|
);
|
);
|
PORT (
|
PORT (
|
rst : IN STD_LOGIC;
|
rst : IN STD_LOGIC;
|
clk : IN STD_LOGIC;
|
clk : IN STD_LOGIC;
|
clken : IN STD_LOGIC := '1';
|
clken : IN STD_LOGIC := '1';
|
switch_high : IN STD_LOGIC; -- A pulse on switch_high makes the out_level go high
|
switch_high : IN STD_LOGIC; -- A pulse on switch_high makes the out_level go high
|
switch_low : IN STD_LOGIC; -- A pulse on switch_low makes the out_level go low
|
switch_low : IN STD_LOGIC; -- A pulse on switch_low makes the out_level go low
|
out_level : OUT STD_LOGIC
|
out_level : OUT STD_LOGIC
|
);
|
);
|
END;
|
END;
|
|
|
ARCHITECTURE rtl OF common_switch IS
|
ARCHITECTURE rtl OF common_switch IS
|
|
|
SIGNAL switch_level : STD_LOGIC := g_rst_level;
|
SIGNAL switch_level : STD_LOGIC := g_rst_level;
|
SIGNAL nxt_switch_level : STD_LOGIC;
|
SIGNAL nxt_switch_level : STD_LOGIC;
|
|
|
BEGIN
|
BEGIN
|
|
|
gen_wire : IF g_or_high=FALSE AND g_and_low=FALSE GENERATE
|
gen_wire : IF g_or_high=FALSE AND g_and_low=FALSE GENERATE
|
out_level <= switch_level;
|
out_level <= switch_level;
|
END GENERATE;
|
END GENERATE;
|
|
|
gen_or : IF g_or_high=TRUE AND g_and_low=FALSE GENERATE
|
gen_or : IF g_or_high=TRUE AND g_and_low=FALSE GENERATE
|
out_level <= switch_level OR switch_high;
|
out_level <= switch_level OR switch_high;
|
END GENERATE;
|
END GENERATE;
|
|
|
gen_and : IF g_or_high=FALSE AND g_and_low=TRUE GENERATE
|
gen_and : IF g_or_high=FALSE AND g_and_low=TRUE GENERATE
|
out_level <= switch_level AND (NOT switch_low);
|
out_level <= switch_level AND (NOT switch_low);
|
END GENERATE;
|
END GENERATE;
|
|
|
gen_or_and : IF g_or_high=TRUE AND g_and_low=TRUE GENERATE
|
gen_or_and : IF g_or_high=TRUE AND g_and_low=TRUE GENERATE
|
out_level <= (switch_level OR switch_high) AND (NOT switch_low);
|
out_level <= (switch_level OR switch_high) AND (NOT switch_low);
|
END GENERATE;
|
END GENERATE;
|
|
|
p_reg : PROCESS(rst, clk)
|
p_reg : PROCESS(rst, clk)
|
BEGIN
|
BEGIN
|
IF rst='1' THEN
|
IF rst='1' THEN
|
switch_level <= g_rst_level;
|
switch_level <= g_rst_level;
|
ELSIF rising_edge(clk) THEN
|
ELSIF rising_edge(clk) THEN
|
IF clken='1' THEN
|
IF clken='1' THEN
|
switch_level <= nxt_switch_level;
|
switch_level <= nxt_switch_level;
|
END IF;
|
END IF;
|
END IF;
|
END IF;
|
END PROCESS;
|
END PROCESS;
|
|
|
p_switch_level : PROCESS(switch_level, switch_low, switch_high)
|
p_switch_level : PROCESS(switch_level, switch_low, switch_high)
|
BEGIN
|
BEGIN
|
nxt_switch_level <= switch_level;
|
nxt_switch_level <= switch_level;
|
IF g_priority_lo=TRUE THEN
|
IF g_priority_lo=TRUE THEN
|
IF switch_low='1' THEN
|
IF switch_low='1' THEN
|
nxt_switch_level <= '0';
|
nxt_switch_level <= '0';
|
ELSIF switch_high='1' THEN
|
ELSIF switch_high='1' THEN
|
nxt_switch_level <= '1';
|
nxt_switch_level <= '1';
|
END IF;
|
END IF;
|
ELSE
|
ELSE
|
IF switch_high='1' THEN
|
IF switch_high='1' THEN
|
nxt_switch_level <= '1';
|
nxt_switch_level <= '1';
|
ELSIF switch_low='1' THEN
|
ELSIF switch_low='1' THEN
|
nxt_switch_level <= '0';
|
nxt_switch_level <= '0';
|
END IF;
|
END IF;
|
END IF;
|
END IF;
|
END PROCESS;
|
END PROCESS;
|
END rtl;
|
END rtl;
|
|
|