w11 - vhd 0.794
W11 CPU core and support modules
Loading...
Searching...
No Matches
tst_snhumanio.vhd
Go to the documentation of this file.
1-- $Id: tst_snhumanio.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: tst_snhumanio - syn
7-- Description: simple stand-alone tester for sn_humanio
8--
9-- Dependencies: -
10-- Test bench: -
11--
12-- Target Devices: generic
13-- Tool versions: xst 13.1-14.7; ghdl 0.29-0.31
14--
15-- Revision History:
16-- Date Rev Version Comment
17-- 2011-10-15 416 1.0.2 fix sensitivity list of proc_next
18-- 2011-10-08 412 1.0.1 use better rndm init (so that swi=0 is non-const)
19-- 2011-09-17 410 1.0 Initial version
20------------------------------------------------------------------------------
21
22library ieee;
23use ieee.std_logic_1164.all;
24use ieee.numeric_std.all;
25
26use work.slvtypes.all;
27use work.comlib.all;
28
29-- ----------------------------------------------------------------------------
30
31entity tst_snhumanio is -- tester for rlink
32 generic (
33 BWIDTH : positive := 4); -- BTN port width
34 port (
35 CLK : in slbit; -- clock
36 RESET : in slbit; -- reset
37 CE_MSEC : in slbit; -- msec pulse
38 SWI : in slv8; -- switch settings
39 BTN : in slv(BWIDTH-1 downto 0); -- button settings
40 LED : out slv8; -- led data
41 DSP_DAT : out slv16; -- display data
42 DSP_DP : out slv4 -- display decimal points
43 );
45
46architecture syn of tst_snhumanio is
47
48 constant c_mode_rndm : slv2 := "00";
49 constant c_mode_cnt : slv2 := "01";
50 constant c_mode_swi : slv2 := "10";
51 constant c_mode_btst : slv2 := "11";
52
53 type regs_type is record
54 mode : slv2; -- current mode
55 allon : slbit; -- all LEDs on if set
56 cnt : slv16; -- counter
57 tcnt : slv16; -- swi/btn toggle counter
58 rndm : slv8; -- random number
59 swi_1 : slv8; -- last SWI state
60 btn_1 : slv(BWIDTH-1 downto 0); -- last BTN state
61 led : slv8; -- LED output state
62 dsp : slv16; -- display data
63 dp : slv4; -- display decimal points
64 end record regs_type;
65
66 -- the rndm start value is /= 0 because a seed of 0 with a SWI setting of 0
67 -- will result in a 0-0-0 sequence. The 01010101 start will get trapped in a
68 -- constant sequence with a 01100011 switch setting, which is rather unlikely.
69 constant rndminit : slv8 := "01010101";
70
71 constant btnzero : slv(BWIDTH-1 downto 0) := (others=>'0');
72
73 constant regs_init : regs_type := (
74 c_mode_rndm, -- mode
75 '0', -- allon
76 (others=>'0'), -- cnt
77 (others=>'0'), -- tcnt
78 rndminit, -- rndm
79 (others=>'0'), -- swi_1
80 btnzero, -- btn_1
81 (others=>'0'), -- led
82 (others=>'0'), -- dsp
83 (others=>'0') -- dp
84
85 );
86
87 signal R_REGS : regs_type := regs_init; -- state registers
88 signal N_REGS : regs_type := regs_init; -- next value state regs
89
90 signal BTN4 : slbit := '0';
91
92begin
93
94 assert BWIDTH>=4
95 report "assert(BWIDTH>=4): at least 4 BTNs available"
96 severity failure;
97
98 B4YES: if BWIDTH > 4 generate
99 BTN4 <= BTN(4);
100 end generate B4YES;
101 B4NO: if BWIDTH = 4 generate
102 BTN4 <= '0';
103 end generate B4NO;
104
105 proc_regs: process (CLK)
106 begin
107
108 if rising_edge(CLK) then
109 if RESET = '1' then
110 R_REGS <= regs_init;
111 else
112 R_REGS <= N_REGS;
113 end if;
114 end if;
115
116 end process proc_regs;
117
118 proc_next: process (R_REGS, CE_MSEC, SWI, BTN, BTN4)
119
120 variable r : regs_type := regs_init;
121 variable n : regs_type := regs_init;
122 variable btn03 : slv4 := (others=>'0');
123
124 begin
125 r := R_REGS;
126 n := R_REGS;
127
128 n.swi_1 := SWI;
129 n.btn_1 := BTN;
130
131 if SWI/=r.swi_1 or BTN/=r.btn_1 then
132 n.tcnt := slv(unsigned(r.tcnt) + 1);
133 end if;
134
135 btn03 := BTN(3 downto 0);
136 n.allon := BTN4;
137
138 if unsigned(BTN) /= 0 then -- is a button being pressed ?
139 if r.mode /= c_mode_btst then -- not in btst mode
140 case btn03 is
141 when "0001" => -- 0001 single button -> rndm mode
142 n.mode := c_mode_rndm;
143 n.rndm := rndminit;
144
145 when "0010" => -- 0010 single button -> cnt mode
146 n.mode := c_mode_cnt;
147
148 when "0100" => -- 0100 single button -> swi mode
149 n.mode := c_mode_swi;
150
151 when "1000" => -- 1001 single button -> btst mode
152 n.mode := c_mode_btst;
153 n.tcnt := (others=>'0');
154
155 when others => -- any 2+ button combo -> led test
156 n.allon := '1';
157 end case;
158
159 else -- button press in btst mode
160
161 case btn03 is
162 when "1001" => -- 1001 double btn -> rndm mode
163 n.mode := c_mode_rndm;
164 when "1010" => -- 1010 double btn -> rndm cnt
165 n.mode := c_mode_cnt;
166 when "1100" => -- 1100 double btn -> rndm swi
167 n.mode := c_mode_swi;
168 when others => null;
169 end case;
170
171 end if;
172
173 else -- no button being pressed
174
175 if CE_MSEC = '1' then -- on every usec
176 n.cnt := slv(unsigned(r.cnt) + 1); -- inc counter
177 if unsigned(r.cnt(8 downto 0)) = 0 then -- every 1/2 sec (approx.)
178 n.rndm := crc8_update(r.rndm, SWI); -- update rndm state
179 end if;
180 end if;
181 end if;
182
183 if r.allon = '1' then -- if led test selected
184 n.led := (others=>'1'); -- all led,dsp,dp on
185 n.dsp := (others=>'1');
186 n.dp := (others=>'1');
187
188 else -- no led test, normal output
189
190 case r.mode is
191 when c_mode_rndm =>
192 n.led := r.rndm;
193 n.dsp(7 downto 0) := r.rndm;
194 n.dsp(15 downto 8) := not r.rndm;
195
196 when c_mode_cnt =>
197 n.led := r.cnt(14 downto 7);
198 n.dsp := r.cnt;
199
200 when c_mode_swi =>
201 n.led := SWI;
202 n.dsp(7 downto 0) := SWI;
203 n.dsp(15 downto 8) := not SWI;
204
205 when c_mode_btst =>
206 n.led := SWI;
207 n.dsp := r.tcnt;
208
209 when others => null;
210 end case;
211
212 n.dp := BTN(3 downto 0);
213
214 end if;
215
216 N_REGS <= n;
217
218 LED <= r.led;
219 DSP_DAT <= r.dsp;
220 DSP_DP <= r.dp;
221
222 end process proc_next;
223
224
225end syn;
std_logic_vector( 3 downto 0) slv4
Definition: slvtypes.vhd:36
std_logic_vector( 15 downto 0) slv16
Definition: slvtypes.vhd:48
std_logic slbit
Definition: slvtypes.vhd:30
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
slv2 := "00" c_mode_rndm
regs_type := regs_init N_REGS
slv8 := "01010101" rndminit
slv( BWIDTH- 1 downto 0) :=( others => '0') btnzero
slbit := '0' BTN4
regs_type := regs_init R_REGS
slv2 := "10" c_mode_swi
slv2 := "01" c_mode_cnt
slv2 := "11" c_mode_btst
regs_type :=( c_mode_rndm, '0',( others => '0'),( others => '0'), rndminit,( others => '0'), btnzero,( others => '0'),( others => '0'),( others => '0')) regs_init
in RESET slbit
out DSP_DP slv4
in CLK slbit
in BTN slv( BWIDTH- 1 downto 0)
BWIDTH positive := 4
out DSP_DAT slv16
out LED slv8
in CE_MSEC slbit