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

Subversion Repositories w11

[/] [w11/] [tags/] [w11a_V0.7/] [rtl/] [sys_gen/] [tst_snhumanio/] [tst_snhumanio.vhd] - Blame information for rev 36

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

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

powered by: WebSVN 2.1.0

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