w11 - vhd 0.791
W11 CPU core and support modules
sn_humanio_demu.vhd
Go to the documentation of this file.
1-- $Id: sn_humanio_demu.vhd 1181 2019-07-08 17:00:50Z mueller $
2-- SPDX-License-Identifier: GPL-3.0-or-later
3-- Copyright 2011- by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
4--
5------------------------------------------------------------------------------
6-- Module Name: sn_humanio_demu - syn
7-- Description: All BTN, SWI, LED handling for atlys
8--
9-- Dependencies: bpgen/bp_swibtnled
10--
11-- Test bench: -
12--
13-- Target Devices: generic
14-- Tool versions: xst 13.1-14.7; ghdl 0.29-0.31
15--
16-- Synthesized (xst):
17-- Date Rev ise Target flop lutl lutm slic t peri
18-- 2011-10-10 413 13.1 O40d xc3s1000-4 67 66 0 55 s 6.1 ns
19--
20-- Revision History:
21-- Date Rev Version Comment
22-- 2011-10-11 414 1.0.1 take care of RESET BTN being active low
23-- 2011-10-10 413 1.0 Initial version
24------------------------------------------------------------------------------
25--
26
27library ieee;
28use ieee.std_logic_1164.all;
29use ieee.numeric_std.all;
30
31use work.slvtypes.all;
32use work.bpgenlib.all;
33
34-- ----------------------------------------------------------------------------
35
36entity sn_humanio_demu is -- human i/o handling: swi,btn,led only
37 generic (
38 DEBOUNCE : boolean := true); -- instantiate debouncer for SWI,BTN
39 port (
40 CLK : in slbit; -- clock
41 RESET : in slbit := '0'; -- reset
42 CE_MSEC : in slbit; -- 1 ms clock enable
43 SWI : out slv8; -- switch settings, debounced
44 BTN : out slv4; -- button settings, debounced
45 LED : in slv8; -- led data
46 DSP_DAT : in slv16; -- display data
47 DSP_DP : in slv4; -- display decimal points
48 I_SWI : in slv8; -- pad-i: switches
49 I_BTN : in slv6; -- pad-i: buttons
50 O_LED : out slv8 -- pad-o: leds
51 );
53
54architecture syn of sn_humanio_demu is
55
56 constant c_mode_led : slv2 := "00";
57 constant c_mode_dp : slv2 := "01";
58 constant c_mode_datl : slv2 := "10";
59 constant c_mode_dath : slv2 := "11";
60
61 type regs_type is record
62 mode : slv2; -- current mode
63 cnt : slv9; -- msec counter
64 up_1 : slbit; -- btn up last cycle
65 dn_1 : slbit; -- btn dn last cycle
66 led : slv8; -- led state
67 end record regs_type;
68
69 constant regs_init : regs_type := (
70 c_mode_led, -- mode
71 (others=>'0'), -- cnt
72 '0','0', -- up_1, dn_1
73 (others=>'0') -- led
74 );
75
76 signal R_REGS : regs_type := regs_init; -- state registers
77 signal N_REGS : regs_type := regs_init; -- next value state regs
78
79 signal BTN_HW : slv6 := (others=>'0');
80 signal LED_HW : slv8 := (others=>'0');
81
82begin
83
84 HIO : bp_swibtnled
85 generic map (
86 SWIDTH => 8,
87 BWIDTH => 6,
88 LWIDTH => 8,
90 port map (
91 CLK => CLK,
92 RESET => RESET,
94 SWI => SWI,
95 BTN => BTN_HW,
96 LED => LED_HW,
97 I_SWI => I_SWI,
98 I_BTN => I_BTN,
99 O_LED => O_LED
100 );
101
102 proc_regs: process (CLK)
103 begin
104
105 if rising_edge(CLK) then
106 if RESET = '1' then
107 R_REGS <= regs_init;
108 else
109 R_REGS <= N_REGS;
110 end if;
111 end if;
112
113 end process proc_regs;
114
115 proc_next: process (R_REGS, CE_MSEC, LED, DSP_DAT, DSP_DP, BTN_HW)
116
117 variable r : regs_type := regs_init;
118 variable n : regs_type := regs_init;
119
120 variable ibtn : slv4 := (others=>'0');
121 variable iup : slbit := '0';
122 variable idn : slbit := '0';
123 variable ipuls : slbit := '0';
124
125 begin
126 r := R_REGS;
127 n := R_REGS;
128
129 ibtn(0) := not BTN_HW(5); -- RESET button is act. low !
130 ibtn(1) := BTN_HW(1);
131 ibtn(2) := BTN_HW(4);
132 ibtn(3) := BTN_HW(3);
133 iup := BTN_HW(0);
134 idn := BTN_HW(2);
135
136 ipuls := '0';
137
138
139 n.up_1 := iup;
140 n.dn_1 := idn;
141
142 if iup='0' and idn='0' then
143 n.cnt := (others=>'0');
144 else
145 if CE_MSEC = '1' then
146 n.cnt := slv(unsigned(r.cnt) + 1);
147 if r.cnt = "111111111" then
148 ipuls := '1';
149 end if;
150 end if;
151 end if;
152
153 if iup='1' or idn='1' then
154 n.led := (others=>'0');
155 case r.mode is
156 when c_mode_led => n.led(0) := '1';
157 when c_mode_dp => n.led(1) := '1';
158 when c_mode_datl => n.led(2) := '1';
159 when c_mode_dath => n.led(3) := '1';
160 when others => null;
161 end case;
162
163 if iup='1' and (r.up_1='0' or ipuls='1') then
164 n.mode := slv(unsigned(r.mode) + 1);
165 elsif idn='1' and (r.dn_1='0' or ipuls='1') then
166 n.mode := slv(unsigned(r.mode) - 1);
167 end if;
168
169 else
170 case r.mode is
171 when c_mode_led => n.led := LED;
172 when c_mode_dp => n.led := "0000" & DSP_DP;
173 when c_mode_datl => n.led := DSP_DAT( 7 downto 0);
174 when c_mode_dath => n.led := DSP_DAT(15 downto 8);
175 when others => null;
176 end case;
177 end if;
178
179 N_REGS <= n;
180
181 BTN <= ibtn;
182 LED_HW <= r.led;
183
184 end process proc_next;
185
186end syn;
DEBOUNCE boolean := true
SWIDTH positive := 4
out O_LED slv( LWIDTH- 1 downto 0)
out SWI slv( SWIDTH- 1 downto 0)
in I_BTN slv( BWIDTH- 1 downto 0)
LWIDTH positive := 4
in I_SWI slv( SWIDTH- 1 downto 0)
out BTN slv( BWIDTH- 1 downto 0)
in CLK slbit
BWIDTH positive := 4
in LED slv( LWIDTH- 1 downto 0)
in RESET slbit := '0'
in CE_MSEC slbit
std_logic_vector( 3 downto 0) slv4
Definition: slvtypes.vhd:36
std_logic_vector( 8 downto 0) slv9
Definition: slvtypes.vhd:41
std_logic_vector( 15 downto 0) slv16
Definition: slvtypes.vhd:48
std_logic slbit
Definition: slvtypes.vhd:30
std_logic_vector( 5 downto 0) slv6
Definition: slvtypes.vhd:38
std_logic_vector( 7 downto 0) slv8
Definition: slvtypes.vhd:40
std_logic_vector( 1 downto 0) slv2
Definition: slvtypes.vhd:34
std_logic_vector slv
Definition: slvtypes.vhd:31
slv6 :=( others => '0') BTN_HW
slv2 := "10" c_mode_datl
regs_type := regs_init N_REGS
slv2 := "11" c_mode_dath
regs_type :=( c_mode_led,( others => '0'), '0', '0',( others => '0')) regs_init
regs_type := regs_init R_REGS
slv2 := "01" c_mode_dp
slv2 := "00" c_mode_led
slv8 :=( others => '0') LED_HW
DEBOUNCE boolean := true
in RESET slbit := '0'